Skip to content

Commit

Permalink
[chore][processor/servicegraph][connector/servicegraph] Assign an exp…
Browse files Browse the repository at this point in the history
…orted function to a variable and pass checkapi (#29023)

**Description:**
Assign an exported function to a variable and pass checkapi.

**Link to tracking Issue:**

#26304

**Testing:**
go run cmd/checkapi/main.go .
go test for servicegraphconnector
go test for servicegraphprocessor

**Documentation:**

Signed-off-by: sakulali <sakulali@126.com>
  • Loading branch information
sakulali authored Dec 5, 2023
1 parent 1af5d17 commit d826261
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 23 deletions.
4 changes: 1 addition & 3 deletions cmd/checkapi/allowlist.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
connector/servicegraphconnector
extension/observer
processor/servicegraphprocessor
extension/observer
7 changes: 6 additions & 1 deletion connector/servicegraphconnector/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,13 @@
package servicegraphconnector // import "github.com/open-telemetry/opentelemetry-collector-contrib/connector/servicegraphconnector"

import (
"go.opentelemetry.io/collector/connector"

"github.com/open-telemetry/opentelemetry-collector-contrib/connector/servicegraphconnector/internal/metadata"
"github.com/open-telemetry/opentelemetry-collector-contrib/processor/servicegraphprocessor"
)

var NewFactory = servicegraphprocessor.NewConnectorFactoryFunc(metadata.Type, metadata.TracesToMetricsStability)
// NewFactory returns a ConnectorFactory.
func NewFactory() connector.Factory {
return servicegraphprocessor.NewConnectorFactoryFunc(metadata.Type, metadata.TracesToMetricsStability)
}
7 changes: 1 addition & 6 deletions processor/servicegraphprocessor/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/connector"
"go.opentelemetry.io/collector/otelcol/otelcoltest"

"github.com/open-telemetry/opentelemetry-collector-contrib/processor/servicegraphprocessor/internal/metadata"
Expand All @@ -23,7 +22,7 @@ func TestLoadConfig(t *testing.T) {
require.NoError(t, err)

factories.Processors[metadata.Type] = NewFactory()
factories.Connectors[metadata.Type] = newConnectorFactory()
factories.Connectors[metadata.Type] = NewConnectorFactoryFunc("servicegraph", component.StabilityLevelAlpha)

// Test
cfg, err := otelcoltest.LoadConfigAndValidate(filepath.Join("testdata", "service-graph-config.yaml"), factories)
Expand Down Expand Up @@ -67,7 +66,3 @@ func TestLoadConfig(t *testing.T) {
)

}

func newConnectorFactory() connector.Factory {
return NewConnectorFactoryFunc("servicegraph", component.StabilityLevelAlpha)()
}
18 changes: 8 additions & 10 deletions processor/servicegraphprocessor/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,14 @@ func NewFactory() processor.Factory {
}

// NewConnectorFactoryFunc creates a function that returns a factory for the servicegraph connector.
func NewConnectorFactoryFunc(cfgType component.Type, tracesToMetricsStability component.StabilityLevel) func() connector.Factory {
return func() connector.Factory {
// TODO: Handle this err
_ = view.Register(serviceGraphProcessorViews()...)
return connector.NewFactory(
cfgType,
createDefaultConfig,
connector.WithTracesToMetrics(createTracesToMetricsConnector, tracesToMetricsStability),
)
}
var NewConnectorFactoryFunc = func(cfgType component.Type, tracesToMetricsStability component.StabilityLevel) connector.Factory {
// TODO: Handle this err
_ = view.Register(serviceGraphProcessorViews()...)
return connector.NewFactory(
cfgType,
createDefaultConfig,
connector.WithTracesToMetrics(createTracesToMetricsConnector, tracesToMetricsStability),
)
}

func createDefaultConfig() component.Config {
Expand Down
3 changes: 2 additions & 1 deletion processor/servicegraphprocessor/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"time"

"github.com/stretchr/testify/assert"
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/connector/connectortest"
"go.opentelemetry.io/collector/consumer/consumertest"
"go.opentelemetry.io/collector/processor/processortest"
Expand Down Expand Up @@ -79,7 +80,7 @@ func TestNewConnector(t *testing.T) {
} {
t.Run(tc.name, func(t *testing.T) {
// Prepare
factory := newConnectorFactory()
factory := NewConnectorFactoryFunc("servicegraph", component.StabilityLevelAlpha)

creationParams := connectortest.NewNopCreateSettings()
cfg := factory.CreateDefaultConfig().(*Config)
Expand Down
4 changes: 2 additions & 2 deletions processor/servicegraphprocessor/processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func TestProcessorStart(t *testing.T) {

func TestConnectorStart(t *testing.T) {
// Create servicegraph processor
factory := newConnectorFactory()
factory := NewConnectorFactoryFunc("servicegraph", component.StabilityLevelAlpha)
cfg := factory.CreateDefaultConfig().(*Config)

procCreationParams := connectortest.NewNopCreateSettings()
Expand Down Expand Up @@ -109,7 +109,7 @@ func TestProcessorShutdown(t *testing.T) {

func TestConnectorShutdown(t *testing.T) {
// Prepare
factory := newConnectorFactory()
factory := NewConnectorFactoryFunc("servicegraph", component.StabilityLevelAlpha)
cfg := factory.CreateDefaultConfig().(*Config)

// Test
Expand Down

0 comments on commit d826261

Please sign in to comment.