diff --git a/config/exporter.go b/config/exporter.go index 7cb7b2ff6d2..80e2672df54 100644 --- a/config/exporter.go +++ b/config/exporter.go @@ -24,11 +24,17 @@ type Exporters map[string]Exporter // ExporterSettings defines common settings for an exporter configuration. // Specific exporters can embed this struct and extend it with more fields if needed. +// When embedded in the exporter config it must be with `mapstructure:"-"` tag. type ExporterSettings struct { TypeVal Type `mapstructure:"-"` NameVal string `mapstructure:"-"` } +// NewExporterSettings return a new ExporterSettings with the given type. +func NewExporterSettings(typeVal Type) *ExporterSettings { + return &ExporterSettings{TypeVal: typeVal, NameVal: string(typeVal)} +} + var _ Exporter = (*ExporterSettings)(nil) // Name gets the exporter name. diff --git a/config/extension.go b/config/extension.go index 0c1afb4654b..f8666cbbe3e 100644 --- a/config/extension.go +++ b/config/extension.go @@ -24,13 +24,19 @@ type Extension interface { // Extensions is a map of names to extensions. type Extensions map[string]Extension -// ExtensionSettings defines common settings for a service extension configuration. +// ExtensionSettings defines common settings for a extension configuration. // Specific extensions can embed this struct and extend it with more fields if needed. +// When embedded in the extension config it must be with `mapstructure:"-"` tag. type ExtensionSettings struct { TypeVal Type `mapstructure:"-"` NameVal string `mapstructure:"-"` } +// NewExtensionSettings return a new ExtensionSettings with the given type. +func NewExtensionSettings(typeVal Type) *ExtensionSettings { + return &ExtensionSettings{TypeVal: typeVal, NameVal: string(typeVal)} +} + var _ Extension = (*ExtensionSettings)(nil) // Name gets the extension name. diff --git a/config/processor.go b/config/processor.go index ec416e92f04..c511fe7c7b9 100644 --- a/config/processor.go +++ b/config/processor.go @@ -25,11 +25,17 @@ type Processors map[string]Processor // ProcessorSettings defines common settings for a processor configuration. // Specific processors can embed this struct and extend it with more fields if needed. +// When embedded in the processor config it must be with `mapstructure:"-"` tag. type ProcessorSettings struct { TypeVal Type `mapstructure:"-"` NameVal string `mapstructure:"-"` } +// NewProcessorSettings return a new ProcessorSettings with the given type. +func NewProcessorSettings(typeVal Type) *ProcessorSettings { + return &ProcessorSettings{TypeVal: typeVal, NameVal: string(typeVal)} +} + var _ Processor = (*ProcessorSettings)(nil) // Name gets the processor name. diff --git a/config/receiver.go b/config/receiver.go index 155fa3455b3..5e01c3dab24 100644 --- a/config/receiver.go +++ b/config/receiver.go @@ -28,6 +28,7 @@ type Receivers map[string]Receiver // ReceiverSettings defines common settings for a 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 processor config it must be with `mapstructure:"-"` tag. type ReceiverSettings struct { TypeVal Type `mapstructure:"-"` NameVal string `mapstructure:"-"` diff --git a/exporter/fileexporter/config.go b/exporter/fileexporter/config.go index 820bbba8aba..042ace1cab1 100644 --- a/exporter/fileexporter/config.go +++ b/exporter/fileexporter/config.go @@ -20,7 +20,7 @@ import ( // Config defines configuration for file exporter. type Config struct { - config.ExporterSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct. + *config.ExporterSettings `mapstructure:"-"` // Path of the file to write to. Path is relative to current directory. Path string `mapstructure:"path"` diff --git a/exporter/fileexporter/config_test.go b/exporter/fileexporter/config_test.go index 0fc858a96f0..1a616408266 100644 --- a/exporter/fileexporter/config_test.go +++ b/exporter/fileexporter/config_test.go @@ -43,7 +43,7 @@ func TestLoadConfig(t *testing.T) { e1 := cfg.Exporters["file/2"] assert.Equal(t, e1, &Config{ - ExporterSettings: config.ExporterSettings{ + ExporterSettings: &config.ExporterSettings{ NameVal: "file/2", TypeVal: "file", }, diff --git a/exporter/fileexporter/factory.go b/exporter/fileexporter/factory.go index bb2d6e447ff..dc43a5a55b6 100644 --- a/exporter/fileexporter/factory.go +++ b/exporter/fileexporter/factory.go @@ -40,10 +40,7 @@ func NewFactory() component.ExporterFactory { func createDefaultConfig() config.Exporter { return &Config{ - ExporterSettings: config.ExporterSettings{ - TypeVal: typeStr, - NameVal: typeStr, - }, + ExporterSettings: config.NewExporterSettings(typeStr), } } diff --git a/exporter/jaegerexporter/config.go b/exporter/jaegerexporter/config.go index 25c9c189e5a..22bb4eb635c 100644 --- a/exporter/jaegerexporter/config.go +++ b/exporter/jaegerexporter/config.go @@ -22,7 +22,7 @@ import ( // Config defines configuration for Jaeger gRPC exporter. type Config struct { - config.ExporterSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct. + *config.ExporterSettings `mapstructure:"-"` exporterhelper.TimeoutSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct. exporterhelper.QueueSettings `mapstructure:"sending_queue"` exporterhelper.RetrySettings `mapstructure:"retry_on_failure"` diff --git a/exporter/jaegerexporter/config_test.go b/exporter/jaegerexporter/config_test.go index 347d73db317..b104cb8d438 100644 --- a/exporter/jaegerexporter/config_test.go +++ b/exporter/jaegerexporter/config_test.go @@ -49,7 +49,7 @@ func TestLoadConfig(t *testing.T) { e1 := cfg.Exporters["jaeger/2"] assert.Equal(t, e1, &Config{ - ExporterSettings: config.ExporterSettings{ + ExporterSettings: &config.ExporterSettings{ NameVal: "jaeger/2", TypeVal: "jaeger", }, diff --git a/exporter/jaegerexporter/exporter_test.go b/exporter/jaegerexporter/exporter_test.go index 503533cebfd..1f155d55dd7 100644 --- a/exporter/jaegerexporter/exporter_test.go +++ b/exporter/jaegerexporter/exporter_test.go @@ -33,6 +33,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/configtls" "go.opentelemetry.io/collector/consumer/pdata" @@ -52,6 +53,7 @@ func TestNew(t *testing.T) { name: "createExporter", args: args{ config: Config{ + ExporterSettings: config.NewExporterSettings(typeStr), GRPCClientSettings: configgrpc.GRPCClientSettings{ Headers: nil, Endpoint: "foo.bar", @@ -68,6 +70,7 @@ func TestNew(t *testing.T) { name: "createExporterWithHeaders", args: args{ config: Config{ + ExporterSettings: config.NewExporterSettings(typeStr), GRPCClientSettings: configgrpc.GRPCClientSettings{ Headers: map[string]string{"extra-header": "header-value"}, Endpoint: "foo.bar", @@ -81,6 +84,7 @@ func TestNew(t *testing.T) { name: "createBasicSecureExporter", args: args{ config: Config{ + ExporterSettings: config.NewExporterSettings(typeStr), GRPCClientSettings: configgrpc.GRPCClientSettings{ Headers: nil, Endpoint: "foo.bar", @@ -94,6 +98,7 @@ func TestNew(t *testing.T) { name: "createSecureExporterWithClientTLS", args: args{ config: Config{ + ExporterSettings: config.NewExporterSettings(typeStr), GRPCClientSettings: configgrpc.GRPCClientSettings{ Headers: nil, Endpoint: "foo.bar", @@ -113,6 +118,7 @@ func TestNew(t *testing.T) { name: "createSecureExporterWithKeepAlive", args: args{ config: Config{ + ExporterSettings: config.NewExporterSettings(typeStr), GRPCClientSettings: configgrpc.GRPCClientSettings{ Headers: nil, Endpoint: "foo.bar", @@ -137,6 +143,7 @@ func TestNew(t *testing.T) { name: "createSecureExporterWithMissingFile", args: args{ config: Config{ + ExporterSettings: config.NewExporterSettings(typeStr), GRPCClientSettings: configgrpc.GRPCClientSettings{ Headers: nil, Endpoint: "foo.bar", diff --git a/exporter/jaegerexporter/factory.go b/exporter/jaegerexporter/factory.go index ac55c435575..8f4c94c51a4 100644 --- a/exporter/jaegerexporter/factory.go +++ b/exporter/jaegerexporter/factory.go @@ -39,13 +39,10 @@ func NewFactory() component.ExporterFactory { func createDefaultConfig() config.Exporter { return &Config{ - ExporterSettings: config.ExporterSettings{ - TypeVal: typeStr, - NameVal: typeStr, - }, - TimeoutSettings: exporterhelper.DefaultTimeoutSettings(), - RetrySettings: exporterhelper.DefaultRetrySettings(), - QueueSettings: exporterhelper.DefaultQueueSettings(), + ExporterSettings: config.NewExporterSettings(typeStr), + TimeoutSettings: exporterhelper.DefaultTimeoutSettings(), + RetrySettings: exporterhelper.DefaultRetrySettings(), + QueueSettings: exporterhelper.DefaultQueueSettings(), GRPCClientSettings: configgrpc.GRPCClientSettings{ // We almost read 0 bytes, so no need to tune ReadBufferSize. WriteBufferSize: 512 * 1024, diff --git a/exporter/kafkaexporter/config.go b/exporter/kafkaexporter/config.go index 71e67432d0d..5601882dcc6 100644 --- a/exporter/kafkaexporter/config.go +++ b/exporter/kafkaexporter/config.go @@ -23,7 +23,7 @@ import ( // Config defines configuration for Kafka exporter. type Config struct { - config.ExporterSettings `mapstructure:",squash"` + *config.ExporterSettings `mapstructure:"-"` exporterhelper.TimeoutSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct. exporterhelper.QueueSettings `mapstructure:"sending_queue"` exporterhelper.RetrySettings `mapstructure:"retry_on_failure"` diff --git a/exporter/kafkaexporter/config_test.go b/exporter/kafkaexporter/config_test.go index 7e6666c5832..a914de58948 100644 --- a/exporter/kafkaexporter/config_test.go +++ b/exporter/kafkaexporter/config_test.go @@ -40,10 +40,7 @@ func TestLoadConfig(t *testing.T) { c := cfg.Exporters[typeStr].(*Config) assert.Equal(t, &Config{ - ExporterSettings: config.ExporterSettings{ - NameVal: typeStr, - TypeVal: typeStr, - }, + ExporterSettings: config.NewExporterSettings(typeStr), TimeoutSettings: exporterhelper.TimeoutSettings{ Timeout: 10 * time.Second, }, diff --git a/exporter/kafkaexporter/factory.go b/exporter/kafkaexporter/factory.go index 6b376952445..1873c56c606 100644 --- a/exporter/kafkaexporter/factory.go +++ b/exporter/kafkaexporter/factory.go @@ -67,14 +67,11 @@ func NewFactory(options ...FactoryOption) component.ExporterFactory { func createDefaultConfig() config.Exporter { return &Config{ - ExporterSettings: config.ExporterSettings{ - TypeVal: typeStr, - NameVal: typeStr, - }, - TimeoutSettings: exporterhelper.DefaultTimeoutSettings(), - RetrySettings: exporterhelper.DefaultRetrySettings(), - QueueSettings: exporterhelper.DefaultQueueSettings(), - Brokers: []string{defaultBroker}, + ExporterSettings: config.NewExporterSettings(typeStr), + TimeoutSettings: exporterhelper.DefaultTimeoutSettings(), + RetrySettings: exporterhelper.DefaultRetrySettings(), + QueueSettings: exporterhelper.DefaultQueueSettings(), + Brokers: []string{defaultBroker}, // using an empty topic to track when it has not been set by user, default is based on traces or metrics. Topic: "", Encoding: defaultEncoding, diff --git a/exporter/loggingexporter/config.go b/exporter/loggingexporter/config.go index 8ca609ede5f..e315de32a18 100644 --- a/exporter/loggingexporter/config.go +++ b/exporter/loggingexporter/config.go @@ -20,7 +20,7 @@ import ( // Config defines configuration for logging exporter. type Config struct { - config.ExporterSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct. + *config.ExporterSettings `mapstructure:"-"` // LogLevel defines log level of the logging exporter; options are debug, info, warn, error. LogLevel string `mapstructure:"loglevel"` diff --git a/exporter/loggingexporter/config_test.go b/exporter/loggingexporter/config_test.go index d332f832c99..84221dc8ca4 100644 --- a/exporter/loggingexporter/config_test.go +++ b/exporter/loggingexporter/config_test.go @@ -43,7 +43,7 @@ func TestLoadConfig(t *testing.T) { e1 := cfg.Exporters["logging/2"] assert.Equal(t, e1, &Config{ - ExporterSettings: config.ExporterSettings{ + ExporterSettings: &config.ExporterSettings{ NameVal: "logging/2", TypeVal: "logging", }, diff --git a/exporter/loggingexporter/factory.go b/exporter/loggingexporter/factory.go index 97015aa7292..973847376ab 100644 --- a/exporter/loggingexporter/factory.go +++ b/exporter/loggingexporter/factory.go @@ -44,10 +44,7 @@ func NewFactory() component.ExporterFactory { func createDefaultConfig() config.Exporter { return &Config{ - ExporterSettings: config.ExporterSettings{ - TypeVal: typeStr, - NameVal: typeStr, - }, + ExporterSettings: config.NewExporterSettings(typeStr), LogLevel: "info", SamplingInitial: defaultSamplingInitial, SamplingThereafter: defaultSamplingThereafter, diff --git a/exporter/opencensusexporter/config.go b/exporter/opencensusexporter/config.go index 269a7dbb141..a48deef0bde 100644 --- a/exporter/opencensusexporter/config.go +++ b/exporter/opencensusexporter/config.go @@ -22,7 +22,7 @@ import ( // Config defines configuration for OpenCensus exporter. type Config struct { - config.ExporterSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct. + *config.ExporterSettings `mapstructure:"-"` configgrpc.GRPCClientSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct. exporterhelper.QueueSettings `mapstructure:"sending_queue"` exporterhelper.RetrySettings `mapstructure:"retry_on_failure"` diff --git a/exporter/opencensusexporter/config_test.go b/exporter/opencensusexporter/config_test.go index c103056c824..6cd4852a825 100644 --- a/exporter/opencensusexporter/config_test.go +++ b/exporter/opencensusexporter/config_test.go @@ -47,7 +47,7 @@ func TestLoadConfig(t *testing.T) { e1 := cfg.Exporters["opencensus/2"] assert.Equal(t, e1, &Config{ - ExporterSettings: config.ExporterSettings{ + ExporterSettings: &config.ExporterSettings{ NameVal: "opencensus/2", TypeVal: "opencensus", }, diff --git a/exporter/opencensusexporter/factory.go b/exporter/opencensusexporter/factory.go index ba3cb16ec1e..1b4643583ee 100644 --- a/exporter/opencensusexporter/factory.go +++ b/exporter/opencensusexporter/factory.go @@ -39,10 +39,7 @@ func NewFactory() component.ExporterFactory { func createDefaultConfig() config.Exporter { return &Config{ - ExporterSettings: config.ExporterSettings{ - TypeVal: typeStr, - NameVal: typeStr, - }, + ExporterSettings: config.NewExporterSettings(typeStr), GRPCClientSettings: configgrpc.GRPCClientSettings{ Headers: map[string]string{}, // We almost read 0 bytes, so no need to tune ReadBufferSize. diff --git a/exporter/opencensusexporter/factory_test.go b/exporter/opencensusexporter/factory_test.go index e243af20865..97b9f231e7e 100644 --- a/exporter/opencensusexporter/factory_test.go +++ b/exporter/opencensusexporter/factory_test.go @@ -24,6 +24,7 @@ import ( "go.uber.org/zap" "go.opentelemetry.io/collector/component" + "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/config/configcheck" "go.opentelemetry.io/collector/config/configgrpc" "go.opentelemetry.io/collector/config/configtls" @@ -46,6 +47,7 @@ func TestCreateTraceExporter(t *testing.T) { { name: "NoEndpoint", config: Config{ + ExporterSettings: config.NewExporterSettings(typeStr), GRPCClientSettings: configgrpc.GRPCClientSettings{ Endpoint: "", }, @@ -56,6 +58,7 @@ func TestCreateTraceExporter(t *testing.T) { { name: "ZeroNumWorkers", config: Config{ + ExporterSettings: config.NewExporterSettings(typeStr), GRPCClientSettings: configgrpc.GRPCClientSettings{ Endpoint: endpoint, TLSSetting: configtls.TLSClientSetting{ @@ -69,6 +72,7 @@ func TestCreateTraceExporter(t *testing.T) { { name: "UseSecure", config: Config{ + ExporterSettings: config.NewExporterSettings(typeStr), GRPCClientSettings: configgrpc.GRPCClientSettings{ Endpoint: endpoint, TLSSetting: configtls.TLSClientSetting{ @@ -81,6 +85,7 @@ func TestCreateTraceExporter(t *testing.T) { { name: "Keepalive", config: Config{ + ExporterSettings: config.NewExporterSettings(typeStr), GRPCClientSettings: configgrpc.GRPCClientSettings{ Endpoint: endpoint, Keepalive: &configgrpc.KeepaliveClientConfig{ @@ -95,6 +100,7 @@ func TestCreateTraceExporter(t *testing.T) { { name: "Compression", config: Config{ + ExporterSettings: config.NewExporterSettings(typeStr), GRPCClientSettings: configgrpc.GRPCClientSettings{ Endpoint: endpoint, Compression: configgrpc.CompressionGzip, @@ -105,6 +111,7 @@ func TestCreateTraceExporter(t *testing.T) { { name: "Headers", config: Config{ + ExporterSettings: config.NewExporterSettings(typeStr), GRPCClientSettings: configgrpc.GRPCClientSettings{ Endpoint: endpoint, Headers: map[string]string{ @@ -118,6 +125,7 @@ func TestCreateTraceExporter(t *testing.T) { { name: "CompressionError", config: Config{ + ExporterSettings: config.NewExporterSettings(typeStr), GRPCClientSettings: configgrpc.GRPCClientSettings{ Endpoint: endpoint, Compression: "unknown compression", @@ -129,6 +137,7 @@ func TestCreateTraceExporter(t *testing.T) { { name: "CaCert", config: Config{ + ExporterSettings: config.NewExporterSettings(typeStr), GRPCClientSettings: configgrpc.GRPCClientSettings{ Endpoint: endpoint, TLSSetting: configtls.TLSClientSetting{ @@ -143,6 +152,7 @@ func TestCreateTraceExporter(t *testing.T) { { name: "CertPemFileError", config: Config{ + ExporterSettings: config.NewExporterSettings(typeStr), GRPCClientSettings: configgrpc.GRPCClientSettings{ Endpoint: endpoint, TLSSetting: configtls.TLSClientSetting{ diff --git a/exporter/otlpexporter/config.go b/exporter/otlpexporter/config.go index 9ff29f0f700..060622cecf1 100644 --- a/exporter/otlpexporter/config.go +++ b/exporter/otlpexporter/config.go @@ -22,7 +22,7 @@ import ( // Config defines configuration for OpenCensus exporter. type Config struct { - config.ExporterSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct. + *config.ExporterSettings `mapstructure:"-"` exporterhelper.TimeoutSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct. exporterhelper.QueueSettings `mapstructure:"sending_queue"` exporterhelper.RetrySettings `mapstructure:"retry_on_failure"` diff --git a/exporter/otlpexporter/config_test.go b/exporter/otlpexporter/config_test.go index 47b140116f7..1c44670654f 100644 --- a/exporter/otlpexporter/config_test.go +++ b/exporter/otlpexporter/config_test.go @@ -47,7 +47,7 @@ func TestLoadConfig(t *testing.T) { e1 := cfg.Exporters["otlp/2"] assert.Equal(t, e1, &Config{ - ExporterSettings: config.ExporterSettings{ + ExporterSettings: &config.ExporterSettings{ NameVal: "otlp/2", TypeVal: "otlp", }, diff --git a/exporter/otlpexporter/factory.go b/exporter/otlpexporter/factory.go index 263695374e0..d513a83b3ef 100644 --- a/exporter/otlpexporter/factory.go +++ b/exporter/otlpexporter/factory.go @@ -40,13 +40,10 @@ func NewFactory() component.ExporterFactory { func createDefaultConfig() config.Exporter { return &Config{ - ExporterSettings: config.ExporterSettings{ - TypeVal: typeStr, - NameVal: typeStr, - }, - TimeoutSettings: exporterhelper.DefaultTimeoutSettings(), - RetrySettings: exporterhelper.DefaultRetrySettings(), - QueueSettings: exporterhelper.DefaultQueueSettings(), + ExporterSettings: config.NewExporterSettings(typeStr), + TimeoutSettings: exporterhelper.DefaultTimeoutSettings(), + RetrySettings: exporterhelper.DefaultRetrySettings(), + QueueSettings: exporterhelper.DefaultQueueSettings(), GRPCClientSettings: configgrpc.GRPCClientSettings{ Headers: map[string]string{}, // We almost read 0 bytes, so no need to tune ReadBufferSize. diff --git a/exporter/otlpexporter/factory_test.go b/exporter/otlpexporter/factory_test.go index 0659e52b1cd..5d5736d4055 100644 --- a/exporter/otlpexporter/factory_test.go +++ b/exporter/otlpexporter/factory_test.go @@ -24,6 +24,7 @@ import ( "go.uber.org/zap" "go.opentelemetry.io/collector/component" + "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/config/configcheck" "go.opentelemetry.io/collector/config/configgrpc" "go.opentelemetry.io/collector/config/configtls" @@ -65,6 +66,7 @@ func TestCreateTraceExporter(t *testing.T) { { name: "NoEndpoint", config: Config{ + ExporterSettings: config.NewExporterSettings(typeStr), GRPCClientSettings: configgrpc.GRPCClientSettings{ Endpoint: "", }, @@ -74,6 +76,7 @@ func TestCreateTraceExporter(t *testing.T) { { name: "UseSecure", config: Config{ + ExporterSettings: config.NewExporterSettings(typeStr), GRPCClientSettings: configgrpc.GRPCClientSettings{ Endpoint: endpoint, TLSSetting: configtls.TLSClientSetting{ @@ -85,6 +88,7 @@ func TestCreateTraceExporter(t *testing.T) { { name: "Keepalive", config: Config{ + ExporterSettings: config.NewExporterSettings(typeStr), GRPCClientSettings: configgrpc.GRPCClientSettings{ Endpoint: endpoint, Keepalive: &configgrpc.KeepaliveClientConfig{ @@ -98,6 +102,7 @@ func TestCreateTraceExporter(t *testing.T) { { name: "Compression", config: Config{ + ExporterSettings: config.NewExporterSettings(typeStr), GRPCClientSettings: configgrpc.GRPCClientSettings{ Endpoint: endpoint, Compression: configgrpc.CompressionGzip, @@ -107,6 +112,7 @@ func TestCreateTraceExporter(t *testing.T) { { name: "Headers", config: Config{ + ExporterSettings: config.NewExporterSettings(typeStr), GRPCClientSettings: configgrpc.GRPCClientSettings{ Endpoint: endpoint, Headers: map[string]string{ @@ -119,6 +125,7 @@ func TestCreateTraceExporter(t *testing.T) { { name: "NumConsumers", config: Config{ + ExporterSettings: config.NewExporterSettings(typeStr), GRPCClientSettings: configgrpc.GRPCClientSettings{ Endpoint: endpoint, }, @@ -127,6 +134,7 @@ func TestCreateTraceExporter(t *testing.T) { { name: "CompressionError", config: Config{ + ExporterSettings: config.NewExporterSettings(typeStr), GRPCClientSettings: configgrpc.GRPCClientSettings{ Endpoint: endpoint, Compression: "unknown compression", @@ -137,6 +145,7 @@ func TestCreateTraceExporter(t *testing.T) { { name: "CaCert", config: Config{ + ExporterSettings: config.NewExporterSettings(typeStr), GRPCClientSettings: configgrpc.GRPCClientSettings{ Endpoint: endpoint, TLSSetting: configtls.TLSClientSetting{ @@ -150,6 +159,7 @@ func TestCreateTraceExporter(t *testing.T) { { name: "CertPemFileError", config: Config{ + ExporterSettings: config.NewExporterSettings(typeStr), GRPCClientSettings: configgrpc.GRPCClientSettings{ Endpoint: endpoint, TLSSetting: configtls.TLSClientSetting{ diff --git a/exporter/otlphttpexporter/config.go b/exporter/otlphttpexporter/config.go index 259c607a619..07778785636 100644 --- a/exporter/otlphttpexporter/config.go +++ b/exporter/otlphttpexporter/config.go @@ -22,7 +22,7 @@ import ( // Config defines configuration for OTLP/HTTP exporter. type Config struct { - config.ExporterSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct. + *config.ExporterSettings `mapstructure:"-"` confighttp.HTTPClientSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct. exporterhelper.QueueSettings `mapstructure:"sending_queue"` exporterhelper.RetrySettings `mapstructure:"retry_on_failure"` diff --git a/exporter/otlphttpexporter/config_test.go b/exporter/otlphttpexporter/config_test.go index a470d48c375..f43f6603441 100644 --- a/exporter/otlphttpexporter/config_test.go +++ b/exporter/otlphttpexporter/config_test.go @@ -47,7 +47,7 @@ func TestLoadConfig(t *testing.T) { e1 := cfg.Exporters["otlphttp/2"] assert.Equal(t, e1, &Config{ - ExporterSettings: config.ExporterSettings{ + ExporterSettings: &config.ExporterSettings{ NameVal: "otlphttp/2", TypeVal: "otlphttp", }, diff --git a/exporter/otlphttpexporter/factory.go b/exporter/otlphttpexporter/factory.go index e43231587d1..daedfabd686 100644 --- a/exporter/otlphttpexporter/factory.go +++ b/exporter/otlphttpexporter/factory.go @@ -43,12 +43,9 @@ func NewFactory() component.ExporterFactory { func createDefaultConfig() config.Exporter { return &Config{ - ExporterSettings: config.ExporterSettings{ - TypeVal: typeStr, - NameVal: typeStr, - }, - RetrySettings: exporterhelper.DefaultRetrySettings(), - QueueSettings: exporterhelper.DefaultQueueSettings(), + ExporterSettings: config.NewExporterSettings(typeStr), + RetrySettings: exporterhelper.DefaultRetrySettings(), + QueueSettings: exporterhelper.DefaultQueueSettings(), HTTPClientSettings: confighttp.HTTPClientSettings{ Endpoint: "", Timeout: 30 * time.Second, diff --git a/exporter/otlphttpexporter/factory_test.go b/exporter/otlphttpexporter/factory_test.go index c9c76a3e2dd..e2ef378407b 100644 --- a/exporter/otlphttpexporter/factory_test.go +++ b/exporter/otlphttpexporter/factory_test.go @@ -24,6 +24,7 @@ import ( "go.uber.org/zap" "go.opentelemetry.io/collector/component" + "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/config/configcheck" "go.opentelemetry.io/collector/config/confighttp" "go.opentelemetry.io/collector/config/configtls" @@ -68,6 +69,7 @@ func TestCreateTraceExporter(t *testing.T) { { name: "NoEndpoint", config: Config{ + ExporterSettings: config.NewExporterSettings(typeStr), HTTPClientSettings: confighttp.HTTPClientSettings{ Endpoint: "", }, @@ -77,6 +79,7 @@ func TestCreateTraceExporter(t *testing.T) { { name: "UseSecure", config: Config{ + ExporterSettings: config.NewExporterSettings(typeStr), HTTPClientSettings: confighttp.HTTPClientSettings{ Endpoint: endpoint, TLSSetting: configtls.TLSClientSetting{ @@ -88,6 +91,7 @@ func TestCreateTraceExporter(t *testing.T) { { name: "Headers", config: Config{ + ExporterSettings: config.NewExporterSettings(typeStr), HTTPClientSettings: confighttp.HTTPClientSettings{ Endpoint: endpoint, Headers: map[string]string{ @@ -100,6 +104,7 @@ func TestCreateTraceExporter(t *testing.T) { { name: "CaCert", config: Config{ + ExporterSettings: config.NewExporterSettings(typeStr), HTTPClientSettings: confighttp.HTTPClientSettings{ Endpoint: endpoint, TLSSetting: configtls.TLSClientSetting{ @@ -113,6 +118,7 @@ func TestCreateTraceExporter(t *testing.T) { { name: "CertPemFileError", config: Config{ + ExporterSettings: config.NewExporterSettings(typeStr), HTTPClientSettings: confighttp.HTTPClientSettings{ Endpoint: endpoint, TLSSetting: configtls.TLSClientSetting{ diff --git a/exporter/otlphttpexporter/otlp_test.go b/exporter/otlphttpexporter/otlp_test.go index 2b68e511677..7699c7552af 100644 --- a/exporter/otlphttpexporter/otlp_test.go +++ b/exporter/otlphttpexporter/otlp_test.go @@ -443,7 +443,8 @@ func TestErrorResponses(t *testing.T) { }() cfg := &Config{ - TracesEndpoint: fmt.Sprintf("http://%s/v1/traces", addr), + ExporterSettings: config.NewExporterSettings(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. } diff --git a/exporter/prometheusexporter/config.go b/exporter/prometheusexporter/config.go index 4824d6c7f7e..1c7dc51edcc 100644 --- a/exporter/prometheusexporter/config.go +++ b/exporter/prometheusexporter/config.go @@ -24,7 +24,7 @@ import ( // Config defines configuration for Prometheus exporter. type Config struct { - config.ExporterSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct. + *config.ExporterSettings `mapstructure:"-"` // The address on which the Prometheus scrape handler will be run on. Endpoint string `mapstructure:"endpoint"` diff --git a/exporter/prometheusexporter/config_test.go b/exporter/prometheusexporter/config_test.go index 8914759bf2d..09e592eabd2 100644 --- a/exporter/prometheusexporter/config_test.go +++ b/exporter/prometheusexporter/config_test.go @@ -44,7 +44,7 @@ func TestLoadConfig(t *testing.T) { e1 := cfg.Exporters["prometheus/2"] assert.Equal(t, e1, &Config{ - ExporterSettings: config.ExporterSettings{ + ExporterSettings: &config.ExporterSettings{ NameVal: "prometheus/2", TypeVal: "prometheus", }, diff --git a/exporter/prometheusexporter/factory.go b/exporter/prometheusexporter/factory.go index 732b252882d..1bdebd21c60 100644 --- a/exporter/prometheusexporter/factory.go +++ b/exporter/prometheusexporter/factory.go @@ -37,10 +37,7 @@ func NewFactory() component.ExporterFactory { func createDefaultConfig() config.Exporter { return &Config{ - ExporterSettings: config.ExporterSettings{ - TypeVal: typeStr, - NameVal: typeStr, - }, + ExporterSettings: config.NewExporterSettings(typeStr), ConstLabels: map[string]string{}, SendTimestamps: false, MetricExpiration: time.Minute * 5, diff --git a/exporter/prometheusexporter/prometheus_test.go b/exporter/prometheusexporter/prometheus_test.go index 14683aa6ab5..61019a6fc56 100644 --- a/exporter/prometheusexporter/prometheus_test.go +++ b/exporter/prometheusexporter/prometheus_test.go @@ -31,6 +31,7 @@ import ( "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/component/componenttest" + "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/translator/internaldata" ) @@ -42,7 +43,8 @@ func TestPrometheusExporter(t *testing.T) { }{ { config: &Config{ - Namespace: "test", + ExporterSettings: config.NewExporterSettings(typeStr), + Namespace: "test", ConstLabels: map[string]string{ "foo0": "bar0", "code0": "one0", @@ -54,12 +56,15 @@ func TestPrometheusExporter(t *testing.T) { }, { config: &Config{ - Endpoint: ":88999", + ExporterSettings: config.NewExporterSettings(typeStr), + Endpoint: ":88999", }, wantStartErr: "listen tcp: address 88999: invalid port", }, { - config: &Config{}, + config: &Config{ + ExporterSettings: config.NewExporterSettings(typeStr), + }, wantErr: "expecting a non-blank address to run the Prometheus metrics handler", }, } @@ -95,8 +100,9 @@ func TestPrometheusExporter(t *testing.T) { } func TestPrometheusExporter_endToEnd(t *testing.T) { - config := &Config{ - Namespace: "test", + cfg := &Config{ + ExporterSettings: config.NewExporterSettings(typeStr), + Namespace: "test", ConstLabels: map[string]string{ "foo1": "bar1", "code1": "one1", @@ -107,7 +113,7 @@ func TestPrometheusExporter_endToEnd(t *testing.T) { factory := NewFactory() creationParams := component.ExporterCreateParams{Logger: zap.NewNop()} - exp, err := factory.CreateMetricsExporter(context.Background(), creationParams, config) + exp, err := factory.CreateMetricsExporter(context.Background(), creationParams, cfg) assert.NoError(t, err) t.Cleanup(func() { @@ -170,8 +176,9 @@ func TestPrometheusExporter_endToEnd(t *testing.T) { } func TestPrometheusExporter_endToEndWithTimestamps(t *testing.T) { - config := &Config{ - Namespace: "test", + cfg := &Config{ + ExporterSettings: config.NewExporterSettings(typeStr), + Namespace: "test", ConstLabels: map[string]string{ "foo2": "bar2", "code2": "one2", @@ -183,7 +190,7 @@ func TestPrometheusExporter_endToEndWithTimestamps(t *testing.T) { factory := NewFactory() creationParams := component.ExporterCreateParams{Logger: zap.NewNop()} - exp, err := factory.CreateMetricsExporter(context.Background(), creationParams, config) + exp, err := factory.CreateMetricsExporter(context.Background(), creationParams, cfg) assert.NoError(t, err) t.Cleanup(func() { diff --git a/exporter/prometheusremotewriteexporter/config.go b/exporter/prometheusremotewriteexporter/config.go index 5b1a01b9e4d..dbf9284feff 100644 --- a/exporter/prometheusremotewriteexporter/config.go +++ b/exporter/prometheusremotewriteexporter/config.go @@ -22,9 +22,8 @@ import ( // Config defines configuration for Remote Write exporter. type Config struct { - // squash ensures fields are correctly decoded in embedded struct. - config.ExporterSettings `mapstructure:",squash"` - exporterhelper.TimeoutSettings `mapstructure:",squash"` + *config.ExporterSettings `mapstructure:"-"` + exporterhelper.TimeoutSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct. exporterhelper.QueueSettings `mapstructure:"sending_queue"` exporterhelper.RetrySettings `mapstructure:"retry_on_failure"` @@ -35,5 +34,5 @@ type Config struct { // ExternalLabels defines a map of label keys and values that are allowed to start with reserved prefix "__" ExternalLabels map[string]string `mapstructure:"external_labels"` - HTTPClientSettings confighttp.HTTPClientSettings `mapstructure:",squash"` + HTTPClientSettings confighttp.HTTPClientSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct. } diff --git a/exporter/prometheusremotewriteexporter/config_test.go b/exporter/prometheusremotewriteexporter/config_test.go index 724c723355c..0135e46f9ea 100644 --- a/exporter/prometheusremotewriteexporter/config_test.go +++ b/exporter/prometheusremotewriteexporter/config_test.go @@ -50,7 +50,7 @@ func Test_loadConfig(t *testing.T) { e1 := cfg.Exporters["prometheusremotewrite/2"] assert.Equal(t, e1, &Config{ - ExporterSettings: config.ExporterSettings{ + ExporterSettings: &config.ExporterSettings{ NameVal: "prometheusremotewrite/2", TypeVal: "prometheusremotewrite", }, diff --git a/exporter/prometheusremotewriteexporter/exporter_test.go b/exporter/prometheusremotewriteexporter/exporter_test.go index 6d6108ea35e..a353a1544d8 100644 --- a/exporter/prometheusremotewriteexporter/exporter_test.go +++ b/exporter/prometheusremotewriteexporter/exporter_test.go @@ -43,7 +43,7 @@ import ( // Test_ NewPrwExporter checks that a new exporter instance with non-nil fields is initialized func Test_NewPrwExporter(t *testing.T) { cfg := &Config{ - ExporterSettings: config.ExporterSettings{}, + ExporterSettings: config.NewExporterSettings(typeStr), TimeoutSettings: exporterhelper.TimeoutSettings{}, QueueSettings: exporterhelper.QueueSettings{}, RetrySettings: exporterhelper.RetrySettings{}, @@ -685,11 +685,8 @@ func Test_PushMetrics(t *testing.T) { assert.NoError(t, uErr) config := &Config{ - ExporterSettings: config.ExporterSettings{ - TypeVal: "prometheusremotewrite", - NameVal: "prometheusremotewrite", - }, - Namespace: "", + ExporterSettings: config.NewExporterSettings(typeStr), + Namespace: "", HTTPClientSettings: confighttp.HTTPClientSettings{ Endpoint: "http://some.url:9411/api/prom/push", // We almost read 0 bytes, so no need to tune ReadBufferSize. diff --git a/exporter/prometheusremotewriteexporter/factory.go b/exporter/prometheusremotewriteexporter/factory.go index 8cc71530450..a4939f69d72 100644 --- a/exporter/prometheusremotewriteexporter/factory.go +++ b/exporter/prometheusremotewriteexporter/factory.go @@ -69,15 +69,12 @@ func createMetricsExporter(_ context.Context, params component.ExporterCreatePar func createDefaultConfig() config.Exporter { return &Config{ - ExporterSettings: config.ExporterSettings{ - TypeVal: typeStr, - NameVal: typeStr, - }, - Namespace: "", - ExternalLabels: map[string]string{}, - TimeoutSettings: exporterhelper.DefaultTimeoutSettings(), - RetrySettings: exporterhelper.DefaultRetrySettings(), - QueueSettings: exporterhelper.DefaultQueueSettings(), + ExporterSettings: config.NewExporterSettings(typeStr), + Namespace: "", + ExternalLabels: map[string]string{}, + TimeoutSettings: exporterhelper.DefaultTimeoutSettings(), + RetrySettings: exporterhelper.DefaultRetrySettings(), + QueueSettings: exporterhelper.DefaultQueueSettings(), HTTPClientSettings: confighttp.HTTPClientSettings{ Endpoint: "http://some.url:9411/api/prom/push", // We almost read 0 bytes, so no need to tune ReadBufferSize. diff --git a/extension/healthcheckextension/config.go b/extension/healthcheckextension/config.go index 0937c30e079..e3558ae95b8 100644 --- a/extension/healthcheckextension/config.go +++ b/extension/healthcheckextension/config.go @@ -22,7 +22,7 @@ import ( // Config has the configuration for the extension enabling the health check // extension, used to report the health status of the service. type Config struct { - config.ExtensionSettings `mapstructure:",squash"` + *config.ExtensionSettings `mapstructure:"-"` // Port is the port used to publish the health check status. // The default value is 13133. diff --git a/extension/healthcheckextension/config_test.go b/extension/healthcheckextension/config_test.go index 6fab9e9d2bf..497f2c132d7 100644 --- a/extension/healthcheckextension/config_test.go +++ b/extension/healthcheckextension/config_test.go @@ -44,7 +44,7 @@ func TestLoadConfig(t *testing.T) { ext1 := cfg.Extensions["health_check/1"] assert.Equal(t, &Config{ - ExtensionSettings: config.ExtensionSettings{ + ExtensionSettings: &config.ExtensionSettings{ TypeVal: "health_check", NameVal: "health_check/1", }, diff --git a/extension/healthcheckextension/factory.go b/extension/healthcheckextension/factory.go index a654841b0b4..9b7494d4408 100644 --- a/extension/healthcheckextension/factory.go +++ b/extension/healthcheckextension/factory.go @@ -42,10 +42,7 @@ func NewFactory() component.ExtensionFactory { func createDefaultConfig() config.Extension { return &Config{ - ExtensionSettings: config.ExtensionSettings{ - TypeVal: typeStr, - NameVal: typeStr, - }, + ExtensionSettings: config.NewExtensionSettings(typeStr), TCPAddr: confignet.TCPAddr{ Endpoint: defaultEndpoint, }, diff --git a/extension/healthcheckextension/factory_test.go b/extension/healthcheckextension/factory_test.go index 85db6913282..095b80949e0 100644 --- a/extension/healthcheckextension/factory_test.go +++ b/extension/healthcheckextension/factory_test.go @@ -32,10 +32,7 @@ import ( func TestFactory_CreateDefaultConfig(t *testing.T) { cfg := createDefaultConfig() assert.Equal(t, &Config{ - ExtensionSettings: config.ExtensionSettings{ - NameVal: typeStr, - TypeVal: typeStr, - }, + ExtensionSettings: config.NewExtensionSettings(typeStr), TCPAddr: confignet.TCPAddr{ Endpoint: defaultEndpoint, }, diff --git a/extension/pprofextension/config.go b/extension/pprofextension/config.go index 898682181bd..a0892f363b2 100644 --- a/extension/pprofextension/config.go +++ b/extension/pprofextension/config.go @@ -22,7 +22,7 @@ import ( // Config has the configuration for the extension enabling the golang // net/http/pprof (Performance Profiler) extension. type Config struct { - config.ExtensionSettings `mapstructure:",squash"` + *config.ExtensionSettings `mapstructure:"-"` // TCPAddr is the address and port in which the pprof will be listening to. // Use localhost: to make it available only locally, or ":" to diff --git a/extension/pprofextension/config_test.go b/extension/pprofextension/config_test.go index 64b844b9714..44bad6206d1 100644 --- a/extension/pprofextension/config_test.go +++ b/extension/pprofextension/config_test.go @@ -44,7 +44,7 @@ func TestLoadConfig(t *testing.T) { ext1 := cfg.Extensions["pprof/1"] assert.Equal(t, &Config{ - ExtensionSettings: config.ExtensionSettings{ + ExtensionSettings: &config.ExtensionSettings{ TypeVal: "pprof", NameVal: "pprof/1", }, diff --git a/extension/pprofextension/factory.go b/extension/pprofextension/factory.go index a4048121fc0..176a53f200f 100644 --- a/extension/pprofextension/factory.go +++ b/extension/pprofextension/factory.go @@ -41,10 +41,7 @@ func NewFactory() component.ExtensionFactory { func createDefaultConfig() config.Extension { return &Config{ - ExtensionSettings: config.ExtensionSettings{ - TypeVal: typeStr, - NameVal: typeStr, - }, + ExtensionSettings: config.NewExtensionSettings(typeStr), TCPAddr: confignet.TCPAddr{ Endpoint: defaultEndpoint, }, diff --git a/extension/pprofextension/factory_test.go b/extension/pprofextension/factory_test.go index 0ada40d1db6..8244b081b22 100644 --- a/extension/pprofextension/factory_test.go +++ b/extension/pprofextension/factory_test.go @@ -32,11 +32,8 @@ import ( func TestFactory_CreateDefaultConfig(t *testing.T) { cfg := createDefaultConfig() assert.Equal(t, &Config{ - ExtensionSettings: config.ExtensionSettings{ - NameVal: typeStr, - TypeVal: typeStr, - }, - TCPAddr: confignet.TCPAddr{Endpoint: defaultEndpoint}, + ExtensionSettings: config.NewExtensionSettings(typeStr), + TCPAddr: confignet.TCPAddr{Endpoint: defaultEndpoint}, }, cfg) diff --git a/extension/zpagesextension/config.go b/extension/zpagesextension/config.go index fc1dabfa5b4..88f44d9695f 100644 --- a/extension/zpagesextension/config.go +++ b/extension/zpagesextension/config.go @@ -21,7 +21,7 @@ import ( // Config has the configuration for the extension enabling the zPages extension. type Config struct { - config.ExtensionSettings `mapstructure:",squash"` + *config.ExtensionSettings `mapstructure:"-"` // 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 28d659b0bcc..cac583d69fa 100644 --- a/extension/zpagesextension/config_test.go +++ b/extension/zpagesextension/config_test.go @@ -44,7 +44,7 @@ func TestLoadConfig(t *testing.T) { ext1 := cfg.Extensions["zpages/1"] assert.Equal(t, &Config{ - ExtensionSettings: config.ExtensionSettings{ + ExtensionSettings: &config.ExtensionSettings{ TypeVal: "zpages", NameVal: "zpages/1", }, diff --git a/extension/zpagesextension/factory.go b/extension/zpagesextension/factory.go index 33420cfc3c1..1c4108acd8e 100644 --- a/extension/zpagesextension/factory.go +++ b/extension/zpagesextension/factory.go @@ -41,10 +41,7 @@ func NewFactory() component.ExtensionFactory { func createDefaultConfig() config.Extension { return &Config{ - ExtensionSettings: config.ExtensionSettings{ - TypeVal: typeStr, - NameVal: typeStr, - }, + ExtensionSettings: config.NewExtensionSettings(typeStr), TCPAddr: confignet.TCPAddr{ Endpoint: defaultEndpoint, }, diff --git a/extension/zpagesextension/factory_test.go b/extension/zpagesextension/factory_test.go index b6f8d61ce70..558a7260b67 100644 --- a/extension/zpagesextension/factory_test.go +++ b/extension/zpagesextension/factory_test.go @@ -32,10 +32,7 @@ import ( func TestFactory_CreateDefaultConfig(t *testing.T) { cfg := createDefaultConfig() assert.Equal(t, &Config{ - ExtensionSettings: config.ExtensionSettings{ - NameVal: typeStr, - TypeVal: typeStr, - }, + ExtensionSettings: config.NewExtensionSettings(typeStr), TCPAddr: confignet.TCPAddr{ Endpoint: "localhost:55679", }, diff --git a/processor/attributesprocessor/config.go b/processor/attributesprocessor/config.go index 9ccda8f5ecb..73317b45a62 100644 --- a/processor/attributesprocessor/config.go +++ b/processor/attributesprocessor/config.go @@ -28,7 +28,7 @@ import ( // This determines if a span is to be processed or not. // The list of actions is applied in order specified in the configuration. type Config struct { - config.ProcessorSettings `mapstructure:",squash"` + *config.ProcessorSettings `mapstructure:"-"` filterconfig.MatchConfig `mapstructure:",squash"` diff --git a/processor/attributesprocessor/config_test.go b/processor/attributesprocessor/config_test.go index d781b5b6210..d8d2892573d 100644 --- a/processor/attributesprocessor/config_test.go +++ b/processor/attributesprocessor/config_test.go @@ -41,7 +41,7 @@ func TestLoadingConfig(t *testing.T) { p0 := cfg.Processors["attributes/insert"] assert.Equal(t, p0, &Config{ - ProcessorSettings: config.ProcessorSettings{ + ProcessorSettings: &config.ProcessorSettings{ NameVal: "attributes/insert", TypeVal: typeStr, }, @@ -55,7 +55,7 @@ func TestLoadingConfig(t *testing.T) { p1 := cfg.Processors["attributes/update"] assert.Equal(t, p1, &Config{ - ProcessorSettings: config.ProcessorSettings{ + ProcessorSettings: &config.ProcessorSettings{ NameVal: "attributes/update", TypeVal: typeStr, }, @@ -69,7 +69,7 @@ func TestLoadingConfig(t *testing.T) { p2 := cfg.Processors["attributes/upsert"] assert.Equal(t, p2, &Config{ - ProcessorSettings: config.ProcessorSettings{ + ProcessorSettings: &config.ProcessorSettings{ NameVal: "attributes/upsert", TypeVal: typeStr, }, @@ -83,7 +83,7 @@ func TestLoadingConfig(t *testing.T) { p3 := cfg.Processors["attributes/delete"] assert.Equal(t, p3, &Config{ - ProcessorSettings: config.ProcessorSettings{ + ProcessorSettings: &config.ProcessorSettings{ NameVal: "attributes/delete", TypeVal: typeStr, }, @@ -97,7 +97,7 @@ func TestLoadingConfig(t *testing.T) { p4 := cfg.Processors["attributes/hash"] assert.Equal(t, p4, &Config{ - ProcessorSettings: config.ProcessorSettings{ + ProcessorSettings: &config.ProcessorSettings{ NameVal: "attributes/hash", TypeVal: typeStr, }, @@ -110,7 +110,7 @@ func TestLoadingConfig(t *testing.T) { p5 := cfg.Processors["attributes/excludemulti"] assert.Equal(t, p5, &Config{ - ProcessorSettings: config.ProcessorSettings{ + ProcessorSettings: &config.ProcessorSettings{ NameVal: "attributes/excludemulti", TypeVal: typeStr, }, @@ -134,7 +134,7 @@ func TestLoadingConfig(t *testing.T) { p6 := cfg.Processors["attributes/includeservices"] assert.Equal(t, p6, &Config{ - ProcessorSettings: config.ProcessorSettings{ + ProcessorSettings: &config.ProcessorSettings{ NameVal: "attributes/includeservices", TypeVal: typeStr, }, @@ -154,7 +154,7 @@ func TestLoadingConfig(t *testing.T) { p7 := cfg.Processors["attributes/selectiveprocessing"] assert.Equal(t, p7, &Config{ - ProcessorSettings: config.ProcessorSettings{ + ProcessorSettings: &config.ProcessorSettings{ NameVal: "attributes/selectiveprocessing", TypeVal: typeStr, }, @@ -180,7 +180,7 @@ func TestLoadingConfig(t *testing.T) { p8 := cfg.Processors["attributes/complex"] assert.Equal(t, p8, &Config{ - ProcessorSettings: config.ProcessorSettings{ + ProcessorSettings: &config.ProcessorSettings{ NameVal: "attributes/complex", TypeVal: typeStr, }, @@ -195,7 +195,7 @@ func TestLoadingConfig(t *testing.T) { p9 := cfg.Processors["attributes/example"] assert.Equal(t, p9, &Config{ - ProcessorSettings: config.ProcessorSettings{ + ProcessorSettings: &config.ProcessorSettings{ NameVal: "attributes/example", TypeVal: typeStr, }, @@ -212,7 +212,7 @@ func TestLoadingConfig(t *testing.T) { p10 := cfg.Processors["attributes/regexp"] assert.Equal(t, p10, &Config{ - ProcessorSettings: config.ProcessorSettings{ + ProcessorSettings: &config.ProcessorSettings{ NameVal: "attributes/regexp", TypeVal: typeStr, }, diff --git a/processor/attributesprocessor/factory.go b/processor/attributesprocessor/factory.go index aa13930ec5b..67126032ba2 100644 --- a/processor/attributesprocessor/factory.go +++ b/processor/attributesprocessor/factory.go @@ -45,10 +45,7 @@ func NewFactory() component.ProcessorFactory { // Note: This isn't a valid configuration because the processor would do no work. func createDefaultConfig() config.Processor { return &Config{ - ProcessorSettings: config.ProcessorSettings{ - TypeVal: typeStr, - NameVal: typeStr, - }, + ProcessorSettings: config.NewProcessorSettings(typeStr), } } diff --git a/processor/attributesprocessor/factory_test.go b/processor/attributesprocessor/factory_test.go index cff14978e2a..a4f7c6293ee 100644 --- a/processor/attributesprocessor/factory_test.go +++ b/processor/attributesprocessor/factory_test.go @@ -38,10 +38,7 @@ func TestFactory_CreateDefaultConfig(t *testing.T) { factory := NewFactory() cfg := factory.CreateDefaultConfig() assert.Equal(t, cfg, &Config{ - ProcessorSettings: config.ProcessorSettings{ - NameVal: typeStr, - TypeVal: typeStr, - }, + ProcessorSettings: config.NewProcessorSettings(typeStr), }) assert.NoError(t, configcheck.ValidateConfig(cfg)) } diff --git a/processor/batchprocessor/batch_processor_test.go b/processor/batchprocessor/batch_processor_test.go index 0adc7d63344..abf1302e86f 100644 --- a/processor/batchprocessor/batch_processor_test.go +++ b/processor/batchprocessor/batch_processor_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/consumertest" "go.opentelemetry.io/collector/consumer/pdata" @@ -227,8 +228,9 @@ func TestBatchProcessorSentByTimeout(t *testing.T) { func TestBatchProcessorTraceSendWhenClosing(t *testing.T) { cfg := Config{ - Timeout: 3 * time.Second, - SendBatchSize: 1000, + ProcessorSettings: config.NewProcessorSettings(typeStr), + Timeout: 3 * time.Second, + SendBatchSize: 1000, } sink := new(consumertest.TracesSink) @@ -253,8 +255,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{ - Timeout: 200 * time.Millisecond, - SendBatchSize: 50, + ProcessorSettings: config.NewProcessorSettings(typeStr), + Timeout: 200 * time.Millisecond, + SendBatchSize: 50, } requestCount := 100 @@ -304,8 +307,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{ - Timeout: 100 * time.Millisecond, - SendBatchSize: 50, + ProcessorSettings: config.NewProcessorSettings(typeStr), + Timeout: 100 * time.Millisecond, + SendBatchSize: 50, } requestCount := 100 @@ -360,8 +364,9 @@ func TestBatchMetricProcessor_BatchSize(t *testing.T) { func TestBatchMetricsProcessor_Timeout(t *testing.T) { cfg := Config{ - Timeout: 100 * time.Millisecond, - SendBatchSize: 100, + ProcessorSettings: config.NewProcessorSettings(typeStr), + Timeout: 100 * time.Millisecond, + SendBatchSize: 100, } requestCount := 5 metricsPerRequest := 10 @@ -407,8 +412,9 @@ func TestBatchMetricsProcessor_Timeout(t *testing.T) { func TestBatchMetricProcessor_Shutdown(t *testing.T) { cfg := Config{ - Timeout: 3 * time.Second, - SendBatchSize: 1000, + ProcessorSettings: config.NewProcessorSettings(typeStr), + Timeout: 3 * time.Second, + SendBatchSize: 1000, } requestCount := 5 metricsPerRequest := 10 @@ -491,8 +497,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{ - Timeout: 200 * time.Millisecond, - SendBatchSize: 50, + ProcessorSettings: config.NewProcessorSettings(typeStr), + Timeout: 200 * time.Millisecond, + SendBatchSize: 50, } requestCount := 100 @@ -542,8 +549,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{ - Timeout: 100 * time.Millisecond, - SendBatchSize: 50, + ProcessorSettings: config.NewProcessorSettings(typeStr), + Timeout: 100 * time.Millisecond, + SendBatchSize: 50, } requestCount := 100 @@ -598,8 +606,9 @@ func TestBatchLogProcessor_BatchSize(t *testing.T) { func TestBatchLogsProcessor_Timeout(t *testing.T) { cfg := Config{ - Timeout: 100 * time.Millisecond, - SendBatchSize: 100, + ProcessorSettings: config.NewProcessorSettings(typeStr), + Timeout: 100 * time.Millisecond, + SendBatchSize: 100, } requestCount := 5 logsPerRequest := 10 @@ -645,8 +654,9 @@ func TestBatchLogsProcessor_Timeout(t *testing.T) { func TestBatchLogProcessor_Shutdown(t *testing.T) { cfg := Config{ - Timeout: 3 * time.Second, - SendBatchSize: 1000, + ProcessorSettings: config.NewProcessorSettings(typeStr), + Timeout: 3 * time.Second, + SendBatchSize: 1000, } requestCount := 5 logsPerRequest := 10 diff --git a/processor/batchprocessor/config.go b/processor/batchprocessor/config.go index 90a14f0234a..40832b344d7 100644 --- a/processor/batchprocessor/config.go +++ b/processor/batchprocessor/config.go @@ -22,7 +22,7 @@ import ( // Config defines configuration for batch processor. type Config struct { - config.ProcessorSettings `mapstructure:",squash"` + *config.ProcessorSettings `mapstructure:"-"` // Timeout sets the time after which a batch will be sent regardless of size. Timeout time.Duration `mapstructure:"timeout,omitempty"` diff --git a/processor/batchprocessor/config_test.go b/processor/batchprocessor/config_test.go index 7c1790313b0..b954557cb63 100644 --- a/processor/batchprocessor/config_test.go +++ b/processor/batchprocessor/config_test.go @@ -49,7 +49,7 @@ func TestLoadConfig(t *testing.T) { assert.Equal(t, p1, &Config{ - ProcessorSettings: config.ProcessorSettings{ + ProcessorSettings: &config.ProcessorSettings{ TypeVal: "batch", NameVal: "batch/2", }, diff --git a/processor/batchprocessor/factory.go b/processor/batchprocessor/factory.go index 99f5fb34971..327b7129b63 100644 --- a/processor/batchprocessor/factory.go +++ b/processor/batchprocessor/factory.go @@ -45,12 +45,9 @@ func NewFactory() component.ProcessorFactory { func createDefaultConfig() config.Processor { return &Config{ - ProcessorSettings: config.ProcessorSettings{ - TypeVal: typeStr, - NameVal: typeStr, - }, - SendBatchSize: defaultSendBatchSize, - Timeout: defaultTimeout, + ProcessorSettings: config.NewProcessorSettings(typeStr), + SendBatchSize: defaultSendBatchSize, + Timeout: defaultTimeout, } } diff --git a/processor/filterprocessor/config.go b/processor/filterprocessor/config.go index 7b65ec728a1..6d9b4f040ba 100644 --- a/processor/filterprocessor/config.go +++ b/processor/filterprocessor/config.go @@ -21,8 +21,8 @@ import ( // Config defines configuration for Resource processor. type Config struct { - config.ProcessorSettings `mapstructure:",squash"` - Metrics MetricFilters `mapstructure:"metrics"` + *config.ProcessorSettings `mapstructure:"-"` + Metrics MetricFilters `mapstructure:"metrics"` } // MetricFilter filters by Metric properties. diff --git a/processor/filterprocessor/config_test.go b/processor/filterprocessor/config_test.go index 9b7e9c5c670..fe90aa69085 100644 --- a/processor/filterprocessor/config_test.go +++ b/processor/filterprocessor/config_test.go @@ -58,7 +58,7 @@ func TestLoadingConfigStrict(t *testing.T) { { filterName: "filter/empty", expCfg: &Config{ - ProcessorSettings: config.ProcessorSettings{ + ProcessorSettings: &config.ProcessorSettings{ NameVal: "filter/empty", TypeVal: typeStr, }, @@ -71,7 +71,7 @@ func TestLoadingConfigStrict(t *testing.T) { }, { filterName: "filter/include", expCfg: &Config{ - ProcessorSettings: config.ProcessorSettings{ + ProcessorSettings: &config.ProcessorSettings{ NameVal: "filter/include", TypeVal: typeStr, }, @@ -82,7 +82,7 @@ func TestLoadingConfigStrict(t *testing.T) { }, { filterName: "filter/exclude", expCfg: &Config{ - ProcessorSettings: config.ProcessorSettings{ + ProcessorSettings: &config.ProcessorSettings{ NameVal: "filter/exclude", TypeVal: typeStr, }, @@ -93,7 +93,7 @@ func TestLoadingConfigStrict(t *testing.T) { }, { filterName: "filter/includeexclude", expCfg: &Config{ - ProcessorSettings: config.ProcessorSettings{ + ProcessorSettings: &config.ProcessorSettings{ NameVal: "filter/includeexclude", TypeVal: typeStr, }, @@ -152,7 +152,7 @@ func TestLoadingConfigRegexp(t *testing.T) { { filterName: "filter/include", expCfg: &Config{ - ProcessorSettings: config.ProcessorSettings{ + ProcessorSettings: &config.ProcessorSettings{ NameVal: "filter/include", TypeVal: typeStr, }, @@ -163,7 +163,7 @@ func TestLoadingConfigRegexp(t *testing.T) { }, { filterName: "filter/exclude", expCfg: &Config{ - ProcessorSettings: config.ProcessorSettings{ + ProcessorSettings: &config.ProcessorSettings{ NameVal: "filter/exclude", TypeVal: typeStr, }, @@ -174,7 +174,7 @@ func TestLoadingConfigRegexp(t *testing.T) { }, { filterName: "filter/unlimitedcache", expCfg: &Config{ - ProcessorSettings: config.ProcessorSettings{ + ProcessorSettings: &config.ProcessorSettings{ NameVal: "filter/unlimitedcache", TypeVal: typeStr, }, @@ -191,7 +191,7 @@ func TestLoadingConfigRegexp(t *testing.T) { }, { filterName: "filter/limitedcache", expCfg: &Config{ - ProcessorSettings: config.ProcessorSettings{ + ProcessorSettings: &config.ProcessorSettings{ NameVal: "filter/limitedcache", TypeVal: typeStr, }, @@ -233,7 +233,7 @@ func TestLoadingConfigExpr(t *testing.T) { { filterName: "filter/empty", expCfg: &Config{ - ProcessorSettings: config.ProcessorSettings{ + ProcessorSettings: &config.ProcessorSettings{ NameVal: "filter/empty", TypeVal: typeStr, }, @@ -247,7 +247,7 @@ func TestLoadingConfigExpr(t *testing.T) { { filterName: "filter/include", expCfg: &Config{ - ProcessorSettings: config.ProcessorSettings{ + ProcessorSettings: &config.ProcessorSettings{ NameVal: "filter/include", TypeVal: typeStr, }, @@ -265,7 +265,7 @@ func TestLoadingConfigExpr(t *testing.T) { { filterName: "filter/exclude", expCfg: &Config{ - ProcessorSettings: config.ProcessorSettings{ + ProcessorSettings: &config.ProcessorSettings{ NameVal: "filter/exclude", TypeVal: typeStr, }, @@ -283,7 +283,7 @@ func TestLoadingConfigExpr(t *testing.T) { { filterName: "filter/includeexclude", expCfg: &Config{ - ProcessorSettings: config.ProcessorSettings{ + ProcessorSettings: &config.ProcessorSettings{ NameVal: "filter/includeexclude", TypeVal: typeStr, }, diff --git a/processor/filterprocessor/factory.go b/processor/filterprocessor/factory.go index d0d38ae9131..7abebd474cd 100644 --- a/processor/filterprocessor/factory.go +++ b/processor/filterprocessor/factory.go @@ -40,10 +40,7 @@ func NewFactory() component.ProcessorFactory { func createDefaultConfig() config.Processor { return &Config{ - ProcessorSettings: config.ProcessorSettings{ - TypeVal: typeStr, - NameVal: typeStr, - }, + ProcessorSettings: config.NewProcessorSettings(typeStr), } } diff --git a/processor/filterprocessor/factory_test.go b/processor/filterprocessor/factory_test.go index e7687a890c7..727573bf808 100644 --- a/processor/filterprocessor/factory_test.go +++ b/processor/filterprocessor/factory_test.go @@ -42,10 +42,7 @@ func TestCreateDefaultConfig(t *testing.T) { factory := NewFactory() cfg := factory.CreateDefaultConfig() assert.Equal(t, cfg, &Config{ - ProcessorSettings: config.ProcessorSettings{ - NameVal: typeStr, - TypeVal: typeStr, - }, + ProcessorSettings: config.NewProcessorSettings(typeStr), }) assert.NoError(t, configcheck.ValidateConfig(cfg)) } diff --git a/processor/filterprocessor/filter_processor_test.go b/processor/filterprocessor/filter_processor_test.go index 2f5fb4190c1..15d83e605b1 100644 --- a/processor/filterprocessor/filter_processor_test.go +++ b/processor/filterprocessor/filter_processor_test.go @@ -306,10 +306,7 @@ func TestFilterMetricProcessor(t *testing.T) { // next stores the results of the filter metric processor next := new(consumertest.MetricsSink) cfg := &Config{ - ProcessorSettings: config.ProcessorSettings{ - TypeVal: typeStr, - NameVal: typeStr, - }, + ProcessorSettings: config.NewProcessorSettings(typeStr), Metrics: MetricFilters{ Include: test.inc, Exclude: test.exc, diff --git a/processor/memorylimiter/config.go b/processor/memorylimiter/config.go index a45cebc981b..fbb4027fade 100644 --- a/processor/memorylimiter/config.go +++ b/processor/memorylimiter/config.go @@ -25,7 +25,7 @@ import ( // Config defines configuration for memory memoryLimiter processor. type Config struct { - config.ProcessorSettings `mapstructure:",squash"` + *config.ProcessorSettings `mapstructure:"-"` // 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/memorylimiter/config_test.go b/processor/memorylimiter/config_test.go index b67022c3a93..a640c457999 100644 --- a/processor/memorylimiter/config_test.go +++ b/processor/memorylimiter/config_test.go @@ -45,16 +45,13 @@ func TestLoadConfig(t *testing.T) { p0 := cfg.Processors["memory_limiter"] assert.Equal(t, p0, &Config{ - ProcessorSettings: config.ProcessorSettings{ - TypeVal: "memory_limiter", - NameVal: "memory_limiter", - }, + ProcessorSettings: config.NewProcessorSettings(typeStr), }) p1 := cfg.Processors["memory_limiter/with-settings"] assert.Equal(t, p1, &Config{ - ProcessorSettings: config.ProcessorSettings{ + ProcessorSettings: &config.ProcessorSettings{ TypeVal: "memory_limiter", NameVal: "memory_limiter/with-settings", }, diff --git a/processor/memorylimiter/factory.go b/processor/memorylimiter/factory.go index 0ba78ed6286..b4bb6e6c8af 100644 --- a/processor/memorylimiter/factory.go +++ b/processor/memorylimiter/factory.go @@ -44,10 +44,7 @@ func NewFactory() component.ProcessorFactory { // that the default configuration is expected to fail for this processor. func createDefaultConfig() config.Processor { return &Config{ - ProcessorSettings: config.ProcessorSettings{ - TypeVal: typeStr, - NameVal: typeStr, - }, + ProcessorSettings: config.NewProcessorSettings(typeStr), } } diff --git a/processor/memorylimiter/memorylimiter_test.go b/processor/memorylimiter/memorylimiter_test.go index 9d6e9237864..ed3d6843cb8 100644 --- a/processor/memorylimiter/memorylimiter_test.go +++ b/processor/memorylimiter/memorylimiter_test.go @@ -119,10 +119,7 @@ func TestMetricsMemoryPressureResponse(t *testing.T) { } mp, err := processorhelper.NewMetricsProcessor( &Config{ - ProcessorSettings: config.ProcessorSettings{ - TypeVal: typeStr, - NameVal: typeStr, - }, + ProcessorSettings: config.NewProcessorSettings(typeStr), }, consumertest.NewMetricsNop(), ml, @@ -193,10 +190,7 @@ func TestTraceMemoryPressureResponse(t *testing.T) { } tp, err := processorhelper.NewTraceProcessor( &Config{ - ProcessorSettings: config.ProcessorSettings{ - TypeVal: typeStr, - NameVal: typeStr, - }, + ProcessorSettings: config.NewProcessorSettings(typeStr), }, consumertest.NewTracesNop(), ml, @@ -267,10 +261,7 @@ func TestLogMemoryPressureResponse(t *testing.T) { } lp, err := processorhelper.NewLogsProcessor( &Config{ - ProcessorSettings: config.ProcessorSettings{ - TypeVal: typeStr, - NameVal: typeStr, - }, + ProcessorSettings: config.NewProcessorSettings(typeStr), }, consumertest.NewLogsNop(), ml, diff --git a/processor/probabilisticsamplerprocessor/config.go b/processor/probabilisticsamplerprocessor/config.go index ed7eccfa90c..758ef93c9f9 100644 --- a/processor/probabilisticsamplerprocessor/config.go +++ b/processor/probabilisticsamplerprocessor/config.go @@ -20,7 +20,7 @@ import ( // Config has the configuration guiding the trace sampler processor. type Config struct { - config.ProcessorSettings `mapstructure:",squash"` + *config.ProcessorSettings `mapstructure:"-"` // SamplingPercentage is the percentage rate at which traces are going to be sampled. Defaults to zero, i.e.: no sample. // Values greater or equal 100 are treated as "sample all traces". SamplingPercentage float32 `mapstructure:"sampling_percentage"` diff --git a/processor/probabilisticsamplerprocessor/config_test.go b/processor/probabilisticsamplerprocessor/config_test.go index cc5676a19f4..04022bdc7bc 100644 --- a/processor/probabilisticsamplerprocessor/config_test.go +++ b/processor/probabilisticsamplerprocessor/config_test.go @@ -41,10 +41,7 @@ func TestLoadConfig(t *testing.T) { p0 := cfg.Processors["probabilistic_sampler"] assert.Equal(t, p0, &Config{ - ProcessorSettings: config.ProcessorSettings{ - TypeVal: "probabilistic_sampler", - NameVal: "probabilistic_sampler", - }, + ProcessorSettings: config.NewProcessorSettings(typeStr), SamplingPercentage: 15.3, HashSeed: 22, }) diff --git a/processor/probabilisticsamplerprocessor/factory.go b/processor/probabilisticsamplerprocessor/factory.go index f0cfef8b4dd..8f66958a49b 100644 --- a/processor/probabilisticsamplerprocessor/factory.go +++ b/processor/probabilisticsamplerprocessor/factory.go @@ -38,10 +38,7 @@ func NewFactory() component.ProcessorFactory { func createDefaultConfig() config.Processor { return &Config{ - ProcessorSettings: config.ProcessorSettings{ - TypeVal: typeStr, - NameVal: typeStr, - }, + ProcessorSettings: config.NewProcessorSettings(typeStr), } } diff --git a/processor/resourceprocessor/config.go b/processor/resourceprocessor/config.go index 15cb3c7bb95..6d15c465c12 100644 --- a/processor/resourceprocessor/config.go +++ b/processor/resourceprocessor/config.go @@ -21,7 +21,7 @@ import ( // Config defines configuration for Resource processor. type Config struct { - config.ProcessorSettings `mapstructure:",squash"` + *config.ProcessorSettings `mapstructure:"-"` // AttributesActions specifies the list of actions to be applied on resource attributes. // The set of actions are {INSERT, UPDATE, UPSERT, DELETE, HASH, EXTRACT}. diff --git a/processor/resourceprocessor/config_test.go b/processor/resourceprocessor/config_test.go index 357ef7f944e..f3f6537c7c3 100644 --- a/processor/resourceprocessor/config_test.go +++ b/processor/resourceprocessor/config_test.go @@ -37,10 +37,7 @@ func TestLoadConfig(t *testing.T) { assert.NotNil(t, cfg) assert.Equal(t, cfg.Processors["resource"], &Config{ - ProcessorSettings: config.ProcessorSettings{ - TypeVal: "resource", - NameVal: "resource", - }, + ProcessorSettings: config.NewProcessorSettings(typeStr), AttributesActions: []processorhelper.ActionKeyValue{ {Key: "cloud.availability_zone", Value: "zone-1", Action: processorhelper.UPSERT}, {Key: "k8s.cluster.name", FromAttribute: "k8s-cluster", Action: processorhelper.INSERT}, @@ -49,7 +46,7 @@ func TestLoadConfig(t *testing.T) { }) assert.Equal(t, cfg.Processors["resource/invalid"], &Config{ - ProcessorSettings: config.ProcessorSettings{ + ProcessorSettings: &config.ProcessorSettings{ TypeVal: "resource", NameVal: "resource/invalid", }, diff --git a/processor/resourceprocessor/factory.go b/processor/resourceprocessor/factory.go index 478978d8eec..6407e75a618 100644 --- a/processor/resourceprocessor/factory.go +++ b/processor/resourceprocessor/factory.go @@ -44,10 +44,7 @@ func NewFactory() component.ProcessorFactory { // Note: This isn't a valid configuration because the processor would do no work. func createDefaultConfig() config.Processor { return &Config{ - ProcessorSettings: config.ProcessorSettings{ - TypeVal: typeStr, - NameVal: typeStr, - }, + ProcessorSettings: config.NewProcessorSettings(typeStr), } } diff --git a/processor/resourceprocessor/factory_test.go b/processor/resourceprocessor/factory_test.go index 8626e4d62f6..62ade8723c2 100644 --- a/processor/resourceprocessor/factory_test.go +++ b/processor/resourceprocessor/factory_test.go @@ -37,10 +37,7 @@ func TestCreateDefaultConfig(t *testing.T) { func TestCreateProcessor(t *testing.T) { factory := NewFactory() cfg := &Config{ - ProcessorSettings: config.ProcessorSettings{ - TypeVal: "resource", - NameVal: "resource", - }, + ProcessorSettings: config.NewProcessorSettings(typeStr), AttributesActions: []processorhelper.ActionKeyValue{ {Key: "cloud.availability_zone", Value: "zone-1", Action: processorhelper.UPSERT}, }, @@ -69,10 +66,7 @@ func TestInvalidEmptyActions(t *testing.T) { func TestInvalidAttributeActions(t *testing.T) { factory := NewFactory() cfg := &Config{ - ProcessorSettings: config.ProcessorSettings{ - TypeVal: "resource", - NameVal: "resource", - }, + ProcessorSettings: config.NewProcessorSettings(typeStr), AttributesActions: []processorhelper.ActionKeyValue{ {Key: "k", Value: "v", Action: "invalid-action"}, }, diff --git a/processor/resourceprocessor/resource_processor_test.go b/processor/resourceprocessor/resource_processor_test.go index 9eb1b2792d3..ea046ddb101 100644 --- a/processor/resourceprocessor/resource_processor_test.go +++ b/processor/resourceprocessor/resource_processor_test.go @@ -29,13 +29,8 @@ import ( ) var ( - processorSettings = config.ProcessorSettings{ - TypeVal: "resource", - NameVal: "resource", - } - cfg = &Config{ - ProcessorSettings: processorSettings, + ProcessorSettings: config.NewProcessorSettings(typeStr), AttributesActions: []processorhelper.ActionKeyValue{ {Key: "cloud.availability_zone", Value: "zone-1", Action: processorhelper.UPSERT}, {Key: "k8s.cluster.name", FromAttribute: "k8s-cluster", Action: processorhelper.INSERT}, @@ -84,7 +79,7 @@ func TestResourceProcessorAttributesUpsert(t *testing.T) { { name: "config_attributes_replacement", config: &Config{ - ProcessorSettings: processorSettings, + ProcessorSettings: config.NewProcessorSettings(typeStr), AttributesActions: []processorhelper.ActionKeyValue{ {Key: "k8s.cluster.name", FromAttribute: "k8s-cluster", Action: processorhelper.INSERT}, {Key: "k8s-cluster", Action: processorhelper.DELETE}, @@ -146,7 +141,7 @@ func TestResourceProcessorError(t *testing.T) { ttn := &testTraceConsumer{} badCfg := &Config{ - ProcessorSettings: processorSettings, + ProcessorSettings: config.NewProcessorSettings(typeStr), AttributesActions: nil, } diff --git a/processor/spanprocessor/config.go b/processor/spanprocessor/config.go index 591579b56c2..e670bff75a4 100644 --- a/processor/spanprocessor/config.go +++ b/processor/spanprocessor/config.go @@ -24,7 +24,7 @@ import ( // the include properties and then the exclude properties if they are specified. // This determines if a span is to be processed or not. type Config struct { - config.ProcessorSettings `mapstructure:",squash"` + *config.ProcessorSettings `mapstructure:"-"` filterconfig.MatchConfig `mapstructure:",squash"` diff --git a/processor/spanprocessor/config_test.go b/processor/spanprocessor/config_test.go index bdffbd736d3..69cc0f7a9ca 100644 --- a/processor/spanprocessor/config_test.go +++ b/processor/spanprocessor/config_test.go @@ -41,7 +41,7 @@ func TestLoadConfig(t *testing.T) { p0 := cfg.Processors["span/custom"] assert.Equal(t, p0, &Config{ - ProcessorSettings: config.ProcessorSettings{ + ProcessorSettings: &config.ProcessorSettings{ TypeVal: typeStr, NameVal: "span/custom", }, @@ -53,7 +53,7 @@ func TestLoadConfig(t *testing.T) { p1 := cfg.Processors["span/no-separator"] assert.Equal(t, p1, &Config{ - ProcessorSettings: config.ProcessorSettings{ + ProcessorSettings: &config.ProcessorSettings{ TypeVal: typeStr, NameVal: "span/no-separator", }, @@ -65,7 +65,7 @@ func TestLoadConfig(t *testing.T) { p2 := cfg.Processors["span/to_attributes"] assert.Equal(t, p2, &Config{ - ProcessorSettings: config.ProcessorSettings{ + ProcessorSettings: &config.ProcessorSettings{ TypeVal: typeStr, NameVal: "span/to_attributes", }, @@ -78,7 +78,7 @@ func TestLoadConfig(t *testing.T) { p3 := cfg.Processors["span/includeexclude"] assert.Equal(t, p3, &Config{ - ProcessorSettings: config.ProcessorSettings{ + ProcessorSettings: &config.ProcessorSettings{ TypeVal: typeStr, NameVal: "span/includeexclude", }, diff --git a/processor/spanprocessor/factory.go b/processor/spanprocessor/factory.go index 1d039a5351b..5a03da6794c 100644 --- a/processor/spanprocessor/factory.go +++ b/processor/spanprocessor/factory.go @@ -47,10 +47,7 @@ func NewFactory() component.ProcessorFactory { func createDefaultConfig() config.Processor { return &Config{ - ProcessorSettings: config.ProcessorSettings{ - TypeVal: typeStr, - NameVal: typeStr, - }, + ProcessorSettings: config.NewProcessorSettings(typeStr), } } diff --git a/service/internal/builder/exporters_builder_test.go b/service/internal/builder/exporters_builder_test.go index 5e236b1d3cd..419d994f323 100644 --- a/service/internal/builder/exporters_builder_test.go +++ b/service/internal/builder/exporters_builder_test.go @@ -41,10 +41,7 @@ func TestBuildExporters(t *testing.T) { cfg := &config.Config{ Exporters: map[string]config.Exporter{ "opencensus": &opencensusexporter.Config{ - ExporterSettings: config.ExporterSettings{ - NameVal: "opencensus", - TypeVal: "opencensus", - }, + ExporterSettings: config.NewExporterSettings("opencensus"), GRPCClientSettings: configgrpc.GRPCClientSettings{ Endpoint: "0.0.0.0:12345", },