From bd203e6d3b4c77851c64ebe5eaf126243920c6cc Mon Sep 17 00:00:00 2001 From: dhruv-vora Date: Mon, 5 Apr 2021 17:03:42 -0700 Subject: [PATCH 1/5] Made changes to componenttest package --- component/componenttest/nop_exporter.go | 10 ++++++---- component/componenttest/nop_extension.go | 6 ++---- component/componenttest/nop_processor.go | 8 +++----- component/componenttest/nop_receiver.go | 8 +++----- component/exporter.go | 5 ++++- component/exporter_test.go | 9 +++++---- 6 files changed, 23 insertions(+), 23 deletions(-) diff --git a/component/componenttest/nop_exporter.go b/component/componenttest/nop_exporter.go index 7c9b964d0c1..25ba0d798a1 100644 --- a/component/componenttest/nop_exporter.go +++ b/component/componenttest/nop_exporter.go @@ -20,17 +20,16 @@ import ( "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/component/componenthelper" "go.opentelemetry.io/collector/config" + "go.opentelemetry.io/collector/consumer" "go.opentelemetry.io/collector/consumer/consumertest" ) // nopExporterFactory is factory for nopExporter. type nopExporterFactory struct{} -var nopExporterFactoryInstance = &nopExporterFactory{} - // NewNopExporterFactory returns a component.ExporterFactory that constructs nop exporters. func NewNopExporterFactory() component.ExporterFactory { - return nopExporterFactoryInstance + return &nopExporterFactory{} } // Type gets the type of the Exporter config created by this factory. @@ -50,6 +49,7 @@ func (f *nopExporterFactory) CreateTracesExporter( _ context.Context, _ component.ExporterCreateParams, _ config.Exporter, + _ consumer.Traces, ) (component.TracesExporter, error) { return nopExporterInstance, nil } @@ -59,15 +59,17 @@ func (f *nopExporterFactory) CreateMetricsExporter( _ context.Context, _ component.ExporterCreateParams, _ config.Exporter, + _ consumer.Metrics, ) (component.MetricsExporter, error) { return nopExporterInstance, nil } -// CreateMetricsExporter implements component.ExporterFactory interface. +// CreateLogsExporter implements component.ExporterFactory interface. func (f *nopExporterFactory) CreateLogsExporter( _ context.Context, _ component.ExporterCreateParams, _ config.Exporter, + _ consumer.Logs, ) (component.LogsExporter, error) { return nopExporterInstance, nil } diff --git a/component/componenttest/nop_extension.go b/component/componenttest/nop_extension.go index b3346ded98b..0cba164d5a9 100644 --- a/component/componenttest/nop_extension.go +++ b/component/componenttest/nop_extension.go @@ -25,11 +25,9 @@ import ( // nopExtensionFactory is factory for nopExtension. type nopExtensionFactory struct{} -var nopExtensionFactoryInstance = &nopExtensionFactory{} - -// NewNopExtensionFactory returns a component.ExtensionFactory that constructs nop exporters. +// NewNopExtensionFactory returns a component.ExtensionFactory that constructs nop extensions. func NewNopExtensionFactory() component.ExtensionFactory { - return nopExtensionFactoryInstance + return &nopExtensionFactory{} } // Type gets the type of the Extension config created by this factory. diff --git a/component/componenttest/nop_processor.go b/component/componenttest/nop_processor.go index bf6f564d8c7..251d6134f88 100644 --- a/component/componenttest/nop_processor.go +++ b/component/componenttest/nop_processor.go @@ -29,11 +29,9 @@ type nopProcessorFactory struct { component.BaseProcessorFactory } -var nopProcessorFactoryInstance = &nopProcessorFactory{} - -// NewNopProcessorFactory returns a component.ProcessorFactory that constructs nop exporters. +// NewNopProcessorFactory returns a component.ProcessorFactory that constructs nop processors. func NewNopProcessorFactory() component.ProcessorFactory { - return nopProcessorFactoryInstance + return &nopProcessorFactory{} } // Type gets the type of the Processor config created by this factory. @@ -68,7 +66,7 @@ func (f *nopProcessorFactory) CreateMetricsProcessor( return nopProcessorInstance, nil } -// CreateMetricsProcessor implements component.ProcessorFactory interface. +// CreateLogsProcessor implements component.ProcessorFactory interface. func (f *nopProcessorFactory) CreateLogsProcessor( _ context.Context, _ component.ProcessorCreateParams, diff --git a/component/componenttest/nop_receiver.go b/component/componenttest/nop_receiver.go index 839e97de797..f0f099b7db0 100644 --- a/component/componenttest/nop_receiver.go +++ b/component/componenttest/nop_receiver.go @@ -26,11 +26,9 @@ import ( // nopReceiverFactory is factory for nopReceiver. type nopReceiverFactory struct{} -var nopReceiverFactoryInstance = &nopReceiverFactory{} - -// NewNopReceiverFactory returns a component.ReceiverFactory that constructs nop exporters. +// NewNopReceiverFactory returns a component.ReceiverFactory that constructs nop receivers. func NewNopReceiverFactory() component.ReceiverFactory { - return nopReceiverFactoryInstance + return &nopReceiverFactory{} } // Type gets the type of the Receiver config created by this factory. @@ -65,7 +63,7 @@ func (f *nopReceiverFactory) CreateMetricsReceiver( return nopReceiverInstance, nil } -// CreateMetricsReceiver implements component.ReceiverFactory interface. +// CreateLogsReceiver implements component.ReceiverFactory interface. func (f *nopReceiverFactory) CreateLogsReceiver( _ context.Context, _ component.ReceiverCreateParams, diff --git a/component/exporter.go b/component/exporter.go index b971e617afe..3c17150d20f 100644 --- a/component/exporter.go +++ b/component/exporter.go @@ -56,7 +56,7 @@ type ExporterCreateParams struct { ApplicationStartInfo ApplicationStartInfo } -// ExporterFactory can create TracesExporter and MetricsExporter. This is the +// ExporterFactory can create TracesExporter, MetricsExporter and LogsExporter. This is the // new factory type that can create new style exporters. type ExporterFactory interface { Factory @@ -77,6 +77,7 @@ type ExporterFactory interface { ctx context.Context, params ExporterCreateParams, cfg config.Exporter, + nextConsumer consumer.Traces, ) (TracesExporter, error) // CreateMetricsExporter creates a metrics exporter based on this config. @@ -86,6 +87,7 @@ type ExporterFactory interface { ctx context.Context, params ExporterCreateParams, cfg config.Exporter, + nextConsumer consumer.Metrics, ) (MetricsExporter, error) // CreateLogsExporter creates an exporter based on the config. @@ -95,5 +97,6 @@ type ExporterFactory interface { ctx context.Context, params ExporterCreateParams, cfg config.Exporter, + nextConsumer consumer.Logs, ) (LogsExporter, error) } diff --git a/component/exporter_test.go b/component/exporter_test.go index 36aa1aecfad..c5bb9329141 100644 --- a/component/exporter_test.go +++ b/component/exporter_test.go @@ -22,6 +22,7 @@ import ( "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/config/configerror" + "go.opentelemetry.io/collector/consumer" ) type TestExporterFactory struct { @@ -39,17 +40,17 @@ func (f *TestExporterFactory) CreateDefaultConfig() config.Exporter { } // CreateTraceExporter creates a trace exporter based on this config. -func (f *TestExporterFactory) CreateTracesExporter(context.Context, ExporterCreateParams, config.Exporter) (TracesExporter, error) { +func (f *TestExporterFactory) CreateTracesExporter(context.Context, ExporterCreateParams, config.Exporter, consumer.Traces) (TracesExporter, error) { return nil, configerror.ErrDataTypeIsNotSupported } // CreateMetricsExporter creates a metrics exporter based on this config. -func (f *TestExporterFactory) CreateMetricsExporter(context.Context, ExporterCreateParams, config.Exporter) (MetricsExporter, error) { +func (f *TestExporterFactory) CreateMetricsExporter(context.Context, ExporterCreateParams, config.Exporter, consumer.Metrics) (MetricsExporter, error) { return nil, configerror.ErrDataTypeIsNotSupported } -// CreateMetricsExporter creates a logs exporter based on this config. -func (f *TestExporterFactory) CreateLogsExporter(context.Context, ExporterCreateParams, config.Exporter) (LogsExporter, error) { +// CreateLogsExporter creates a logs exporter based on this config. +func (f *TestExporterFactory) CreateLogsExporter(context.Context, ExporterCreateParams, config.Exporter, consumer.Logs) (LogsExporter, error) { return nil, configerror.ErrDataTypeIsNotSupported } From dfb042f8b45c328790783178763a1f9a83ee6495 Mon Sep 17 00:00:00 2001 From: dhruv-vora Date: Mon, 5 Apr 2021 17:18:35 -0700 Subject: [PATCH 2/5] Changes to nop_exporter_test --- component/componenttest/nop_exporter_test.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/component/componenttest/nop_exporter_test.go b/component/componenttest/nop_exporter_test.go index 2fd24c363a3..cce9fc78b63 100644 --- a/component/componenttest/nop_exporter_test.go +++ b/component/componenttest/nop_exporter_test.go @@ -24,6 +24,7 @@ import ( "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/consumer/pdata" + "go.opentelemetry.io/collector/consumer/consumertest" ) func TestNewNopExporterFactory(t *testing.T) { @@ -33,19 +34,19 @@ func TestNewNopExporterFactory(t *testing.T) { cfg := factory.CreateDefaultConfig() assert.Equal(t, &config.ExporterSettings{TypeVal: factory.Type()}, cfg) - traces, err := factory.CreateTracesExporter(context.Background(), component.ExporterCreateParams{}, cfg) + traces, err := factory.CreateTracesExporter(context.Background(), component.ExporterCreateParams{}, cfg, consumertest.NewNop()) require.NoError(t, err) 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.CreateMetricsExporter(context.Background(), component.ExporterCreateParams{}, cfg) + metrics, err := factory.CreateMetricsExporter(context.Background(), component.ExporterCreateParams{}, cfg, consumertest.NewNop()) require.NoError(t, err) 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.CreateLogsExporter(context.Background(), component.ExporterCreateParams{}, cfg) + logs, err := factory.CreateLogsExporter(context.Background(), component.ExporterCreateParams{}, cfg, consumertest.NewNop()) require.NoError(t, err) assert.NoError(t, logs.Start(context.Background(), NewNopHost())) assert.NoError(t, logs.ConsumeLogs(context.Background(), pdata.NewLogs())) From 8789bdd65e1faac31fccebac834728364ddff9d6 Mon Sep 17 00:00:00 2001 From: dhruv-vora Date: Wed, 14 Apr 2021 20:06:35 -0700 Subject: [PATCH 3/5] Reverted the changes in exporter and nop_exporter --- component/componenttest/nop_exporter.go | 4 ---- component/componenttest/nop_exporter_test.go | 7 +++---- component/exporter.go | 3 --- component/exporter_test.go | 7 +++---- 4 files changed, 6 insertions(+), 15 deletions(-) diff --git a/component/componenttest/nop_exporter.go b/component/componenttest/nop_exporter.go index 25ba0d798a1..4db04a84d63 100644 --- a/component/componenttest/nop_exporter.go +++ b/component/componenttest/nop_exporter.go @@ -20,7 +20,6 @@ import ( "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/component/componenthelper" "go.opentelemetry.io/collector/config" - "go.opentelemetry.io/collector/consumer" "go.opentelemetry.io/collector/consumer/consumertest" ) @@ -49,7 +48,6 @@ func (f *nopExporterFactory) CreateTracesExporter( _ context.Context, _ component.ExporterCreateParams, _ config.Exporter, - _ consumer.Traces, ) (component.TracesExporter, error) { return nopExporterInstance, nil } @@ -59,7 +57,6 @@ func (f *nopExporterFactory) CreateMetricsExporter( _ context.Context, _ component.ExporterCreateParams, _ config.Exporter, - _ consumer.Metrics, ) (component.MetricsExporter, error) { return nopExporterInstance, nil } @@ -69,7 +66,6 @@ func (f *nopExporterFactory) CreateLogsExporter( _ context.Context, _ component.ExporterCreateParams, _ config.Exporter, - _ consumer.Logs, ) (component.LogsExporter, error) { return nopExporterInstance, nil } diff --git a/component/componenttest/nop_exporter_test.go b/component/componenttest/nop_exporter_test.go index cce9fc78b63..2fd24c363a3 100644 --- a/component/componenttest/nop_exporter_test.go +++ b/component/componenttest/nop_exporter_test.go @@ -24,7 +24,6 @@ import ( "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/consumer/pdata" - "go.opentelemetry.io/collector/consumer/consumertest" ) func TestNewNopExporterFactory(t *testing.T) { @@ -34,19 +33,19 @@ func TestNewNopExporterFactory(t *testing.T) { cfg := factory.CreateDefaultConfig() assert.Equal(t, &config.ExporterSettings{TypeVal: factory.Type()}, cfg) - traces, err := factory.CreateTracesExporter(context.Background(), component.ExporterCreateParams{}, cfg, consumertest.NewNop()) + traces, err := factory.CreateTracesExporter(context.Background(), component.ExporterCreateParams{}, cfg) require.NoError(t, err) 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.CreateMetricsExporter(context.Background(), component.ExporterCreateParams{}, cfg, consumertest.NewNop()) + metrics, err := factory.CreateMetricsExporter(context.Background(), component.ExporterCreateParams{}, cfg) require.NoError(t, err) 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.CreateLogsExporter(context.Background(), component.ExporterCreateParams{}, cfg, consumertest.NewNop()) + logs, err := factory.CreateLogsExporter(context.Background(), component.ExporterCreateParams{}, cfg) require.NoError(t, err) assert.NoError(t, logs.Start(context.Background(), NewNopHost())) assert.NoError(t, logs.ConsumeLogs(context.Background(), pdata.NewLogs())) diff --git a/component/exporter.go b/component/exporter.go index 3c17150d20f..e9ae032cae8 100644 --- a/component/exporter.go +++ b/component/exporter.go @@ -77,7 +77,6 @@ type ExporterFactory interface { ctx context.Context, params ExporterCreateParams, cfg config.Exporter, - nextConsumer consumer.Traces, ) (TracesExporter, error) // CreateMetricsExporter creates a metrics exporter based on this config. @@ -87,7 +86,6 @@ type ExporterFactory interface { ctx context.Context, params ExporterCreateParams, cfg config.Exporter, - nextConsumer consumer.Metrics, ) (MetricsExporter, error) // CreateLogsExporter creates an exporter based on the config. @@ -97,6 +95,5 @@ type ExporterFactory interface { ctx context.Context, params ExporterCreateParams, cfg config.Exporter, - nextConsumer consumer.Logs, ) (LogsExporter, error) } diff --git a/component/exporter_test.go b/component/exporter_test.go index c5bb9329141..6ebe20bac8c 100644 --- a/component/exporter_test.go +++ b/component/exporter_test.go @@ -22,7 +22,6 @@ import ( "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/config/configerror" - "go.opentelemetry.io/collector/consumer" ) type TestExporterFactory struct { @@ -40,17 +39,17 @@ func (f *TestExporterFactory) CreateDefaultConfig() config.Exporter { } // CreateTraceExporter creates a trace exporter based on this config. -func (f *TestExporterFactory) CreateTracesExporter(context.Context, ExporterCreateParams, config.Exporter, consumer.Traces) (TracesExporter, error) { +func (f *TestExporterFactory) CreateTracesExporter(context.Context, ExporterCreateParams, config.Exporter) (TracesExporter, error) { return nil, configerror.ErrDataTypeIsNotSupported } // CreateMetricsExporter creates a metrics exporter based on this config. -func (f *TestExporterFactory) CreateMetricsExporter(context.Context, ExporterCreateParams, config.Exporter, consumer.Metrics) (MetricsExporter, error) { +func (f *TestExporterFactory) CreateMetricsExporter(context.Context, ExporterCreateParams, config.Exporter) (MetricsExporter, error) { return nil, configerror.ErrDataTypeIsNotSupported } // CreateLogsExporter creates a logs exporter based on this config. -func (f *TestExporterFactory) CreateLogsExporter(context.Context, ExporterCreateParams, config.Exporter, consumer.Logs) (LogsExporter, error) { +func (f *TestExporterFactory) CreateLogsExporter(context.Context, ExporterCreateParams, config.Exporter) (LogsExporter, error) { return nil, configerror.ErrDataTypeIsNotSupported } From 1d6e7b49088e4d61fc77ecf60cbd26779dca1d45 Mon Sep 17 00:00:00 2001 From: dhruv-vora Date: Mon, 26 Apr 2021 11:46:03 -0700 Subject: [PATCH 4/5] Updated comments for the Factory --- component/exporter.go | 2 +- component/receiver.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/component/exporter.go b/component/exporter.go index e9ae032cae8..5d1e1b81914 100644 --- a/component/exporter.go +++ b/component/exporter.go @@ -56,7 +56,7 @@ type ExporterCreateParams struct { ApplicationStartInfo ApplicationStartInfo } -// ExporterFactory can create TracesExporter, MetricsExporter and LogsExporter. This is the +// ExporterFactory can create TracesExporter, MetricsExporter, and LogsExporter. This is the // new factory type that can create new style exporters. type ExporterFactory interface { Factory diff --git a/component/receiver.go b/component/receiver.go index 98aaded1c3d..800126fc3c8 100644 --- a/component/receiver.go +++ b/component/receiver.go @@ -63,7 +63,7 @@ type ReceiverCreateParams struct { ApplicationStartInfo ApplicationStartInfo } -// ReceiverFactory can create TracesReceiver and MetricsReceiver. This is the +// ReceiverFactory can create TracesReceiver, MetricsReceiver, and LogsReceiver. This is the // new factory type that can create new style receivers. type ReceiverFactory interface { Factory From c3cdb72aa17fe8145797cc9b19f4195a255b674b Mon Sep 17 00:00:00 2001 From: dhruv-vora Date: Wed, 12 May 2021 10:53:53 -0700 Subject: [PATCH 5/5] reverted usage of singletons --- component/componenttest/nop_exporter.go | 4 +++- component/componenttest/nop_extension.go | 4 +++- component/componenttest/nop_processor.go | 4 +++- component/componenttest/nop_receiver.go | 4 +++- 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/component/componenttest/nop_exporter.go b/component/componenttest/nop_exporter.go index 4db04a84d63..4c6030888bf 100644 --- a/component/componenttest/nop_exporter.go +++ b/component/componenttest/nop_exporter.go @@ -26,9 +26,11 @@ import ( // nopExporterFactory is factory for nopExporter. type nopExporterFactory struct{} +var nopExporterFactoryInstance = &nopExporterFactory{} + // NewNopExporterFactory returns a component.ExporterFactory that constructs nop exporters. func NewNopExporterFactory() component.ExporterFactory { - return &nopExporterFactory{} + return nopExporterFactoryInstance } // Type gets the type of the Exporter config created by this factory. diff --git a/component/componenttest/nop_extension.go b/component/componenttest/nop_extension.go index 0cba164d5a9..9bbadc5bb01 100644 --- a/component/componenttest/nop_extension.go +++ b/component/componenttest/nop_extension.go @@ -25,9 +25,11 @@ import ( // nopExtensionFactory is factory for nopExtension. type nopExtensionFactory struct{} +var nopExtensionFactoryInstance = &nopExtensionFactory{} + // NewNopExtensionFactory returns a component.ExtensionFactory that constructs nop extensions. func NewNopExtensionFactory() component.ExtensionFactory { - return &nopExtensionFactory{} + return nopExtensionFactoryInstance } // Type gets the type of the Extension config created by this factory. diff --git a/component/componenttest/nop_processor.go b/component/componenttest/nop_processor.go index 251d6134f88..63ed36d6b5f 100644 --- a/component/componenttest/nop_processor.go +++ b/component/componenttest/nop_processor.go @@ -29,9 +29,11 @@ type nopProcessorFactory struct { component.BaseProcessorFactory } +var nopProcessorFactoryInstance = &nopProcessorFactory{} + // NewNopProcessorFactory returns a component.ProcessorFactory that constructs nop processors. func NewNopProcessorFactory() component.ProcessorFactory { - return &nopProcessorFactory{} + return nopProcessorFactoryInstance } // Type gets the type of the Processor config created by this factory. diff --git a/component/componenttest/nop_receiver.go b/component/componenttest/nop_receiver.go index f0f099b7db0..9c8aaef60a3 100644 --- a/component/componenttest/nop_receiver.go +++ b/component/componenttest/nop_receiver.go @@ -26,9 +26,11 @@ import ( // nopReceiverFactory is factory for nopReceiver. type nopReceiverFactory struct{} +var nopReceiverFactoryInstance = &nopReceiverFactory{} + // NewNopReceiverFactory returns a component.ReceiverFactory that constructs nop receivers. func NewNopReceiverFactory() component.ReceiverFactory { - return &nopReceiverFactory{} + return nopReceiverFactoryInstance } // Type gets the type of the Receiver config created by this factory.