Skip to content

Commit

Permalink
Replace ProcessorCreateParams with ComponentSettings.
Browse files Browse the repository at this point in the history
Replace all dependencies in Processors.

Signed-off-by: Patryk Matyjasek <pmatyjasek@sumologic.com>
  • Loading branch information
pmatyjasek-sumo committed May 14, 2021
1 parent 98748f7 commit bbfc87e
Show file tree
Hide file tree
Showing 32 changed files with 172 additions and 184 deletions.
6 changes: 3 additions & 3 deletions component/componenttest/nop_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func (f *nopProcessorFactory) CreateDefaultConfig() config.Processor {
// CreateTracesProcessor implements component.ProcessorFactory interface.
func (f *nopProcessorFactory) CreateTracesProcessor(
_ context.Context,
_ component.ProcessorCreateParams,
_ component.ComponentSettings,
_ config.Processor,
_ consumer.Traces,
) (component.TracesProcessor, error) {
Expand All @@ -65,7 +65,7 @@ func (f *nopProcessorFactory) CreateTracesProcessor(
// CreateMetricsProcessor implements component.ProcessorFactory interface.
func (f *nopProcessorFactory) CreateMetricsProcessor(
_ context.Context,
_ component.ProcessorCreateParams,
_ component.ComponentSettings,
_ config.Processor,
_ consumer.Metrics,
) (component.MetricsProcessor, error) {
Expand All @@ -75,7 +75,7 @@ func (f *nopProcessorFactory) CreateMetricsProcessor(
// CreateLogsProcessor implements component.ProcessorFactory interface.
func (f *nopProcessorFactory) CreateLogsProcessor(
_ context.Context,
_ component.ProcessorCreateParams,
_ component.ComponentSettings,
_ config.Processor,
_ consumer.Logs,
) (component.LogsProcessor, error) {
Expand Down
6 changes: 3 additions & 3 deletions component/componenttest/nop_processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,21 @@ func TestNewNopProcessorFactory(t *testing.T) {
cfg := factory.CreateDefaultConfig()
assert.Equal(t, &nopProcessorConfig{ProcessorSettings: config.NewProcessorSettings(config.NewID("nop"))}, cfg)

traces, err := factory.CreateTracesProcessor(context.Background(), component.ProcessorCreateParams{}, cfg, consumertest.NewNop())
traces, err := factory.CreateTracesProcessor(context.Background(), component.ComponentSettings{}, cfg, consumertest.NewNop())
require.NoError(t, err)
assert.Equal(t, consumer.Capabilities{MutatesData: false}, traces.Capabilities())
assert.NoError(t, traces.Start(context.Background(), NewNopHost()))
assert.NoError(t, traces.ConsumeTraces(context.Background(), pdata.NewTraces()))
assert.NoError(t, traces.Shutdown(context.Background()))

metrics, err := factory.CreateMetricsProcessor(context.Background(), component.ProcessorCreateParams{}, cfg, consumertest.NewNop())
metrics, err := factory.CreateMetricsProcessor(context.Background(), component.ComponentSettings{}, cfg, consumertest.NewNop())
require.NoError(t, err)
assert.Equal(t, consumer.Capabilities{MutatesData: false}, metrics.Capabilities())
assert.NoError(t, metrics.Start(context.Background(), NewNopHost()))
assert.NoError(t, metrics.ConsumeMetrics(context.Background(), pdata.NewMetrics()))
assert.NoError(t, metrics.Shutdown(context.Background()))

logs, err := factory.CreateLogsProcessor(context.Background(), component.ProcessorCreateParams{}, cfg, consumertest.NewNop())
logs, err := factory.CreateLogsProcessor(context.Background(), component.ComponentSettings{}, cfg, consumertest.NewNop())
require.NoError(t, err)
assert.Equal(t, consumer.Capabilities{MutatesData: false}, logs.Capabilities())
assert.NoError(t, logs.Start(context.Background(), NewNopHost()))
Expand Down
2 changes: 1 addition & 1 deletion component/componenttest/shutdown_verifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func verifyTracesProcessorDoesntProduceAfterShutdown(t *testing.T, factory compo
nextSink := new(consumertest.TracesSink)
processor, err := factory.CreateTracesProcessor(
context.Background(),
component.ProcessorCreateParams{Logger: zap.NewNop()},
component.ComponentSettings{Logger: zap.NewNop()},
cfg,
nextSink,
)
Expand Down
24 changes: 6 additions & 18 deletions component/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ package component
import (
"context"

"go.uber.org/zap"

"go.opentelemetry.io/collector/component/componenterror"
"go.opentelemetry.io/collector/config"
"go.opentelemetry.io/collector/consumer"
Expand Down Expand Up @@ -48,16 +46,6 @@ type LogsProcessor interface {
consumer.Logs
}

// ProcessorCreateParams is passed to Create* functions in ProcessorFactory.
type ProcessorCreateParams struct {
// Logger that the factory can use during creation and can pass to the created
// component to be used later as well.
Logger *zap.Logger

// BuildInfo can be used by components for informational purposes
BuildInfo BuildInfo
}

// ProcessorFactory is factory interface for processors. This is the
// new factory type that can create new style processors.
//
Expand All @@ -80,7 +68,7 @@ type ProcessorFactory interface {
// error will be returned instead.
CreateTracesProcessor(
ctx context.Context,
params ProcessorCreateParams,
componentSettings ComponentSettings,
cfg config.Processor,
nextConsumer consumer.Traces,
) (TracesProcessor, error)
Expand All @@ -90,7 +78,7 @@ type ProcessorFactory interface {
// error will be returned instead.
CreateMetricsProcessor(
ctx context.Context,
params ProcessorCreateParams,
componentSettings ComponentSettings,
cfg config.Processor,
nextConsumer consumer.Metrics,
) (MetricsProcessor, error)
Expand All @@ -100,7 +88,7 @@ type ProcessorFactory interface {
// error will be returned instead.
CreateLogsProcessor(
ctx context.Context,
params ProcessorCreateParams,
componentSettings ComponentSettings,
cfg config.Processor,
nextConsumer consumer.Logs,
) (LogsProcessor, error)
Expand All @@ -125,17 +113,17 @@ func (b BaseProcessorFactory) CreateDefaultConfig() config.Processor {
}

// CreateTracesProcessor default implemented as not supported date type.
func (b BaseProcessorFactory) CreateTracesProcessor(context.Context, ProcessorCreateParams, config.Processor, consumer.Traces) (TracesProcessor, error) {
func (b BaseProcessorFactory) CreateTracesProcessor(context.Context, ComponentSettings, config.Processor, consumer.Traces) (TracesProcessor, error) {
return nil, componenterror.ErrDataTypeIsNotSupported
}

// CreateMetricsProcessor default implemented as not supported date type.
func (b BaseProcessorFactory) CreateMetricsProcessor(context.Context, ProcessorCreateParams, config.Processor, consumer.Metrics) (MetricsProcessor, error) {
func (b BaseProcessorFactory) CreateMetricsProcessor(context.Context, ComponentSettings, config.Processor, consumer.Metrics) (MetricsProcessor, error) {
return nil, componenterror.ErrDataTypeIsNotSupported
}

// CreateLogsProcessor default implemented as not supported date type.
func (b BaseProcessorFactory) CreateLogsProcessor(context.Context, ProcessorCreateParams, config.Processor, consumer.Logs) (LogsProcessor, error) {
func (b BaseProcessorFactory) CreateLogsProcessor(context.Context, ComponentSettings, config.Processor, consumer.Logs) (LogsProcessor, error) {
return nil, componenterror.ErrDataTypeIsNotSupported
}

Expand Down
6 changes: 3 additions & 3 deletions component/processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,10 @@ func TestBaseProcessorFactory(t *testing.T) {
})
assert.NotPanics(t, bpf.unexportedProcessor)
defaultCfg := config.NewProcessorSettings(config.NewID("nop"))
_, err := bpf.CreateTracesProcessor(context.Background(), ProcessorCreateParams{}, &defaultCfg, consumertest.NewNop())
_, err := bpf.CreateTracesProcessor(context.Background(), ComponentSettings{}, &defaultCfg, consumertest.NewNop())
assert.ErrorIs(t, err, componenterror.ErrDataTypeIsNotSupported)
_, err = bpf.CreateMetricsProcessor(context.Background(), ProcessorCreateParams{}, &defaultCfg, consumertest.NewNop())
_, err = bpf.CreateMetricsProcessor(context.Background(), ComponentSettings{}, &defaultCfg, consumertest.NewNop())
assert.ErrorIs(t, err, componenterror.ErrDataTypeIsNotSupported)
_, err = bpf.CreateLogsProcessor(context.Background(), ProcessorCreateParams{}, &defaultCfg, consumertest.NewNop())
_, err = bpf.CreateLogsProcessor(context.Background(), ComponentSettings{}, &defaultCfg, consumertest.NewNop())
assert.ErrorIs(t, err, componenterror.ErrDataTypeIsNotSupported)
}
6 changes: 3 additions & 3 deletions internal/testcomponents/example_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,15 @@ func createDefaultConfig() config.Processor {
}
}

func createTracesProcessor(_ context.Context, _ component.ProcessorCreateParams, _ config.Processor, nextConsumer consumer.Traces) (component.TracesProcessor, error) {
func createTracesProcessor(_ context.Context, _ component.ComponentSettings, _ config.Processor, nextConsumer consumer.Traces) (component.TracesProcessor, error) {
return &exampleProcessor{Traces: nextConsumer}, nil
}

func createMetricsProcessor(_ context.Context, _ component.ProcessorCreateParams, _ config.Processor, nextConsumer consumer.Metrics) (component.MetricsProcessor, error) {
func createMetricsProcessor(_ context.Context, _ component.ComponentSettings, _ config.Processor, nextConsumer consumer.Metrics) (component.MetricsProcessor, error) {
return &exampleProcessor{Metrics: nextConsumer}, nil
}

func createLogsProcessor(_ context.Context, _ component.ProcessorCreateParams, _ config.Processor, nextConsumer consumer.Logs) (component.LogsProcessor, error) {
func createLogsProcessor(_ context.Context, _ component.ComponentSettings, _ config.Processor, nextConsumer consumer.Logs) (component.LogsProcessor, error) {
return &exampleProcessor{Logs: nextConsumer}, nil
}

Expand Down
12 changes: 6 additions & 6 deletions processor/attributesprocessor/attributes_log_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func TestLogProcessor_NilEmptyData(t *testing.T) {
}

tp, err := factory.CreateLogsProcessor(
context.Background(), component.ProcessorCreateParams{Logger: zap.NewNop()}, oCfg, consumertest.NewNop())
context.Background(), component.ComponentSettings{Logger: zap.NewNop()}, oCfg, consumertest.NewNop())
require.Nil(t, err)
require.NotNil(t, tp)
for i := range testCases {
Expand Down Expand Up @@ -169,7 +169,7 @@ func TestAttributes_FilterLogs(t *testing.T) {
},
Config: *createConfig(filterset.Strict),
}
tp, err := factory.CreateLogsProcessor(context.Background(), component.ProcessorCreateParams{}, cfg, consumertest.NewNop())
tp, err := factory.CreateLogsProcessor(context.Background(), component.ComponentSettings{}, cfg, consumertest.NewNop())
require.Nil(t, err)
require.NotNil(t, tp)

Expand Down Expand Up @@ -232,7 +232,7 @@ func TestAttributes_FilterLogsByNameStrict(t *testing.T) {
LogNames: []string{"dont_apply"},
Config: *createConfig(filterset.Strict),
}
tp, err := factory.CreateLogsProcessor(context.Background(), component.ProcessorCreateParams{}, cfg, consumertest.NewNop())
tp, err := factory.CreateLogsProcessor(context.Background(), component.ComponentSettings{}, cfg, consumertest.NewNop())
require.Nil(t, err)
require.NotNil(t, tp)

Expand Down Expand Up @@ -295,7 +295,7 @@ func TestAttributes_FilterLogsByNameRegexp(t *testing.T) {
LogNames: []string{".*dont_apply$"},
Config: *createConfig(filterset.Regexp),
}
tp, err := factory.CreateLogsProcessor(context.Background(), component.ProcessorCreateParams{}, cfg, consumertest.NewNop())
tp, err := factory.CreateLogsProcessor(context.Background(), component.ComponentSettings{}, cfg, consumertest.NewNop())
require.Nil(t, err)
require.NotNil(t, tp)

Expand Down Expand Up @@ -354,7 +354,7 @@ func TestLogAttributes_Hash(t *testing.T) {
{Key: "user.authenticated", Action: processorhelper.HASH},
}

tp, err := factory.CreateLogsProcessor(context.Background(), component.ProcessorCreateParams{}, cfg, consumertest.NewNop())
tp, err := factory.CreateLogsProcessor(context.Background(), component.ComponentSettings{}, cfg, consumertest.NewNop())
require.Nil(t, err)
require.NotNil(t, tp)

Expand Down Expand Up @@ -398,7 +398,7 @@ func BenchmarkAttributes_FilterLogsByName(b *testing.B) {
oCfg.Include = &filterconfig.MatchProperties{
LogNames: []string{"^apply.*"},
}
tp, err := factory.CreateLogsProcessor(context.Background(), component.ProcessorCreateParams{}, cfg, consumertest.NewNop())
tp, err := factory.CreateLogsProcessor(context.Background(), component.ComponentSettings{}, cfg, consumertest.NewNop())
require.Nil(b, err)
require.NotNil(b, tp)

Expand Down
12 changes: 6 additions & 6 deletions processor/attributesprocessor/attributes_trace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func TestSpanProcessor_NilEmptyData(t *testing.T) {
{Key: "attribute1", Action: processorhelper.DELETE},
}

tp, err := factory.CreateTracesProcessor(context.Background(), component.ProcessorCreateParams{Logger: zap.NewNop()}, oCfg, consumertest.NewNop())
tp, err := factory.CreateTracesProcessor(context.Background(), component.ComponentSettings{Logger: zap.NewNop()}, oCfg, consumertest.NewNop())
require.Nil(t, err)
require.NotNil(t, tp)
for i := range testCases {
Expand Down Expand Up @@ -183,7 +183,7 @@ func TestAttributes_FilterSpans(t *testing.T) {
},
Config: *createConfig(filterset.Strict),
}
tp, err := factory.CreateTracesProcessor(context.Background(), component.ProcessorCreateParams{}, cfg, consumertest.NewNop())
tp, err := factory.CreateTracesProcessor(context.Background(), component.ComponentSettings{}, cfg, consumertest.NewNop())
require.Nil(t, err)
require.NotNil(t, tp)

Expand Down Expand Up @@ -251,7 +251,7 @@ func TestAttributes_FilterSpansByNameStrict(t *testing.T) {
SpanNames: []string{"dont_apply"},
Config: *createConfig(filterset.Strict),
}
tp, err := factory.CreateTracesProcessor(context.Background(), component.ProcessorCreateParams{}, cfg, consumertest.NewNop())
tp, err := factory.CreateTracesProcessor(context.Background(), component.ComponentSettings{}, cfg, consumertest.NewNop())
require.Nil(t, err)
require.NotNil(t, tp)

Expand Down Expand Up @@ -319,7 +319,7 @@ func TestAttributes_FilterSpansByNameRegexp(t *testing.T) {
SpanNames: []string{".*dont_apply$"},
Config: *createConfig(filterset.Regexp),
}
tp, err := factory.CreateTracesProcessor(context.Background(), component.ProcessorCreateParams{}, cfg, consumertest.NewNop())
tp, err := factory.CreateTracesProcessor(context.Background(), component.ComponentSettings{}, cfg, consumertest.NewNop())
require.Nil(t, err)
require.NotNil(t, tp)

Expand Down Expand Up @@ -378,7 +378,7 @@ func TestAttributes_Hash(t *testing.T) {
{Key: "user.authenticated", Action: processorhelper.HASH},
}

tp, err := factory.CreateTracesProcessor(context.Background(), component.ProcessorCreateParams{}, cfg, consumertest.NewNop())
tp, err := factory.CreateTracesProcessor(context.Background(), component.ComponentSettings{}, cfg, consumertest.NewNop())
require.Nil(t, err)
require.NotNil(t, tp)

Expand Down Expand Up @@ -422,7 +422,7 @@ func BenchmarkAttributes_FilterSpansByName(b *testing.B) {
oCfg.Include = &filterconfig.MatchProperties{
SpanNames: []string{"^apply.*"},
}
tp, err := factory.CreateTracesProcessor(context.Background(), component.ProcessorCreateParams{}, cfg, consumertest.NewNop())
tp, err := factory.CreateTracesProcessor(context.Background(), component.ComponentSettings{}, cfg, consumertest.NewNop())
require.Nil(b, err)
require.NotNil(b, tp)

Expand Down
4 changes: 2 additions & 2 deletions processor/attributesprocessor/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func createDefaultConfig() config.Processor {

func createTracesProcessor(
_ context.Context,
_ component.ProcessorCreateParams,
_ component.ComponentSettings,
cfg config.Processor,
nextConsumer consumer.Traces,
) (component.TracesProcessor, error) {
Expand Down Expand Up @@ -81,7 +81,7 @@ func createTracesProcessor(

func createLogProcessor(
_ context.Context,
_ component.ProcessorCreateParams,
_ component.ComponentSettings,
cfg config.Processor,
nextConsumer consumer.Logs,
) (component.LogsProcessor, error) {
Expand Down
22 changes: 11 additions & 11 deletions processor/attributesprocessor/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func TestFactory_CreateDefaultConfig(t *testing.T) {
func TestFactoryCreateTracesProcessor_EmptyActions(t *testing.T) {
factory := NewFactory()
cfg := factory.CreateDefaultConfig()
ap, err := factory.CreateTracesProcessor(context.Background(), component.ProcessorCreateParams{}, cfg, consumertest.NewNop())
ap, err := factory.CreateTracesProcessor(context.Background(), component.ComponentSettings{}, cfg, consumertest.NewNop())
assert.Error(t, err)
assert.Nil(t, ap)
}
Expand All @@ -59,7 +59,7 @@ func TestFactoryCreateTracesProcessor_InvalidActions(t *testing.T) {
oCfg.Actions = []processorhelper.ActionKeyValue{
{Key: "", Value: 123, Action: processorhelper.UPSERT},
}
ap, err := factory.CreateTracesProcessor(context.Background(), component.ProcessorCreateParams{}, cfg, consumertest.NewNop())
ap, err := factory.CreateTracesProcessor(context.Background(), component.ComponentSettings{}, cfg, consumertest.NewNop())
assert.Error(t, err)
assert.Nil(t, ap)
}
Expand All @@ -72,18 +72,18 @@ func TestFactoryCreateTracesProcessor(t *testing.T) {
{Key: "a key", Action: processorhelper.DELETE},
}

tp, err := factory.CreateTracesProcessor(context.Background(), component.ProcessorCreateParams{}, cfg, consumertest.NewNop())
tp, err := factory.CreateTracesProcessor(context.Background(), component.ComponentSettings{}, cfg, consumertest.NewNop())
assert.NotNil(t, tp)
assert.NoError(t, err)

tp, err = factory.CreateTracesProcessor(context.Background(), component.ProcessorCreateParams{}, cfg, nil)
tp, err = factory.CreateTracesProcessor(context.Background(), component.ComponentSettings{}, cfg, nil)
assert.Nil(t, tp)
assert.Error(t, err)

oCfg.Actions = []processorhelper.ActionKeyValue{
{Action: processorhelper.DELETE},
}
tp, err = factory.CreateTracesProcessor(context.Background(), component.ProcessorCreateParams{}, cfg, consumertest.NewNop())
tp, err = factory.CreateTracesProcessor(context.Background(), component.ComponentSettings{}, cfg, consumertest.NewNop())
assert.Nil(t, tp)
assert.Error(t, err)
}
Expand All @@ -92,15 +92,15 @@ func TestFactory_CreateMetricsProcessor(t *testing.T) {
factory := NewFactory()
cfg := factory.CreateDefaultConfig()

mp, err := factory.CreateMetricsProcessor(context.Background(), component.ProcessorCreateParams{}, cfg, nil)
mp, err := factory.CreateMetricsProcessor(context.Background(), component.ComponentSettings{}, cfg, nil)
require.Nil(t, mp)
assert.Equal(t, err, componenterror.ErrDataTypeIsNotSupported)
}

func TestFactoryCreateLogsProcessor_EmptyActions(t *testing.T) {
factory := NewFactory()
cfg := factory.CreateDefaultConfig()
ap, err := factory.CreateLogsProcessor(context.Background(), component.ProcessorCreateParams{}, cfg, consumertest.NewNop())
ap, err := factory.CreateLogsProcessor(context.Background(), component.ComponentSettings{}, cfg, consumertest.NewNop())
assert.Error(t, err)
assert.Nil(t, ap)
}
Expand All @@ -113,7 +113,7 @@ func TestFactoryCreateLogsProcessor_InvalidActions(t *testing.T) {
oCfg.Actions = []processorhelper.ActionKeyValue{
{Key: "", Value: 123, Action: processorhelper.UPSERT},
}
ap, err := factory.CreateLogsProcessor(context.Background(), component.ProcessorCreateParams{}, cfg, consumertest.NewNop())
ap, err := factory.CreateLogsProcessor(context.Background(), component.ComponentSettings{}, cfg, consumertest.NewNop())
assert.Error(t, err)
assert.Nil(t, ap)
}
Expand All @@ -127,20 +127,20 @@ func TestFactoryCreateLogsProcessor(t *testing.T) {
}

tp, err := factory.CreateLogsProcessor(
context.Background(), component.ProcessorCreateParams{}, cfg, consumertest.NewNop())
context.Background(), component.ComponentSettings{}, cfg, consumertest.NewNop())
assert.NotNil(t, tp)
assert.NoError(t, err)

tp, err = factory.CreateLogsProcessor(
context.Background(), component.ProcessorCreateParams{}, cfg, nil)
context.Background(), component.ComponentSettings{}, cfg, nil)
assert.Nil(t, tp)
assert.Error(t, err)

oCfg.Actions = []processorhelper.ActionKeyValue{
{Action: processorhelper.DELETE},
}
tp, err = factory.CreateLogsProcessor(
context.Background(), component.ProcessorCreateParams{}, cfg, consumertest.NewNop())
context.Background(), component.ComponentSettings{}, cfg, consumertest.NewNop())
assert.Nil(t, tp)
assert.Error(t, err)
}
Loading

0 comments on commit bbfc87e

Please sign in to comment.