From fbf1e2a09c32918e28f557226d91c337070230cc Mon Sep 17 00:00:00 2001 From: Bogdan Date: Tue, 1 Nov 2022 15:14:09 -0700 Subject: [PATCH] Revert changes to config.[Receiver|Processor|Exporter|Extension]Settings Signed-off-by: Bogdan --- .chloggen/deprecateallconfig.yaml | 6 +- .../builder/templates/components_test.go.tmpl | 10 +-- component/componenttest/nop_exporter.go | 5 +- component/componenttest/nop_exporter_test.go | 3 +- component/componenttest/nop_extension.go | 5 +- component/componenttest/nop_extension_test.go | 3 +- component/componenttest/nop_processor.go | 5 +- component/componenttest/nop_processor_test.go | 3 +- component/componenttest/nop_receiver.go | 5 +- component/componenttest/nop_receiver_test.go | 3 +- component/exporter.go | 17 +++++ component/exporter_config.go | 69 ------------------- component/exporter_test.go | 49 +++++++------ component/extension.go | 18 +++++ component/extension_config.go | 69 ------------------- component/extension_test.go | 25 ++++--- component/processor.go | 17 +++++ component/processor_config.go | 69 ------------------- component/processor_test.go | 48 +++++++------ component/receiver.go | 17 +++++ component/receiver_config.go | 69 ------------------- component/receiver_test.go | 48 +++++++------ config/exporter.go | 51 ++++++++++++++ config/extension.go | 51 ++++++++++++++ config/moved_config.go | 24 ------- config/processor.go | 51 ++++++++++++++ config/receiver.go | 51 ++++++++++++++ exporter/exporterhelper/common_test.go | 3 +- exporter/exporterhelper/logs_test.go | 3 +- exporter/exporterhelper/metrics_test.go | 3 +- exporter/exporterhelper/traces_test.go | 3 +- exporter/loggingexporter/config.go | 3 +- exporter/loggingexporter/config_test.go | 35 +++++----- exporter/loggingexporter/factory.go | 11 +-- exporter/otlpexporter/config.go | 9 +-- exporter/otlpexporter/config_test.go | 3 +- exporter/otlpexporter/factory.go | 9 +-- exporter/otlpexporter/factory_test.go | 19 ++--- exporter/otlphttpexporter/config.go | 9 +-- exporter/otlphttpexporter/config_test.go | 3 +- exporter/otlphttpexporter/factory.go | 7 +- exporter/otlphttpexporter/factory_test.go | 19 ++--- exporter/otlphttpexporter/otlp_test.go | 17 ++--- extension/ballastextension/config.go | 4 +- extension/ballastextension/config_test.go | 7 +- extension/ballastextension/factory.go | 3 +- extension/ballastextension/factory_test.go | 3 +- extension/zpagesextension/config.go | 3 +- extension/zpagesextension/config_test.go | 3 +- extension/zpagesextension/factory.go | 3 +- extension/zpagesextension/factory_test.go | 3 +- .../batchprocessor/batch_processor_test.go | 61 ++++++++-------- processor/batchprocessor/config.go | 3 +- processor/batchprocessor/config_test.go | 27 ++++---- processor/batchprocessor/factory.go | 7 +- processor/memorylimiterprocessor/config.go | 3 +- .../memorylimiterprocessor/config_test.go | 9 +-- processor/memorylimiterprocessor/factory.go | 3 +- .../memorylimiter_test.go | 7 +- processor/processorhelper/logs_test.go | 3 +- processor/processorhelper/metrics_test.go | 3 +- processor/processorhelper/traces_test.go | 3 +- receiver/otlpreceiver/config.go | 3 +- receiver/otlpreceiver/config_test.go | 5 +- receiver/otlpreceiver/factory.go | 3 +- receiver/otlpreceiver/factory_test.go | 25 +++---- receiver/otlpreceiver/otlp_test.go | 11 +-- receiver/scraperhelper/scrapercontroller.go | 11 +-- service/config_test.go | 33 ++++----- service/extensions/extensions_test.go | 9 +-- service/internal/pipelines/pipelines_test.go | 24 +++---- .../testcomponents/example_exporter.go | 5 +- .../testcomponents/example_processor.go | 5 +- .../testcomponents/example_receiver.go | 5 +- 74 files changed, 642 insertions(+), 602 deletions(-) delete mode 100644 component/exporter_config.go delete mode 100644 component/extension_config.go delete mode 100644 component/processor_config.go delete mode 100644 component/receiver_config.go create mode 100644 config/exporter.go create mode 100644 config/extension.go create mode 100644 config/processor.go create mode 100644 config/receiver.go diff --git a/.chloggen/deprecateallconfig.yaml b/.chloggen/deprecateallconfig.yaml index 4c96c631d2..d3fdc39e72 100755 --- a/.chloggen/deprecateallconfig.yaml +++ b/.chloggen/deprecateallconfig.yaml @@ -5,7 +5,7 @@ change_type: deprecation component: config # A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). -note: Deprecate all types and funcs in `config` package +note: Deprecate multiple types and funcs in `config` package # One or more tracking issues or pull requests related to the change issues: [6422] @@ -19,13 +19,9 @@ subtext: | - config.DataType => component.DataType - config.Receiver => component.ReceiverConfig - config.UnmarshalReceiver => component.UnmarshalReceiverConfig - - config.[New]ReceiverSettings => component.[New]ReceiverConfigSettings - config.Processor => component.ProcessorConfig - config.UnmarshalProcessor => component.UnmarshalProcessorConfig - - config.[New]ProcessorSettings => component.[New]ProcessorConfigSettings - config.Exporter => component.ExporterConfig - config.UnmarshalExporter => component.UnmarshalExporterConfig - - config.[New]ExporterSettings => component.[New]ExporterConfigSettings - config.Extension => component.ExtensionConfig - config.UnmarshalExtension => component.UnmarshalExtensionConfig - - config.[New]ExtensionSettings => component.[New]ExtensionConfigSettings diff --git a/cmd/builder/internal/builder/templates/components_test.go.tmpl b/cmd/builder/internal/builder/templates/components_test.go.tmpl index 8e1f194ed5..09f867d84f 100644 --- a/cmd/builder/internal/builder/templates/components_test.go.tmpl +++ b/cmd/builder/internal/builder/templates/components_test.go.tmpl @@ -7,7 +7,7 @@ import ( "github.com/stretchr/testify/assert" - "go.opentelemetry.io/collector/config/configtest" + "go.opentelemetry.io/collector/component/componenttest" ) func TestValidateConfigs(t *testing.T) { @@ -15,15 +15,15 @@ func TestValidateConfigs(t *testing.T) { assert.NoError(t, err) for _, factory := range factories.Receivers { - assert.NoError(t, configtest.CheckConfigStruct(factory.CreateDefaultConfig())) + assert.NoError(t, componenttest.CheckConfigStruct(factory.CreateDefaultConfig())) } for _, factory := range factories.Processors { - assert.NoError(t, configtest.CheckConfigStruct(factory.CreateDefaultConfig())) + assert.NoError(t, componenttest.CheckConfigStruct(factory.CreateDefaultConfig())) } for _, factory := range factories.Exporters { - assert.NoError(t, configtest.CheckConfigStruct(factory.CreateDefaultConfig())) + assert.NoError(t, componenttest.CheckConfigStruct(factory.CreateDefaultConfig())) } for _, factory := range factories.Extensions { - assert.NoError(t, configtest.CheckConfigStruct(factory.CreateDefaultConfig())) + assert.NoError(t, componenttest.CheckConfigStruct(factory.CreateDefaultConfig())) } } diff --git a/component/componenttest/nop_exporter.go b/component/componenttest/nop_exporter.go index ec63710775..2617d7c29d 100644 --- a/component/componenttest/nop_exporter.go +++ b/component/componenttest/nop_exporter.go @@ -18,6 +18,7 @@ import ( "context" "go.opentelemetry.io/collector/component" + "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/consumer/consumertest" ) @@ -30,7 +31,7 @@ func NewNopExporterCreateSettings() component.ExporterCreateSettings { } type nopExporterConfig struct { - component.ExporterConfigSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct + config.ExporterSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct } // NewNopExporterFactory returns a component.ExporterFactory that constructs nop exporters. @@ -39,7 +40,7 @@ func NewNopExporterFactory() component.ExporterFactory { "nop", func() component.ExporterConfig { return &nopExporterConfig{ - ExporterConfigSettings: component.NewExporterConfigSettings(component.NewID("nop")), + ExporterSettings: config.NewExporterSettings(component.NewID("nop")), } }, component.WithTracesExporter(createTracesExporter, component.StabilityLevelStable), diff --git a/component/componenttest/nop_exporter_test.go b/component/componenttest/nop_exporter_test.go index 827254e35e..19694f3dd4 100644 --- a/component/componenttest/nop_exporter_test.go +++ b/component/componenttest/nop_exporter_test.go @@ -22,6 +22,7 @@ import ( "github.com/stretchr/testify/require" "go.opentelemetry.io/collector/component" + "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/pdata/plog" "go.opentelemetry.io/collector/pdata/pmetric" "go.opentelemetry.io/collector/pdata/ptrace" @@ -32,7 +33,7 @@ func TestNewNopExporterFactory(t *testing.T) { require.NotNil(t, factory) assert.Equal(t, component.Type("nop"), factory.Type()) cfg := factory.CreateDefaultConfig() - assert.Equal(t, &nopExporterConfig{ExporterConfigSettings: component.NewExporterConfigSettings(component.NewID("nop"))}, cfg) + assert.Equal(t, &nopExporterConfig{ExporterSettings: config.NewExporterSettings(component.NewID("nop"))}, cfg) traces, err := factory.CreateTracesExporter(context.Background(), NewNopExporterCreateSettings(), cfg) require.NoError(t, err) diff --git a/component/componenttest/nop_extension.go b/component/componenttest/nop_extension.go index 94073d62b3..8960e53001 100644 --- a/component/componenttest/nop_extension.go +++ b/component/componenttest/nop_extension.go @@ -18,6 +18,7 @@ import ( "context" "go.opentelemetry.io/collector/component" + "go.opentelemetry.io/collector/config" ) // NewNopExtensionCreateSettings returns a new nop settings for Create*Extension functions. @@ -29,7 +30,7 @@ func NewNopExtensionCreateSettings() component.ExtensionCreateSettings { } type nopExtensionConfig struct { - component.ExtensionConfigSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct + config.ExtensionSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct } // NewNopExtensionFactory returns a component.ExtensionFactory that constructs nop extensions. @@ -38,7 +39,7 @@ func NewNopExtensionFactory() component.ExtensionFactory { "nop", func() component.ExtensionConfig { return &nopExtensionConfig{ - ExtensionConfigSettings: component.NewExtensionConfigSettings(component.NewID("nop")), + ExtensionSettings: config.NewExtensionSettings(component.NewID("nop")), } }, func(context.Context, component.ExtensionCreateSettings, component.ExtensionConfig) (component.Extension, error) { diff --git a/component/componenttest/nop_extension_test.go b/component/componenttest/nop_extension_test.go index d3a71d4b30..9587cc302a 100644 --- a/component/componenttest/nop_extension_test.go +++ b/component/componenttest/nop_extension_test.go @@ -22,6 +22,7 @@ import ( "github.com/stretchr/testify/require" "go.opentelemetry.io/collector/component" + "go.opentelemetry.io/collector/config" ) func TestNewNopExtensionFactory(t *testing.T) { @@ -29,7 +30,7 @@ func TestNewNopExtensionFactory(t *testing.T) { require.NotNil(t, factory) assert.Equal(t, component.Type("nop"), factory.Type()) cfg := factory.CreateDefaultConfig() - assert.Equal(t, &nopExtensionConfig{ExtensionConfigSettings: component.NewExtensionConfigSettings(component.NewID("nop"))}, cfg) + assert.Equal(t, &nopExtensionConfig{ExtensionSettings: config.NewExtensionSettings(component.NewID("nop"))}, cfg) traces, err := factory.CreateExtension(context.Background(), NewNopExtensionCreateSettings(), cfg) require.NoError(t, err) diff --git a/component/componenttest/nop_processor.go b/component/componenttest/nop_processor.go index c1f1ea6001..6fa0a4052b 100644 --- a/component/componenttest/nop_processor.go +++ b/component/componenttest/nop_processor.go @@ -18,6 +18,7 @@ import ( "context" "go.opentelemetry.io/collector/component" + "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/consumer" "go.opentelemetry.io/collector/consumer/consumertest" ) @@ -31,7 +32,7 @@ func NewNopProcessorCreateSettings() component.ProcessorCreateSettings { } type nopProcessorConfig struct { - component.ProcessorConfigSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct + config.ProcessorSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct } // NewNopProcessorFactory returns a component.ProcessorFactory that constructs nop processors. @@ -40,7 +41,7 @@ func NewNopProcessorFactory() component.ProcessorFactory { "nop", func() component.ProcessorConfig { return &nopProcessorConfig{ - ProcessorConfigSettings: component.NewProcessorConfigSettings(component.NewID("nop")), + ProcessorSettings: config.NewProcessorSettings(component.NewID("nop")), } }, component.WithTracesProcessor(createTracesProcessor, component.StabilityLevelStable), diff --git a/component/componenttest/nop_processor_test.go b/component/componenttest/nop_processor_test.go index 0855f6c9da..8601a89bbc 100644 --- a/component/componenttest/nop_processor_test.go +++ b/component/componenttest/nop_processor_test.go @@ -22,6 +22,7 @@ import ( "github.com/stretchr/testify/require" "go.opentelemetry.io/collector/component" + "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/consumer" "go.opentelemetry.io/collector/consumer/consumertest" "go.opentelemetry.io/collector/pdata/plog" @@ -34,7 +35,7 @@ func TestNewNopProcessorFactory(t *testing.T) { require.NotNil(t, factory) assert.Equal(t, component.Type("nop"), factory.Type()) cfg := factory.CreateDefaultConfig() - assert.Equal(t, &nopProcessorConfig{ProcessorConfigSettings: component.NewProcessorConfigSettings(component.NewID("nop"))}, cfg) + assert.Equal(t, &nopProcessorConfig{ProcessorSettings: config.NewProcessorSettings(component.NewID("nop"))}, cfg) traces, err := factory.CreateTracesProcessor(context.Background(), NewNopProcessorCreateSettings(), cfg, consumertest.NewNop()) require.NoError(t, err) diff --git a/component/componenttest/nop_receiver.go b/component/componenttest/nop_receiver.go index 328429515d..8adc4b4615 100644 --- a/component/componenttest/nop_receiver.go +++ b/component/componenttest/nop_receiver.go @@ -18,6 +18,7 @@ import ( "context" "go.opentelemetry.io/collector/component" + "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/consumer" ) @@ -30,7 +31,7 @@ func NewNopReceiverCreateSettings() component.ReceiverCreateSettings { } type nopReceiverConfig struct { - component.ReceiverConfigSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct + config.ReceiverSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct } // NewNopReceiverFactory returns a component.ReceiverFactory that constructs nop receivers. @@ -39,7 +40,7 @@ func NewNopReceiverFactory() component.ReceiverFactory { "nop", func() component.ReceiverConfig { return &nopReceiverConfig{ - ReceiverConfigSettings: component.NewReceiverConfigSettings(component.NewID("nop")), + ReceiverSettings: config.NewReceiverSettings(component.NewID("nop")), } }, component.WithTracesReceiver(createTracesReceiver, component.StabilityLevelStable), diff --git a/component/componenttest/nop_receiver_test.go b/component/componenttest/nop_receiver_test.go index b96cf34772..723f49f631 100644 --- a/component/componenttest/nop_receiver_test.go +++ b/component/componenttest/nop_receiver_test.go @@ -22,6 +22,7 @@ import ( "github.com/stretchr/testify/require" "go.opentelemetry.io/collector/component" + "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/consumer/consumertest" ) @@ -30,7 +31,7 @@ func TestNewNopReceiverFactory(t *testing.T) { require.NotNil(t, factory) assert.Equal(t, component.Type("nop"), factory.Type()) cfg := factory.CreateDefaultConfig() - assert.Equal(t, &nopReceiverConfig{ReceiverConfigSettings: component.NewReceiverConfigSettings(component.NewID("nop"))}, cfg) + assert.Equal(t, &nopReceiverConfig{ReceiverSettings: config.NewReceiverSettings(component.NewID("nop"))}, cfg) traces, err := factory.CreateTracesReceiver(context.Background(), NewNopReceiverCreateSettings(), cfg, consumertest.NewNop()) require.NoError(t, err) diff --git a/component/exporter.go b/component/exporter.go index f610c2b575..e824c022ff 100644 --- a/component/exporter.go +++ b/component/exporter.go @@ -17,9 +17,26 @@ package component // import "go.opentelemetry.io/collector/component" import ( "context" + "go.opentelemetry.io/collector/confmap" "go.opentelemetry.io/collector/consumer" ) +// ExporterConfig is the configuration of a component.Exporter. Specific extensions must implement +// this interface and must embed config.ExporterSettings struct or a struct that extends it. +type ExporterConfig interface { + identifiable + validatable + + privateConfigExporter() +} + +// UnmarshalExporterConfig helper function to unmarshal an ExporterConfig. +// It checks if the config implements confmap.Unmarshaler and uses that if available, +// otherwise uses Map.UnmarshalExact, erroring if a field is nonexistent. +func UnmarshalExporterConfig(conf *confmap.Conf, cfg ExporterConfig) error { + return unmarshal(conf, cfg) +} + // Exporter exports telemetry data from the collector to a destination. type Exporter interface { Component diff --git a/component/exporter_config.go b/component/exporter_config.go deleted file mode 100644 index ae10a51d0b..0000000000 --- a/component/exporter_config.go +++ /dev/null @@ -1,69 +0,0 @@ -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package component // import "go.opentelemetry.io/collector/component" - -import ( - "go.opentelemetry.io/collector/confmap" -) - -// ExporterConfig is the configuration of a component.Exporter. Specific extensions must implement -// this interface and must embed ExporterSettings struct or a struct that extends it. -type ExporterConfig interface { - identifiable - validatable - - privateConfigExporter() -} - -// UnmarshalExporterConfig helper function to unmarshal an ExporterConfig. -// It checks if the config implements confmap.Unmarshaler and uses that if available, -// otherwise uses Map.UnmarshalExact, erroring if a field is nonexistent. -func UnmarshalExporterConfig(conf *confmap.Conf, cfg ExporterConfig) error { - return unmarshal(conf, cfg) -} - -// ExporterConfigSettings defines common settings for a component.Exporter configuration. -// Specific exporters can embed this struct and extend it with more fields if needed. -// -// It is highly recommended to "override" the Validate() function. -// -// When embedded in the exporter config, it must be with `mapstructure:",squash"` tag. -type ExporterConfigSettings struct { - id ID `mapstructure:"-"` -} - -// NewExporterConfigSettings return a new ExporterSettings with the given ComponentID. -func NewExporterConfigSettings(id ID) ExporterConfigSettings { - return ExporterConfigSettings{id: ID{typeVal: id.Type(), nameVal: id.Name()}} -} - -var _ ExporterConfig = (*ExporterConfigSettings)(nil) - -// ID returns the receiver ComponentID. -func (es *ExporterConfigSettings) ID() ID { - return es.id -} - -// SetIDName sets the receiver name. -func (es *ExporterConfigSettings) SetIDName(idName string) { - es.id.nameVal = idName -} - -// Validate validates the configuration and returns an error if invalid. -func (es *ExporterConfigSettings) Validate() error { - return nil -} - -func (es *ExporterConfigSettings) privateConfigExporter() {} diff --git a/component/exporter_test.go b/component/exporter_test.go index 553710dd20..ef541cec19 100644 --- a/component/exporter_test.go +++ b/component/exporter_test.go @@ -12,64 +12,69 @@ // See the License for the specific language governing permissions and // limitations under the License. -package component +// TODO: Move tests back to component package after config.*Settings are removed. + +package component_test import ( "context" "testing" "github.com/stretchr/testify/assert" + + "go.opentelemetry.io/collector/component" + "go.opentelemetry.io/collector/config" ) func TestNewExporterFactory(t *testing.T) { const typeStr = "test" - defaultCfg := NewExporterConfigSettings(NewID(typeStr)) - factory := NewExporterFactory( + defaultCfg := config.NewExporterSettings(component.NewID(typeStr)) + factory := component.NewExporterFactory( typeStr, - func() ExporterConfig { return &defaultCfg }) + func() component.ExporterConfig { return &defaultCfg }) assert.EqualValues(t, typeStr, factory.Type()) assert.EqualValues(t, &defaultCfg, factory.CreateDefaultConfig()) - _, err := factory.CreateTracesExporter(context.Background(), ExporterCreateSettings{}, &defaultCfg) + _, err := factory.CreateTracesExporter(context.Background(), component.ExporterCreateSettings{}, &defaultCfg) assert.Error(t, err) - _, err = factory.CreateMetricsExporter(context.Background(), ExporterCreateSettings{}, &defaultCfg) + _, err = factory.CreateMetricsExporter(context.Background(), component.ExporterCreateSettings{}, &defaultCfg) assert.Error(t, err) - _, err = factory.CreateLogsExporter(context.Background(), ExporterCreateSettings{}, &defaultCfg) + _, err = factory.CreateLogsExporter(context.Background(), component.ExporterCreateSettings{}, &defaultCfg) assert.Error(t, err) } func TestNewExporterFactory_WithOptions(t *testing.T) { const typeStr = "test" - defaultCfg := NewExporterConfigSettings(NewID(typeStr)) - factory := NewExporterFactory( + defaultCfg := config.NewExporterSettings(component.NewID(typeStr)) + factory := component.NewExporterFactory( typeStr, - func() ExporterConfig { return &defaultCfg }, - WithTracesExporter(createTracesExporter, StabilityLevelInDevelopment), - WithMetricsExporter(createMetricsExporter, StabilityLevelAlpha), - WithLogsExporter(createLogsExporter, StabilityLevelDeprecated)) + func() component.ExporterConfig { return &defaultCfg }, + component.WithTracesExporter(createTracesExporter, component.StabilityLevelInDevelopment), + component.WithMetricsExporter(createMetricsExporter, component.StabilityLevelAlpha), + component.WithLogsExporter(createLogsExporter, component.StabilityLevelDeprecated)) assert.EqualValues(t, typeStr, factory.Type()) assert.EqualValues(t, &defaultCfg, factory.CreateDefaultConfig()) - assert.Equal(t, StabilityLevelInDevelopment, factory.TracesExporterStability()) - _, err := factory.CreateTracesExporter(context.Background(), ExporterCreateSettings{}, &defaultCfg) + assert.Equal(t, component.StabilityLevelInDevelopment, factory.TracesExporterStability()) + _, err := factory.CreateTracesExporter(context.Background(), component.ExporterCreateSettings{}, &defaultCfg) assert.NoError(t, err) - assert.Equal(t, StabilityLevelAlpha, factory.MetricsExporterStability()) - _, err = factory.CreateMetricsExporter(context.Background(), ExporterCreateSettings{}, &defaultCfg) + assert.Equal(t, component.StabilityLevelAlpha, factory.MetricsExporterStability()) + _, err = factory.CreateMetricsExporter(context.Background(), component.ExporterCreateSettings{}, &defaultCfg) assert.NoError(t, err) - assert.Equal(t, StabilityLevelDeprecated, factory.LogsExporterStability()) - _, err = factory.CreateLogsExporter(context.Background(), ExporterCreateSettings{}, &defaultCfg) + assert.Equal(t, component.StabilityLevelDeprecated, factory.LogsExporterStability()) + _, err = factory.CreateLogsExporter(context.Background(), component.ExporterCreateSettings{}, &defaultCfg) assert.NoError(t, err) } -func createTracesExporter(context.Context, ExporterCreateSettings, ExporterConfig) (TracesExporter, error) { +func createTracesExporter(context.Context, component.ExporterCreateSettings, component.ExporterConfig) (component.TracesExporter, error) { return nil, nil } -func createMetricsExporter(context.Context, ExporterCreateSettings, ExporterConfig) (MetricsExporter, error) { +func createMetricsExporter(context.Context, component.ExporterCreateSettings, component.ExporterConfig) (component.MetricsExporter, error) { return nil, nil } -func createLogsExporter(context.Context, ExporterCreateSettings, ExporterConfig) (LogsExporter, error) { +func createLogsExporter(context.Context, component.ExporterCreateSettings, component.ExporterConfig) (component.LogsExporter, error) { return nil, nil } diff --git a/component/extension.go b/component/extension.go index 4daff94036..c6f2cdf002 100644 --- a/component/extension.go +++ b/component/extension.go @@ -16,8 +16,26 @@ package component // import "go.opentelemetry.io/collector/component" import ( "context" + + "go.opentelemetry.io/collector/confmap" ) +// ExtensionConfig is the configuration of a component.Extension. Specific extensions must implement +// this interface and must embed config.ExtensionSettings struct or a struct that extends it. +type ExtensionConfig interface { + identifiable + validatable + + privateConfigExtension() +} + +// UnmarshalExtensionConfig helper function to unmarshal an ExtensionConfig. +// It checks if the config implements confmap.Unmarshaler and uses that if available, +// otherwise uses Map.UnmarshalExact, erroring if a field is nonexistent. +func UnmarshalExtensionConfig(conf *confmap.Conf, cfg ExtensionConfig) error { + return unmarshal(conf, cfg) +} + // Extension is the interface for objects hosted by the OpenTelemetry Collector that // don't participate directly on data pipelines but provide some functionality // to the service, examples: health check endpoint, z-pages, etc. diff --git a/component/extension_config.go b/component/extension_config.go deleted file mode 100644 index 3d521c1094..0000000000 --- a/component/extension_config.go +++ /dev/null @@ -1,69 +0,0 @@ -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package component // import "go.opentelemetry.io/collector/component" - -import ( - "go.opentelemetry.io/collector/confmap" -) - -// ExtensionConfig is the configuration of a component.Extension. Specific extensions must implement -// this interface and must embed ExtensionConfigSettings struct or a struct that extends it. -type ExtensionConfig interface { - identifiable - validatable - - privateConfigExtension() -} - -// UnmarshalExtensionConfig helper function to unmarshal an ExtensionConfig. -// It checks if the config implements confmap.Unmarshaler and uses that if available, -// otherwise uses Map.UnmarshalExact, erroring if a field is nonexistent. -func UnmarshalExtensionConfig(conf *confmap.Conf, cfg ExtensionConfig) error { - return unmarshal(conf, cfg) -} - -// ExtensionConfigSettings defines common settings for a component.Extension configuration. -// Specific processors can embed this struct and extend it with more fields if needed. -// -// It is highly recommended to "override" the Validate() function. -// -// When embedded in the extension config, it must be with `mapstructure:",squash"` tag. -type ExtensionConfigSettings struct { - id ID `mapstructure:"-"` -} - -// NewExtensionConfigSettings return a new ExtensionConfigSettings with the given ID. -func NewExtensionConfigSettings(id ID) ExtensionConfigSettings { - return ExtensionConfigSettings{id: ID{typeVal: id.Type(), nameVal: id.Name()}} -} - -var _ ExtensionConfig = (*ExtensionConfigSettings)(nil) - -// ID returns the receiver ID. -func (es *ExtensionConfigSettings) ID() ID { - return es.id -} - -// SetIDName sets the receiver name. -func (es *ExtensionConfigSettings) SetIDName(idName string) { - es.id.nameVal = idName -} - -// Validate validates the configuration and returns an error if invalid. -func (es *ExtensionConfigSettings) Validate() error { - return nil -} - -func (es *ExtensionConfigSettings) privateConfigExtension() {} diff --git a/component/extension_test.go b/component/extension_test.go index e89d1733de..24c34386c4 100644 --- a/component/extension_test.go +++ b/component/extension_test.go @@ -12,37 +12,42 @@ // See the License for the specific language governing permissions and // limitations under the License. -package component +// TODO: Move tests back to component package after config.*Settings are removed. + +package component_test import ( "context" "testing" "github.com/stretchr/testify/assert" + + "go.opentelemetry.io/collector/component" + "go.opentelemetry.io/collector/config" ) type nopExtension struct { - StartFunc - ShutdownFunc + component.StartFunc + component.ShutdownFunc } func TestNewExtensionFactory(t *testing.T) { const typeStr = "test" - defaultCfg := NewExtensionConfigSettings(NewID(typeStr)) + defaultCfg := config.NewExtensionSettings(component.NewID(typeStr)) nopExtensionInstance := new(nopExtension) - factory := NewExtensionFactory( + factory := component.NewExtensionFactory( typeStr, - func() ExtensionConfig { return &defaultCfg }, - func(ctx context.Context, settings ExtensionCreateSettings, extension ExtensionConfig) (Extension, error) { + func() component.ExtensionConfig { return &defaultCfg }, + func(ctx context.Context, settings component.ExtensionCreateSettings, extension component.ExtensionConfig) (component.Extension, error) { return nopExtensionInstance, nil }, - StabilityLevelInDevelopment) + component.StabilityLevelInDevelopment) assert.EqualValues(t, typeStr, factory.Type()) assert.EqualValues(t, &defaultCfg, factory.CreateDefaultConfig()) - assert.Equal(t, StabilityLevelInDevelopment, factory.ExtensionStability()) - ext, err := factory.CreateExtension(context.Background(), ExtensionCreateSettings{}, &defaultCfg) + assert.Equal(t, component.StabilityLevelInDevelopment, factory.ExtensionStability()) + ext, err := factory.CreateExtension(context.Background(), component.ExtensionCreateSettings{}, &defaultCfg) assert.NoError(t, err) assert.Same(t, nopExtensionInstance, ext) } diff --git a/component/processor.go b/component/processor.go index f02e9e06ff..e3c78fa6f7 100644 --- a/component/processor.go +++ b/component/processor.go @@ -17,9 +17,26 @@ package component // import "go.opentelemetry.io/collector/component" import ( "context" + "go.opentelemetry.io/collector/confmap" "go.opentelemetry.io/collector/consumer" ) +// ProcessorConfig is the configuration of a component.Processor. Specific extensions must implement +// this interface and must embed ProcessorSettings struct or a struct that extends it. +type ProcessorConfig interface { + identifiable + validatable + + privateConfigProcessor() +} + +// UnmarshalProcessorConfig helper function to unmarshal a ProcessorConfig. +// It checks if the config implements confmap.Unmarshaler and uses that if available, +// otherwise uses Map.UnmarshalExact, erroring if a field is nonexistent. +func UnmarshalProcessorConfig(conf *confmap.Conf, cfg ProcessorConfig) error { + return unmarshal(conf, cfg) +} + // Processor defines the common functions that must be implemented by TracesProcessor // and MetricsProcessor. type Processor interface { diff --git a/component/processor_config.go b/component/processor_config.go deleted file mode 100644 index 047f6bbad5..0000000000 --- a/component/processor_config.go +++ /dev/null @@ -1,69 +0,0 @@ -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package component // import "go.opentelemetry.io/collector/component" - -import ( - "go.opentelemetry.io/collector/confmap" -) - -// ProcessorConfig is the configuration of a component.Processor. Specific extensions must implement -// this interface and must embed ProcessorConfigSettings struct or a struct that extends it. -type ProcessorConfig interface { - identifiable - validatable - - privateConfigProcessor() -} - -// UnmarshalProcessorConfig helper function to unmarshal a ProcessorConfig. -// It checks if the config implements confmap.Unmarshaler and uses that if available, -// otherwise uses Map.UnmarshalExact, erroring if a field is nonexistent. -func UnmarshalProcessorConfig(conf *confmap.Conf, cfg ProcessorConfig) error { - return unmarshal(conf, cfg) -} - -// ProcessorConfigSettings defines common settings for a component.Processor configuration. -// Specific processors can embed this struct and extend it with more fields if needed. -// -// It is highly recommended to "override" the Validate() function. -// -// When embedded in the processor config it must be with `mapstructure:",squash"` tag. -type ProcessorConfigSettings struct { - id ID `mapstructure:"-"` -} - -// NewProcessorConfigSettings return a new ProcessorConfigSettings with the given ComponentID. -func NewProcessorConfigSettings(id ID) ProcessorConfigSettings { - return ProcessorConfigSettings{id: ID{typeVal: id.Type(), nameVal: id.Name()}} -} - -var _ ProcessorConfig = (*ProcessorConfigSettings)(nil) - -// ID returns the receiver ComponentID. -func (ps *ProcessorConfigSettings) ID() ID { - return ps.id -} - -// SetIDName sets the receiver name. -func (ps *ProcessorConfigSettings) SetIDName(idName string) { - ps.id.nameVal = idName -} - -// Validate validates the configuration and returns an error if invalid. -func (ps *ProcessorConfigSettings) Validate() error { - return nil -} - -func (ps *ProcessorConfigSettings) privateConfigProcessor() {} diff --git a/component/processor_test.go b/component/processor_test.go index e532059d5e..2fa697f1f1 100644 --- a/component/processor_test.go +++ b/component/processor_test.go @@ -12,7 +12,9 @@ // See the License for the specific language governing permissions and // limitations under the License. -package component +// TODO: Move tests back to component package after config.*Settings are removed. + +package component_test import ( "context" @@ -20,58 +22,60 @@ import ( "github.com/stretchr/testify/assert" + "go.opentelemetry.io/collector/component" + "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/consumer" ) func TestNewProcessorFactory(t *testing.T) { const typeStr = "test" - defaultCfg := NewProcessorConfigSettings(NewID(typeStr)) - factory := NewProcessorFactory( + defaultCfg := config.NewProcessorSettings(component.NewID(typeStr)) + factory := component.NewProcessorFactory( typeStr, - func() ProcessorConfig { return &defaultCfg }) + func() component.ProcessorConfig { return &defaultCfg }) assert.EqualValues(t, typeStr, factory.Type()) assert.EqualValues(t, &defaultCfg, factory.CreateDefaultConfig()) - _, err := factory.CreateTracesProcessor(context.Background(), ProcessorCreateSettings{}, &defaultCfg, nil) + _, err := factory.CreateTracesProcessor(context.Background(), component.ProcessorCreateSettings{}, &defaultCfg, nil) assert.Error(t, err) - _, err = factory.CreateMetricsProcessor(context.Background(), ProcessorCreateSettings{}, &defaultCfg, nil) + _, err = factory.CreateMetricsProcessor(context.Background(), component.ProcessorCreateSettings{}, &defaultCfg, nil) assert.Error(t, err) - _, err = factory.CreateLogsProcessor(context.Background(), ProcessorCreateSettings{}, &defaultCfg, nil) + _, err = factory.CreateLogsProcessor(context.Background(), component.ProcessorCreateSettings{}, &defaultCfg, nil) assert.Error(t, err) } func TestNewProcessorFactory_WithOptions(t *testing.T) { const typeStr = "test" - defaultCfg := NewProcessorConfigSettings(NewID(typeStr)) - factory := NewProcessorFactory( + defaultCfg := config.NewProcessorSettings(component.NewID(typeStr)) + factory := component.NewProcessorFactory( typeStr, - func() ProcessorConfig { return &defaultCfg }, - WithTracesProcessor(createTracesProcessor, StabilityLevelAlpha), - WithMetricsProcessor(createMetricsProcessor, StabilityLevelBeta), - WithLogsProcessor(createLogsProcessor, StabilityLevelUnmaintained)) + func() component.ProcessorConfig { return &defaultCfg }, + component.WithTracesProcessor(createTracesProcessor, component.StabilityLevelAlpha), + component.WithMetricsProcessor(createMetricsProcessor, component.StabilityLevelBeta), + component.WithLogsProcessor(createLogsProcessor, component.StabilityLevelUnmaintained)) assert.EqualValues(t, typeStr, factory.Type()) assert.EqualValues(t, &defaultCfg, factory.CreateDefaultConfig()) - assert.Equal(t, StabilityLevelAlpha, factory.TracesProcessorStability()) - _, err := factory.CreateTracesProcessor(context.Background(), ProcessorCreateSettings{}, &defaultCfg, nil) + assert.Equal(t, component.StabilityLevelAlpha, factory.TracesProcessorStability()) + _, err := factory.CreateTracesProcessor(context.Background(), component.ProcessorCreateSettings{}, &defaultCfg, nil) assert.NoError(t, err) - assert.Equal(t, StabilityLevelBeta, factory.MetricsProcessorStability()) - _, err = factory.CreateMetricsProcessor(context.Background(), ProcessorCreateSettings{}, &defaultCfg, nil) + assert.Equal(t, component.StabilityLevelBeta, factory.MetricsProcessorStability()) + _, err = factory.CreateMetricsProcessor(context.Background(), component.ProcessorCreateSettings{}, &defaultCfg, nil) assert.NoError(t, err) - assert.Equal(t, StabilityLevelUnmaintained, factory.LogsProcessorStability()) - _, err = factory.CreateLogsProcessor(context.Background(), ProcessorCreateSettings{}, &defaultCfg, nil) + assert.Equal(t, component.StabilityLevelUnmaintained, factory.LogsProcessorStability()) + _, err = factory.CreateLogsProcessor(context.Background(), component.ProcessorCreateSettings{}, &defaultCfg, nil) assert.NoError(t, err) } -func createTracesProcessor(context.Context, ProcessorCreateSettings, ProcessorConfig, consumer.Traces) (TracesProcessor, error) { +func createTracesProcessor(context.Context, component.ProcessorCreateSettings, component.ProcessorConfig, consumer.Traces) (component.TracesProcessor, error) { return nil, nil } -func createMetricsProcessor(context.Context, ProcessorCreateSettings, ProcessorConfig, consumer.Metrics) (MetricsProcessor, error) { +func createMetricsProcessor(context.Context, component.ProcessorCreateSettings, component.ProcessorConfig, consumer.Metrics) (component.MetricsProcessor, error) { return nil, nil } -func createLogsProcessor(context.Context, ProcessorCreateSettings, ProcessorConfig, consumer.Logs) (LogsProcessor, error) { +func createLogsProcessor(context.Context, component.ProcessorCreateSettings, component.ProcessorConfig, consumer.Logs) (component.LogsProcessor, error) { return nil, nil } diff --git a/component/receiver.go b/component/receiver.go index 4d59a757bf..dcf4bf7e10 100644 --- a/component/receiver.go +++ b/component/receiver.go @@ -17,9 +17,26 @@ package component // import "go.opentelemetry.io/collector/component" import ( "context" + "go.opentelemetry.io/collector/confmap" "go.opentelemetry.io/collector/consumer" ) +// ReceiverConfig is the configuration of a component.Receiver. Specific extensions must implement +// this interface and must embed ReceiverSettings struct or a struct that extends it. +type ReceiverConfig interface { + identifiable + validatable + + privateConfigReceiver() +} + +// UnmarshalReceiverConfig helper function to unmarshal a ReceiverConfig. +// It checks if the config implements confmap.Unmarshaler and uses that if available, +// otherwise uses Map.UnmarshalExact, erroring if a field is nonexistent. +func UnmarshalReceiverConfig(conf *confmap.Conf, cfg ReceiverConfig) error { + return unmarshal(conf, cfg) +} + // Receiver allows the collector to receive metrics, traces and logs. // // Receiver receives data from a source (either from a remote source via network diff --git a/component/receiver_config.go b/component/receiver_config.go deleted file mode 100644 index 5f9c79a72d..0000000000 --- a/component/receiver_config.go +++ /dev/null @@ -1,69 +0,0 @@ -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package component // import "go.opentelemetry.io/collector/component" - -import ( - "go.opentelemetry.io/collector/confmap" -) - -// ReceiverConfig is the configuration of a component.Receiver. Specific extensions must implement -// this interface and must embed ReceiverConfigSettings struct or a struct that extends it. -type ReceiverConfig interface { - identifiable - validatable - - privateConfigReceiver() -} - -// UnmarshalReceiverConfig helper function to unmarshal a ReceiverConfig. -// It checks if the config implements confmap.Unmarshaler and uses that if available, -// otherwise uses Map.UnmarshalExact, erroring if a field is nonexistent. -func UnmarshalReceiverConfig(conf *confmap.Conf, cfg ReceiverConfig) error { - return unmarshal(conf, cfg) -} - -// ReceiverConfigSettings defines common settings for a component.Receiver configuration. -// Specific receivers can embed this struct and extend it with more fields if needed. -// -// It is highly recommended to "override" the Validate() function. -// -// When embedded in the receiver config it must be with `mapstructure:",squash"` tag. -type ReceiverConfigSettings struct { - id ID `mapstructure:"-"` -} - -// NewReceiverConfigSettings return a new ReceiverConfigSettings with the given ID. -func NewReceiverConfigSettings(id ID) ReceiverConfigSettings { - return ReceiverConfigSettings{id: ID{typeVal: id.Type(), nameVal: id.Name()}} -} - -var _ ReceiverConfig = (*ReceiverConfigSettings)(nil) - -// ID returns the receiver ID. -func (rs *ReceiverConfigSettings) ID() ID { - return rs.id -} - -// SetIDName sets the receiver name. -func (rs *ReceiverConfigSettings) SetIDName(idName string) { - rs.id.nameVal = idName -} - -// Validate validates the configuration and returns an error if invalid. -func (rs *ReceiverConfigSettings) Validate() error { - return nil -} - -func (rs *ReceiverConfigSettings) privateConfigReceiver() {} diff --git a/component/receiver_test.go b/component/receiver_test.go index 3c6f995e43..01d03e7f7f 100644 --- a/component/receiver_test.go +++ b/component/receiver_test.go @@ -12,7 +12,9 @@ // See the License for the specific language governing permissions and // limitations under the License. -package component +// TODO: Move tests back to component package after config.*Settings are removed. + +package component_test import ( "context" @@ -20,58 +22,60 @@ import ( "github.com/stretchr/testify/assert" + "go.opentelemetry.io/collector/component" + "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/consumer" ) func TestNewReceiverFactory(t *testing.T) { const typeStr = "test" - defaultCfg := NewReceiverConfigSettings(NewID(typeStr)) - factory := NewReceiverFactory( + defaultCfg := config.NewReceiverSettings(component.NewID(typeStr)) + factory := component.NewReceiverFactory( typeStr, - func() ReceiverConfig { return &defaultCfg }) + func() component.ReceiverConfig { return &defaultCfg }) assert.EqualValues(t, typeStr, factory.Type()) assert.EqualValues(t, &defaultCfg, factory.CreateDefaultConfig()) - _, err := factory.CreateTracesReceiver(context.Background(), ReceiverCreateSettings{}, &defaultCfg, nil) + _, err := factory.CreateTracesReceiver(context.Background(), component.ReceiverCreateSettings{}, &defaultCfg, nil) assert.Error(t, err) - _, err = factory.CreateMetricsReceiver(context.Background(), ReceiverCreateSettings{}, &defaultCfg, nil) + _, err = factory.CreateMetricsReceiver(context.Background(), component.ReceiverCreateSettings{}, &defaultCfg, nil) assert.Error(t, err) - _, err = factory.CreateLogsReceiver(context.Background(), ReceiverCreateSettings{}, &defaultCfg, nil) + _, err = factory.CreateLogsReceiver(context.Background(), component.ReceiverCreateSettings{}, &defaultCfg, nil) assert.Error(t, err) } func TestNewReceiverFactory_WithOptions(t *testing.T) { const typeStr = "test" - defaultCfg := NewReceiverConfigSettings(NewID(typeStr)) - factory := NewReceiverFactory( + defaultCfg := config.NewReceiverSettings(component.NewID(typeStr)) + factory := component.NewReceiverFactory( typeStr, - func() ReceiverConfig { return &defaultCfg }, - WithTracesReceiver(createTracesReceiver, StabilityLevelDeprecated), - WithMetricsReceiver(createMetricsReceiver, StabilityLevelAlpha), - WithLogsReceiver(createLogsReceiver, StabilityLevelStable)) + func() component.ReceiverConfig { return &defaultCfg }, + component.WithTracesReceiver(createTracesReceiver, component.StabilityLevelDeprecated), + component.WithMetricsReceiver(createMetricsReceiver, component.StabilityLevelAlpha), + component.WithLogsReceiver(createLogsReceiver, component.StabilityLevelStable)) assert.EqualValues(t, typeStr, factory.Type()) assert.EqualValues(t, &defaultCfg, factory.CreateDefaultConfig()) - assert.Equal(t, StabilityLevelDeprecated, factory.TracesReceiverStability()) - _, err := factory.CreateTracesReceiver(context.Background(), ReceiverCreateSettings{}, &defaultCfg, nil) + assert.Equal(t, component.StabilityLevelDeprecated, factory.TracesReceiverStability()) + _, err := factory.CreateTracesReceiver(context.Background(), component.ReceiverCreateSettings{}, &defaultCfg, nil) assert.NoError(t, err) - assert.Equal(t, StabilityLevelAlpha, factory.MetricsReceiverStability()) - _, err = factory.CreateMetricsReceiver(context.Background(), ReceiverCreateSettings{}, &defaultCfg, nil) + assert.Equal(t, component.StabilityLevelAlpha, factory.MetricsReceiverStability()) + _, err = factory.CreateMetricsReceiver(context.Background(), component.ReceiverCreateSettings{}, &defaultCfg, nil) assert.NoError(t, err) - assert.Equal(t, StabilityLevelStable, factory.LogsReceiverStability()) - _, err = factory.CreateLogsReceiver(context.Background(), ReceiverCreateSettings{}, &defaultCfg, nil) + assert.Equal(t, component.StabilityLevelStable, factory.LogsReceiverStability()) + _, err = factory.CreateLogsReceiver(context.Background(), component.ReceiverCreateSettings{}, &defaultCfg, nil) assert.NoError(t, err) } -func createTracesReceiver(context.Context, ReceiverCreateSettings, ReceiverConfig, consumer.Traces) (TracesReceiver, error) { +func createTracesReceiver(context.Context, component.ReceiverCreateSettings, component.ReceiverConfig, consumer.Traces) (component.TracesReceiver, error) { return nil, nil } -func createMetricsReceiver(context.Context, ReceiverCreateSettings, ReceiverConfig, consumer.Metrics) (MetricsReceiver, error) { +func createMetricsReceiver(context.Context, component.ReceiverCreateSettings, component.ReceiverConfig, consumer.Metrics) (component.MetricsReceiver, error) { return nil, nil } -func createLogsReceiver(context.Context, ReceiverCreateSettings, ReceiverConfig, consumer.Logs) (LogsReceiver, error) { +func createLogsReceiver(context.Context, component.ReceiverCreateSettings, component.ReceiverConfig, consumer.Logs) (component.LogsReceiver, error) { return nil, nil } diff --git a/config/exporter.go b/config/exporter.go new file mode 100644 index 0000000000..eb7c5b9460 --- /dev/null +++ b/config/exporter.go @@ -0,0 +1,51 @@ +// Copyright The OpenTelemetry Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package config // import "go.opentelemetry.io/collector/config" +import ( + "go.opentelemetry.io/collector/component" +) + +// ExporterSettings defines common settings for a component.Exporter configuration. +// Specific exporters can embed this struct and extend it with more fields if needed. +// +// It is highly recommended to "override" the Validate() function. +// +// When embedded in the exporter config, it must be with `mapstructure:",squash"` tag. +type ExporterSettings struct { + id component.ID `mapstructure:"-"` + component.ExporterConfig +} + +// NewExporterSettings return a new ExporterSettings with the given ComponentID. +func NewExporterSettings(id component.ID) ExporterSettings { + return ExporterSettings{id: id} +} + +var _ component.ExporterConfig = (*ExporterSettings)(nil) + +// ID returns the receiver component.ID. +func (es *ExporterSettings) ID() component.ID { + return es.id +} + +// SetIDName sets the receiver name. +func (es *ExporterSettings) SetIDName(idName string) { + es.id = component.NewIDWithName(es.id.Type(), idName) +} + +// Validate validates the configuration and returns an error if invalid. +func (es *ExporterSettings) Validate() error { + return nil +} diff --git a/config/extension.go b/config/extension.go new file mode 100644 index 0000000000..9addb5169f --- /dev/null +++ b/config/extension.go @@ -0,0 +1,51 @@ +// Copyright The OpenTelemetry Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package config // import "go.opentelemetry.io/collector/config" +import ( + "go.opentelemetry.io/collector/component" +) + +// ExtensionSettings defines common settings for a component.Extension configuration. +// Specific processors can embed this struct and extend it with more fields if needed. +// +// It is highly recommended to "override" the Validate() function. +// +// When embedded in the extension config, it must be with `mapstructure:",squash"` tag. +type ExtensionSettings struct { + id component.ID `mapstructure:"-"` + component.ExtensionConfig +} + +// NewExtensionSettings return a new ExtensionSettings with the given ID. +func NewExtensionSettings(id component.ID) ExtensionSettings { + return ExtensionSettings{id: id} +} + +var _ component.ExtensionConfig = (*ExtensionSettings)(nil) + +// ID returns the receiver ID. +func (es *ExtensionSettings) ID() component.ID { + return es.id +} + +// SetIDName sets the receiver name. +func (es *ExtensionSettings) SetIDName(idName string) { + es.id = component.NewIDWithName(es.id.Type(), idName) +} + +// Validate validates the configuration and returns an error if invalid. +func (es *ExtensionSettings) Validate() error { + return nil +} diff --git a/config/moved_config.go b/config/moved_config.go index 8c4033e5d7..cf387859d9 100644 --- a/config/moved_config.go +++ b/config/moved_config.go @@ -35,48 +35,24 @@ type Receiver = component.ReceiverConfig // Deprecated: [v0.64.0] use component.UnmarshalReceiverConfig. var UnmarshalReceiver = component.UnmarshalReceiverConfig -// Deprecated: [v0.64.0] use component.ReceiverConfigSettings. -type ReceiverSettings = component.ReceiverConfigSettings - -// Deprecated: [v0.64.0] use component.NewReceiverConfigSettings. -var NewReceiverSettings = component.NewReceiverConfigSettings - // Deprecated: [v0.64.0] use component.ProcessorConfig. type Processor = component.ProcessorConfig // Deprecated: [v0.64.0] use component.UnmarshalProcessorConfig. var UnmarshalProcessor = component.UnmarshalProcessorConfig -// Deprecated: [v0.64.0] use component.ProcessorConfigSettings. -type ProcessorSettings = component.ProcessorConfigSettings - -// Deprecated: [v0.64.0] use component.NewProcessorConfigSettings. -var NewProcessorSettings = component.NewProcessorConfigSettings - // Deprecated: [v0.64.0] use component.ExporterConfig. type Exporter = component.ExporterConfig // Deprecated: [v0.64.0] use component.UnmarshalExporterConfig. var UnmarshalExporter = component.UnmarshalExporterConfig -// Deprecated: [v0.64.0] use component.ExporterConfigSettings. -type ExporterSettings = component.ExporterConfigSettings - -// Deprecated: [v0.64.0] use component.NewExporterConfigSettings. -var NewExporterSettings = component.NewExporterConfigSettings - // Deprecated: [v0.64.0] use component.ExtensionConfig. type Extension = component.ExtensionConfig // Deprecated: [v0.64.0] use component.UnmarshalExtensionConfig. var UnmarshalExtension = component.UnmarshalExtensionConfig -// Deprecated: [v0.64.0] use component.ExtensionConfigSettings. -type ExtensionSettings = component.ExtensionConfigSettings - -// Deprecated: [v0.64.0] use component.NewExtensionConfigSettings. -var NewExtensionSettings = component.NewExtensionConfigSettings - // Deprecated: [v0.64.0] use component.Type. type Type = component.Type diff --git a/config/processor.go b/config/processor.go new file mode 100644 index 0000000000..b6c54369b8 --- /dev/null +++ b/config/processor.go @@ -0,0 +1,51 @@ +// Copyright The OpenTelemetry Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package config // import "go.opentelemetry.io/collector/config" +import ( + "go.opentelemetry.io/collector/component" +) + +// ProcessorSettings defines common settings for a component.Processor configuration. +// Specific processors can embed this struct and extend it with more fields if needed. +// +// It is highly recommended to "override" the Validate() function. +// +// When embedded in the processor config it must be with `mapstructure:",squash"` tag. +type ProcessorSettings struct { + id component.ID `mapstructure:"-"` + component.ProcessorConfig +} + +// NewProcessorSettings return a new ProcessorSettings with the given ComponentID. +func NewProcessorSettings(id component.ID) ProcessorSettings { + return ProcessorSettings{id: id} +} + +var _ component.ProcessorConfig = (*ProcessorSettings)(nil) + +// ID returns the receiver ComponentID. +func (ps *ProcessorSettings) ID() component.ID { + return ps.id +} + +// SetIDName sets the receiver name. +func (ps *ProcessorSettings) SetIDName(idName string) { + ps.id = component.NewIDWithName(ps.id.Type(), idName) +} + +// Validate validates the configuration and returns an error if invalid. +func (ps *ProcessorSettings) Validate() error { + return nil +} diff --git a/config/receiver.go b/config/receiver.go new file mode 100644 index 0000000000..49ee2cb3f8 --- /dev/null +++ b/config/receiver.go @@ -0,0 +1,51 @@ +// Copyright The OpenTelemetry Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package config // import "go.opentelemetry.io/collector/config" +import ( + "go.opentelemetry.io/collector/component" +) + +// ReceiverSettings defines common settings for a component.Receiver configuration. +// Specific receivers can embed this struct and extend it with more fields if needed. +// +// It is highly recommended to "override" the Validate() function. +// +// When embedded in the receiver config it must be with `mapstructure:",squash"` tag. +type ReceiverSettings struct { + id component.ID `mapstructure:"-"` + component.ReceiverConfig +} + +// NewReceiverSettings return a new ReceiverSettings with the given ID. +func NewReceiverSettings(id component.ID) ReceiverSettings { + return ReceiverSettings{id: id} +} + +var _ component.ReceiverConfig = (*ReceiverSettings)(nil) + +// ID returns the receiver ID. +func (rs *ReceiverSettings) ID() component.ID { + return rs.id +} + +// SetIDName sets the receiver name. +func (rs *ReceiverSettings) SetIDName(idName string) { + rs.id = component.NewIDWithName(rs.id.Type(), idName) +} + +// Validate validates the configuration and returns an error if invalid. +func (rs *ReceiverSettings) Validate() error { + return nil +} diff --git a/exporter/exporterhelper/common_test.go b/exporter/exporterhelper/common_test.go index e2fd3f4942..5c5e3e1862 100644 --- a/exporter/exporterhelper/common_test.go +++ b/exporter/exporterhelper/common_test.go @@ -25,13 +25,14 @@ import ( "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/component/componenttest" + "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/consumer" "go.opentelemetry.io/collector/exporter/exporterhelper/internal" "go.opentelemetry.io/collector/pdata/ptrace" ) var ( - defaultExporterCfg = component.NewExporterConfigSettings(component.NewID("test")) + defaultExporterCfg = config.NewExporterSettings(component.NewID("test")) exporterTag, _ = tag.NewKey("exporter") defaultExporterTags = []tag.Tag{ {Key: exporterTag, Value: "test"}, diff --git a/exporter/exporterhelper/logs_test.go b/exporter/exporterhelper/logs_test.go index be67b21f07..1b496d1788 100644 --- a/exporter/exporterhelper/logs_test.go +++ b/exporter/exporterhelper/logs_test.go @@ -28,6 +28,7 @@ import ( "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/component/componenttest" + "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/consumer" "go.opentelemetry.io/collector/consumer/consumererror" "go.opentelemetry.io/collector/internal/obsreportconfig/obsmetrics" @@ -43,7 +44,7 @@ const ( var fakeLogsExporterName = component.NewIDWithName("fake_logs_exporter", "with_name") var ( - fakeLogsExporterConfig = component.NewExporterConfigSettings(fakeLogsExporterName) + fakeLogsExporterConfig = config.NewExporterSettings(fakeLogsExporterName) ) func TestLogsRequest(t *testing.T) { diff --git a/exporter/exporterhelper/metrics_test.go b/exporter/exporterhelper/metrics_test.go index d5ab33d030..4f7651eb13 100644 --- a/exporter/exporterhelper/metrics_test.go +++ b/exporter/exporterhelper/metrics_test.go @@ -28,6 +28,7 @@ import ( "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/component/componenttest" + "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/consumer" "go.opentelemetry.io/collector/consumer/consumererror" "go.opentelemetry.io/collector/internal/obsreportconfig/obsmetrics" @@ -42,7 +43,7 @@ const ( var ( fakeMetricsExporterName = component.NewIDWithName("fake_metrics_exporter", "with_name") - fakeMetricsExporterConfig = component.NewExporterConfigSettings(fakeMetricsExporterName) + fakeMetricsExporterConfig = config.NewExporterSettings(fakeMetricsExporterName) ) func TestMetricsRequest(t *testing.T) { diff --git a/exporter/exporterhelper/traces_test.go b/exporter/exporterhelper/traces_test.go index d6ea12d017..c27973aa70 100644 --- a/exporter/exporterhelper/traces_test.go +++ b/exporter/exporterhelper/traces_test.go @@ -28,6 +28,7 @@ import ( "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/component/componenttest" + "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/consumer" "go.opentelemetry.io/collector/consumer/consumererror" "go.opentelemetry.io/collector/internal/obsreportconfig/obsmetrics" @@ -42,7 +43,7 @@ const ( var ( fakeTracesExporterName = component.NewIDWithName("fake_traces_exporter", "with_name") - fakeTracesExporterConfig = component.NewExporterConfigSettings(fakeTracesExporterName) + fakeTracesExporterConfig = config.NewExporterSettings(fakeTracesExporterName) ) func TestTracesRequest(t *testing.T) { diff --git a/exporter/loggingexporter/config.go b/exporter/loggingexporter/config.go index e0131246dc..7dbff1bba2 100644 --- a/exporter/loggingexporter/config.go +++ b/exporter/loggingexporter/config.go @@ -20,6 +20,7 @@ import ( "go.uber.org/zap/zapcore" "go.opentelemetry.io/collector/component" + "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/config/configtelemetry" "go.opentelemetry.io/collector/confmap" ) @@ -36,7 +37,7 @@ var ( // Config defines configuration for logging exporter. type Config struct { - component.ExporterConfigSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct + config.ExporterSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct // LogLevel defines log level of the logging exporter; options are debug, info, warn, error. // Deprecated: Use `Verbosity` instead. diff --git a/exporter/loggingexporter/config_test.go b/exporter/loggingexporter/config_test.go index 90bfbfbf17..b100d490d9 100644 --- a/exporter/loggingexporter/config_test.go +++ b/exporter/loggingexporter/config_test.go @@ -23,6 +23,7 @@ import ( "go.uber.org/zap/zapcore" "go.opentelemetry.io/collector/component" + "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/config/configtelemetry" "go.opentelemetry.io/collector/confmap" "go.opentelemetry.io/collector/confmap/confmaptest" @@ -44,33 +45,33 @@ func TestUnmarshalConfig(t *testing.T) { { filename: "config_loglevel.yaml", cfg: &Config{ - ExporterConfigSettings: component.NewExporterConfigSettings(component.NewID(typeStr)), - LogLevel: zapcore.DebugLevel, - Verbosity: configtelemetry.LevelDetailed, - SamplingInitial: 10, - SamplingThereafter: 50, - warnLogLevel: true, + ExporterSettings: config.NewExporterSettings(component.NewID(typeStr)), + LogLevel: zapcore.DebugLevel, + Verbosity: configtelemetry.LevelDetailed, + SamplingInitial: 10, + SamplingThereafter: 50, + warnLogLevel: true, }, }, { filename: "config_verbosity.yaml", cfg: &Config{ - ExporterConfigSettings: component.NewExporterConfigSettings(component.NewID(typeStr)), - LogLevel: zapcore.InfoLevel, - Verbosity: configtelemetry.LevelDetailed, - SamplingInitial: 10, - SamplingThereafter: 50, + ExporterSettings: config.NewExporterSettings(component.NewID(typeStr)), + LogLevel: zapcore.InfoLevel, + Verbosity: configtelemetry.LevelDetailed, + SamplingInitial: 10, + SamplingThereafter: 50, }, }, { filename: "loglevel_info.yaml", cfg: &Config{ - ExporterConfigSettings: component.NewExporterConfigSettings(component.NewID(typeStr)), - LogLevel: zapcore.InfoLevel, - Verbosity: configtelemetry.LevelNormal, - SamplingInitial: 2, - SamplingThereafter: 500, - warnLogLevel: true, + ExporterSettings: config.NewExporterSettings(component.NewID(typeStr)), + LogLevel: zapcore.InfoLevel, + Verbosity: configtelemetry.LevelNormal, + SamplingInitial: 2, + SamplingThereafter: 500, + warnLogLevel: true, }, }, { diff --git a/exporter/loggingexporter/factory.go b/exporter/loggingexporter/factory.go index 655b05edb5..a87c7cec2d 100644 --- a/exporter/loggingexporter/factory.go +++ b/exporter/loggingexporter/factory.go @@ -23,6 +23,7 @@ import ( "go.uber.org/zap/zapcore" "go.opentelemetry.io/collector/component" + "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/config/configtelemetry" "go.opentelemetry.io/collector/consumer" "go.opentelemetry.io/collector/exporter/exporterhelper" @@ -50,11 +51,11 @@ func NewFactory() component.ExporterFactory { func createDefaultConfig() component.ExporterConfig { return &Config{ - ExporterConfigSettings: component.NewExporterConfigSettings(component.NewID(typeStr)), - LogLevel: zapcore.InfoLevel, - Verbosity: configtelemetry.LevelNormal, - SamplingInitial: defaultSamplingInitial, - SamplingThereafter: defaultSamplingThereafter, + ExporterSettings: config.NewExporterSettings(component.NewID(typeStr)), + LogLevel: zapcore.InfoLevel, + Verbosity: configtelemetry.LevelNormal, + SamplingInitial: defaultSamplingInitial, + SamplingThereafter: defaultSamplingThereafter, } } diff --git a/exporter/otlpexporter/config.go b/exporter/otlpexporter/config.go index 7254feebf7..c15770fa9e 100644 --- a/exporter/otlpexporter/config.go +++ b/exporter/otlpexporter/config.go @@ -18,16 +18,17 @@ import ( "fmt" "go.opentelemetry.io/collector/component" + "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/config/configgrpc" "go.opentelemetry.io/collector/exporter/exporterhelper" ) // Config defines configuration for OpenCensus exporter. type Config struct { - component.ExporterConfigSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct - exporterhelper.TimeoutSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct. - exporterhelper.QueueSettings `mapstructure:"sending_queue"` - exporterhelper.RetrySettings `mapstructure:"retry_on_failure"` + config.ExporterSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct + exporterhelper.TimeoutSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct. + exporterhelper.QueueSettings `mapstructure:"sending_queue"` + exporterhelper.RetrySettings `mapstructure:"retry_on_failure"` configgrpc.GRPCClientSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct. } diff --git a/exporter/otlpexporter/config_test.go b/exporter/otlpexporter/config_test.go index d9295356da..6679a42a4d 100644 --- a/exporter/otlpexporter/config_test.go +++ b/exporter/otlpexporter/config_test.go @@ -23,6 +23,7 @@ import ( "github.com/stretchr/testify/require" "go.opentelemetry.io/collector/component" + "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/config/configauth" "go.opentelemetry.io/collector/config/configgrpc" "go.opentelemetry.io/collector/config/configtls" @@ -46,7 +47,7 @@ func TestUnmarshalConfig(t *testing.T) { assert.NoError(t, component.UnmarshalExporterConfig(cm, cfg)) assert.Equal(t, &Config{ - ExporterConfigSettings: component.NewExporterConfigSettings(component.NewID(typeStr)), + ExporterSettings: config.NewExporterSettings(component.NewID(typeStr)), TimeoutSettings: exporterhelper.TimeoutSettings{ Timeout: 10 * time.Second, }, diff --git a/exporter/otlpexporter/factory.go b/exporter/otlpexporter/factory.go index f2540fcf54..3a14097437 100644 --- a/exporter/otlpexporter/factory.go +++ b/exporter/otlpexporter/factory.go @@ -18,6 +18,7 @@ import ( "context" "go.opentelemetry.io/collector/component" + "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/config/configcompression" "go.opentelemetry.io/collector/config/configgrpc" "go.opentelemetry.io/collector/consumer" @@ -42,10 +43,10 @@ func NewFactory() component.ExporterFactory { func createDefaultConfig() component.ExporterConfig { return &Config{ - ExporterConfigSettings: component.NewExporterConfigSettings(component.NewID(typeStr)), - TimeoutSettings: exporterhelper.NewDefaultTimeoutSettings(), - RetrySettings: exporterhelper.NewDefaultRetrySettings(), - QueueSettings: exporterhelper.NewDefaultQueueSettings(), + ExporterSettings: config.NewExporterSettings(component.NewID(typeStr)), + TimeoutSettings: exporterhelper.NewDefaultTimeoutSettings(), + RetrySettings: exporterhelper.NewDefaultRetrySettings(), + QueueSettings: exporterhelper.NewDefaultQueueSettings(), GRPCClientSettings: configgrpc.GRPCClientSettings{ Headers: map[string]string{}, // Default to gzip compression diff --git a/exporter/otlpexporter/factory_test.go b/exporter/otlpexporter/factory_test.go index b56d6442da..0f6f8bd29c 100644 --- a/exporter/otlpexporter/factory_test.go +++ b/exporter/otlpexporter/factory_test.go @@ -25,6 +25,7 @@ import ( "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/component/componenttest" + "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/config/configcompression" "go.opentelemetry.io/collector/config/configgrpc" "go.opentelemetry.io/collector/config/configtls" @@ -67,7 +68,7 @@ func TestCreateTracesExporter(t *testing.T) { { name: "NoEndpoint", config: Config{ - ExporterConfigSettings: component.NewExporterConfigSettings(component.NewID(typeStr)), + ExporterSettings: config.NewExporterSettings(component.NewID(typeStr)), GRPCClientSettings: configgrpc.GRPCClientSettings{ Endpoint: "", }, @@ -77,7 +78,7 @@ func TestCreateTracesExporter(t *testing.T) { { name: "UseSecure", config: Config{ - ExporterConfigSettings: component.NewExporterConfigSettings(component.NewID(typeStr)), + ExporterSettings: config.NewExporterSettings(component.NewID(typeStr)), GRPCClientSettings: configgrpc.GRPCClientSettings{ Endpoint: endpoint, TLSSetting: configtls.TLSClientSetting{ @@ -89,7 +90,7 @@ func TestCreateTracesExporter(t *testing.T) { { name: "Keepalive", config: Config{ - ExporterConfigSettings: component.NewExporterConfigSettings(component.NewID(typeStr)), + ExporterSettings: config.NewExporterSettings(component.NewID(typeStr)), GRPCClientSettings: configgrpc.GRPCClientSettings{ Endpoint: endpoint, Keepalive: &configgrpc.KeepaliveClientConfig{ @@ -103,7 +104,7 @@ func TestCreateTracesExporter(t *testing.T) { { name: "NoneCompression", config: Config{ - ExporterConfigSettings: component.NewExporterConfigSettings(component.NewID(typeStr)), + ExporterSettings: config.NewExporterSettings(component.NewID(typeStr)), GRPCClientSettings: configgrpc.GRPCClientSettings{ Endpoint: endpoint, Compression: "none", @@ -113,7 +114,7 @@ func TestCreateTracesExporter(t *testing.T) { { name: "GzipCompression", config: Config{ - ExporterConfigSettings: component.NewExporterConfigSettings(component.NewID(typeStr)), + ExporterSettings: config.NewExporterSettings(component.NewID(typeStr)), GRPCClientSettings: configgrpc.GRPCClientSettings{ Endpoint: endpoint, Compression: configcompression.Gzip, @@ -141,7 +142,7 @@ func TestCreateTracesExporter(t *testing.T) { { name: "Headers", config: Config{ - ExporterConfigSettings: component.NewExporterConfigSettings(component.NewID(typeStr)), + ExporterSettings: config.NewExporterSettings(component.NewID(typeStr)), GRPCClientSettings: configgrpc.GRPCClientSettings{ Endpoint: endpoint, Headers: map[string]string{ @@ -154,7 +155,7 @@ func TestCreateTracesExporter(t *testing.T) { { name: "NumConsumers", config: Config{ - ExporterConfigSettings: component.NewExporterConfigSettings(component.NewID(typeStr)), + ExporterSettings: config.NewExporterSettings(component.NewID(typeStr)), GRPCClientSettings: configgrpc.GRPCClientSettings{ Endpoint: endpoint, }, @@ -163,7 +164,7 @@ func TestCreateTracesExporter(t *testing.T) { { name: "CaCert", config: Config{ - ExporterConfigSettings: component.NewExporterConfigSettings(component.NewID(typeStr)), + ExporterSettings: config.NewExporterSettings(component.NewID(typeStr)), GRPCClientSettings: configgrpc.GRPCClientSettings{ Endpoint: endpoint, TLSSetting: configtls.TLSClientSetting{ @@ -177,7 +178,7 @@ func TestCreateTracesExporter(t *testing.T) { { name: "CertPemFileError", config: Config{ - ExporterConfigSettings: component.NewExporterConfigSettings(component.NewID(typeStr)), + ExporterSettings: config.NewExporterSettings(component.NewID(typeStr)), GRPCClientSettings: configgrpc.GRPCClientSettings{ Endpoint: endpoint, TLSSetting: configtls.TLSClientSetting{ diff --git a/exporter/otlphttpexporter/config.go b/exporter/otlphttpexporter/config.go index 2db393e1c1..04fbf7d4bc 100644 --- a/exporter/otlphttpexporter/config.go +++ b/exporter/otlphttpexporter/config.go @@ -18,16 +18,17 @@ import ( "errors" "go.opentelemetry.io/collector/component" + "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/config/confighttp" "go.opentelemetry.io/collector/exporter/exporterhelper" ) // Config defines configuration for OTLP/HTTP exporter. type Config struct { - component.ExporterConfigSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct - confighttp.HTTPClientSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct. - exporterhelper.QueueSettings `mapstructure:"sending_queue"` - exporterhelper.RetrySettings `mapstructure:"retry_on_failure"` + config.ExporterSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct + confighttp.HTTPClientSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct. + exporterhelper.QueueSettings `mapstructure:"sending_queue"` + exporterhelper.RetrySettings `mapstructure:"retry_on_failure"` // The URL to send traces to. If omitted the Endpoint + "/v1/traces" will be used. TracesEndpoint string `mapstructure:"traces_endpoint"` diff --git a/exporter/otlphttpexporter/config_test.go b/exporter/otlphttpexporter/config_test.go index 261ca74a7a..9f37c11014 100644 --- a/exporter/otlphttpexporter/config_test.go +++ b/exporter/otlphttpexporter/config_test.go @@ -23,6 +23,7 @@ import ( "github.com/stretchr/testify/require" "go.opentelemetry.io/collector/component" + "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/config/confighttp" "go.opentelemetry.io/collector/config/configtls" "go.opentelemetry.io/collector/confmap" @@ -47,7 +48,7 @@ func TestUnmarshalConfig(t *testing.T) { assert.NoError(t, component.UnmarshalExporterConfig(cm, cfg)) assert.Equal(t, &Config{ - ExporterConfigSettings: component.NewExporterConfigSettings(component.NewID(typeStr)), + ExporterSettings: config.NewExporterSettings(component.NewID(typeStr)), RetrySettings: exporterhelper.RetrySettings{ Enabled: true, InitialInterval: 10 * time.Second, diff --git a/exporter/otlphttpexporter/factory.go b/exporter/otlphttpexporter/factory.go index ba1926e27c..5048d920f0 100644 --- a/exporter/otlphttpexporter/factory.go +++ b/exporter/otlphttpexporter/factory.go @@ -21,6 +21,7 @@ import ( "time" "go.opentelemetry.io/collector/component" + "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/config/configcompression" "go.opentelemetry.io/collector/config/confighttp" "go.opentelemetry.io/collector/consumer" @@ -45,9 +46,9 @@ func NewFactory() component.ExporterFactory { func createDefaultConfig() component.ExporterConfig { return &Config{ - ExporterConfigSettings: component.NewExporterConfigSettings(component.NewID(typeStr)), - RetrySettings: exporterhelper.NewDefaultRetrySettings(), - QueueSettings: exporterhelper.NewDefaultQueueSettings(), + ExporterSettings: config.NewExporterSettings(component.NewID(typeStr)), + RetrySettings: exporterhelper.NewDefaultRetrySettings(), + QueueSettings: exporterhelper.NewDefaultQueueSettings(), HTTPClientSettings: confighttp.HTTPClientSettings{ Endpoint: "", Timeout: 30 * time.Second, diff --git a/exporter/otlphttpexporter/factory_test.go b/exporter/otlphttpexporter/factory_test.go index 7529899855..16502c2027 100644 --- a/exporter/otlphttpexporter/factory_test.go +++ b/exporter/otlphttpexporter/factory_test.go @@ -25,6 +25,7 @@ import ( "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/component/componenttest" + "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/config/configcompression" "go.opentelemetry.io/collector/config/confighttp" "go.opentelemetry.io/collector/config/configtls" @@ -71,7 +72,7 @@ func TestCreateTracesExporter(t *testing.T) { { name: "NoEndpoint", config: Config{ - ExporterConfigSettings: component.NewExporterConfigSettings(component.NewID(typeStr)), + ExporterSettings: config.NewExporterSettings(component.NewID(typeStr)), HTTPClientSettings: confighttp.HTTPClientSettings{ Endpoint: "", }, @@ -81,7 +82,7 @@ func TestCreateTracesExporter(t *testing.T) { { name: "UseSecure", config: Config{ - ExporterConfigSettings: component.NewExporterConfigSettings(component.NewID(typeStr)), + ExporterSettings: config.NewExporterSettings(component.NewID(typeStr)), HTTPClientSettings: confighttp.HTTPClientSettings{ Endpoint: endpoint, TLSSetting: configtls.TLSClientSetting{ @@ -93,7 +94,7 @@ func TestCreateTracesExporter(t *testing.T) { { name: "Headers", config: Config{ - ExporterConfigSettings: component.NewExporterConfigSettings(component.NewID(typeStr)), + ExporterSettings: config.NewExporterSettings(component.NewID(typeStr)), HTTPClientSettings: confighttp.HTTPClientSettings{ Endpoint: endpoint, Headers: map[string]string{ @@ -106,7 +107,7 @@ func TestCreateTracesExporter(t *testing.T) { { name: "CaCert", config: Config{ - ExporterConfigSettings: component.NewExporterConfigSettings(component.NewID(typeStr)), + ExporterSettings: config.NewExporterSettings(component.NewID(typeStr)), HTTPClientSettings: confighttp.HTTPClientSettings{ Endpoint: endpoint, TLSSetting: configtls.TLSClientSetting{ @@ -120,7 +121,7 @@ func TestCreateTracesExporter(t *testing.T) { { name: "CertPemFileError", config: Config{ - ExporterConfigSettings: component.NewExporterConfigSettings(component.NewID(typeStr)), + ExporterSettings: config.NewExporterSettings(component.NewID(typeStr)), HTTPClientSettings: confighttp.HTTPClientSettings{ Endpoint: endpoint, TLSSetting: configtls.TLSClientSetting{ @@ -136,7 +137,7 @@ func TestCreateTracesExporter(t *testing.T) { { name: "NoneCompression", config: Config{ - ExporterConfigSettings: component.NewExporterConfigSettings(component.NewID(typeStr)), + ExporterSettings: config.NewExporterSettings(component.NewID(typeStr)), HTTPClientSettings: confighttp.HTTPClientSettings{ Endpoint: endpoint, Compression: "none", @@ -146,7 +147,7 @@ func TestCreateTracesExporter(t *testing.T) { { name: "GzipCompression", config: Config{ - ExporterConfigSettings: component.NewExporterConfigSettings(component.NewID(typeStr)), + ExporterSettings: config.NewExporterSettings(component.NewID(typeStr)), HTTPClientSettings: confighttp.HTTPClientSettings{ Endpoint: endpoint, Compression: configcompression.Gzip, @@ -156,7 +157,7 @@ func TestCreateTracesExporter(t *testing.T) { { name: "SnappyCompression", config: Config{ - ExporterConfigSettings: component.NewExporterConfigSettings(component.NewID(typeStr)), + ExporterSettings: config.NewExporterSettings(component.NewID(typeStr)), HTTPClientSettings: confighttp.HTTPClientSettings{ Endpoint: endpoint, Compression: configcompression.Snappy, @@ -166,7 +167,7 @@ func TestCreateTracesExporter(t *testing.T) { { name: "ZstdCompression", config: Config{ - ExporterConfigSettings: component.NewExporterConfigSettings(component.NewID(typeStr)), + ExporterSettings: config.NewExporterSettings(component.NewID(typeStr)), HTTPClientSettings: confighttp.HTTPClientSettings{ Endpoint: endpoint, Compression: configcompression.Zstd, diff --git a/exporter/otlphttpexporter/otlp_test.go b/exporter/otlphttpexporter/otlp_test.go index c1a15b43f7..d43f26345a 100644 --- a/exporter/otlphttpexporter/otlp_test.go +++ b/exporter/otlphttpexporter/otlp_test.go @@ -37,6 +37,7 @@ import ( "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/component/componenttest" + "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/config/confighttp" "go.opentelemetry.io/collector/consumer" "go.opentelemetry.io/collector/consumer/consumererror" @@ -480,8 +481,8 @@ func TestErrorResponses(t *testing.T) { }() cfg := &Config{ - ExporterConfigSettings: component.NewExporterConfigSettings(component.NewID(typeStr)), - TracesEndpoint: fmt.Sprintf("http://%s/v1/traces", addr), + ExporterSettings: config.NewExporterSettings(component.NewID(typeStr)), + TracesEndpoint: fmt.Sprintf("http://%s/v1/traces", addr), // Create without QueueSettings and RetrySettings so that ConsumeTraces // returns the errors that we want to check immediately. } @@ -557,8 +558,8 @@ func TestUserAgent(t *testing.T) { }() cfg := &Config{ - ExporterConfigSettings: component.NewExporterConfigSettings(component.NewID(typeStr)), - TracesEndpoint: fmt.Sprintf("http://%s/v1/traces", addr), + ExporterSettings: config.NewExporterSettings(component.NewID(typeStr)), + TracesEndpoint: fmt.Sprintf("http://%s/v1/traces", addr), HTTPClientSettings: confighttp.HTTPClientSettings{ Headers: test.headers, }, @@ -602,8 +603,8 @@ func TestUserAgent(t *testing.T) { }() cfg := &Config{ - ExporterConfigSettings: component.NewExporterConfigSettings(component.NewID(typeStr)), - MetricsEndpoint: fmt.Sprintf("http://%s/v1/metrics", addr), + ExporterSettings: config.NewExporterSettings(component.NewID(typeStr)), + MetricsEndpoint: fmt.Sprintf("http://%s/v1/metrics", addr), HTTPClientSettings: confighttp.HTTPClientSettings{ Headers: test.headers, }, @@ -647,8 +648,8 @@ func TestUserAgent(t *testing.T) { }() cfg := &Config{ - ExporterConfigSettings: component.NewExporterConfigSettings(component.NewID(typeStr)), - LogsEndpoint: fmt.Sprintf("http://%s/v1/logs", addr), + ExporterSettings: config.NewExporterSettings(component.NewID(typeStr)), + LogsEndpoint: fmt.Sprintf("http://%s/v1/logs", addr), HTTPClientSettings: confighttp.HTTPClientSettings{ Headers: test.headers, }, diff --git a/extension/ballastextension/config.go b/extension/ballastextension/config.go index 89c0a4bb44..52063e4f79 100644 --- a/extension/ballastextension/config.go +++ b/extension/ballastextension/config.go @@ -17,12 +17,12 @@ package ballastextension // import "go.opentelemetry.io/collector/extension/ball import ( "errors" - "go.opentelemetry.io/collector/component" + "go.opentelemetry.io/collector/config" ) // Config has the configuration for the ballast extension. type Config struct { - component.ExtensionConfigSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct + config.ExtensionSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct // SizeMiB is the size, in MiB, of the memory ballast // to be created for this process. diff --git a/extension/ballastextension/config_test.go b/extension/ballastextension/config_test.go index 01b93ef4f4..f61e15524c 100644 --- a/extension/ballastextension/config_test.go +++ b/extension/ballastextension/config_test.go @@ -22,6 +22,7 @@ import ( "github.com/stretchr/testify/require" "go.opentelemetry.io/collector/component" + "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/confmap" "go.opentelemetry.io/collector/confmap/confmaptest" ) @@ -41,9 +42,9 @@ func TestUnmarshalConfig(t *testing.T) { assert.NoError(t, component.UnmarshalExtensionConfig(cm, cfg)) assert.Equal(t, &Config{ - ExtensionConfigSettings: component.NewExtensionConfigSettings(component.NewID(typeStr)), - SizeMiB: 123, - SizeInPercentage: 20, + ExtensionSettings: config.NewExtensionSettings(component.NewID(typeStr)), + SizeMiB: 123, + SizeInPercentage: 20, }, cfg) } diff --git a/extension/ballastextension/factory.go b/extension/ballastextension/factory.go index 3a244aa3e5..6d5687c328 100644 --- a/extension/ballastextension/factory.go +++ b/extension/ballastextension/factory.go @@ -18,6 +18,7 @@ import ( "context" "go.opentelemetry.io/collector/component" + "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/internal/iruntime" ) @@ -36,7 +37,7 @@ func NewFactory() component.ExtensionFactory { func createDefaultConfig() component.ExtensionConfig { return &Config{ - ExtensionConfigSettings: component.NewExtensionConfigSettings(component.NewID(typeStr)), + ExtensionSettings: config.NewExtensionSettings(component.NewID(typeStr)), } } diff --git a/extension/ballastextension/factory_test.go b/extension/ballastextension/factory_test.go index 8ced4d6b27..39b82f399f 100644 --- a/extension/ballastextension/factory_test.go +++ b/extension/ballastextension/factory_test.go @@ -23,11 +23,12 @@ import ( "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/component/componenttest" + "go.opentelemetry.io/collector/config" ) func TestFactory_CreateDefaultConfig(t *testing.T) { cfg := createDefaultConfig() - assert.Equal(t, &Config{ExtensionConfigSettings: component.NewExtensionConfigSettings(component.NewID(typeStr))}, cfg) + assert.Equal(t, &Config{ExtensionSettings: config.NewExtensionSettings(component.NewID(typeStr))}, cfg) assert.NoError(t, componenttest.CheckConfigStruct(cfg)) ext, err := createExtension(context.Background(), componenttest.NewNopExtensionCreateSettings(), cfg) diff --git a/extension/zpagesextension/config.go b/extension/zpagesextension/config.go index 1fb47523e2..8774f870d7 100644 --- a/extension/zpagesextension/config.go +++ b/extension/zpagesextension/config.go @@ -18,12 +18,13 @@ import ( "errors" "go.opentelemetry.io/collector/component" + "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/config/confignet" ) // Config has the configuration for the extension enabling the zPages extension. type Config struct { - component.ExtensionConfigSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct + config.ExtensionSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct // TCPAddr is the address and port in which the zPages will be listening to. // Use localhost: to make it available only locally, or ":" to diff --git a/extension/zpagesextension/config_test.go b/extension/zpagesextension/config_test.go index a9af78689a..d698d4f1da 100644 --- a/extension/zpagesextension/config_test.go +++ b/extension/zpagesextension/config_test.go @@ -22,6 +22,7 @@ import ( "github.com/stretchr/testify/require" "go.opentelemetry.io/collector/component" + "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/config/confignet" "go.opentelemetry.io/collector/confmap" "go.opentelemetry.io/collector/confmap/confmaptest" @@ -42,7 +43,7 @@ func TestUnmarshalConfig(t *testing.T) { assert.NoError(t, component.UnmarshalExtensionConfig(cm, cfg)) assert.Equal(t, &Config{ - ExtensionConfigSettings: component.NewExtensionConfigSettings(component.NewID(typeStr)), + ExtensionSettings: config.NewExtensionSettings(component.NewID(typeStr)), TCPAddr: confignet.TCPAddr{ Endpoint: "localhost:56888", }, diff --git a/extension/zpagesextension/factory.go b/extension/zpagesextension/factory.go index 88815952fc..5d7a458c5d 100644 --- a/extension/zpagesextension/factory.go +++ b/extension/zpagesextension/factory.go @@ -18,6 +18,7 @@ import ( "context" "go.opentelemetry.io/collector/component" + "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/config/confignet" ) @@ -35,7 +36,7 @@ func NewFactory() component.ExtensionFactory { func createDefaultConfig() component.ExtensionConfig { return &Config{ - ExtensionConfigSettings: component.NewExtensionConfigSettings(component.NewID(typeStr)), + ExtensionSettings: config.NewExtensionSettings(component.NewID(typeStr)), TCPAddr: confignet.TCPAddr{ Endpoint: defaultEndpoint, }, diff --git a/extension/zpagesextension/factory_test.go b/extension/zpagesextension/factory_test.go index 8afb574d76..0e5c710807 100644 --- a/extension/zpagesextension/factory_test.go +++ b/extension/zpagesextension/factory_test.go @@ -23,6 +23,7 @@ import ( "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/component/componenttest" + "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/config/confignet" "go.opentelemetry.io/collector/internal/testutil" ) @@ -30,7 +31,7 @@ import ( func TestFactory_CreateDefaultConfig(t *testing.T) { cfg := createDefaultConfig() assert.Equal(t, &Config{ - ExtensionConfigSettings: component.NewExtensionConfigSettings(component.NewID(typeStr)), + ExtensionSettings: config.NewExtensionSettings(component.NewID(typeStr)), TCPAddr: confignet.TCPAddr{ Endpoint: "localhost:55679", }, diff --git a/processor/batchprocessor/batch_processor_test.go b/processor/batchprocessor/batch_processor_test.go index 09eb064347..dd7b979f3b 100644 --- a/processor/batchprocessor/batch_processor_test.go +++ b/processor/batchprocessor/batch_processor_test.go @@ -28,6 +28,7 @@ import ( "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/component/componenttest" + "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/config/configtelemetry" "go.opentelemetry.io/collector/consumer" "go.opentelemetry.io/collector/consumer/consumertest" @@ -285,9 +286,9 @@ func TestBatchProcessorSentByTimeout(t *testing.T) { func TestBatchProcessorTraceSendWhenClosing(t *testing.T) { cfg := Config{ - ProcessorConfigSettings: component.NewProcessorConfigSettings(component.NewID(typeStr)), - Timeout: 3 * time.Second, - SendBatchSize: 1000, + ProcessorSettings: config.NewProcessorSettings(component.NewID(typeStr)), + Timeout: 3 * time.Second, + SendBatchSize: 1000, } sink := new(consumertest.TracesSink) @@ -313,9 +314,9 @@ func TestBatchMetricProcessor_ReceivingData(t *testing.T) { // Instantiate the batch processor with low config values to test data // gets sent through the processor. cfg := Config{ - ProcessorConfigSettings: component.NewProcessorConfigSettings(component.NewID(typeStr)), - Timeout: 200 * time.Millisecond, - SendBatchSize: 50, + ProcessorSettings: config.NewProcessorSettings(component.NewID(typeStr)), + Timeout: 200 * time.Millisecond, + SendBatchSize: 50, } requestCount := 100 @@ -367,9 +368,9 @@ func TestBatchMetricProcessor_BatchSize(t *testing.T) { // Instantiate the batch processor with low config values to test data // gets sent through the processor. cfg := Config{ - ProcessorConfigSettings: component.NewProcessorConfigSettings(component.NewID(typeStr)), - Timeout: 100 * time.Millisecond, - SendBatchSize: 50, + ProcessorSettings: config.NewProcessorSettings(component.NewID(typeStr)), + Timeout: 100 * time.Millisecond, + SendBatchSize: 50, } requestCount := 100 @@ -446,9 +447,9 @@ func TestBatchMetrics_UnevenBatchMaxSize(t *testing.T) { func TestBatchMetricsProcessor_Timeout(t *testing.T) { cfg := Config{ - ProcessorConfigSettings: component.NewProcessorConfigSettings(component.NewID(typeStr)), - Timeout: 100 * time.Millisecond, - SendBatchSize: 101, + ProcessorSettings: config.NewProcessorSettings(component.NewID(typeStr)), + Timeout: 100 * time.Millisecond, + SendBatchSize: 101, } requestCount := 5 metricsPerRequest := 10 @@ -495,9 +496,9 @@ func TestBatchMetricsProcessor_Timeout(t *testing.T) { func TestBatchMetricProcessor_Shutdown(t *testing.T) { cfg := Config{ - ProcessorConfigSettings: component.NewProcessorConfigSettings(component.NewID(typeStr)), - Timeout: 3 * time.Second, - SendBatchSize: 1000, + ProcessorSettings: config.NewProcessorSettings(component.NewID(typeStr)), + Timeout: 3 * time.Second, + SendBatchSize: 1000, } requestCount := 5 metricsPerRequest := 10 @@ -581,9 +582,9 @@ func BenchmarkTraceSizeSpanCount(b *testing.B) { func BenchmarkBatchMetricProcessor(b *testing.B) { b.StopTimer() cfg := Config{ - ProcessorConfigSettings: component.NewProcessorConfigSettings(component.NewID(typeStr)), - Timeout: 100 * time.Millisecond, - SendBatchSize: 2000, + ProcessorSettings: config.NewProcessorSettings(component.NewID(typeStr)), + Timeout: 100 * time.Millisecond, + SendBatchSize: 2000, } ctx := context.Background() sink := new(metricsSink) @@ -631,9 +632,9 @@ func TestBatchLogProcessor_ReceivingData(t *testing.T) { // Instantiate the batch processor with low config values to test data // gets sent through the processor. cfg := Config{ - ProcessorConfigSettings: component.NewProcessorConfigSettings(component.NewID(typeStr)), - Timeout: 200 * time.Millisecond, - SendBatchSize: 50, + ProcessorSettings: config.NewProcessorSettings(component.NewID(typeStr)), + Timeout: 200 * time.Millisecond, + SendBatchSize: 50, } requestCount := 100 @@ -685,9 +686,9 @@ func TestBatchLogProcessor_BatchSize(t *testing.T) { // Instantiate the batch processor with low config values to test data // gets sent through the processor. cfg := Config{ - ProcessorConfigSettings: component.NewProcessorConfigSettings(component.NewID(typeStr)), - Timeout: 100 * time.Millisecond, - SendBatchSize: 50, + ProcessorSettings: config.NewProcessorSettings(component.NewID(typeStr)), + Timeout: 100 * time.Millisecond, + SendBatchSize: 50, } requestCount := 100 @@ -743,9 +744,9 @@ func TestBatchLogProcessor_BatchSize(t *testing.T) { func TestBatchLogsProcessor_Timeout(t *testing.T) { cfg := Config{ - ProcessorConfigSettings: component.NewProcessorConfigSettings(component.NewID(typeStr)), - Timeout: 100 * time.Millisecond, - SendBatchSize: 100, + ProcessorSettings: config.NewProcessorSettings(component.NewID(typeStr)), + Timeout: 100 * time.Millisecond, + SendBatchSize: 100, } requestCount := 5 logsPerRequest := 10 @@ -792,9 +793,9 @@ func TestBatchLogsProcessor_Timeout(t *testing.T) { func TestBatchLogProcessor_Shutdown(t *testing.T) { cfg := Config{ - ProcessorConfigSettings: component.NewProcessorConfigSettings(component.NewID(typeStr)), - Timeout: 3 * time.Second, - SendBatchSize: 1000, + ProcessorSettings: config.NewProcessorSettings(component.NewID(typeStr)), + Timeout: 3 * time.Second, + SendBatchSize: 1000, } requestCount := 5 logsPerRequest := 10 diff --git a/processor/batchprocessor/config.go b/processor/batchprocessor/config.go index 7f24259d03..664e1bbcd0 100644 --- a/processor/batchprocessor/config.go +++ b/processor/batchprocessor/config.go @@ -19,11 +19,12 @@ import ( "time" "go.opentelemetry.io/collector/component" + "go.opentelemetry.io/collector/config" ) // Config defines configuration for batch processor. type Config struct { - component.ProcessorConfigSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct + config.ProcessorSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct // Timeout sets the time after which a batch will be sent regardless of size. Timeout time.Duration `mapstructure:"timeout"` diff --git a/processor/batchprocessor/config_test.go b/processor/batchprocessor/config_test.go index fe1f9f40b0..4119714a9c 100644 --- a/processor/batchprocessor/config_test.go +++ b/processor/batchprocessor/config_test.go @@ -23,6 +23,7 @@ import ( "github.com/stretchr/testify/require" "go.opentelemetry.io/collector/component" + "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/confmap" "go.opentelemetry.io/collector/confmap/confmaptest" ) @@ -42,27 +43,27 @@ func TestUnmarshalConfig(t *testing.T) { assert.NoError(t, component.UnmarshalProcessorConfig(cm, cfg)) assert.Equal(t, &Config{ - ProcessorConfigSettings: component.NewProcessorConfigSettings(component.NewID(typeStr)), - SendBatchSize: uint32(10000), - SendBatchMaxSize: uint32(11000), - Timeout: time.Second * 10, + ProcessorSettings: config.NewProcessorSettings(component.NewID(typeStr)), + SendBatchSize: uint32(10000), + SendBatchMaxSize: uint32(11000), + Timeout: time.Second * 10, }, cfg) } func TestValidateConfig_DefaultBatchMaxSize(t *testing.T) { cfg := &Config{ - ProcessorConfigSettings: component.NewProcessorConfigSettings(component.NewIDWithName(typeStr, "2")), - SendBatchSize: 100, - SendBatchMaxSize: 0, + ProcessorSettings: config.NewProcessorSettings(component.NewIDWithName(typeStr, "2")), + SendBatchSize: 100, + SendBatchMaxSize: 0, } assert.NoError(t, cfg.Validate()) } func TestValidateConfig_ValidBatchSizes(t *testing.T) { cfg := &Config{ - ProcessorConfigSettings: component.NewProcessorConfigSettings(component.NewIDWithName(typeStr, "2")), - SendBatchSize: 100, - SendBatchMaxSize: 1000, + ProcessorSettings: config.NewProcessorSettings(component.NewIDWithName(typeStr, "2")), + SendBatchSize: 100, + SendBatchMaxSize: 1000, } assert.NoError(t, cfg.Validate()) @@ -70,9 +71,9 @@ func TestValidateConfig_ValidBatchSizes(t *testing.T) { func TestValidateConfig_InvalidBatchSize(t *testing.T) { cfg := &Config{ - ProcessorConfigSettings: component.NewProcessorConfigSettings(component.NewIDWithName(typeStr, "2")), - SendBatchSize: 1000, - SendBatchMaxSize: 100, + ProcessorSettings: config.NewProcessorSettings(component.NewIDWithName(typeStr, "2")), + SendBatchSize: 1000, + SendBatchMaxSize: 100, } assert.Error(t, cfg.Validate()) } diff --git a/processor/batchprocessor/factory.go b/processor/batchprocessor/factory.go index 2ba5253a28..d8da53ee9f 100644 --- a/processor/batchprocessor/factory.go +++ b/processor/batchprocessor/factory.go @@ -19,6 +19,7 @@ import ( "time" "go.opentelemetry.io/collector/component" + "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/consumer" ) @@ -42,9 +43,9 @@ func NewFactory() component.ProcessorFactory { func createDefaultConfig() component.ProcessorConfig { return &Config{ - ProcessorConfigSettings: component.NewProcessorConfigSettings(component.NewID(typeStr)), - SendBatchSize: defaultSendBatchSize, - Timeout: defaultTimeout, + ProcessorSettings: config.NewProcessorSettings(component.NewID(typeStr)), + SendBatchSize: defaultSendBatchSize, + Timeout: defaultTimeout, } } diff --git a/processor/memorylimiterprocessor/config.go b/processor/memorylimiterprocessor/config.go index 372dd95180..9c7e5f2d12 100644 --- a/processor/memorylimiterprocessor/config.go +++ b/processor/memorylimiterprocessor/config.go @@ -21,11 +21,12 @@ import ( "time" "go.opentelemetry.io/collector/component" + "go.opentelemetry.io/collector/config" ) // Config defines configuration for memory memoryLimiter processor. type Config struct { - component.ProcessorConfigSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct + config.ProcessorSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct // CheckInterval is the time between measurements of memory usage for the // purposes of avoiding going over the limits. Defaults to zero, so no diff --git a/processor/memorylimiterprocessor/config_test.go b/processor/memorylimiterprocessor/config_test.go index 6d0c137caf..cedd68308e 100644 --- a/processor/memorylimiterprocessor/config_test.go +++ b/processor/memorylimiterprocessor/config_test.go @@ -23,6 +23,7 @@ import ( "github.com/stretchr/testify/require" "go.opentelemetry.io/collector/component" + "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/confmap" "go.opentelemetry.io/collector/confmap/confmaptest" ) @@ -42,9 +43,9 @@ func TestUnmarshalConfig(t *testing.T) { assert.NoError(t, component.UnmarshalProcessorConfig(cm, cfg)) assert.Equal(t, &Config{ - ProcessorConfigSettings: component.NewProcessorConfigSettings(component.NewID(typeStr)), - CheckInterval: 5 * time.Second, - MemoryLimitMiB: 4000, - MemorySpikeLimitMiB: 500, + ProcessorSettings: config.NewProcessorSettings(component.NewID(typeStr)), + CheckInterval: 5 * time.Second, + MemoryLimitMiB: 4000, + MemorySpikeLimitMiB: 500, }, cfg) } diff --git a/processor/memorylimiterprocessor/factory.go b/processor/memorylimiterprocessor/factory.go index 0d634f2163..735b77bc23 100644 --- a/processor/memorylimiterprocessor/factory.go +++ b/processor/memorylimiterprocessor/factory.go @@ -19,6 +19,7 @@ import ( "sync" "go.opentelemetry.io/collector/component" + "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/consumer" "go.opentelemetry.io/collector/processor/processorhelper" ) @@ -54,7 +55,7 @@ func NewFactory() component.ProcessorFactory { // that the default configuration is expected to fail for this processor. func createDefaultConfig() component.ProcessorConfig { return &Config{ - ProcessorConfigSettings: component.NewProcessorConfigSettings(component.NewID(typeStr)), + ProcessorSettings: config.NewProcessorSettings(component.NewID(typeStr)), } } diff --git a/processor/memorylimiterprocessor/memorylimiter_test.go b/processor/memorylimiterprocessor/memorylimiter_test.go index 7ac21d6065..609614e13c 100644 --- a/processor/memorylimiterprocessor/memorylimiter_test.go +++ b/processor/memorylimiterprocessor/memorylimiter_test.go @@ -27,6 +27,7 @@ import ( "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/component/componenttest" + "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/config/configtelemetry" "go.opentelemetry.io/collector/consumer" "go.opentelemetry.io/collector/consumer/consumertest" @@ -122,7 +123,7 @@ func TestMetricsMemoryPressureResponse(t *testing.T) { context.Background(), componenttest.NewNopProcessorCreateSettings(), &Config{ - ProcessorConfigSettings: component.NewProcessorConfigSettings(component.NewID(typeStr)), + ProcessorSettings: config.NewProcessorSettings(component.NewID(typeStr)), }, consumertest.NewNop(), ml.processMetrics, @@ -193,7 +194,7 @@ func TestTraceMemoryPressureResponse(t *testing.T) { context.Background(), componenttest.NewNopProcessorCreateSettings(), &Config{ - ProcessorConfigSettings: component.NewProcessorConfigSettings(component.NewID(typeStr)), + ProcessorSettings: config.NewProcessorSettings(component.NewID(typeStr)), }, consumertest.NewNop(), ml.processTraces, @@ -264,7 +265,7 @@ func TestLogMemoryPressureResponse(t *testing.T) { context.Background(), componenttest.NewNopProcessorCreateSettings(), &Config{ - ProcessorConfigSettings: component.NewProcessorConfigSettings(component.NewID(typeStr)), + ProcessorSettings: config.NewProcessorSettings(component.NewID(typeStr)), }, consumertest.NewNop(), ml.processLogs, diff --git a/processor/processorhelper/logs_test.go b/processor/processorhelper/logs_test.go index ee0f570109..2f8848e117 100644 --- a/processor/processorhelper/logs_test.go +++ b/processor/processorhelper/logs_test.go @@ -24,12 +24,13 @@ import ( "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/component/componenttest" + "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/consumer" "go.opentelemetry.io/collector/consumer/consumertest" "go.opentelemetry.io/collector/pdata/plog" ) -var testLogsCfg = component.NewProcessorConfigSettings(component.NewID("test")) +var testLogsCfg = config.NewProcessorSettings(component.NewID("test")) func TestNewLogsProcessor(t *testing.T) { lp, err := NewLogsProcessor(context.Background(), componenttest.NewNopProcessorCreateSettings(), &testLogsCfg, consumertest.NewNop(), newTestLProcessor(nil)) diff --git a/processor/processorhelper/metrics_test.go b/processor/processorhelper/metrics_test.go index cfe3be03d4..4ae83bfd67 100644 --- a/processor/processorhelper/metrics_test.go +++ b/processor/processorhelper/metrics_test.go @@ -24,12 +24,13 @@ import ( "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/component/componenttest" + "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/consumer" "go.opentelemetry.io/collector/consumer/consumertest" "go.opentelemetry.io/collector/pdata/pmetric" ) -var testMetricsCfg = component.NewProcessorConfigSettings(component.NewID("test")) +var testMetricsCfg = config.NewProcessorSettings(component.NewID("test")) func TestNewMetricsProcessor(t *testing.T) { mp, err := NewMetricsProcessor(context.Background(), componenttest.NewNopProcessorCreateSettings(), &testMetricsCfg, consumertest.NewNop(), newTestMProcessor(nil)) diff --git a/processor/processorhelper/traces_test.go b/processor/processorhelper/traces_test.go index 8aaf81adc2..045d5de413 100644 --- a/processor/processorhelper/traces_test.go +++ b/processor/processorhelper/traces_test.go @@ -24,12 +24,13 @@ import ( "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/component/componenttest" + "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/consumer" "go.opentelemetry.io/collector/consumer/consumertest" "go.opentelemetry.io/collector/pdata/ptrace" ) -var testTracesCfg = component.NewProcessorConfigSettings(component.NewID("test")) +var testTracesCfg = config.NewProcessorSettings(component.NewID("test")) func TestNewTracesProcessor(t *testing.T) { tp, err := NewTracesProcessor(context.Background(), componenttest.NewNopProcessorCreateSettings(), &testTracesCfg, consumertest.NewNop(), newTestTProcessor(nil)) diff --git a/receiver/otlpreceiver/config.go b/receiver/otlpreceiver/config.go index 911d61e4a7..78bdde3c2d 100644 --- a/receiver/otlpreceiver/config.go +++ b/receiver/otlpreceiver/config.go @@ -18,6 +18,7 @@ import ( "errors" "go.opentelemetry.io/collector/component" + "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/config/configgrpc" "go.opentelemetry.io/collector/config/confighttp" "go.opentelemetry.io/collector/confmap" @@ -38,7 +39,7 @@ type Protocols struct { // Config defines configuration for OTLP receiver. type Config struct { - component.ReceiverConfigSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct + config.ReceiverSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct // Protocols is the configuration for the supported protocols, currently gRPC and HTTP (Proto and JSON). Protocols `mapstructure:"protocols"` } diff --git a/receiver/otlpreceiver/config_test.go b/receiver/otlpreceiver/config_test.go index e72518faf0..c54008b636 100644 --- a/receiver/otlpreceiver/config_test.go +++ b/receiver/otlpreceiver/config_test.go @@ -23,6 +23,7 @@ import ( "github.com/stretchr/testify/require" "go.opentelemetry.io/collector/component" + "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/config/configgrpc" "go.opentelemetry.io/collector/config/confighttp" "go.opentelemetry.io/collector/config/confignet" @@ -96,7 +97,7 @@ func TestUnmarshalConfig(t *testing.T) { assert.NoError(t, component.UnmarshalReceiverConfig(cm, cfg)) assert.Equal(t, &Config{ - ReceiverConfigSettings: component.NewReceiverConfigSettings(component.NewID(typeStr)), + ReceiverSettings: config.NewReceiverSettings(component.NewID(typeStr)), Protocols: Protocols{ GRPC: &configgrpc.GRPCServerSettings{ NetAddr: confignet.NetAddr{ @@ -153,7 +154,7 @@ func TestUnmarshalConfigUnix(t *testing.T) { assert.NoError(t, component.UnmarshalReceiverConfig(cm, cfg)) assert.Equal(t, &Config{ - ReceiverConfigSettings: component.NewReceiverConfigSettings(component.NewID(typeStr)), + ReceiverSettings: config.NewReceiverSettings(component.NewID(typeStr)), Protocols: Protocols{ GRPC: &configgrpc.GRPCServerSettings{ NetAddr: confignet.NetAddr{ diff --git a/receiver/otlpreceiver/factory.go b/receiver/otlpreceiver/factory.go index 9d78608e51..475d700b3d 100644 --- a/receiver/otlpreceiver/factory.go +++ b/receiver/otlpreceiver/factory.go @@ -18,6 +18,7 @@ import ( "context" "go.opentelemetry.io/collector/component" + "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/config/configgrpc" "go.opentelemetry.io/collector/config/confighttp" "go.opentelemetry.io/collector/config/confignet" @@ -45,7 +46,7 @@ func NewFactory() component.ReceiverFactory { // createDefaultConfig creates the default configuration for receiver. func createDefaultConfig() component.ReceiverConfig { return &Config{ - ReceiverConfigSettings: component.NewReceiverConfigSettings(component.NewID(typeStr)), + ReceiverSettings: config.NewReceiverSettings(component.NewID(typeStr)), Protocols: Protocols{ GRPC: &configgrpc.GRPCServerSettings{ NetAddr: confignet.NetAddr{ diff --git a/receiver/otlpreceiver/factory_test.go b/receiver/otlpreceiver/factory_test.go index 142a12d3a6..aae87b8325 100644 --- a/receiver/otlpreceiver/factory_test.go +++ b/receiver/otlpreceiver/factory_test.go @@ -23,6 +23,7 @@ import ( "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/component/componenttest" + "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/config/configgrpc" "go.opentelemetry.io/collector/config/confighttp" "go.opentelemetry.io/collector/config/confignet" @@ -74,7 +75,7 @@ func TestCreateTracesReceiver(t *testing.T) { { name: "default", cfg: &Config{ - ReceiverConfigSettings: component.NewReceiverConfigSettings(component.NewID(typeStr)), + ReceiverSettings: config.NewReceiverSettings(component.NewID(typeStr)), Protocols: Protocols{ GRPC: defaultGRPCSettings, HTTP: defaultHTTPSettings, @@ -84,7 +85,7 @@ func TestCreateTracesReceiver(t *testing.T) { { name: "invalid_grpc_port", cfg: &Config{ - ReceiverConfigSettings: component.NewReceiverConfigSettings(component.NewID(typeStr)), + ReceiverSettings: config.NewReceiverSettings(component.NewID(typeStr)), Protocols: Protocols{ GRPC: &configgrpc.GRPCServerSettings{ NetAddr: confignet.NetAddr{ @@ -100,7 +101,7 @@ func TestCreateTracesReceiver(t *testing.T) { { name: "invalid_http_port", cfg: &Config{ - ReceiverConfigSettings: component.NewReceiverConfigSettings(component.NewID(typeStr)), + ReceiverSettings: config.NewReceiverSettings(component.NewID(typeStr)), Protocols: Protocols{ GRPC: defaultGRPCSettings, HTTP: &confighttp.HTTPServerSettings{ @@ -150,7 +151,7 @@ func TestCreateMetricReceiver(t *testing.T) { { name: "default", cfg: &Config{ - ReceiverConfigSettings: component.NewReceiverConfigSettings(component.NewID(typeStr)), + ReceiverSettings: config.NewReceiverSettings(component.NewID(typeStr)), Protocols: Protocols{ GRPC: defaultGRPCSettings, HTTP: defaultHTTPSettings, @@ -160,7 +161,7 @@ func TestCreateMetricReceiver(t *testing.T) { { name: "invalid_grpc_address", cfg: &Config{ - ReceiverConfigSettings: component.NewReceiverConfigSettings(component.NewID(typeStr)), + ReceiverSettings: config.NewReceiverSettings(component.NewID(typeStr)), Protocols: Protocols{ GRPC: &configgrpc.GRPCServerSettings{ NetAddr: confignet.NetAddr{ @@ -176,7 +177,7 @@ func TestCreateMetricReceiver(t *testing.T) { { name: "invalid_http_address", cfg: &Config{ - ReceiverConfigSettings: component.NewReceiverConfigSettings(component.NewID(typeStr)), + ReceiverSettings: config.NewReceiverSettings(component.NewID(typeStr)), Protocols: Protocols{ GRPC: defaultGRPCSettings, HTTP: &confighttp.HTTPServerSettings{ @@ -227,7 +228,7 @@ func TestCreateLogReceiver(t *testing.T) { { name: "default", cfg: &Config{ - ReceiverConfigSettings: component.NewReceiverConfigSettings(component.NewID(typeStr)), + ReceiverSettings: config.NewReceiverSettings(component.NewID(typeStr)), Protocols: Protocols{ GRPC: defaultGRPCSettings, HTTP: defaultHTTPSettings, @@ -238,7 +239,7 @@ func TestCreateLogReceiver(t *testing.T) { { name: "invalid_grpc_address", cfg: &Config{ - ReceiverConfigSettings: component.NewReceiverConfigSettings(component.NewID(typeStr)), + ReceiverSettings: config.NewReceiverSettings(component.NewID(typeStr)), Protocols: Protocols{ GRPC: &configgrpc.GRPCServerSettings{ NetAddr: confignet.NetAddr{ @@ -255,7 +256,7 @@ func TestCreateLogReceiver(t *testing.T) { { name: "invalid_http_address", cfg: &Config{ - ReceiverConfigSettings: component.NewReceiverConfigSettings(component.NewID(typeStr)), + ReceiverSettings: config.NewReceiverSettings(component.NewID(typeStr)), Protocols: Protocols{ GRPC: defaultGRPCSettings, HTTP: &confighttp.HTTPServerSettings{ @@ -269,7 +270,7 @@ func TestCreateLogReceiver(t *testing.T) { { name: "no_next_consumer", cfg: &Config{ - ReceiverConfigSettings: component.NewReceiverConfigSettings(component.NewID(typeStr)), + ReceiverSettings: config.NewReceiverSettings(component.NewID(typeStr)), Protocols: Protocols{ GRPC: defaultGRPCSettings, HTTP: &confighttp.HTTPServerSettings{ @@ -283,8 +284,8 @@ func TestCreateLogReceiver(t *testing.T) { { name: "no_http_or_grcp_config", cfg: &Config{ - ReceiverConfigSettings: component.NewReceiverConfigSettings(component.NewID(typeStr)), - Protocols: Protocols{}, + ReceiverSettings: config.NewReceiverSettings(component.NewID(typeStr)), + Protocols: Protocols{}, }, wantErr: false, sink: new(consumertest.LogsSink), diff --git a/receiver/otlpreceiver/otlp_test.go b/receiver/otlpreceiver/otlp_test.go index 687a1ea8f7..e46ac72eb0 100644 --- a/receiver/otlpreceiver/otlp_test.go +++ b/receiver/otlpreceiver/otlp_test.go @@ -39,6 +39,7 @@ import ( "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/component/componenttest" + "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/config/configgrpc" "go.opentelemetry.io/collector/config/confighttp" "go.opentelemetry.io/collector/config/confignet" @@ -183,8 +184,8 @@ func TestJsonHttp(t *testing.T) { func TestHandleInvalidRequests(t *testing.T) { endpoint := testutil.GetAvailableLocalAddress(t) cfg := &Config{ - ReceiverConfigSettings: component.NewReceiverConfigSettings(component.NewID(typeStr)), - Protocols: Protocols{HTTP: &confighttp.HTTPServerSettings{Endpoint: endpoint}}, + ReceiverSettings: config.NewReceiverSettings(component.NewID(typeStr)), + Protocols: Protocols{HTTP: &confighttp.HTTPServerSettings{Endpoint: endpoint}}, } // Traces @@ -707,7 +708,7 @@ func TestOTLPReceiverTrace_HandleNextConsumerResponse(t *testing.T) { func TestGRPCInvalidTLSCredentials(t *testing.T) { cfg := &Config{ - ReceiverConfigSettings: component.NewReceiverConfigSettings(component.NewID(typeStr)), + ReceiverSettings: config.NewReceiverSettings(component.NewID(typeStr)), Protocols: Protocols{ GRPC: &configgrpc.GRPCServerSettings{ NetAddr: confignet.NetAddr{ @@ -778,7 +779,7 @@ func TestGRPCMaxRecvSize(t *testing.T) { func TestHTTPInvalidTLSCredentials(t *testing.T) { cfg := &Config{ - ReceiverConfigSettings: component.NewReceiverConfigSettings(component.NewID(typeStr)), + ReceiverSettings: config.NewReceiverSettings(component.NewID(typeStr)), Protocols: Protocols{ HTTP: &confighttp.HTTPServerSettings{ Endpoint: testutil.GetAvailableLocalAddress(t), @@ -807,7 +808,7 @@ func testHTTPMaxRequestBodySizeJSON(t *testing.T, payload []byte, size int, expe endpoint := testutil.GetAvailableLocalAddress(t) url := fmt.Sprintf("http://%s/v1/traces", endpoint) cfg := &Config{ - ReceiverConfigSettings: component.NewReceiverConfigSettings(component.NewID(typeStr)), + ReceiverSettings: config.NewReceiverSettings(component.NewID(typeStr)), Protocols: Protocols{ HTTP: &confighttp.HTTPServerSettings{ Endpoint: endpoint, diff --git a/receiver/scraperhelper/scrapercontroller.go b/receiver/scraperhelper/scrapercontroller.go index d426a8e198..5fcb893c8c 100644 --- a/receiver/scraperhelper/scrapercontroller.go +++ b/receiver/scraperhelper/scrapercontroller.go @@ -23,6 +23,7 @@ import ( "go.uber.org/zap" "go.opentelemetry.io/collector/component" + "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/consumer" "go.opentelemetry.io/collector/obsreport" "go.opentelemetry.io/collector/pdata/pmetric" @@ -31,18 +32,18 @@ import ( // ScraperControllerSettings defines common settings for a scraper controller // configuration. Scraper controller receivers can embed this struct, instead -// of component.ReceiverConfigSettings, and extend it with more fields if needed. +// of component.ReceiverSettings, and extend it with more fields if needed. type ScraperControllerSettings struct { - component.ReceiverConfigSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct - CollectionInterval time.Duration `mapstructure:"collection_interval"` + config.ReceiverSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct + CollectionInterval time.Duration `mapstructure:"collection_interval"` } // NewDefaultScraperControllerSettings returns default scraper controller // settings with a collection interval of one minute. func NewDefaultScraperControllerSettings(cfgType component.Type) ScraperControllerSettings { return ScraperControllerSettings{ - ReceiverConfigSettings: component.NewReceiverConfigSettings(component.NewID(cfgType)), - CollectionInterval: time.Minute, + ReceiverSettings: config.NewReceiverSettings(component.NewID(cfgType)), + CollectionInterval: time.Minute, } } diff --git a/service/config_test.go b/service/config_test.go index 1463c5771a..6c14118d7e 100644 --- a/service/config_test.go +++ b/service/config_test.go @@ -23,6 +23,7 @@ import ( "go.uber.org/zap/zapcore" "go.opentelemetry.io/collector/component" + "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/config/configtelemetry" "go.opentelemetry.io/collector/service/telemetry" ) @@ -35,7 +36,7 @@ var ( ) type nopRecvConfig struct { - component.ReceiverConfigSettings + config.ReceiverSettings validateErr error } @@ -44,7 +45,7 @@ func (nc *nopRecvConfig) Validate() error { } type nopExpConfig struct { - component.ExporterConfigSettings + config.ExporterSettings validateErr error } @@ -53,7 +54,7 @@ func (nc *nopExpConfig) Validate() error { } type nopProcConfig struct { - component.ProcessorConfigSettings + config.ProcessorSettings validateErr error } @@ -62,7 +63,7 @@ func (nc *nopProcConfig) Validate() error { } type nopExtConfig struct { - component.ExtensionConfigSettings + config.ExtensionSettings validateErr error } @@ -181,8 +182,8 @@ func TestConfigValidate(t *testing.T) { cfgFn: func() *Config { cfg := generateConfig() cfg.Receivers[component.NewID("nop")] = &nopRecvConfig{ - ReceiverConfigSettings: component.NewReceiverConfigSettings(component.NewID("nop")), - validateErr: errInvalidRecvConfig, + ReceiverSettings: config.NewReceiverSettings(component.NewID("nop")), + validateErr: errInvalidRecvConfig, } return cfg }, @@ -193,8 +194,8 @@ func TestConfigValidate(t *testing.T) { cfgFn: func() *Config { cfg := generateConfig() cfg.Exporters[component.NewID("nop")] = &nopExpConfig{ - ExporterConfigSettings: component.NewExporterConfigSettings(component.NewID("nop")), - validateErr: errInvalidExpConfig, + ExporterSettings: config.NewExporterSettings(component.NewID("nop")), + validateErr: errInvalidExpConfig, } return cfg }, @@ -205,8 +206,8 @@ func TestConfigValidate(t *testing.T) { cfgFn: func() *Config { cfg := generateConfig() cfg.Processors[component.NewID("nop")] = &nopProcConfig{ - ProcessorConfigSettings: component.NewProcessorConfigSettings(component.NewID("nop")), - validateErr: errInvalidProcConfig, + ProcessorSettings: config.NewProcessorSettings(component.NewID("nop")), + validateErr: errInvalidProcConfig, } return cfg }, @@ -217,8 +218,8 @@ func TestConfigValidate(t *testing.T) { cfgFn: func() *Config { cfg := generateConfig() cfg.Extensions[component.NewID("nop")] = &nopExtConfig{ - ExtensionConfigSettings: component.NewExtensionConfigSettings(component.NewID("nop")), - validateErr: errInvalidExtConfig, + ExtensionSettings: config.NewExtensionSettings(component.NewID("nop")), + validateErr: errInvalidExtConfig, } return cfg }, @@ -251,22 +252,22 @@ func generateConfig() *Config { return &Config{ Receivers: map[component.ID]component.ReceiverConfig{ component.NewID("nop"): &nopRecvConfig{ - ReceiverConfigSettings: component.NewReceiverConfigSettings(component.NewID("nop")), + ReceiverSettings: config.NewReceiverSettings(component.NewID("nop")), }, }, Exporters: map[component.ID]component.ExporterConfig{ component.NewID("nop"): &nopExpConfig{ - ExporterConfigSettings: component.NewExporterConfigSettings(component.NewID("nop")), + ExporterSettings: config.NewExporterSettings(component.NewID("nop")), }, }, Processors: map[component.ID]component.ProcessorConfig{ component.NewID("nop"): &nopProcConfig{ - ProcessorConfigSettings: component.NewProcessorConfigSettings(component.NewID("nop")), + ProcessorSettings: config.NewProcessorSettings(component.NewID("nop")), }, }, Extensions: map[component.ID]component.ExtensionConfig{ component.NewID("nop"): &nopExtConfig{ - ExtensionConfigSettings: component.NewExtensionConfigSettings(component.NewID("nop")), + ExtensionSettings: config.NewExtensionSettings(component.NewID("nop")), }, }, Service: ConfigService{ diff --git a/service/extensions/extensions_test.go b/service/extensions/extensions_test.go index 8691f10c48..05e7622951 100644 --- a/service/extensions/extensions_test.go +++ b/service/extensions/extensions_test.go @@ -24,6 +24,7 @@ import ( "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/component/componenttest" + "go.opentelemetry.io/collector/config" ) func TestBuildExtensions(t *testing.T) { @@ -109,9 +110,9 @@ func newBadExtensionFactory() component.ExtensionFactory { "bf", func() component.ExtensionConfig { return &struct { - component.ExtensionConfigSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct + config.ExtensionSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct }{ - ExtensionConfigSettings: component.NewExtensionConfigSettings(component.NewID("bf")), + ExtensionSettings: config.NewExtensionSettings(component.NewID("bf")), } }, func(ctx context.Context, set component.ExtensionCreateSettings, extension component.ExtensionConfig) (component.Extension, error) { @@ -126,9 +127,9 @@ func newCreateErrorExtensionFactory() component.ExtensionFactory { "err", func() component.ExtensionConfig { return &struct { - component.ExtensionConfigSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct + config.ExtensionSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct }{ - ExtensionConfigSettings: component.NewExtensionConfigSettings(component.NewID("err")), + ExtensionSettings: config.NewExtensionSettings(component.NewID("err")), } }, func(ctx context.Context, set component.ExtensionCreateSettings, extension component.ExtensionConfig) (component.Extension, error) { diff --git a/service/internal/pipelines/pipelines_test.go b/service/internal/pipelines/pipelines_test.go index 4f991ead2c..921abff2c3 100644 --- a/service/internal/pipelines/pipelines_test.go +++ b/service/internal/pipelines/pipelines_test.go @@ -348,9 +348,9 @@ func TestFailToStartAndShutdown(t *testing.T) { func newBadReceiverFactory() component.ReceiverFactory { return component.NewReceiverFactory("bf", func() component.ReceiverConfig { return &struct { - component.ReceiverConfigSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct + config.ReceiverSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct }{ - ReceiverConfigSettings: component.NewReceiverConfigSettings(component.NewID("bf")), + ReceiverSettings: config.NewReceiverSettings(component.NewID("bf")), } }) } @@ -358,9 +358,9 @@ func newBadReceiverFactory() component.ReceiverFactory { func newBadProcessorFactory() component.ProcessorFactory { return component.NewProcessorFactory("bf", func() component.ProcessorConfig { return &struct { - component.ProcessorConfigSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct + config.ProcessorSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct }{ - ProcessorConfigSettings: component.NewProcessorConfigSettings(component.NewID("bf")), + ProcessorSettings: config.NewProcessorSettings(component.NewID("bf")), } }) } @@ -368,9 +368,9 @@ func newBadProcessorFactory() component.ProcessorFactory { func newBadExporterFactory() component.ExporterFactory { return component.NewExporterFactory("bf", func() component.ExporterConfig { return &struct { - component.ExporterConfigSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct + config.ExporterSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct }{ - ExporterConfigSettings: component.NewExporterConfigSettings(component.NewID("bf")), + ExporterSettings: config.NewExporterSettings(component.NewID("bf")), } }) } @@ -378,9 +378,9 @@ func newBadExporterFactory() component.ExporterFactory { func newErrReceiverFactory() component.ReceiverFactory { return component.NewReceiverFactory("err", func() component.ReceiverConfig { return &struct { - component.ReceiverConfigSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct + config.ReceiverSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct }{ - ReceiverConfigSettings: component.NewReceiverConfigSettings(component.NewID("bf")), + ReceiverSettings: config.NewReceiverSettings(component.NewID("bf")), } }, component.WithTracesReceiver(func(context.Context, component.ReceiverCreateSettings, component.ReceiverConfig, consumer.Traces) (component.TracesReceiver, error) { @@ -398,9 +398,9 @@ func newErrReceiverFactory() component.ReceiverFactory { func newErrProcessorFactory() component.ProcessorFactory { return component.NewProcessorFactory("err", func() component.ProcessorConfig { return &struct { - component.ProcessorConfigSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct + config.ProcessorSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct }{ - ProcessorConfigSettings: component.NewProcessorConfigSettings(component.NewID("bf")), + ProcessorSettings: config.NewProcessorSettings(component.NewID("bf")), } }, component.WithTracesProcessor(func(context.Context, component.ProcessorCreateSettings, component.ProcessorConfig, consumer.Traces) (component.TracesProcessor, error) { @@ -418,9 +418,9 @@ func newErrProcessorFactory() component.ProcessorFactory { func newErrExporterFactory() component.ExporterFactory { return component.NewExporterFactory("err", func() component.ExporterConfig { return &struct { - component.ExporterConfigSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct + config.ExporterSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct }{ - ExporterConfigSettings: component.NewExporterConfigSettings(component.NewID("bf")), + ExporterSettings: config.NewExporterSettings(component.NewID("bf")), } }, component.WithTracesExporter(func(context.Context, component.ExporterCreateSettings, component.ExporterConfig) (component.TracesExporter, error) { diff --git a/service/internal/testcomponents/example_exporter.go b/service/internal/testcomponents/example_exporter.go index c44d666f6d..722dddc9b1 100644 --- a/service/internal/testcomponents/example_exporter.go +++ b/service/internal/testcomponents/example_exporter.go @@ -18,6 +18,7 @@ import ( "context" "go.opentelemetry.io/collector/component" + "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/consumer" "go.opentelemetry.io/collector/pdata/plog" "go.opentelemetry.io/collector/pdata/pmetric" @@ -31,7 +32,7 @@ const ( // ExampleExporterConfig config for ExampleExporter. type ExampleExporterConfig struct { - component.ExporterConfigSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct + config.ExporterSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct } // ExampleExporterFactory is factory for ExampleExporter. @@ -45,7 +46,7 @@ var ExampleExporterFactory = component.NewExporterFactory( func createExporterDefaultConfig() component.ExporterConfig { return &ExampleExporterConfig{ - ExporterConfigSettings: component.NewExporterConfigSettings(component.NewID(typeStr)), + ExporterSettings: config.NewExporterSettings(component.NewID(typeStr)), } } diff --git a/service/internal/testcomponents/example_processor.go b/service/internal/testcomponents/example_processor.go index bf32030daf..8ea683c70c 100644 --- a/service/internal/testcomponents/example_processor.go +++ b/service/internal/testcomponents/example_processor.go @@ -18,6 +18,7 @@ import ( "context" "go.opentelemetry.io/collector/component" + "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/consumer" ) @@ -25,7 +26,7 @@ const procType = "exampleprocessor" // ExampleProcessorConfig config for ExampleProcessor. type ExampleProcessorConfig struct { - component.ProcessorConfigSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct + config.ProcessorSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct } // ExampleProcessorFactory is factory for ExampleProcessor. @@ -39,7 +40,7 @@ var ExampleProcessorFactory = component.NewProcessorFactory( // CreateDefaultConfig creates the default configuration for the Processor. func createDefaultConfig() component.ProcessorConfig { return &ExampleProcessorConfig{ - ProcessorConfigSettings: component.NewProcessorConfigSettings(component.NewID(procType)), + ProcessorSettings: config.NewProcessorSettings(component.NewID(procType)), } } diff --git a/service/internal/testcomponents/example_receiver.go b/service/internal/testcomponents/example_receiver.go index 7a1b4cc2c9..4351f7b360 100644 --- a/service/internal/testcomponents/example_receiver.go +++ b/service/internal/testcomponents/example_receiver.go @@ -18,6 +18,7 @@ import ( "context" "go.opentelemetry.io/collector/component" + "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/consumer" ) @@ -25,7 +26,7 @@ const receiverType = component.Type("examplereceiver") // ExampleReceiverConfig config for ExampleReceiver. type ExampleReceiverConfig struct { - component.ReceiverConfigSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct + config.ReceiverSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct } // ExampleReceiverFactory is factory for ExampleReceiver. @@ -38,7 +39,7 @@ var ExampleReceiverFactory = component.NewReceiverFactory( func createReceiverDefaultConfig() component.ReceiverConfig { return &ExampleReceiverConfig{ - ReceiverConfigSettings: component.NewReceiverConfigSettings(component.NewID(receiverType)), + ReceiverSettings: config.NewReceiverSettings(component.NewID(receiverType)), } }