diff --git a/.chloggen/deprecateallconfig.yaml b/.chloggen/deprecateallconfig.yaml new file mode 100755 index 00000000000..4c96c631d21 --- /dev/null +++ b/.chloggen/deprecateallconfig.yaml @@ -0,0 +1,31 @@ +# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' +change_type: deprecation + +# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver) +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 + +# One or more tracking issues or pull requests related to the change +issues: [6422] + +# (Optional) One or more lines of additional information to render under the primary note. +# These lines will be padded with 2 spaces and then inserted directly into the document. +# Use pipe (|) for multiline entries. +subtext: | + - config.ComponentID => component.ID + - config.Type => component.Type + - 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/otelcorecol/components_test.go b/cmd/otelcorecol/components_test.go index 8e1f194ed5f..09f867d84f8 100644 --- a/cmd/otelcorecol/components_test.go +++ b/cmd/otelcorecol/components_test.go @@ -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/component.go b/component/component.go index 14b23c122d7..277bf938fa8 100644 --- a/component/component.go +++ b/component/component.go @@ -17,8 +17,6 @@ package component // import "go.opentelemetry.io/collector/component" import ( "context" "errors" - - "go.opentelemetry.io/collector/config" ) var ( @@ -162,17 +160,17 @@ func (sl StabilityLevel) LogMessage() string { // use the factory helpers for the appropriate component type. type Factory interface { // Type gets the type of the component created by this factory. - Type() config.Type + Type() Type unexportedFactoryFunc() } type baseFactory struct { - cfgType config.Type + cfgType Type } func (baseFactory) unexportedFactoryFunc() {} -func (bf baseFactory) Type() config.Type { +func (bf baseFactory) Type() Type { return bf.cfgType } diff --git a/component/componenttest/configtest.go b/component/componenttest/configtest.go new file mode 100644 index 00000000000..bbbf3b3bdfe --- /dev/null +++ b/component/componenttest/configtest.go @@ -0,0 +1,147 @@ +// 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 componenttest // import "go.opentelemetry.io/collector/component/componenttest" + +import ( + "fmt" + "reflect" + "regexp" + "strings" + + "go.uber.org/multierr" +) + +// The regular expression for valid config field tag. +var configFieldTagRegExp = regexp.MustCompile("^[a-z0-9][a-z0-9_]*$") + +// CheckConfigStruct enforces that given configuration object is following the patterns +// used by the collector. This ensures consistency between different implementations +// of components and extensions. It is recommended for implementers of components +// to call this function on their tests passing the default configuration of the +// component factory. +func CheckConfigStruct(config interface{}) error { + t := reflect.TypeOf(config) + if t.Kind() == reflect.Ptr { + t = t.Elem() + } + + if t.Kind() != reflect.Struct { + return fmt.Errorf("config must be a struct or a pointer to one, the passed object is a %s", t.Kind()) + } + + return validateConfigDataType(t) +} + +// validateConfigDataType performs a descending validation of the given type. +// If the type is a struct it goes to each of its fields to check for the proper +// tags. +func validateConfigDataType(t reflect.Type) error { + var errs error + + switch t.Kind() { + case reflect.Ptr: + errs = multierr.Append(errs, validateConfigDataType(t.Elem())) + case reflect.Struct: + // Reflect on the pointed data and check each of its fields. + nf := t.NumField() + for i := 0; i < nf; i++ { + f := t.Field(i) + errs = multierr.Append(errs, checkStructFieldTags(f)) + } + default: + // The config object can carry other types but they are not used when + // reading the configuration via koanf so ignore them. Basically ignore: + // reflect.Uintptr, reflect.Chan, reflect.Func, reflect.Interface, and + // reflect.UnsafePointer. + } + + if errs != nil { + return fmt.Errorf("type %q from package %q has invalid config settings: %w", t.Name(), t.PkgPath(), errs) + } + + return nil +} + +// checkStructFieldTags inspects the tags of a struct field. +func checkStructFieldTags(f reflect.StructField) error { + + tagValue := f.Tag.Get("mapstructure") + if tagValue == "" { + + // Ignore special types. + switch f.Type.Kind() { + case reflect.Interface, reflect.Chan, reflect.Func, reflect.Uintptr, reflect.UnsafePointer: + // Allow the config to carry the types above, but since they are not read + // when loading configuration, just ignore them. + return nil + } + + // Public fields of other types should be tagged. + chars := []byte(f.Name) + if len(chars) > 0 && chars[0] >= 'A' && chars[0] <= 'Z' { + return fmt.Errorf("mapstructure tag not present on field %q", f.Name) + } + + // Not public field, no need to have a tag. + return nil + } + + tagParts := strings.Split(tagValue, ",") + if tagParts[0] != "" { + if tagParts[0] == "-" { + // Nothing to do, as mapstructure decode skips this field. + return nil + } + } + + // Check if squash is specified. + squash := false + for _, tag := range tagParts[1:] { + if tag == "squash" { + squash = true + break + } + } + + if squash { + // Field was squashed. + if (f.Type.Kind() != reflect.Struct) && (f.Type.Kind() != reflect.Ptr || f.Type.Elem().Kind() != reflect.Struct) { + return fmt.Errorf( + "attempt to squash non-struct type on field %q", f.Name) + } + } + + switch f.Type.Kind() { + case reflect.Struct: + // It is another struct, continue down-level. + return validateConfigDataType(f.Type) + + case reflect.Map, reflect.Slice, reflect.Array: + // The element of map, array, or slice can be itself a configuration object. + return validateConfigDataType(f.Type.Elem()) + + default: + fieldTag := tagParts[0] + if !configFieldTagRegExp.MatchString(fieldTag) { + return fmt.Errorf( + "field %q has config tag %q which doesn't satisfy %q", + f.Name, + fieldTag, + configFieldTagRegExp.String()) + } + } + + return nil +} diff --git a/config/configtest/configtest_test.go b/component/componenttest/configtest_test.go similarity index 99% rename from config/configtest/configtest_test.go rename to component/componenttest/configtest_test.go index 6b2a0a0d2b6..36f8585e80a 100644 --- a/config/configtest/configtest_test.go +++ b/component/componenttest/configtest_test.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package configtest +package componenttest import ( "io" diff --git a/component/componenttest/nop_exporter.go b/component/componenttest/nop_exporter.go index 7e2e24ee867..ec63710775b 100644 --- a/component/componenttest/nop_exporter.go +++ b/component/componenttest/nop_exporter.go @@ -18,7 +18,6 @@ import ( "context" "go.opentelemetry.io/collector/component" - "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/consumer/consumertest" ) @@ -31,16 +30,16 @@ func NewNopExporterCreateSettings() component.ExporterCreateSettings { } type nopExporterConfig struct { - config.ExporterSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct + component.ExporterConfigSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct } // NewNopExporterFactory returns a component.ExporterFactory that constructs nop exporters. func NewNopExporterFactory() component.ExporterFactory { return component.NewExporterFactory( "nop", - func() config.Exporter { + func() component.ExporterConfig { return &nopExporterConfig{ - ExporterSettings: config.NewExporterSettings(config.NewComponentID("nop")), + ExporterConfigSettings: component.NewExporterConfigSettings(component.NewID("nop")), } }, component.WithTracesExporter(createTracesExporter, component.StabilityLevelStable), @@ -49,15 +48,15 @@ func NewNopExporterFactory() component.ExporterFactory { ) } -func createTracesExporter(context.Context, component.ExporterCreateSettings, config.Exporter) (component.TracesExporter, error) { +func createTracesExporter(context.Context, component.ExporterCreateSettings, component.ExporterConfig) (component.TracesExporter, error) { return nopExporterInstance, nil } -func createMetricsExporter(context.Context, component.ExporterCreateSettings, config.Exporter) (component.MetricsExporter, error) { +func createMetricsExporter(context.Context, component.ExporterCreateSettings, component.ExporterConfig) (component.MetricsExporter, error) { return nopExporterInstance, nil } -func createLogsExporter(context.Context, component.ExporterCreateSettings, config.Exporter) (component.LogsExporter, error) { +func createLogsExporter(context.Context, component.ExporterCreateSettings, component.ExporterConfig) (component.LogsExporter, error) { return nopExporterInstance, nil } diff --git a/component/componenttest/nop_exporter_test.go b/component/componenttest/nop_exporter_test.go index bb6f07d5060..827254e35e8 100644 --- a/component/componenttest/nop_exporter_test.go +++ b/component/componenttest/nop_exporter_test.go @@ -21,7 +21,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "go.opentelemetry.io/collector/config" + "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/pdata/plog" "go.opentelemetry.io/collector/pdata/pmetric" "go.opentelemetry.io/collector/pdata/ptrace" @@ -30,9 +30,9 @@ import ( func TestNewNopExporterFactory(t *testing.T) { factory := NewNopExporterFactory() require.NotNil(t, factory) - assert.Equal(t, config.Type("nop"), factory.Type()) + assert.Equal(t, component.Type("nop"), factory.Type()) cfg := factory.CreateDefaultConfig() - assert.Equal(t, &nopExporterConfig{ExporterSettings: config.NewExporterSettings(config.NewComponentID("nop"))}, cfg) + assert.Equal(t, &nopExporterConfig{ExporterConfigSettings: component.NewExporterConfigSettings(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 52c4a1cc5f6..94073d62b30 100644 --- a/component/componenttest/nop_extension.go +++ b/component/componenttest/nop_extension.go @@ -18,7 +18,6 @@ import ( "context" "go.opentelemetry.io/collector/component" - "go.opentelemetry.io/collector/config" ) // NewNopExtensionCreateSettings returns a new nop settings for Create*Extension functions. @@ -30,19 +29,19 @@ func NewNopExtensionCreateSettings() component.ExtensionCreateSettings { } type nopExtensionConfig struct { - config.ExtensionSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct + component.ExtensionConfigSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct } // NewNopExtensionFactory returns a component.ExtensionFactory that constructs nop extensions. func NewNopExtensionFactory() component.ExtensionFactory { return component.NewExtensionFactory( "nop", - func() config.Extension { + func() component.ExtensionConfig { return &nopExtensionConfig{ - ExtensionSettings: config.NewExtensionSettings(config.NewComponentID("nop")), + ExtensionConfigSettings: component.NewExtensionConfigSettings(component.NewID("nop")), } }, - func(context.Context, component.ExtensionCreateSettings, config.Extension) (component.Extension, error) { + func(context.Context, component.ExtensionCreateSettings, component.ExtensionConfig) (component.Extension, error) { return nopExtensionInstance, nil }, component.StabilityLevelStable) diff --git a/component/componenttest/nop_extension_test.go b/component/componenttest/nop_extension_test.go index bc43c274532..d3a71d4b302 100644 --- a/component/componenttest/nop_extension_test.go +++ b/component/componenttest/nop_extension_test.go @@ -21,15 +21,15 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "go.opentelemetry.io/collector/config" + "go.opentelemetry.io/collector/component" ) func TestNewNopExtensionFactory(t *testing.T) { factory := NewNopExtensionFactory() require.NotNil(t, factory) - assert.Equal(t, config.Type("nop"), factory.Type()) + assert.Equal(t, component.Type("nop"), factory.Type()) cfg := factory.CreateDefaultConfig() - assert.Equal(t, &nopExtensionConfig{ExtensionSettings: config.NewExtensionSettings(config.NewComponentID("nop"))}, cfg) + assert.Equal(t, &nopExtensionConfig{ExtensionConfigSettings: component.NewExtensionConfigSettings(component.NewID("nop"))}, cfg) traces, err := factory.CreateExtension(context.Background(), NewNopExtensionCreateSettings(), cfg) require.NoError(t, err) diff --git a/component/componenttest/nop_host.go b/component/componenttest/nop_host.go index 820a8d3ba6b..b535b674af6 100644 --- a/component/componenttest/nop_host.go +++ b/component/componenttest/nop_host.go @@ -16,7 +16,6 @@ package componenttest // import "go.opentelemetry.io/collector/component/compone import ( "go.opentelemetry.io/collector/component" - "go.opentelemetry.io/collector/config" ) // nopHost mocks a receiver.ReceiverHost for test purposes. @@ -29,14 +28,14 @@ func NewNopHost() component.Host { func (nh *nopHost) ReportFatalError(_ error) {} -func (nh *nopHost) GetFactory(_ component.Kind, _ config.Type) component.Factory { +func (nh *nopHost) GetFactory(_ component.Kind, _ component.Type) component.Factory { return nil } -func (nh *nopHost) GetExtensions() map[config.ComponentID]component.Extension { +func (nh *nopHost) GetExtensions() map[component.ID]component.Extension { return nil } -func (nh *nopHost) GetExporters() map[config.DataType]map[config.ComponentID]component.Exporter { +func (nh *nopHost) GetExporters() map[component.DataType]map[component.ID]component.Exporter { return nil } diff --git a/component/componenttest/nop_processor.go b/component/componenttest/nop_processor.go index ee81e50e122..c1f1ea60016 100644 --- a/component/componenttest/nop_processor.go +++ b/component/componenttest/nop_processor.go @@ -18,7 +18,6 @@ import ( "context" "go.opentelemetry.io/collector/component" - "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/consumer" "go.opentelemetry.io/collector/consumer/consumertest" ) @@ -32,16 +31,16 @@ func NewNopProcessorCreateSettings() component.ProcessorCreateSettings { } type nopProcessorConfig struct { - config.ProcessorSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct + component.ProcessorConfigSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct } // NewNopProcessorFactory returns a component.ProcessorFactory that constructs nop processors. func NewNopProcessorFactory() component.ProcessorFactory { return component.NewProcessorFactory( "nop", - func() config.Processor { + func() component.ProcessorConfig { return &nopProcessorConfig{ - ProcessorSettings: config.NewProcessorSettings(config.NewComponentID("nop")), + ProcessorConfigSettings: component.NewProcessorConfigSettings(component.NewID("nop")), } }, component.WithTracesProcessor(createTracesProcessor, component.StabilityLevelStable), @@ -50,15 +49,15 @@ func NewNopProcessorFactory() component.ProcessorFactory { ) } -func createTracesProcessor(context.Context, component.ProcessorCreateSettings, config.Processor, consumer.Traces) (component.TracesProcessor, error) { +func createTracesProcessor(context.Context, component.ProcessorCreateSettings, component.ProcessorConfig, consumer.Traces) (component.TracesProcessor, error) { return nopProcessorInstance, nil } -func createMetricsProcessor(context.Context, component.ProcessorCreateSettings, config.Processor, consumer.Metrics) (component.MetricsProcessor, error) { +func createMetricsProcessor(context.Context, component.ProcessorCreateSettings, component.ProcessorConfig, consumer.Metrics) (component.MetricsProcessor, error) { return nopProcessorInstance, nil } -func createLogsProcessor(context.Context, component.ProcessorCreateSettings, config.Processor, consumer.Logs) (component.LogsProcessor, error) { +func createLogsProcessor(context.Context, component.ProcessorCreateSettings, component.ProcessorConfig, consumer.Logs) (component.LogsProcessor, error) { return nopProcessorInstance, nil } diff --git a/component/componenttest/nop_processor_test.go b/component/componenttest/nop_processor_test.go index ad508499209..0855f6c9da9 100644 --- a/component/componenttest/nop_processor_test.go +++ b/component/componenttest/nop_processor_test.go @@ -21,7 +21,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "go.opentelemetry.io/collector/config" + "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/consumer" "go.opentelemetry.io/collector/consumer/consumertest" "go.opentelemetry.io/collector/pdata/plog" @@ -32,9 +32,9 @@ import ( func TestNewNopProcessorFactory(t *testing.T) { factory := NewNopProcessorFactory() require.NotNil(t, factory) - assert.Equal(t, config.Type("nop"), factory.Type()) + assert.Equal(t, component.Type("nop"), factory.Type()) cfg := factory.CreateDefaultConfig() - assert.Equal(t, &nopProcessorConfig{ProcessorSettings: config.NewProcessorSettings(config.NewComponentID("nop"))}, cfg) + assert.Equal(t, &nopProcessorConfig{ProcessorConfigSettings: component.NewProcessorConfigSettings(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 7ddbcb048a1..328429515d4 100644 --- a/component/componenttest/nop_receiver.go +++ b/component/componenttest/nop_receiver.go @@ -18,7 +18,6 @@ import ( "context" "go.opentelemetry.io/collector/component" - "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/consumer" ) @@ -31,16 +30,16 @@ func NewNopReceiverCreateSettings() component.ReceiverCreateSettings { } type nopReceiverConfig struct { - config.ReceiverSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct + component.ReceiverConfigSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct } // NewNopReceiverFactory returns a component.ReceiverFactory that constructs nop receivers. func NewNopReceiverFactory() component.ReceiverFactory { return component.NewReceiverFactory( "nop", - func() config.Receiver { + func() component.ReceiverConfig { return &nopReceiverConfig{ - ReceiverSettings: config.NewReceiverSettings(config.NewComponentID("nop")), + ReceiverConfigSettings: component.NewReceiverConfigSettings(component.NewID("nop")), } }, component.WithTracesReceiver(createTracesReceiver, component.StabilityLevelStable), @@ -48,15 +47,15 @@ func NewNopReceiverFactory() component.ReceiverFactory { component.WithLogsReceiver(createLogsReceiver, component.StabilityLevelStable)) } -func createTracesReceiver(context.Context, component.ReceiverCreateSettings, config.Receiver, consumer.Traces) (component.TracesReceiver, error) { +func createTracesReceiver(context.Context, component.ReceiverCreateSettings, component.ReceiverConfig, consumer.Traces) (component.TracesReceiver, error) { return nopReceiverInstance, nil } -func createMetricsReceiver(context.Context, component.ReceiverCreateSettings, config.Receiver, consumer.Metrics) (component.MetricsReceiver, error) { +func createMetricsReceiver(context.Context, component.ReceiverCreateSettings, component.ReceiverConfig, consumer.Metrics) (component.MetricsReceiver, error) { return nopReceiverInstance, nil } -func createLogsReceiver(context.Context, component.ReceiverCreateSettings, config.Receiver, consumer.Logs) (component.LogsReceiver, error) { +func createLogsReceiver(context.Context, component.ReceiverCreateSettings, component.ReceiverConfig, consumer.Logs) (component.LogsReceiver, error) { return nopReceiverInstance, nil } diff --git a/component/componenttest/nop_receiver_test.go b/component/componenttest/nop_receiver_test.go index 2cac9a43650..b96cf34772d 100644 --- a/component/componenttest/nop_receiver_test.go +++ b/component/componenttest/nop_receiver_test.go @@ -21,16 +21,16 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "go.opentelemetry.io/collector/config" + "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/consumer/consumertest" ) func TestNewNopReceiverFactory(t *testing.T) { factory := NewNopReceiverFactory() require.NotNil(t, factory) - assert.Equal(t, config.Type("nop"), factory.Type()) + assert.Equal(t, component.Type("nop"), factory.Type()) cfg := factory.CreateDefaultConfig() - assert.Equal(t, &nopReceiverConfig{ReceiverSettings: config.NewReceiverSettings(config.NewComponentID("nop"))}, cfg) + assert.Equal(t, &nopReceiverConfig{ReceiverConfigSettings: component.NewReceiverConfigSettings(component.NewID("nop"))}, cfg) traces, err := factory.CreateTracesReceiver(context.Background(), NewNopReceiverCreateSettings(), cfg, consumertest.NewNop()) require.NoError(t, err) diff --git a/component/componenttest/shutdown_verifier.go b/component/componenttest/shutdown_verifier.go index 249d3e08bf3..06a6088398c 100644 --- a/component/componenttest/shutdown_verifier.go +++ b/component/componenttest/shutdown_verifier.go @@ -23,12 +23,11 @@ import ( "github.com/stretchr/testify/require" "go.opentelemetry.io/collector/component" - "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/consumer/consumertest" "go.opentelemetry.io/collector/internal/testdata" ) -func verifyTracesProcessorDoesntProduceAfterShutdown(t *testing.T, factory component.ProcessorFactory, cfg config.Processor) { +func verifyTracesProcessorDoesntProduceAfterShutdown(t *testing.T, factory component.ProcessorFactory, cfg component.ProcessorConfig) { // Create a processor and output its produce to a sink. nextSink := new(consumertest.TracesSink) processor, err := factory.CreateTracesProcessor( @@ -62,7 +61,7 @@ func verifyTracesProcessorDoesntProduceAfterShutdown(t *testing.T, factory compo } // VerifyProcessorShutdown verifies the processor doesn't produce telemetry data after shutdown. -func VerifyProcessorShutdown(t *testing.T, factory component.ProcessorFactory, cfg config.Processor) { +func VerifyProcessorShutdown(t *testing.T, factory component.ProcessorFactory, cfg component.ProcessorConfig) { verifyTracesProcessorDoesntProduceAfterShutdown(t, factory, cfg) // TODO: add metrics and logs verification. // TODO: add other shutdown verifications. diff --git a/config/common.go b/component/config.go similarity index 96% rename from config/common.go rename to component/config.go index 23b4e41eaa8..a72d8a25fc9 100644 --- a/config/common.go +++ b/component/config.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package config // import "go.opentelemetry.io/collector/config" +package component // import "go.opentelemetry.io/collector/component" import ( "go.opentelemetry.io/collector/confmap" diff --git a/component/experimental/component/factory.go b/component/experimental/component/factory.go index 420d7885ee9..cb15b114ca1 100644 --- a/component/experimental/component/factory.go +++ b/component/experimental/component/factory.go @@ -20,7 +20,6 @@ import ( "go.uber.org/zap" "go.opentelemetry.io/collector/component" - stableconfig "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/config/experimental/config" "go.opentelemetry.io/collector/config/experimental/configsource" ) @@ -44,7 +43,7 @@ type ConfigSourceFactory interface { // configuration and should not cause side-effects that prevent the creation // of multiple instances of the Source. // The object returned by this method needs to pass the checks implemented by - // 'configtest.CheckConfigStruct'. It is recommended to have such check in the + // 'componenttest.CheckConfigStruct'. It is recommended to have such check in the // tests of any implementation of the ConfigSourceFactory interface. CreateDefaultConfig() config.Source @@ -57,4 +56,4 @@ type ConfigSourceFactory interface { } // ConfigSourceFactories maps the type of a ConfigSource to the respective factory object. -type ConfigSourceFactories map[stableconfig.Type]ConfigSourceFactory +type ConfigSourceFactories map[component.Type]ConfigSourceFactory diff --git a/component/exporter.go b/component/exporter.go index fbceda215e0..f610c2b575c 100644 --- a/component/exporter.go +++ b/component/exporter.go @@ -17,7 +17,6 @@ package component // import "go.opentelemetry.io/collector/component" import ( "context" - "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/consumer" ) @@ -64,14 +63,14 @@ type ExporterFactory interface { // configuration and should not cause side-effects that prevent the creation // of multiple instances of the Exporter. // The object returned by this method needs to pass the checks implemented by - // 'configtest.CheckConfigStruct'. It is recommended to have these checks in the + // 'componenttest.CheckConfigStruct'. It is recommended to have these checks in the // tests of any implementation of the Factory interface. - CreateDefaultConfig() config.Exporter + CreateDefaultConfig() ExporterConfig // CreateTracesExporter creates a TracesExporter based on this config. // If the exporter type does not support tracing or if the config is not valid, // an error will be returned instead. - CreateTracesExporter(ctx context.Context, set ExporterCreateSettings, cfg config.Exporter) (TracesExporter, error) + CreateTracesExporter(ctx context.Context, set ExporterCreateSettings, cfg ExporterConfig) (TracesExporter, error) // TracesExporterStability gets the stability level of the TracesExporter. TracesExporterStability() StabilityLevel @@ -79,7 +78,7 @@ type ExporterFactory interface { // CreateMetricsExporter creates a MetricsExporter based on this config. // If the exporter type does not support metrics or if the config is not valid, // an error will be returned instead. - CreateMetricsExporter(ctx context.Context, set ExporterCreateSettings, cfg config.Exporter) (MetricsExporter, error) + CreateMetricsExporter(ctx context.Context, set ExporterCreateSettings, cfg ExporterConfig) (MetricsExporter, error) // MetricsExporterStability gets the stability level of the MetricsExporter. MetricsExporterStability() StabilityLevel @@ -87,7 +86,7 @@ type ExporterFactory interface { // CreateLogsExporter creates a LogsExporter based on the config. // If the exporter type does not support logs or if the config is not valid, // an error will be returned instead. - CreateLogsExporter(ctx context.Context, set ExporterCreateSettings, cfg config.Exporter) (LogsExporter, error) + CreateLogsExporter(ctx context.Context, set ExporterCreateSettings, cfg ExporterConfig) (LogsExporter, error) // LogsExporterStability gets the stability level of the LogsExporter. LogsExporterStability() StabilityLevel @@ -109,18 +108,18 @@ func (f exporterFactoryOptionFunc) applyExporterFactoryOption(o *exporterFactory } // ExporterCreateDefaultConfigFunc is the equivalent of ExporterFactory.CreateDefaultConfig(). -type ExporterCreateDefaultConfigFunc func() config.Exporter +type ExporterCreateDefaultConfigFunc func() ExporterConfig // CreateDefaultConfig implements ExporterFactory.CreateDefaultConfig(). -func (f ExporterCreateDefaultConfigFunc) CreateDefaultConfig() config.Exporter { +func (f ExporterCreateDefaultConfigFunc) CreateDefaultConfig() ExporterConfig { return f() } // CreateTracesExporterFunc is the equivalent of ExporterFactory.CreateTracesExporter(). -type CreateTracesExporterFunc func(context.Context, ExporterCreateSettings, config.Exporter) (TracesExporter, error) +type CreateTracesExporterFunc func(context.Context, ExporterCreateSettings, ExporterConfig) (TracesExporter, error) // CreateTracesExporter implements ExporterFactory.CreateTracesExporter(). -func (f CreateTracesExporterFunc) CreateTracesExporter(ctx context.Context, set ExporterCreateSettings, cfg config.Exporter) (TracesExporter, error) { +func (f CreateTracesExporterFunc) CreateTracesExporter(ctx context.Context, set ExporterCreateSettings, cfg ExporterConfig) (TracesExporter, error) { if f == nil { return nil, ErrDataTypeIsNotSupported } @@ -128,10 +127,10 @@ func (f CreateTracesExporterFunc) CreateTracesExporter(ctx context.Context, set } // CreateMetricsExporterFunc is the equivalent of ExporterFactory.CreateMetricsExporter(). -type CreateMetricsExporterFunc func(context.Context, ExporterCreateSettings, config.Exporter) (MetricsExporter, error) +type CreateMetricsExporterFunc func(context.Context, ExporterCreateSettings, ExporterConfig) (MetricsExporter, error) // CreateMetricsExporter implements ExporterFactory.CreateMetricsExporter(). -func (f CreateMetricsExporterFunc) CreateMetricsExporter(ctx context.Context, set ExporterCreateSettings, cfg config.Exporter) (MetricsExporter, error) { +func (f CreateMetricsExporterFunc) CreateMetricsExporter(ctx context.Context, set ExporterCreateSettings, cfg ExporterConfig) (MetricsExporter, error) { if f == nil { return nil, ErrDataTypeIsNotSupported } @@ -139,10 +138,10 @@ func (f CreateMetricsExporterFunc) CreateMetricsExporter(ctx context.Context, se } // CreateLogsExporterFunc is the equivalent of ExporterFactory.CreateLogsExporter(). -type CreateLogsExporterFunc func(context.Context, ExporterCreateSettings, config.Exporter) (LogsExporter, error) +type CreateLogsExporterFunc func(context.Context, ExporterCreateSettings, ExporterConfig) (LogsExporter, error) // CreateLogsExporter implements ExporterFactory.CreateLogsExporter(). -func (f CreateLogsExporterFunc) CreateLogsExporter(ctx context.Context, set ExporterCreateSettings, cfg config.Exporter) (LogsExporter, error) { +func (f CreateLogsExporterFunc) CreateLogsExporter(ctx context.Context, set ExporterCreateSettings, cfg ExporterConfig) (LogsExporter, error) { if f == nil { return nil, ErrDataTypeIsNotSupported } @@ -197,7 +196,7 @@ func WithLogsExporter(createLogsExporter CreateLogsExporterFunc, sl StabilityLev } // NewExporterFactory returns a ExporterFactory. -func NewExporterFactory(cfgType config.Type, createDefaultConfig ExporterCreateDefaultConfigFunc, options ...ExporterFactoryOption) ExporterFactory { +func NewExporterFactory(cfgType Type, createDefaultConfig ExporterCreateDefaultConfigFunc, options ...ExporterFactoryOption) ExporterFactory { f := &exporterFactory{ baseFactory: baseFactory{cfgType: cfgType}, ExporterCreateDefaultConfigFunc: createDefaultConfig, diff --git a/config/exporter.go b/component/exporter_config.go similarity index 58% rename from config/exporter.go rename to component/exporter_config.go index ed8cbc2d08d..ae10a51d0b2 100644 --- a/config/exporter.go +++ b/component/exporter_config.go @@ -12,57 +12,58 @@ // See the License for the specific language governing permissions and // limitations under the License. -package config // import "go.opentelemetry.io/collector/config" +package component // import "go.opentelemetry.io/collector/component" + import ( "go.opentelemetry.io/collector/confmap" ) -// Exporter is the configuration of a component.Exporter. Specific extensions must implement +// 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 Exporter interface { +type ExporterConfig interface { identifiable validatable privateConfigExporter() } -// UnmarshalExporter helper function to unmarshal an Exporter config. +// 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 UnmarshalExporter(conf *confmap.Conf, cfg Exporter) error { +func UnmarshalExporterConfig(conf *confmap.Conf, cfg ExporterConfig) error { return unmarshal(conf, cfg) } -// ExporterSettings defines common settings for a component.Exporter configuration. +// 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 ExporterSettings struct { - id ComponentID `mapstructure:"-"` +type ExporterConfigSettings struct { + id ID `mapstructure:"-"` } -// NewExporterSettings return a new ExporterSettings with the given ComponentID. -func NewExporterSettings(id ComponentID) ExporterSettings { - return ExporterSettings{id: ComponentID{typeVal: id.Type(), nameVal: id.Name()}} +// 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 _ Exporter = (*ExporterSettings)(nil) +var _ ExporterConfig = (*ExporterConfigSettings)(nil) // ID returns the receiver ComponentID. -func (es *ExporterSettings) ID() ComponentID { +func (es *ExporterConfigSettings) ID() ID { return es.id } // SetIDName sets the receiver name. -func (es *ExporterSettings) SetIDName(idName string) { +func (es *ExporterConfigSettings) SetIDName(idName string) { es.id.nameVal = idName } // Validate validates the configuration and returns an error if invalid. -func (es *ExporterSettings) Validate() error { +func (es *ExporterConfigSettings) Validate() error { return nil } -func (es *ExporterSettings) privateConfigExporter() {} +func (es *ExporterConfigSettings) privateConfigExporter() {} diff --git a/component/exporter_test.go b/component/exporter_test.go index 978b90d2cbb..553710dd208 100644 --- a/component/exporter_test.go +++ b/component/exporter_test.go @@ -19,16 +19,14 @@ import ( "testing" "github.com/stretchr/testify/assert" - - "go.opentelemetry.io/collector/config" ) func TestNewExporterFactory(t *testing.T) { const typeStr = "test" - defaultCfg := config.NewExporterSettings(config.NewComponentID(typeStr)) + defaultCfg := NewExporterConfigSettings(NewID(typeStr)) factory := NewExporterFactory( typeStr, - func() config.Exporter { return &defaultCfg }) + func() ExporterConfig { return &defaultCfg }) assert.EqualValues(t, typeStr, factory.Type()) assert.EqualValues(t, &defaultCfg, factory.CreateDefaultConfig()) _, err := factory.CreateTracesExporter(context.Background(), ExporterCreateSettings{}, &defaultCfg) @@ -41,10 +39,10 @@ func TestNewExporterFactory(t *testing.T) { func TestNewExporterFactory_WithOptions(t *testing.T) { const typeStr = "test" - defaultCfg := config.NewExporterSettings(config.NewComponentID(typeStr)) + defaultCfg := NewExporterConfigSettings(NewID(typeStr)) factory := NewExporterFactory( typeStr, - func() config.Exporter { return &defaultCfg }, + func() ExporterConfig { return &defaultCfg }, WithTracesExporter(createTracesExporter, StabilityLevelInDevelopment), WithMetricsExporter(createMetricsExporter, StabilityLevelAlpha), WithLogsExporter(createLogsExporter, StabilityLevelDeprecated)) @@ -64,14 +62,14 @@ func TestNewExporterFactory_WithOptions(t *testing.T) { assert.NoError(t, err) } -func createTracesExporter(context.Context, ExporterCreateSettings, config.Exporter) (TracesExporter, error) { +func createTracesExporter(context.Context, ExporterCreateSettings, ExporterConfig) (TracesExporter, error) { return nil, nil } -func createMetricsExporter(context.Context, ExporterCreateSettings, config.Exporter) (MetricsExporter, error) { +func createMetricsExporter(context.Context, ExporterCreateSettings, ExporterConfig) (MetricsExporter, error) { return nil, nil } -func createLogsExporter(context.Context, ExporterCreateSettings, config.Exporter) (LogsExporter, error) { +func createLogsExporter(context.Context, ExporterCreateSettings, ExporterConfig) (LogsExporter, error) { return nil, nil } diff --git a/component/extension.go b/component/extension.go index 33a54a83b8c..4daff940361 100644 --- a/component/extension.go +++ b/component/extension.go @@ -16,8 +16,6 @@ package component // import "go.opentelemetry.io/collector/component" import ( "context" - - "go.opentelemetry.io/collector/config" ) // Extension is the interface for objects hosted by the OpenTelemetry Collector that @@ -52,19 +50,19 @@ type ExtensionCreateSettings struct { BuildInfo BuildInfo } -// ExtensionCreateDefaultConfigFunc is the equivalent of component.ExtensionFactory.CreateDefaultConfig() -type ExtensionCreateDefaultConfigFunc func() config.Extension +// ExtensionCreateDefaultConfigFunc is the equivalent of ExtensionFactory.CreateDefaultConfig() +type ExtensionCreateDefaultConfigFunc func() ExtensionConfig // CreateDefaultConfig implements ExtensionFactory.CreateDefaultConfig() -func (f ExtensionCreateDefaultConfigFunc) CreateDefaultConfig() config.Extension { +func (f ExtensionCreateDefaultConfigFunc) CreateDefaultConfig() ExtensionConfig { return f() } -// CreateExtensionFunc is the equivalent of component.ExtensionFactory.CreateExtension() -type CreateExtensionFunc func(context.Context, ExtensionCreateSettings, config.Extension) (Extension, error) +// CreateExtensionFunc is the equivalent of ExtensionFactory.CreateExtension() +type CreateExtensionFunc func(context.Context, ExtensionCreateSettings, ExtensionConfig) (Extension, error) // CreateExtension implements ExtensionFactory.CreateExtension. -func (f CreateExtensionFunc) CreateExtension(ctx context.Context, set ExtensionCreateSettings, cfg config.Extension) (Extension, error) { +func (f CreateExtensionFunc) CreateExtension(ctx context.Context, set ExtensionCreateSettings, cfg ExtensionConfig) (Extension, error) { return f(ctx, set, cfg) } @@ -77,12 +75,12 @@ type ExtensionFactory interface { // configuration and should not cause side-effects that prevent the creation // of multiple instances of the Extension. // The object returned by this method needs to pass the checks implemented by - // 'configtest.CheckConfigStruct'. It is recommended to have these checks in the + // 'componenttest.CheckConfigStruct'. It is recommended to have these checks in the // tests of any implementation of the Factory interface. - CreateDefaultConfig() config.Extension + CreateDefaultConfig() ExtensionConfig // CreateExtension creates an extension based on the given config. - CreateExtension(ctx context.Context, set ExtensionCreateSettings, cfg config.Extension) (Extension, error) + CreateExtension(ctx context.Context, set ExtensionCreateSettings, cfg ExtensionConfig) (Extension, error) // ExtensionStability gets the stability level of the Extension. ExtensionStability() StabilityLevel @@ -101,7 +99,7 @@ func (ef *extensionFactory) ExtensionStability() StabilityLevel { // NewExtensionFactory returns a new ExtensionFactory based on this configuration. func NewExtensionFactory( - cfgType config.Type, + cfgType Type, createDefaultConfig ExtensionCreateDefaultConfigFunc, createServiceExtension CreateExtensionFunc, sl StabilityLevel) ExtensionFactory { diff --git a/config/extension.go b/component/extension_config.go similarity index 53% rename from config/extension.go rename to component/extension_config.go index 8ed02f75487..3d521c10947 100644 --- a/config/extension.go +++ b/component/extension_config.go @@ -12,57 +12,58 @@ // See the License for the specific language governing permissions and // limitations under the License. -package config // import "go.opentelemetry.io/collector/config" +package component // import "go.opentelemetry.io/collector/component" + import ( "go.opentelemetry.io/collector/confmap" ) -// Extension is the configuration of a component.Extension. Specific extensions must implement -// this interface and must embed ExtensionSettings struct or a struct that extends it. -type Extension interface { +// 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() } -// UnmarshalExtension helper function to unmarshal an Extension config. +// 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 UnmarshalExtension(conf *confmap.Conf, cfg Extension) error { +func UnmarshalExtensionConfig(conf *confmap.Conf, cfg ExtensionConfig) error { return unmarshal(conf, cfg) } -// ExtensionSettings defines common settings for a component.Extension configuration. +// 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 ExtensionSettings struct { - id ComponentID `mapstructure:"-"` +type ExtensionConfigSettings struct { + id ID `mapstructure:"-"` } -// NewExtensionSettings return a new ExtensionSettings with the given ComponentID. -func NewExtensionSettings(id ComponentID) ExtensionSettings { - return ExtensionSettings{id: ComponentID{typeVal: id.Type(), nameVal: id.Name()}} +// 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 _ Extension = (*ExtensionSettings)(nil) +var _ ExtensionConfig = (*ExtensionConfigSettings)(nil) -// ID returns the receiver ComponentID. -func (es *ExtensionSettings) ID() ComponentID { +// ID returns the receiver ID. +func (es *ExtensionConfigSettings) ID() ID { return es.id } // SetIDName sets the receiver name. -func (es *ExtensionSettings) SetIDName(idName string) { +func (es *ExtensionConfigSettings) SetIDName(idName string) { es.id.nameVal = idName } // Validate validates the configuration and returns an error if invalid. -func (es *ExtensionSettings) Validate() error { +func (es *ExtensionConfigSettings) Validate() error { return nil } -func (es *ExtensionSettings) privateConfigExtension() {} +func (es *ExtensionConfigSettings) privateConfigExtension() {} diff --git a/component/extension_test.go b/component/extension_test.go index da3b3e0454a..e89d1733dee 100644 --- a/component/extension_test.go +++ b/component/extension_test.go @@ -19,8 +19,6 @@ import ( "testing" "github.com/stretchr/testify/assert" - - "go.opentelemetry.io/collector/config" ) type nopExtension struct { @@ -30,13 +28,13 @@ type nopExtension struct { func TestNewExtensionFactory(t *testing.T) { const typeStr = "test" - defaultCfg := config.NewExtensionSettings(config.NewComponentID(typeStr)) + defaultCfg := NewExtensionConfigSettings(NewID(typeStr)) nopExtensionInstance := new(nopExtension) factory := NewExtensionFactory( typeStr, - func() config.Extension { return &defaultCfg }, - func(ctx context.Context, settings ExtensionCreateSettings, extension config.Extension) (Extension, error) { + func() ExtensionConfig { return &defaultCfg }, + func(ctx context.Context, settings ExtensionCreateSettings, extension ExtensionConfig) (Extension, error) { return nopExtensionInstance, nil }, StabilityLevelInDevelopment) diff --git a/component/factories.go b/component/factories.go index 972e103538c..e666afaf73c 100644 --- a/component/factories.go +++ b/component/factories.go @@ -16,31 +16,29 @@ package component // import "go.opentelemetry.io/collector/component" import ( "fmt" - - "go.opentelemetry.io/collector/config" ) // Factories struct holds in a single type all component factories that // can be handled by the Config. type Factories struct { // Receivers maps receiver type names in the config to the respective factory. - Receivers map[config.Type]ReceiverFactory + Receivers map[Type]ReceiverFactory // Processors maps processor type names in the config to the respective factory. - Processors map[config.Type]ProcessorFactory + Processors map[Type]ProcessorFactory // Exporters maps exporter type names in the config to the respective factory. - Exporters map[config.Type]ExporterFactory + Exporters map[Type]ExporterFactory // Extensions maps extension type names in the config to the respective factory. - Extensions map[config.Type]ExtensionFactory + Extensions map[Type]ExtensionFactory } // MakeReceiverFactoryMap takes a list of receiver factories and returns a map // with factory type as keys. It returns a non-nil error when more than one factories // have the same type. -func MakeReceiverFactoryMap(factories ...ReceiverFactory) (map[config.Type]ReceiverFactory, error) { - fMap := map[config.Type]ReceiverFactory{} +func MakeReceiverFactoryMap(factories ...ReceiverFactory) (map[Type]ReceiverFactory, error) { + fMap := map[Type]ReceiverFactory{} for _, f := range factories { if _, ok := fMap[f.Type()]; ok { return fMap, fmt.Errorf("duplicate receiver factory %q", f.Type()) @@ -53,8 +51,8 @@ func MakeReceiverFactoryMap(factories ...ReceiverFactory) (map[config.Type]Recei // MakeProcessorFactoryMap takes a list of processor factories and returns a map // with factory type as keys. It returns a non-nil error when more than one factories // have the same type. -func MakeProcessorFactoryMap(factories ...ProcessorFactory) (map[config.Type]ProcessorFactory, error) { - fMap := map[config.Type]ProcessorFactory{} +func MakeProcessorFactoryMap(factories ...ProcessorFactory) (map[Type]ProcessorFactory, error) { + fMap := map[Type]ProcessorFactory{} for _, f := range factories { if _, ok := fMap[f.Type()]; ok { return fMap, fmt.Errorf("duplicate processor factory %q", f.Type()) @@ -67,8 +65,8 @@ func MakeProcessorFactoryMap(factories ...ProcessorFactory) (map[config.Type]Pro // MakeExporterFactoryMap takes a list of exporter factories and returns a map // with factory type as keys. It returns a non-nil error when more than one factories // have the same type. -func MakeExporterFactoryMap(factories ...ExporterFactory) (map[config.Type]ExporterFactory, error) { - fMap := map[config.Type]ExporterFactory{} +func MakeExporterFactoryMap(factories ...ExporterFactory) (map[Type]ExporterFactory, error) { + fMap := map[Type]ExporterFactory{} for _, f := range factories { if _, ok := fMap[f.Type()]; ok { return fMap, fmt.Errorf("duplicate exporter factory %q", f.Type()) @@ -81,8 +79,8 @@ func MakeExporterFactoryMap(factories ...ExporterFactory) (map[config.Type]Expor // MakeExtensionFactoryMap takes a list of extension factories and returns a map // with factory type as keys. It returns a non-nil error when more than one factories // have the same type. -func MakeExtensionFactoryMap(factories ...ExtensionFactory) (map[config.Type]ExtensionFactory, error) { - fMap := map[config.Type]ExtensionFactory{} +func MakeExtensionFactoryMap(factories ...ExtensionFactory) (map[Type]ExtensionFactory, error) { + fMap := map[Type]ExtensionFactory{} for _, f := range factories { if _, ok := fMap[f.Type()]; ok { return fMap, fmt.Errorf("duplicate extension factory %q", f.Type()) diff --git a/component/factories_test.go b/component/factories_test.go index 45ca5f13e99..7b1972cd34b 100644 --- a/component/factories_test.go +++ b/component/factories_test.go @@ -18,15 +18,13 @@ import ( "testing" "github.com/stretchr/testify/assert" - - "go.opentelemetry.io/collector/config" ) func TestMakeExtensionFactoryMap(t *testing.T) { type testCase struct { name string in []ExtensionFactory - out map[config.Type]ExtensionFactory + out map[Type]ExtensionFactory } p1 := NewExtensionFactory("p1", nil, nil, StabilityLevelAlpha) @@ -35,7 +33,7 @@ func TestMakeExtensionFactoryMap(t *testing.T) { { name: "different names", in: []ExtensionFactory{p1, p2}, - out: map[config.Type]ExtensionFactory{ + out: map[Type]ExtensionFactory{ p1.Type(): p1, p2.Type(): p2, }, @@ -63,7 +61,7 @@ func TestMakeReceiverFactoryMap(t *testing.T) { type testCase struct { name string in []ReceiverFactory - out map[config.Type]ReceiverFactory + out map[Type]ReceiverFactory } p1 := NewReceiverFactory("p1", nil) @@ -72,7 +70,7 @@ func TestMakeReceiverFactoryMap(t *testing.T) { { name: "different names", in: []ReceiverFactory{p1, p2}, - out: map[config.Type]ReceiverFactory{ + out: map[Type]ReceiverFactory{ p1.Type(): p1, p2.Type(): p2, }, @@ -101,7 +99,7 @@ func TestMakeProcessorFactoryMap(t *testing.T) { type testCase struct { name string in []ProcessorFactory - out map[config.Type]ProcessorFactory + out map[Type]ProcessorFactory } p1 := NewProcessorFactory("p1", nil) @@ -110,7 +108,7 @@ func TestMakeProcessorFactoryMap(t *testing.T) { { name: "different names", in: []ProcessorFactory{p1, p2}, - out: map[config.Type]ProcessorFactory{ + out: map[Type]ProcessorFactory{ p1.Type(): p1, p2.Type(): p2, }, @@ -139,7 +137,7 @@ func TestMakeExporterFactoryMap(t *testing.T) { type testCase struct { name string in []ExporterFactory - out map[config.Type]ExporterFactory + out map[Type]ExporterFactory } p1 := NewExporterFactory("p1", nil) @@ -148,7 +146,7 @@ func TestMakeExporterFactoryMap(t *testing.T) { { name: "different names", in: []ExporterFactory{p1, p2}, - out: map[config.Type]ExporterFactory{ + out: map[Type]ExporterFactory{ p1.Type(): p1, p2.Type(): p2, }, diff --git a/component/host.go b/component/host.go index 2d564d8cd80..92c395b0306 100644 --- a/component/host.go +++ b/component/host.go @@ -14,10 +14,6 @@ package component // import "go.opentelemetry.io/collector/component" -import ( - "go.opentelemetry.io/collector/config" -) - // Host represents the entity that is hosting a Component. It is used to allow communication // between the Component and its host (normally the service.Collector is the host). type Host interface { @@ -40,7 +36,7 @@ type Host interface { // GetFactory can be called by the component anytime after Component.Start() begins and // until Component.Shutdown() ends. Note that the component is responsible for destroying // other components that it creates. - GetFactory(kind Kind, componentType config.Type) Factory + GetFactory(kind Kind, componentType Type) Factory // GetExtensions returns the map of extensions. Only enabled and created extensions will be returned. // Typically is used to find an extension by type or by full config name. Both cases @@ -49,7 +45,7 @@ type Host interface { // // GetExtensions can be called by the component anytime after Component.Start() begins and // until Component.Shutdown() ends. - GetExtensions() map[config.ComponentID]Extension + GetExtensions() map[ID]Extension // GetExporters returns the map of exporters. Only enabled and created exporters will be returned. // Typically is used to find exporters by type or by full config name. Both cases @@ -62,5 +58,5 @@ type Host interface { // // GetExporters can be called by the component anytime after Component.Start() begins and // until Component.Shutdown() ends. - GetExporters() map[config.DataType]map[config.ComponentID]Exporter + GetExporters() map[DataType]map[ID]Exporter } diff --git a/config/identifiable.go b/component/identifiable.go similarity index 62% rename from config/identifiable.go rename to component/identifiable.go index 10637e2c800..33d9ff095dd 100644 --- a/config/identifiable.go +++ b/component/identifiable.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package config // import "go.opentelemetry.io/collector/config" +package component // import "go.opentelemetry.io/collector/component" import ( "errors" @@ -26,57 +26,48 @@ const typeAndNameSeparator = "/" // identifiable is an interface that all components configurations MUST embed. type identifiable interface { // ID returns the ID of the component that this configuration belongs to. - ID() ComponentID + ID() ID // SetIDName updates the name part of the ID for the component that this configuration belongs to. SetIDName(idName string) } -// ComponentID represents the identity for a component. It combines two values: +// ID represents the identity for a component. It combines two values: // * type - the Type of the component. // * name - the name of that component. -// The component ComponentID (combination type + name) is unique for a given component.Kind. -type ComponentID struct { +// The component ID (combination type + name) is unique for a given component.Kind. +type ID struct { typeVal Type `mapstructure:"-"` nameVal string `mapstructure:"-"` } -// NewComponentID returns a new ComponentID with the given Type and empty name. -func NewComponentID(typeVal Type) ComponentID { - return ComponentID{typeVal: typeVal} +// NewID returns a new ID with the given Type and empty name. +func NewID(typeVal Type) ID { + return ID{typeVal: typeVal} } -// NewComponentIDWithName returns a new ComponentID with the given Type and name. -func NewComponentIDWithName(typeVal Type, nameVal string) ComponentID { - return ComponentID{typeVal: typeVal, nameVal: nameVal} -} - -// NewComponentIDFromString decodes a string in type[/name] format into ComponentID. -// The type and name components will have spaces trimmed, the "type" part must be present, -// the forward slash and "name" are optional. -// The returned ComponentID will be invalid if err is not-nil. -func NewComponentIDFromString(idStr string) (ComponentID, error) { - id := ComponentID{} - return id, id.UnmarshalText([]byte(idStr)) +// NewIDWithName returns a new ID with the given Type and name. +func NewIDWithName(typeVal Type, nameVal string) ID { + return ID{typeVal: typeVal, nameVal: nameVal} } // Type returns the type of the component. -func (id ComponentID) Type() Type { +func (id ID) Type() Type { return id.typeVal } // Name returns the custom name of the component. -func (id ComponentID) Name() string { +func (id ID) Name() string { return id.nameVal } // MarshalText implements the encoding.TextMarshaler interface. // This marshals the type and name as one string in the config. -func (id ComponentID) MarshalText() (text []byte, err error) { +func (id ID) MarshalText() (text []byte, err error) { return []byte(id.String()), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. -func (id *ComponentID) UnmarshalText(text []byte) error { +func (id *ID) UnmarshalText(text []byte) error { idStr := string(text) items := strings.SplitN(idStr, typeAndNameSeparator, 2) if len(items) >= 1 { @@ -102,8 +93,8 @@ func (id *ComponentID) UnmarshalText(text []byte) error { return nil } -// String returns the ComponentID string representation as "type[/name]" format. -func (id ComponentID) String() string { +// String returns the ID string representation as "type[/name]" format. +func (id ID) String() string { if id.nameVal == "" { return string(id.typeVal) } diff --git a/config/identifiable_test.go b/component/identifiable_test.go similarity index 81% rename from config/identifiable_test.go rename to component/identifiable_test.go index 09d6be986c7..15b32178360 100644 --- a/config/identifiable_test.go +++ b/component/identifiable_test.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package config +package component import ( "testing" @@ -20,23 +20,30 @@ import ( "github.com/stretchr/testify/assert" ) -func TestIDFromString(t *testing.T) { +func TestMarshalText(t *testing.T) { + id := NewIDWithName("test", "name") + got, err := id.MarshalText() + assert.NoError(t, err) + assert.Equal(t, id.String(), string(got)) +} + +func TestUnmarshalText(t *testing.T) { var testCases = []struct { idStr string expectedErr bool - expectedID ComponentID + expectedID ID }{ { idStr: "valid_type", - expectedID: ComponentID{typeVal: "valid_type", nameVal: ""}, + expectedID: ID{typeVal: "valid_type", nameVal: ""}, }, { idStr: "valid_type/valid_name", - expectedID: ComponentID{typeVal: "valid_type", nameVal: "valid_name"}, + expectedID: ID{typeVal: "valid_type", nameVal: "valid_name"}, }, { idStr: " valid_type / valid_name ", - expectedID: ComponentID{typeVal: "valid_type", nameVal: "valid_name"}, + expectedID: ID{typeVal: "valid_type", nameVal: "valid_name"}, }, { idStr: "/valid_name", @@ -62,7 +69,8 @@ func TestIDFromString(t *testing.T) { for _, test := range testCases { t.Run(test.idStr, func(t *testing.T) { - id, err := NewComponentIDFromString(test.idStr) + id := ID{} + err := id.UnmarshalText([]byte(test.idStr)) if test.expectedErr { assert.Error(t, err) return @@ -76,10 +84,3 @@ func TestIDFromString(t *testing.T) { }) } } - -func TestMarshalText(t *testing.T) { - id := NewComponentIDWithName("test", "name") - got, err := id.MarshalText() - assert.NoError(t, err) - assert.Equal(t, id.String(), string(got)) -} diff --git a/component/processor.go b/component/processor.go index b7dbcf408df..f02e9e06ffa 100644 --- a/component/processor.go +++ b/component/processor.go @@ -17,7 +17,6 @@ package component // import "go.opentelemetry.io/collector/component" import ( "context" - "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/consumer" ) @@ -65,14 +64,14 @@ type ProcessorFactory interface { // configuration and should not cause side-effects that prevent the creation // of multiple instances of the Processor. // The object returned by this method needs to pass the checks implemented by - // 'configtest.CheckConfigStruct'. It is recommended to have these checks in the + // 'componenttest.CheckConfigStruct'. It is recommended to have these checks in the // tests of any implementation of the Factory interface. - CreateDefaultConfig() config.Processor + CreateDefaultConfig() ProcessorConfig // CreateTracesProcessor creates a TracesProcessor based on this config. // If the processor type does not support tracing or if the config is not valid, // an error will be returned instead. - CreateTracesProcessor(ctx context.Context, set ProcessorCreateSettings, cfg config.Processor, nextConsumer consumer.Traces) (TracesProcessor, error) + CreateTracesProcessor(ctx context.Context, set ProcessorCreateSettings, cfg ProcessorConfig, nextConsumer consumer.Traces) (TracesProcessor, error) // TracesProcessorStability gets the stability level of the TracesProcessor. TracesProcessorStability() StabilityLevel @@ -80,7 +79,7 @@ type ProcessorFactory interface { // CreateMetricsProcessor creates a MetricsProcessor based on this config. // If the processor type does not support metrics or if the config is not valid, // an error will be returned instead. - CreateMetricsProcessor(ctx context.Context, set ProcessorCreateSettings, cfg config.Processor, nextConsumer consumer.Metrics) (MetricsProcessor, error) + CreateMetricsProcessor(ctx context.Context, set ProcessorCreateSettings, cfg ProcessorConfig, nextConsumer consumer.Metrics) (MetricsProcessor, error) // MetricsProcessorStability gets the stability level of the MetricsProcessor. MetricsProcessorStability() StabilityLevel @@ -88,17 +87,17 @@ type ProcessorFactory interface { // CreateLogsProcessor creates a LogsProcessor based on the config. // If the processor type does not support logs or if the config is not valid, // an error will be returned instead. - CreateLogsProcessor(ctx context.Context, set ProcessorCreateSettings, cfg config.Processor, nextConsumer consumer.Logs) (LogsProcessor, error) + CreateLogsProcessor(ctx context.Context, set ProcessorCreateSettings, cfg ProcessorConfig, nextConsumer consumer.Logs) (LogsProcessor, error) // LogsProcessorStability gets the stability level of the LogsProcessor. LogsProcessorStability() StabilityLevel } // ProcessorCreateDefaultConfigFunc is the equivalent of ProcessorFactory.CreateDefaultConfig(). -type ProcessorCreateDefaultConfigFunc func() config.Processor +type ProcessorCreateDefaultConfigFunc func() ProcessorConfig // CreateDefaultConfig implements ProcessorFactory.CreateDefaultConfig(). -func (f ProcessorCreateDefaultConfigFunc) CreateDefaultConfig() config.Processor { +func (f ProcessorCreateDefaultConfigFunc) CreateDefaultConfig() ProcessorConfig { return f() } @@ -118,13 +117,13 @@ func (f processorFactoryOptionFunc) applyProcessorFactoryOption(o *processorFact } // CreateTracesProcessorFunc is the equivalent of ProcessorFactory.CreateTracesProcessor(). -type CreateTracesProcessorFunc func(context.Context, ProcessorCreateSettings, config.Processor, consumer.Traces) (TracesProcessor, error) +type CreateTracesProcessorFunc func(context.Context, ProcessorCreateSettings, ProcessorConfig, consumer.Traces) (TracesProcessor, error) // CreateTracesProcessor implements ProcessorFactory.CreateTracesProcessor(). func (f CreateTracesProcessorFunc) CreateTracesProcessor( ctx context.Context, set ProcessorCreateSettings, - cfg config.Processor, + cfg ProcessorConfig, nextConsumer consumer.Traces) (TracesProcessor, error) { if f == nil { return nil, ErrDataTypeIsNotSupported @@ -133,13 +132,13 @@ func (f CreateTracesProcessorFunc) CreateTracesProcessor( } // CreateMetricsProcessorFunc is the equivalent of ProcessorFactory.CreateMetricsProcessor(). -type CreateMetricsProcessorFunc func(context.Context, ProcessorCreateSettings, config.Processor, consumer.Metrics) (MetricsProcessor, error) +type CreateMetricsProcessorFunc func(context.Context, ProcessorCreateSettings, ProcessorConfig, consumer.Metrics) (MetricsProcessor, error) // CreateMetricsProcessor implements ProcessorFactory.CreateMetricsProcessor(). func (f CreateMetricsProcessorFunc) CreateMetricsProcessor( ctx context.Context, set ProcessorCreateSettings, - cfg config.Processor, + cfg ProcessorConfig, nextConsumer consumer.Metrics, ) (MetricsProcessor, error) { if f == nil { @@ -149,13 +148,13 @@ func (f CreateMetricsProcessorFunc) CreateMetricsProcessor( } // CreateLogsProcessorFunc is the equivalent of ProcessorFactory.CreateLogsProcessor(). -type CreateLogsProcessorFunc func(context.Context, ProcessorCreateSettings, config.Processor, consumer.Logs) (LogsProcessor, error) +type CreateLogsProcessorFunc func(context.Context, ProcessorCreateSettings, ProcessorConfig, consumer.Logs) (LogsProcessor, error) // CreateLogsProcessor implements ProcessorFactory.CreateLogsProcessor(). func (f CreateLogsProcessorFunc) CreateLogsProcessor( ctx context.Context, set ProcessorCreateSettings, - cfg config.Processor, + cfg ProcessorConfig, nextConsumer consumer.Logs, ) (LogsProcessor, error) { if f == nil { @@ -212,7 +211,7 @@ func WithLogsProcessor(createLogsProcessor CreateLogsProcessorFunc, sl Stability } // NewProcessorFactory returns a ProcessorFactory. -func NewProcessorFactory(cfgType config.Type, createDefaultConfig ProcessorCreateDefaultConfigFunc, options ...ProcessorFactoryOption) ProcessorFactory { +func NewProcessorFactory(cfgType Type, createDefaultConfig ProcessorCreateDefaultConfigFunc, options ...ProcessorFactoryOption) ProcessorFactory { f := &processorFactory{ baseFactory: baseFactory{cfgType: cfgType}, ProcessorCreateDefaultConfigFunc: createDefaultConfig, diff --git a/config/processor.go b/component/processor_config.go similarity index 54% rename from config/processor.go rename to component/processor_config.go index 5f4ec56db75..047f6bbad5f 100644 --- a/config/processor.go +++ b/component/processor_config.go @@ -12,57 +12,58 @@ // See the License for the specific language governing permissions and // limitations under the License. -package config // import "go.opentelemetry.io/collector/config" +package component // import "go.opentelemetry.io/collector/component" + import ( "go.opentelemetry.io/collector/confmap" ) -// Processor 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 Processor interface { +// 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() } -// UnmarshalProcessor helper function to unmarshal a Processor config. +// 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 UnmarshalProcessor(conf *confmap.Conf, cfg Processor) error { +func UnmarshalProcessorConfig(conf *confmap.Conf, cfg ProcessorConfig) error { return unmarshal(conf, cfg) } -// ProcessorSettings defines common settings for a component.Processor configuration. +// 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 ProcessorSettings struct { - id ComponentID `mapstructure:"-"` +type ProcessorConfigSettings struct { + id ID `mapstructure:"-"` } -// NewProcessorSettings return a new ProcessorSettings with the given ComponentID. -func NewProcessorSettings(id ComponentID) ProcessorSettings { - return ProcessorSettings{id: ComponentID{typeVal: id.Type(), nameVal: id.Name()}} +// 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 _ Processor = (*ProcessorSettings)(nil) +var _ ProcessorConfig = (*ProcessorConfigSettings)(nil) // ID returns the receiver ComponentID. -func (ps *ProcessorSettings) ID() ComponentID { +func (ps *ProcessorConfigSettings) ID() ID { return ps.id } // SetIDName sets the receiver name. -func (ps *ProcessorSettings) SetIDName(idName string) { +func (ps *ProcessorConfigSettings) SetIDName(idName string) { ps.id.nameVal = idName } // Validate validates the configuration and returns an error if invalid. -func (ps *ProcessorSettings) Validate() error { +func (ps *ProcessorConfigSettings) Validate() error { return nil } -func (ps *ProcessorSettings) privateConfigProcessor() {} +func (ps *ProcessorConfigSettings) privateConfigProcessor() {} diff --git a/component/processor_test.go b/component/processor_test.go index 5b8244c4638..e532059d5ee 100644 --- a/component/processor_test.go +++ b/component/processor_test.go @@ -20,16 +20,15 @@ import ( "github.com/stretchr/testify/assert" - "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/consumer" ) func TestNewProcessorFactory(t *testing.T) { const typeStr = "test" - defaultCfg := config.NewProcessorSettings(config.NewComponentID(typeStr)) + defaultCfg := NewProcessorConfigSettings(NewID(typeStr)) factory := NewProcessorFactory( typeStr, - func() config.Processor { return &defaultCfg }) + func() ProcessorConfig { return &defaultCfg }) assert.EqualValues(t, typeStr, factory.Type()) assert.EqualValues(t, &defaultCfg, factory.CreateDefaultConfig()) _, err := factory.CreateTracesProcessor(context.Background(), ProcessorCreateSettings{}, &defaultCfg, nil) @@ -42,10 +41,10 @@ func TestNewProcessorFactory(t *testing.T) { func TestNewProcessorFactory_WithOptions(t *testing.T) { const typeStr = "test" - defaultCfg := config.NewProcessorSettings(config.NewComponentID(typeStr)) + defaultCfg := NewProcessorConfigSettings(NewID(typeStr)) factory := NewProcessorFactory( typeStr, - func() config.Processor { return &defaultCfg }, + func() ProcessorConfig { return &defaultCfg }, WithTracesProcessor(createTracesProcessor, StabilityLevelAlpha), WithMetricsProcessor(createMetricsProcessor, StabilityLevelBeta), WithLogsProcessor(createLogsProcessor, StabilityLevelUnmaintained)) @@ -65,14 +64,14 @@ func TestNewProcessorFactory_WithOptions(t *testing.T) { assert.NoError(t, err) } -func createTracesProcessor(context.Context, ProcessorCreateSettings, config.Processor, consumer.Traces) (TracesProcessor, error) { +func createTracesProcessor(context.Context, ProcessorCreateSettings, ProcessorConfig, consumer.Traces) (TracesProcessor, error) { return nil, nil } -func createMetricsProcessor(context.Context, ProcessorCreateSettings, config.Processor, consumer.Metrics) (MetricsProcessor, error) { +func createMetricsProcessor(context.Context, ProcessorCreateSettings, ProcessorConfig, consumer.Metrics) (MetricsProcessor, error) { return nil, nil } -func createLogsProcessor(context.Context, ProcessorCreateSettings, config.Processor, consumer.Logs) (LogsProcessor, error) { +func createLogsProcessor(context.Context, ProcessorCreateSettings, ProcessorConfig, consumer.Logs) (LogsProcessor, error) { return nil, nil } diff --git a/component/receiver.go b/component/receiver.go index 116921c711f..4d59a757bf1 100644 --- a/component/receiver.go +++ b/component/receiver.go @@ -17,7 +17,6 @@ package component // import "go.opentelemetry.io/collector/component" import ( "context" - "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/consumer" ) @@ -110,14 +109,14 @@ type ReceiverFactory interface { // configuration and should not cause side-effects that prevent the creation // of multiple instances of the Receiver. // The object returned by this method needs to pass the checks implemented by - // 'configtest.CheckConfigStruct'. It is recommended to have these checks in the + // 'componenttest.CheckConfigStruct'. It is recommended to have these checks in the // tests of any implementation of the Factory interface. - CreateDefaultConfig() config.Receiver + CreateDefaultConfig() ReceiverConfig // CreateTracesReceiver creates a TracesReceiver based on this config. // If the receiver type does not support tracing or if the config is not valid // an error will be returned instead. - CreateTracesReceiver(ctx context.Context, set ReceiverCreateSettings, cfg config.Receiver, nextConsumer consumer.Traces) (TracesReceiver, error) + CreateTracesReceiver(ctx context.Context, set ReceiverCreateSettings, cfg ReceiverConfig, nextConsumer consumer.Traces) (TracesReceiver, error) // TracesReceiverStability gets the stability level of the TracesReceiver. TracesReceiverStability() StabilityLevel @@ -125,7 +124,7 @@ type ReceiverFactory interface { // CreateMetricsReceiver creates a MetricsReceiver based on this config. // If the receiver type does not support metrics or if the config is not valid // an error will be returned instead. - CreateMetricsReceiver(ctx context.Context, set ReceiverCreateSettings, cfg config.Receiver, nextConsumer consumer.Metrics) (MetricsReceiver, error) + CreateMetricsReceiver(ctx context.Context, set ReceiverCreateSettings, cfg ReceiverConfig, nextConsumer consumer.Metrics) (MetricsReceiver, error) // MetricsReceiverStability gets the stability level of the MetricsReceiver. MetricsReceiverStability() StabilityLevel @@ -133,7 +132,7 @@ type ReceiverFactory interface { // CreateLogsReceiver creates a LogsReceiver based on this config. // If the receiver type does not support the data type or if the config is not valid // an error will be returned instead. - CreateLogsReceiver(ctx context.Context, set ReceiverCreateSettings, cfg config.Receiver, nextConsumer consumer.Logs) (LogsReceiver, error) + CreateLogsReceiver(ctx context.Context, set ReceiverCreateSettings, cfg ReceiverConfig, nextConsumer consumer.Logs) (LogsReceiver, error) // LogsReceiverStability gets the stability level of the LogsReceiver. LogsReceiverStability() StabilityLevel @@ -155,21 +154,21 @@ func (f receiverFactoryOptionFunc) applyReceiverFactoryOption(o *receiverFactory } // ReceiverCreateDefaultConfigFunc is the equivalent of ReceiverFactory.CreateDefaultConfig(). -type ReceiverCreateDefaultConfigFunc func() config.Receiver +type ReceiverCreateDefaultConfigFunc func() ReceiverConfig // CreateDefaultConfig implements ReceiverFactory.CreateDefaultConfig(). -func (f ReceiverCreateDefaultConfigFunc) CreateDefaultConfig() config.Receiver { +func (f ReceiverCreateDefaultConfigFunc) CreateDefaultConfig() ReceiverConfig { return f() } // CreateTracesReceiverFunc is the equivalent of ReceiverFactory.CreateTracesReceiver(). -type CreateTracesReceiverFunc func(context.Context, ReceiverCreateSettings, config.Receiver, consumer.Traces) (TracesReceiver, error) +type CreateTracesReceiverFunc func(context.Context, ReceiverCreateSettings, ReceiverConfig, consumer.Traces) (TracesReceiver, error) // CreateTracesReceiver implements ReceiverFactory.CreateTracesReceiver(). func (f CreateTracesReceiverFunc) CreateTracesReceiver( ctx context.Context, set ReceiverCreateSettings, - cfg config.Receiver, + cfg ReceiverConfig, nextConsumer consumer.Traces) (TracesReceiver, error) { if f == nil { return nil, ErrDataTypeIsNotSupported @@ -178,13 +177,13 @@ func (f CreateTracesReceiverFunc) CreateTracesReceiver( } // CreateMetricsReceiverFunc is the equivalent of ReceiverFactory.CreateMetricsReceiver(). -type CreateMetricsReceiverFunc func(context.Context, ReceiverCreateSettings, config.Receiver, consumer.Metrics) (MetricsReceiver, error) +type CreateMetricsReceiverFunc func(context.Context, ReceiverCreateSettings, ReceiverConfig, consumer.Metrics) (MetricsReceiver, error) // CreateMetricsReceiver implements ReceiverFactory.CreateMetricsReceiver(). func (f CreateMetricsReceiverFunc) CreateMetricsReceiver( ctx context.Context, set ReceiverCreateSettings, - cfg config.Receiver, + cfg ReceiverConfig, nextConsumer consumer.Metrics, ) (MetricsReceiver, error) { if f == nil { @@ -194,13 +193,13 @@ func (f CreateMetricsReceiverFunc) CreateMetricsReceiver( } // CreateLogsReceiverFunc is the equivalent of ReceiverFactory.CreateLogsReceiver(). -type CreateLogsReceiverFunc func(context.Context, ReceiverCreateSettings, config.Receiver, consumer.Logs) (LogsReceiver, error) +type CreateLogsReceiverFunc func(context.Context, ReceiverCreateSettings, ReceiverConfig, consumer.Logs) (LogsReceiver, error) // CreateLogsReceiver implements ReceiverFactory.CreateLogsReceiver(). func (f CreateLogsReceiverFunc) CreateLogsReceiver( ctx context.Context, set ReceiverCreateSettings, - cfg config.Receiver, + cfg ReceiverConfig, nextConsumer consumer.Logs, ) (LogsReceiver, error) { if f == nil { @@ -257,7 +256,7 @@ func WithLogsReceiver(createLogsReceiver CreateLogsReceiverFunc, sl StabilityLev } // NewReceiverFactory returns a ReceiverFactory. -func NewReceiverFactory(cfgType config.Type, createDefaultConfig ReceiverCreateDefaultConfigFunc, options ...ReceiverFactoryOption) ReceiverFactory { +func NewReceiverFactory(cfgType Type, createDefaultConfig ReceiverCreateDefaultConfigFunc, options ...ReceiverFactoryOption) ReceiverFactory { f := &receiverFactory{ baseFactory: baseFactory{cfgType: cfgType}, ReceiverCreateDefaultConfigFunc: createDefaultConfig, diff --git a/config/receiver.go b/component/receiver_config.go similarity index 54% rename from config/receiver.go rename to component/receiver_config.go index 943799a3f63..5f9c79a72dd 100644 --- a/config/receiver.go +++ b/component/receiver_config.go @@ -12,57 +12,58 @@ // See the License for the specific language governing permissions and // limitations under the License. -package config // import "go.opentelemetry.io/collector/config" +package component // import "go.opentelemetry.io/collector/component" + import ( "go.opentelemetry.io/collector/confmap" ) -// Receiver 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 Receiver interface { +// 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() } -// UnmarshalReceiver helper function to unmarshal a Receiver config. +// 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 UnmarshalReceiver(conf *confmap.Conf, cfg Receiver) error { +func UnmarshalReceiverConfig(conf *confmap.Conf, cfg ReceiverConfig) error { return unmarshal(conf, cfg) } -// ReceiverSettings defines common settings for a component.Receiver configuration. +// 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 ReceiverSettings struct { - id ComponentID `mapstructure:"-"` +type ReceiverConfigSettings struct { + id ID `mapstructure:"-"` } -// NewReceiverSettings return a new ReceiverSettings with the given ComponentID. -func NewReceiverSettings(id ComponentID) ReceiverSettings { - return ReceiverSettings{id: ComponentID{typeVal: id.Type(), nameVal: id.Name()}} +// 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 _ Receiver = (*ReceiverSettings)(nil) +var _ ReceiverConfig = (*ReceiverConfigSettings)(nil) -// ID returns the receiver ComponentID. -func (rs *ReceiverSettings) ID() ComponentID { +// ID returns the receiver ID. +func (rs *ReceiverConfigSettings) ID() ID { return rs.id } // SetIDName sets the receiver name. -func (rs *ReceiverSettings) SetIDName(idName string) { +func (rs *ReceiverConfigSettings) SetIDName(idName string) { rs.id.nameVal = idName } // Validate validates the configuration and returns an error if invalid. -func (rs *ReceiverSettings) Validate() error { +func (rs *ReceiverConfigSettings) Validate() error { return nil } -func (rs *ReceiverSettings) privateConfigReceiver() {} +func (rs *ReceiverConfigSettings) privateConfigReceiver() {} diff --git a/component/receiver_test.go b/component/receiver_test.go index ea59fa95371..3c6f995e431 100644 --- a/component/receiver_test.go +++ b/component/receiver_test.go @@ -20,16 +20,15 @@ import ( "github.com/stretchr/testify/assert" - "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/consumer" ) func TestNewReceiverFactory(t *testing.T) { const typeStr = "test" - defaultCfg := config.NewReceiverSettings(config.NewComponentID(typeStr)) + defaultCfg := NewReceiverConfigSettings(NewID(typeStr)) factory := NewReceiverFactory( typeStr, - func() config.Receiver { return &defaultCfg }) + func() ReceiverConfig { return &defaultCfg }) assert.EqualValues(t, typeStr, factory.Type()) assert.EqualValues(t, &defaultCfg, factory.CreateDefaultConfig()) _, err := factory.CreateTracesReceiver(context.Background(), ReceiverCreateSettings{}, &defaultCfg, nil) @@ -42,10 +41,10 @@ func TestNewReceiverFactory(t *testing.T) { func TestNewReceiverFactory_WithOptions(t *testing.T) { const typeStr = "test" - defaultCfg := config.NewReceiverSettings(config.NewComponentID(typeStr)) + defaultCfg := NewReceiverConfigSettings(NewID(typeStr)) factory := NewReceiverFactory( typeStr, - func() config.Receiver { return &defaultCfg }, + func() ReceiverConfig { return &defaultCfg }, WithTracesReceiver(createTracesReceiver, StabilityLevelDeprecated), WithMetricsReceiver(createMetricsReceiver, StabilityLevelAlpha), WithLogsReceiver(createLogsReceiver, StabilityLevelStable)) @@ -65,14 +64,14 @@ func TestNewReceiverFactory_WithOptions(t *testing.T) { assert.NoError(t, err) } -func createTracesReceiver(context.Context, ReceiverCreateSettings, config.Receiver, consumer.Traces) (TracesReceiver, error) { +func createTracesReceiver(context.Context, ReceiverCreateSettings, ReceiverConfig, consumer.Traces) (TracesReceiver, error) { return nil, nil } -func createMetricsReceiver(context.Context, ReceiverCreateSettings, config.Receiver, consumer.Metrics) (MetricsReceiver, error) { +func createMetricsReceiver(context.Context, ReceiverCreateSettings, ReceiverConfig, consumer.Metrics) (MetricsReceiver, error) { return nil, nil } -func createLogsReceiver(context.Context, ReceiverCreateSettings, config.Receiver, consumer.Logs) (LogsReceiver, error) { +func createLogsReceiver(context.Context, ReceiverCreateSettings, ReceiverConfig, consumer.Logs) (LogsReceiver, error) { return nil, nil } diff --git a/config/configauth/configauth.go b/config/configauth/configauth.go index 92f53e2e85b..30a440497b5 100644 --- a/config/configauth/configauth.go +++ b/config/configauth/configauth.go @@ -19,7 +19,6 @@ import ( "fmt" "go.opentelemetry.io/collector/component" - "go.opentelemetry.io/collector/config" ) var ( @@ -31,12 +30,12 @@ var ( // Authentication defines the auth settings for the receiver. type Authentication struct { // AuthenticatorID specifies the name of the extension to use in order to authenticate the incoming data point. - AuthenticatorID config.ComponentID `mapstructure:"authenticator"` + AuthenticatorID component.ID `mapstructure:"authenticator"` } // GetServerAuthenticator attempts to select the appropriate ServerAuthenticator from the list of extensions, // based on the requested extension name. If an authenticator is not found, an error is returned. -func (a Authentication) GetServerAuthenticator(extensions map[config.ComponentID]component.Extension) (ServerAuthenticator, error) { +func (a Authentication) GetServerAuthenticator(extensions map[component.ID]component.Extension) (ServerAuthenticator, error) { if ext, found := extensions[a.AuthenticatorID]; found { if auth, ok := ext.(ServerAuthenticator); ok { return auth, nil @@ -50,7 +49,7 @@ func (a Authentication) GetServerAuthenticator(extensions map[config.ComponentID // GetClientAuthenticator attempts to select the appropriate ClientAuthenticator from the list of extensions, // based on the component id of the extension. If an authenticator is not found, an error is returned. // This should be only used by HTTP clients. -func (a Authentication) GetClientAuthenticator(extensions map[config.ComponentID]component.Extension) (ClientAuthenticator, error) { +func (a Authentication) GetClientAuthenticator(extensions map[component.ID]component.Extension) (ClientAuthenticator, error) { if ext, found := extensions[a.AuthenticatorID]; found { if auth, ok := ext.(ClientAuthenticator); ok { return auth, nil diff --git a/config/configauth/configauth_test.go b/config/configauth/configauth_test.go index ac488870174..04707e699ef 100644 --- a/config/configauth/configauth_test.go +++ b/config/configauth/configauth_test.go @@ -20,7 +20,6 @@ import ( "github.com/stretchr/testify/assert" "go.opentelemetry.io/collector/component" - "go.opentelemetry.io/collector/config" ) func TestGetServerAuthenticator(t *testing.T) { @@ -44,10 +43,10 @@ func TestGetServerAuthenticator(t *testing.T) { t.Run(tC.desc, func(t *testing.T) { // prepare cfg := &Authentication{ - AuthenticatorID: config.NewComponentID("mock"), + AuthenticatorID: component.NewID("mock"), } - ext := map[config.ComponentID]component.Extension{ - config.NewComponentID("mock"): tC.authenticator, + ext := map[component.ID]component.Extension{ + component.NewID("mock"): tC.authenticator, } authenticator, err := cfg.GetServerAuthenticator(ext) @@ -66,10 +65,10 @@ func TestGetServerAuthenticator(t *testing.T) { func TestGetServerAuthenticatorFails(t *testing.T) { cfg := &Authentication{ - AuthenticatorID: config.NewComponentID("does-not-exist"), + AuthenticatorID: component.NewID("does-not-exist"), } - authenticator, err := cfg.GetServerAuthenticator(map[config.ComponentID]component.Extension{}) + authenticator, err := cfg.GetServerAuthenticator(map[component.ID]component.Extension{}) assert.ErrorIs(t, err, errAuthenticatorNotFound) assert.Nil(t, authenticator) } @@ -95,10 +94,10 @@ func TestGetClientAuthenticator(t *testing.T) { t.Run(tC.desc, func(t *testing.T) { // prepare cfg := &Authentication{ - AuthenticatorID: config.NewComponentID("mock"), + AuthenticatorID: component.NewID("mock"), } - ext := map[config.ComponentID]component.Extension{ - config.NewComponentID("mock"): tC.authenticator, + ext := map[component.ID]component.Extension{ + component.NewID("mock"): tC.authenticator, } authenticator, err := cfg.GetClientAuthenticator(ext) @@ -117,9 +116,9 @@ func TestGetClientAuthenticator(t *testing.T) { func TestGetClientAuthenticatorFails(t *testing.T) { cfg := &Authentication{ - AuthenticatorID: config.NewComponentID("does-not-exist"), + AuthenticatorID: component.NewID("does-not-exist"), } - authenticator, err := cfg.GetClientAuthenticator(map[config.ComponentID]component.Extension{}) + authenticator, err := cfg.GetClientAuthenticator(map[component.ID]component.Extension{}) assert.ErrorIs(t, err, errAuthenticatorNotFound) assert.Nil(t, authenticator) } diff --git a/config/configgrpc/configgrpc_test.go b/config/configgrpc/configgrpc_test.go index 8939e4df395..f9e448c8e55 100644 --- a/config/configgrpc/configgrpc_test.go +++ b/config/configgrpc/configgrpc_test.go @@ -33,7 +33,6 @@ import ( "go.opentelemetry.io/collector/client" "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/component/componenttest" - "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/config/configauth" "go.opentelemetry.io/collector/config/configcompression" "go.opentelemetry.io/collector/config/confignet" @@ -87,11 +86,11 @@ func TestAllGrpcClientSettings(t *testing.T) { WriteBufferSize: 1024, WaitForReady: true, BalancerName: "round_robin", - Auth: &configauth.Authentication{AuthenticatorID: config.NewComponentID("testauth")}, + Auth: &configauth.Authentication{AuthenticatorID: component.NewID("testauth")}, }, host: &mockHost{ - ext: map[config.ComponentID]component.Extension{ - config.NewComponentID("testauth"): &configauth.MockClientAuthenticator{}, + ext: map[component.ID]component.Extension{ + component.NewID("testauth"): &configauth.MockClientAuthenticator{}, }, }, }, @@ -115,11 +114,11 @@ func TestAllGrpcClientSettings(t *testing.T) { WriteBufferSize: 1024, WaitForReady: true, BalancerName: "round_robin", - Auth: &configauth.Authentication{AuthenticatorID: config.NewComponentID("testauth")}, + Auth: &configauth.Authentication{AuthenticatorID: component.NewID("testauth")}, }, host: &mockHost{ - ext: map[config.ComponentID]component.Extension{ - config.NewComponentID("testauth"): &configauth.MockClientAuthenticator{}, + ext: map[component.ID]component.Extension{ + component.NewID("testauth"): &configauth.MockClientAuthenticator{}, }, }, }, @@ -143,11 +142,11 @@ func TestAllGrpcClientSettings(t *testing.T) { WriteBufferSize: 1024, WaitForReady: true, BalancerName: "round_robin", - Auth: &configauth.Authentication{AuthenticatorID: config.NewComponentID("testauth")}, + Auth: &configauth.Authentication{AuthenticatorID: component.NewID("testauth")}, }, host: &mockHost{ - ext: map[config.ComponentID]component.Extension{ - config.NewComponentID("testauth"): &configauth.MockClientAuthenticator{}, + ext: map[component.ID]component.Extension{ + component.NewID("testauth"): &configauth.MockClientAuthenticator{}, }, }, }, @@ -214,11 +213,11 @@ func TestGrpcServerAuthSettings(t *testing.T) { // test gss.Auth = &configauth.Authentication{ - AuthenticatorID: config.NewComponentID("mock"), + AuthenticatorID: component.NewID("mock"), } host := &mockHost{ - ext: map[config.ComponentID]component.Extension{ - config.NewComponentID("mock"): configauth.NewServerAuthenticator(), + ext: map[component.ID]component.Extension{ + component.NewID("mock"): configauth.NewServerAuthenticator(), }, } opts, err := gss.ToServerOption(host, componenttest.NewNopTelemetrySettings()) @@ -297,15 +296,15 @@ func TestGRPCClientSettingsError(t *testing.T) { err: "failed to resolve authenticator \"doesntexist\": authenticator not found", settings: GRPCClientSettings{ Endpoint: "localhost:1234", - Auth: &configauth.Authentication{AuthenticatorID: config.NewComponentID("doesntexist")}, + Auth: &configauth.Authentication{AuthenticatorID: component.NewID("doesntexist")}, }, - host: &mockHost{ext: map[config.ComponentID]component.Extension{}}, + host: &mockHost{ext: map[component.ID]component.Extension{}}, }, { err: "no extensions configuration available", settings: GRPCClientSettings{ Endpoint: "localhost:1234", - Auth: &configauth.Authentication{AuthenticatorID: config.NewComponentID("doesntexist")}, + Auth: &configauth.Authentication{AuthenticatorID: component.NewID("doesntexist")}, }, host: &mockHost{}, }, @@ -1041,9 +1040,9 @@ func tempSocketName(t *testing.T) string { type mockHost struct { component.Host - ext map[config.ComponentID]component.Extension + ext map[component.ID]component.Extension } -func (nh *mockHost) GetExtensions() map[config.ComponentID]component.Extension { +func (nh *mockHost) GetExtensions() map[component.ID]component.Extension { return nh.ext } diff --git a/config/confighttp/confighttp_test.go b/config/confighttp/confighttp_test.go index 4f7877a4299..6d5c128350c 100644 --- a/config/confighttp/confighttp_test.go +++ b/config/confighttp/confighttp_test.go @@ -33,7 +33,6 @@ import ( "go.opentelemetry.io/collector/client" "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/component/componenttest" - "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/config/configauth" "go.opentelemetry.io/collector/config/configtls" ) @@ -49,8 +48,8 @@ func (c *customRoundTripper) RoundTrip(request *http.Request) (*http.Response, e func TestAllHTTPClientSettings(t *testing.T) { host := &mockHost{ - ext: map[config.ComponentID]component.Extension{ - config.NewComponentID("testauth"): &configauth.MockClientAuthenticator{ResultRoundTripper: &customRoundTripper{}}, + ext: map[component.ID]component.Extension{ + component.NewID("testauth"): &configauth.MockClientAuthenticator{ResultRoundTripper: &customRoundTripper{}}, }, } @@ -159,8 +158,8 @@ func TestAllHTTPClientSettings(t *testing.T) { func TestPartialHTTPClientSettings(t *testing.T) { host := &mockHost{ - ext: map[config.ComponentID]component.Extension{ - config.NewComponentID("testauth"): &configauth.MockClientAuthenticator{ResultRoundTripper: &customRoundTripper{}}, + ext: map[component.ID]component.Extension{ + component.NewID("testauth"): &configauth.MockClientAuthenticator{ResultRoundTripper: &customRoundTripper{}}, }, } @@ -210,7 +209,7 @@ func TestDefaultHTTPClientSettings(t *testing.T) { func TestHTTPClientSettingsError(t *testing.T) { host := &mockHost{ - ext: map[config.ComponentID]component.Extension{}, + ext: map[component.ID]component.Extension{}, } tests := []struct { settings HTTPClientSettings @@ -246,7 +245,7 @@ func TestHTTPClientSettingsError(t *testing.T) { err: "failed to resolve authenticator \"dummy\": authenticator not found", settings: HTTPClientSettings{ Endpoint: "https://localhost:1234/v1/traces", - Auth: &configauth.Authentication{AuthenticatorID: config.NewComponentID("dummy")}, + Auth: &configauth.Authentication{AuthenticatorID: component.NewID("dummy")}, }, }, } @@ -273,8 +272,8 @@ func TestHTTPClientSettingWithAuthConfig(t *testing.T) { }, shouldErr: false, host: &mockHost{ - ext: map[config.ComponentID]component.Extension{ - config.NewComponentID("mock"): &configauth.MockClientAuthenticator{ + ext: map[component.ID]component.Extension{ + component.NewID("mock"): &configauth.MockClientAuthenticator{ ResultRoundTripper: &customRoundTripper{}, }, }, @@ -284,12 +283,12 @@ func TestHTTPClientSettingWithAuthConfig(t *testing.T) { name: "with_auth_configuration_and_no_extension", settings: HTTPClientSettings{ Endpoint: "localhost:1234", - Auth: &configauth.Authentication{AuthenticatorID: config.NewComponentID("dummy")}, + Auth: &configauth.Authentication{AuthenticatorID: component.NewID("dummy")}, }, shouldErr: true, host: &mockHost{ - ext: map[config.ComponentID]component.Extension{ - config.NewComponentID("mock"): &configauth.MockClientAuthenticator{ResultRoundTripper: &customRoundTripper{}}, + ext: map[component.ID]component.Extension{ + component.NewID("mock"): &configauth.MockClientAuthenticator{ResultRoundTripper: &customRoundTripper{}}, }, }, }, @@ -297,7 +296,7 @@ func TestHTTPClientSettingWithAuthConfig(t *testing.T) { name: "with_auth_configuration_and_no_extension_map", settings: HTTPClientSettings{ Endpoint: "localhost:1234", - Auth: &configauth.Authentication{AuthenticatorID: config.NewComponentID("dummy")}, + Auth: &configauth.Authentication{AuthenticatorID: component.NewID("dummy")}, }, shouldErr: true, host: componenttest.NewNopHost(), @@ -306,12 +305,12 @@ func TestHTTPClientSettingWithAuthConfig(t *testing.T) { name: "with_auth_configuration_has_extension", settings: HTTPClientSettings{ Endpoint: "localhost:1234", - Auth: &configauth.Authentication{AuthenticatorID: config.NewComponentID("mock")}, + Auth: &configauth.Authentication{AuthenticatorID: component.NewID("mock")}, }, shouldErr: false, host: &mockHost{ - ext: map[config.ComponentID]component.Extension{ - config.NewComponentID("mock"): &configauth.MockClientAuthenticator{ResultRoundTripper: &customRoundTripper{}}, + ext: map[component.ID]component.Extension{ + component.NewID("mock"): &configauth.MockClientAuthenticator{ResultRoundTripper: &customRoundTripper{}}, }, }, }, @@ -319,12 +318,12 @@ func TestHTTPClientSettingWithAuthConfig(t *testing.T) { name: "with_auth_configuration_has_err_extension", settings: HTTPClientSettings{ Endpoint: "localhost:1234", - Auth: &configauth.Authentication{AuthenticatorID: config.NewComponentID("mock")}, + Auth: &configauth.Authentication{AuthenticatorID: component.NewID("mock")}, }, shouldErr: true, host: &mockHost{ - ext: map[config.ComponentID]component.Extension{ - config.NewComponentID("mock"): &configauth.MockClientAuthenticator{ + ext: map[component.ID]component.Extension{ + component.NewID("mock"): &configauth.MockClientAuthenticator{ ResultRoundTripper: &customRoundTripper{}, MustError: true}, }, }, @@ -691,13 +690,13 @@ func TestHttpCorsWithAuthentication(t *testing.T) { AllowedOrigins: []string{"*"}, }, Auth: &configauth.Authentication{ - AuthenticatorID: config.NewComponentID("mock"), + AuthenticatorID: component.NewID("mock"), }, } host := &mockHost{ - ext: map[config.ComponentID]component.Extension{ - config.NewComponentID("mock"): configauth.NewServerAuthenticator( + ext: map[component.ID]component.Extension{ + component.NewID("mock"): configauth.NewServerAuthenticator( configauth.WithAuthenticate(func(ctx context.Context, headers map[string][]string) (context.Context, error) { return ctx, errors.New("authentication failed") }), @@ -885,13 +884,13 @@ func TestServerAuth(t *testing.T) { authCalled := false hss := HTTPServerSettings{ Auth: &configauth.Authentication{ - AuthenticatorID: config.NewComponentID("mock"), + AuthenticatorID: component.NewID("mock"), }, } host := &mockHost{ - ext: map[config.ComponentID]component.Extension{ - config.NewComponentID("mock"): configauth.NewServerAuthenticator( + ext: map[component.ID]component.Extension{ + component.NewID("mock"): configauth.NewServerAuthenticator( configauth.WithAuthenticate(func(ctx context.Context, headers map[string][]string) (context.Context, error) { authCalled = true return ctx, nil @@ -919,7 +918,7 @@ func TestServerAuth(t *testing.T) { func TestInvalidServerAuth(t *testing.T) { hss := HTTPServerSettings{ Auth: &configauth.Authentication{ - AuthenticatorID: config.NewComponentID("non-existing"), + AuthenticatorID: component.NewID("non-existing"), }, } @@ -932,12 +931,12 @@ func TestFailedServerAuth(t *testing.T) { // prepare hss := HTTPServerSettings{ Auth: &configauth.Authentication{ - AuthenticatorID: config.NewComponentID("mock"), + AuthenticatorID: component.NewID("mock"), }, } host := &mockHost{ - ext: map[config.ComponentID]component.Extension{ - config.NewComponentID("mock"): configauth.NewServerAuthenticator( + ext: map[component.ID]component.Extension{ + component.NewID("mock"): configauth.NewServerAuthenticator( configauth.WithAuthenticate(func(ctx context.Context, headers map[string][]string) (context.Context, error) { return ctx, errors.New("authentication failed") }), @@ -959,10 +958,10 @@ func TestFailedServerAuth(t *testing.T) { type mockHost struct { component.Host - ext map[config.ComponentID]component.Extension + ext map[component.ID]component.Extension } -func (nh *mockHost) GetExtensions() map[config.ComponentID]component.Extension { +func (nh *mockHost) GetExtensions() map[component.ID]component.Extension { return nh.ext } diff --git a/config/configtest/configtest.go b/config/configtest/configtest.go index 0a3f3fb3dd5..5a599bbbe2c 100644 --- a/config/configtest/configtest.go +++ b/config/configtest/configtest.go @@ -15,133 +15,8 @@ package configtest // import "go.opentelemetry.io/collector/config/configtest" import ( - "fmt" - "reflect" - "regexp" - "strings" - - "go.uber.org/multierr" + "go.opentelemetry.io/collector/component/componenttest" ) -// The regular expression for valid config field tag. -var configFieldTagRegExp = regexp.MustCompile("^[a-z0-9][a-z0-9_]*$") - -// CheckConfigStruct enforces that given configuration object is following the patterns -// used by the collector. This ensures consistency between different implementations -// of components and extensions. It is recommended for implementers of components -// to call this function on their tests passing the default configuration of the -// component factory. -func CheckConfigStruct(config interface{}) error { - t := reflect.TypeOf(config) - if t.Kind() == reflect.Ptr { - t = t.Elem() - } - - if t.Kind() != reflect.Struct { - return fmt.Errorf("config must be a struct or a pointer to one, the passed object is a %s", t.Kind()) - } - - return validateConfigDataType(t) -} - -// validateConfigDataType performs a descending validation of the given type. -// If the type is a struct it goes to each of its fields to check for the proper -// tags. -func validateConfigDataType(t reflect.Type) error { - var errs error - - switch t.Kind() { - case reflect.Ptr: - errs = multierr.Append(errs, validateConfigDataType(t.Elem())) - case reflect.Struct: - // Reflect on the pointed data and check each of its fields. - nf := t.NumField() - for i := 0; i < nf; i++ { - f := t.Field(i) - errs = multierr.Append(errs, checkStructFieldTags(f)) - } - default: - // The config object can carry other types but they are not used when - // reading the configuration via koanf so ignore them. Basically ignore: - // reflect.Uintptr, reflect.Chan, reflect.Func, reflect.Interface, and - // reflect.UnsafePointer. - } - - if errs != nil { - return fmt.Errorf("type %q from package %q has invalid config settings: %w", t.Name(), t.PkgPath(), errs) - } - - return nil -} - -// checkStructFieldTags inspects the tags of a struct field. -func checkStructFieldTags(f reflect.StructField) error { - - tagValue := f.Tag.Get("mapstructure") - if tagValue == "" { - - // Ignore special types. - switch f.Type.Kind() { - case reflect.Interface, reflect.Chan, reflect.Func, reflect.Uintptr, reflect.UnsafePointer: - // Allow the config to carry the types above, but since they are not read - // when loading configuration, just ignore them. - return nil - } - - // Public fields of other types should be tagged. - chars := []byte(f.Name) - if len(chars) > 0 && chars[0] >= 'A' && chars[0] <= 'Z' { - return fmt.Errorf("mapstructure tag not present on field %q", f.Name) - } - - // Not public field, no need to have a tag. - return nil - } - - tagParts := strings.Split(tagValue, ",") - if tagParts[0] != "" { - if tagParts[0] == "-" { - // Nothing to do, as mapstructure decode skips this field. - return nil - } - } - - // Check if squash is specified. - squash := false - for _, tag := range tagParts[1:] { - if tag == "squash" { - squash = true - break - } - } - - if squash { - // Field was squashed. - if (f.Type.Kind() != reflect.Struct) && (f.Type.Kind() != reflect.Ptr || f.Type.Elem().Kind() != reflect.Struct) { - return fmt.Errorf( - "attempt to squash non-struct type on field %q", f.Name) - } - } - - switch f.Type.Kind() { - case reflect.Struct: - // It is another struct, continue down-level. - return validateConfigDataType(f.Type) - - case reflect.Map, reflect.Slice, reflect.Array: - // The element of map, array, or slice can be itself a configuration object. - return validateConfigDataType(f.Type.Elem()) - - default: - fieldTag := tagParts[0] - if !configFieldTagRegExp.MatchString(fieldTag) { - return fmt.Errorf( - "field %q has config tag %q which doesn't satisfy %q", - f.Name, - fieldTag, - configFieldTagRegExp.String()) - } - } - - return nil -} +// Deprecated: [v0.64.0] use componenttest.CheckConfigStruct. +var CheckConfigStruct = componenttest.CheckConfigStruct diff --git a/config/experimental/config/config.go b/config/experimental/config/config.go index 891a2ff6d86..34f53331528 100644 --- a/config/experimental/config/config.go +++ b/config/experimental/config/config.go @@ -15,28 +15,28 @@ package config // import "go.opentelemetry.io/collector/config/experimental/config" import ( - "go.opentelemetry.io/collector/config" + "go.opentelemetry.io/collector/component" ) // SourceSettings defines common settings of a Source configuration. // Specific config sources can embed this struct and extend it with more fields if needed. // When embedded it must be with `mapstructure:",squash"` tag. type SourceSettings struct { - config.ComponentID `mapstructure:"-"` + id component.ID `mapstructure:"-"` } // ID returns the ID of the component that this configuration belongs to. -func (s *SourceSettings) ID() config.ComponentID { - return s.ComponentID +func (s *SourceSettings) ID() component.ID { + return s.id } // SetIDName updates the name part of the ID for the component that this configuration belongs to. func (s *SourceSettings) SetIDName(idName string) { - s.ComponentID = config.NewComponentIDWithName(s.ComponentID.Type(), idName) + s.id = component.NewIDWithName(s.id.Type(), idName) } // NewSourceSettings return a new config.SourceSettings struct with the given ComponentID. -func NewSourceSettings(id config.ComponentID) SourceSettings { +func NewSourceSettings(id component.ID) SourceSettings { return SourceSettings{id} } @@ -50,7 +50,7 @@ type Source interface { // From config.identifiable: // ID returns the ID of the component that this configuration belongs to. - ID() config.ComponentID + ID() component.ID // SetIDName updates the name part of the ID for the component that this configuration belongs to. SetIDName(idName string) diff --git a/config/moved_config.go b/config/moved_config.go index 2af42942746..8c4033e5d7b 100644 --- a/config/moved_config.go +++ b/config/moved_config.go @@ -14,13 +14,95 @@ package config // import "go.opentelemetry.io/collector/config" +import ( + "go.opentelemetry.io/collector/component" +) + // Pipeline defines a single pipeline. // Deprecated: [v0.52.0] Use service.ConfigServicePipeline type Pipeline struct { - Receivers []ComponentID `mapstructure:"receivers"` - Processors []ComponentID `mapstructure:"processors"` - Exporters []ComponentID `mapstructure:"exporters"` + Receivers []component.ID `mapstructure:"receivers"` + Processors []component.ID `mapstructure:"processors"` + Exporters []component.ID `mapstructure:"exporters"` } // Deprecated: [v0.52.0] will be removed soon. -type Pipelines = map[ComponentID]*Pipeline +type Pipelines = map[component.ID]*Pipeline + +// Deprecated: [v0.64.0] use component.ReceiverConfig. +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 + +// Deprecated: [v0.64.0] use component.DataType. +type DataType = component.DataType + +// Deprecated: [v0.64.0] use component.TracesDataType. +const TracesDataType = component.TracesDataType + +// Deprecated: [v0.64.0] use component.MetricsDataType. +const MetricsDataType = component.MetricsDataType + +// Deprecated: [v0.64.0] use component.LogsDataType. +const LogsDataType = component.LogsDataType + +// Deprecated: [v0.64.0] use component.ID. +type ComponentID = component.ID + +// Deprecated: [v0.64.0] use component.NewID. +var NewComponentID = component.NewID + +// Deprecated: [v0.64.0] use component.NewIDWithName. +var NewComponentIDWithName = component.NewIDWithName + +// Deprecated: [v0.64.0] use component.ID.UnmarshalText. +func NewComponentIDFromString(idStr string) (ComponentID, error) { + id := component.ID{} + return id, id.UnmarshalText([]byte(idStr)) +} diff --git a/exporter/exporterhelper/common.go b/exporter/exporterhelper/common.go index 824193b5042..915acd435ba 100644 --- a/exporter/exporterhelper/common.go +++ b/exporter/exporterhelper/common.go @@ -19,7 +19,6 @@ import ( "time" "go.opentelemetry.io/collector/component" - "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/consumer" "go.opentelemetry.io/collector/exporter/exporterhelper/internal" "go.opentelemetry.io/collector/obsreport" @@ -156,7 +155,7 @@ type baseExporter struct { qrSender *queuedRetrySender } -func newBaseExporter(cfg config.Exporter, set component.ExporterCreateSettings, bs *baseSettings, signal config.DataType, reqUnmarshaler internal.RequestUnmarshaler) *baseExporter { +func newBaseExporter(cfg component.ExporterConfig, set component.ExporterCreateSettings, bs *baseSettings, signal component.DataType, reqUnmarshaler internal.RequestUnmarshaler) *baseExporter { be := &baseExporter{} be.obsrep = newObsExporter(obsreport.ExporterSettings{ExporterID: cfg.ID(), ExporterCreateSettings: set}, globalInstruments) diff --git a/exporter/exporterhelper/common_test.go b/exporter/exporterhelper/common_test.go index 026892c301e..e2fd3f49423 100644 --- a/exporter/exporterhelper/common_test.go +++ b/exporter/exporterhelper/common_test.go @@ -25,14 +25,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/exporter/exporterhelper/internal" "go.opentelemetry.io/collector/pdata/ptrace" ) var ( - defaultExporterCfg = config.NewExporterSettings(config.NewComponentID("test")) + defaultExporterCfg = component.NewExporterConfigSettings(component.NewID("test")) exporterTag, _ = tag.NewKey("exporter") defaultExporterTags = []tag.Tag{ {Key: exporterTag, Value: "test"}, diff --git a/exporter/exporterhelper/internal/persistent_queue.go b/exporter/exporterhelper/internal/persistent_queue.go index 921ba293e17..24f886a042d 100644 --- a/exporter/exporterhelper/internal/persistent_queue.go +++ b/exporter/exporterhelper/internal/persistent_queue.go @@ -21,7 +21,7 @@ import ( "go.uber.org/zap" - "go.opentelemetry.io/collector/config" + "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/extension/experimental/storage" ) @@ -37,12 +37,12 @@ type persistentQueue struct { // buildPersistentStorageName returns a name that is constructed out of queue name and signal type. This is done // to avoid conflicts between different signals, which require unique persistent storage name -func buildPersistentStorageName(name string, signal config.DataType) string { +func buildPersistentStorageName(name string, signal component.DataType) string { return fmt.Sprintf("%s-%s", name, signal) } // NewPersistentQueue creates a new queue backed by file storage; name and signal must be a unique combination that identifies the queue storage -func NewPersistentQueue(ctx context.Context, name string, signal config.DataType, capacity int, logger *zap.Logger, client storage.Client, unmarshaler RequestUnmarshaler) ProducerConsumerQueue { +func NewPersistentQueue(ctx context.Context, name string, signal component.DataType, capacity int, logger *zap.Logger, client storage.Client, unmarshaler RequestUnmarshaler) ProducerConsumerQueue { return &persistentQueue{ logger: logger, stopChan: make(chan struct{}), diff --git a/exporter/exporterhelper/internal/persistent_queue_test.go b/exporter/exporterhelper/internal/persistent_queue_test.go index 76a308893db..36a8003433e 100644 --- a/exporter/exporterhelper/internal/persistent_queue_test.go +++ b/exporter/exporterhelper/internal/persistent_queue_test.go @@ -25,7 +25,6 @@ import ( "go.uber.org/zap" "go.opentelemetry.io/collector/component" - "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/extension/experimental/storage" "go.opentelemetry.io/collector/pdata/pcommon" "go.opentelemetry.io/collector/pdata/ptrace" @@ -34,12 +33,12 @@ import ( func createTestQueue(extension storage.Extension, capacity int) *persistentQueue { logger := zap.NewNop() - client, err := extension.GetClient(context.Background(), component.KindReceiver, config.ComponentID{}, "") + client, err := extension.GetClient(context.Background(), component.KindReceiver, component.ID{}, "") if err != nil { panic(err) } - wq := NewPersistentQueue(context.Background(), "foo", config.TracesDataType, capacity, logger, client, newFakeTracesRequestUnmarshalerFunc()) + wq := NewPersistentQueue(context.Background(), "foo", component.TracesDataType, capacity, logger, client, newFakeTracesRequestUnmarshalerFunc()) return wq.(*persistentQueue) } diff --git a/exporter/exporterhelper/internal/persistent_storage_test.go b/exporter/exporterhelper/internal/persistent_storage_test.go index 1ac9956ec7c..dadd082b730 100644 --- a/exporter/exporterhelper/internal/persistent_storage_test.go +++ b/exporter/exporterhelper/internal/persistent_storage_test.go @@ -27,7 +27,6 @@ import ( "go.uber.org/zap" "go.opentelemetry.io/collector/component" - "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/extension/experimental/storage" "go.opentelemetry.io/collector/pdata/ptrace" ) @@ -38,7 +37,7 @@ func createStorageExtension(_ string) storage.Extension { } func createTestClient(extension storage.Extension) storage.Client { - client, err := extension.GetClient(context.Background(), component.KindReceiver, config.ComponentID{}, "") + client, err := extension.GetClient(context.Background(), component.KindReceiver, component.ID{}, "") if err != nil { panic(err) } @@ -459,7 +458,7 @@ func (m mockStorageExtension) Shutdown(_ context.Context) error { return nil } -func (m mockStorageExtension) GetClient(ctx context.Context, kind component.Kind, id config.ComponentID, s string) (storage.Client, error) { +func (m mockStorageExtension) GetClient(ctx context.Context, kind component.Kind, id component.ID, s string) (storage.Client, error) { return newMockStorageClient(), nil } diff --git a/exporter/exporterhelper/logs.go b/exporter/exporterhelper/logs.go index ee2ac481cb9..01d900674de 100644 --- a/exporter/exporterhelper/logs.go +++ b/exporter/exporterhelper/logs.go @@ -19,7 +19,6 @@ import ( "errors" "go.opentelemetry.io/collector/component" - "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/consumer" "go.opentelemetry.io/collector/consumer/consumererror" "go.opentelemetry.io/collector/exporter/exporterhelper/internal" @@ -82,7 +81,7 @@ type logsExporter struct { func NewLogsExporter( _ context.Context, set component.ExporterCreateSettings, - cfg config.Exporter, + cfg component.ExporterConfig, pusher consumer.ConsumeLogsFunc, options ...Option, ) (component.LogsExporter, error) { @@ -99,7 +98,7 @@ func NewLogsExporter( } bs := fromOptions(options...) - be := newBaseExporter(cfg, set, bs, config.LogsDataType, newLogsRequestUnmarshalerFunc(pusher)) + be := newBaseExporter(cfg, set, bs, component.LogsDataType, newLogsRequestUnmarshalerFunc(pusher)) be.wrapConsumerSender(func(nextSender requestSender) requestSender { return &logsExporterWithObservability{ obsrep: be.obsrep, diff --git a/exporter/exporterhelper/logs_test.go b/exporter/exporterhelper/logs_test.go index 5f06078579b..be67b21f070 100644 --- a/exporter/exporterhelper/logs_test.go +++ b/exporter/exporterhelper/logs_test.go @@ -28,7 +28,6 @@ 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" @@ -41,10 +40,10 @@ const ( fakeLogsParentSpanName = "fake_logs_parent_span_name" ) -var fakeLogsExporterName = config.NewComponentIDWithName("fake_logs_exporter", "with_name") +var fakeLogsExporterName = component.NewIDWithName("fake_logs_exporter", "with_name") var ( - fakeLogsExporterConfig = config.NewExporterSettings(fakeLogsExporterName) + fakeLogsExporterConfig = component.NewExporterConfigSettings(fakeLogsExporterName) ) func TestLogsRequest(t *testing.T) { diff --git a/exporter/exporterhelper/metrics.go b/exporter/exporterhelper/metrics.go index 5d2e7ffd48a..0d6bc13f965 100644 --- a/exporter/exporterhelper/metrics.go +++ b/exporter/exporterhelper/metrics.go @@ -19,7 +19,6 @@ import ( "errors" "go.opentelemetry.io/collector/component" - "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/consumer" "go.opentelemetry.io/collector/consumer/consumererror" "go.opentelemetry.io/collector/exporter/exporterhelper/internal" @@ -83,7 +82,7 @@ type metricsExporter struct { func NewMetricsExporter( _ context.Context, set component.ExporterCreateSettings, - cfg config.Exporter, + cfg component.ExporterConfig, pusher consumer.ConsumeMetricsFunc, options ...Option, ) (component.MetricsExporter, error) { @@ -100,7 +99,7 @@ func NewMetricsExporter( } bs := fromOptions(options...) - be := newBaseExporter(cfg, set, bs, config.MetricsDataType, newMetricsRequestUnmarshalerFunc(pusher)) + be := newBaseExporter(cfg, set, bs, component.MetricsDataType, newMetricsRequestUnmarshalerFunc(pusher)) be.wrapConsumerSender(func(nextSender requestSender) requestSender { return &metricsSenderWithObservability{ obsrep: be.obsrep, diff --git a/exporter/exporterhelper/metrics_test.go b/exporter/exporterhelper/metrics_test.go index c26a86dbeb5..d5ab33d0308 100644 --- a/exporter/exporterhelper/metrics_test.go +++ b/exporter/exporterhelper/metrics_test.go @@ -28,7 +28,6 @@ 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,8 +41,8 @@ const ( ) var ( - fakeMetricsExporterName = config.NewComponentIDWithName("fake_metrics_exporter", "with_name") - fakeMetricsExporterConfig = config.NewExporterSettings(fakeMetricsExporterName) + fakeMetricsExporterName = component.NewIDWithName("fake_metrics_exporter", "with_name") + fakeMetricsExporterConfig = component.NewExporterConfigSettings(fakeMetricsExporterName) ) func TestMetricsRequest(t *testing.T) { diff --git a/exporter/exporterhelper/obsreport_test.go b/exporter/exporterhelper/obsreport_test.go index 3a36699650f..cb9798aff8c 100644 --- a/exporter/exporterhelper/obsreport_test.go +++ b/exporter/exporterhelper/obsreport_test.go @@ -22,7 +22,7 @@ import ( "go.opencensus.io/metric" "go.opencensus.io/tag" - "go.opentelemetry.io/collector/config" + "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/obsreport" "go.opentelemetry.io/collector/obsreport/obsreporttest" ) @@ -32,7 +32,7 @@ func TestExportEnqueueFailure(t *testing.T) { require.NoError(t, err) t.Cleanup(func() { require.NoError(t, tt.Shutdown(context.Background())) }) - exporter := config.NewComponentID("fakeExporter") + exporter := component.NewID("fakeExporter") insts := newInstruments(metric.NewRegistry()) obsrep := newObsExporter(obsreport.ExporterSettings{ @@ -55,24 +55,24 @@ func TestExportEnqueueFailure(t *testing.T) { // checkExporterEnqueueFailedTracesStats checks that reported number of spans failed to enqueue match given values. // When this function is called it is required to also call SetupTelemetry as first thing. -func checkExporterEnqueueFailedTracesStats(t *testing.T, insts *instruments, exporter config.ComponentID, spans int64) { +func checkExporterEnqueueFailedTracesStats(t *testing.T, insts *instruments, exporter component.ID, spans int64) { checkValueForProducer(t, insts.registry, tagsForExporterView(exporter), spans, "exporter/enqueue_failed_spans") } // checkExporterEnqueueFailedMetricsStats checks that reported number of metric points failed to enqueue match given values. // When this function is called it is required to also call SetupTelemetry as first thing. -func checkExporterEnqueueFailedMetricsStats(t *testing.T, insts *instruments, exporter config.ComponentID, metricPoints int64) { +func checkExporterEnqueueFailedMetricsStats(t *testing.T, insts *instruments, exporter component.ID, metricPoints int64) { checkValueForProducer(t, insts.registry, tagsForExporterView(exporter), metricPoints, "exporter/enqueue_failed_metric_points") } // checkExporterEnqueueFailedLogsStats checks that reported number of log records failed to enqueue match given values. // When this function is called it is required to also call SetupTelemetry as first thing. -func checkExporterEnqueueFailedLogsStats(t *testing.T, insts *instruments, exporter config.ComponentID, logRecords int64) { +func checkExporterEnqueueFailedLogsStats(t *testing.T, insts *instruments, exporter component.ID, logRecords int64) { checkValueForProducer(t, insts.registry, tagsForExporterView(exporter), logRecords, "exporter/enqueue_failed_log_records") } // tagsForExporterView returns the tags that are needed for the exporter views. -func tagsForExporterView(exporter config.ComponentID) []tag.Tag { +func tagsForExporterView(exporter component.ID) []tag.Tag { return []tag.Tag{ {Key: exporterTag, Value: exporter.String()}, } diff --git a/exporter/exporterhelper/queued_retry.go b/exporter/exporterhelper/queued_retry.go index affe2b69b2e..c4a93ce143a 100644 --- a/exporter/exporterhelper/queued_retry.go +++ b/exporter/exporterhelper/queued_retry.go @@ -28,7 +28,6 @@ import ( "go.uber.org/zap/zapcore" "go.opentelemetry.io/collector/component" - "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/consumer/consumererror" "go.opentelemetry.io/collector/exporter/exporterhelper/internal" "go.opentelemetry.io/collector/extension/experimental/storage" @@ -51,7 +50,7 @@ type QueueSettings struct { QueueSize int `mapstructure:"queue_size"` // StorageID if not empty, enables the persistent storage and uses the component specified // as a storage extension for the persistent queue - StorageID *config.ComponentID `mapstructure:"storage"` + StorageID *component.ID `mapstructure:"storage"` } // NewDefaultQueueSettings returns the default settings for QueueSettings. @@ -82,8 +81,8 @@ func (qCfg *QueueSettings) Validate() error { type queuedRetrySender struct { fullName string - id config.ComponentID - signal config.DataType + id component.ID + signal component.DataType cfg QueueSettings consumerSender requestSender queue internal.ProducerConsumerQueue @@ -94,7 +93,7 @@ type queuedRetrySender struct { requestUnmarshaler internal.RequestUnmarshaler } -func newQueuedRetrySender(id config.ComponentID, signal config.DataType, qCfg QueueSettings, rCfg RetrySettings, reqUnmarshaler internal.RequestUnmarshaler, nextSender requestSender, logger *zap.Logger) *queuedRetrySender { +func newQueuedRetrySender(id component.ID, signal component.DataType, qCfg QueueSettings, rCfg RetrySettings, reqUnmarshaler internal.RequestUnmarshaler, nextSender requestSender, logger *zap.Logger) *queuedRetrySender { retryStopCh := make(chan struct{}) sampledLogger := createSampledLogger(logger) traceAttr := attribute.String(obsmetrics.ExporterKey, id.String()) @@ -128,7 +127,7 @@ func newQueuedRetrySender(id config.ComponentID, signal config.DataType, qCfg Qu return qrs } -func getStorageExtension(extensions map[config.ComponentID]component.Extension, storageID config.ComponentID) (storage.Extension, error) { +func getStorageExtension(extensions map[component.ID]component.Extension, storageID component.ID) (storage.Extension, error) { if ext, found := extensions[storageID]; found { if storageExt, ok := ext.(storage.Extension); ok { return storageExt, nil @@ -138,7 +137,7 @@ func getStorageExtension(extensions map[config.ComponentID]component.Extension, return nil, errNoStorageClient } -func toStorageClient(ctx context.Context, storageID config.ComponentID, host component.Host, ownerID config.ComponentID, signal config.DataType) (storage.Client, error) { +func toStorageClient(ctx context.Context, storageID component.ID, host component.Host, ownerID component.ID, signal component.DataType) (storage.Client, error) { extension, err := getStorageExtension(host.GetExtensions(), storageID) if err != nil { return nil, err diff --git a/exporter/exporterhelper/queued_retry_test.go b/exporter/exporterhelper/queued_retry_test.go index 1c182029e47..1e34953765e 100644 --- a/exporter/exporterhelper/queued_retry_test.go +++ b/exporter/exporterhelper/queued_retry_test.go @@ -32,7 +32,6 @@ import ( "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/component/componenttest" - "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/consumer/consumererror" "go.opentelemetry.io/collector/exporter/exporterhelper/internal" "go.opentelemetry.io/collector/extension/experimental/storage" @@ -423,17 +422,17 @@ func TestGetRetrySettings(t *testing.T) { for _, tC := range testCases { t.Run(tC.desc, func(t *testing.T) { - storageID := config.NewComponentIDWithName("file_storage", strconv.Itoa(tC.storageIndex)) + storageID := component.NewIDWithName("file_storage", strconv.Itoa(tC.storageIndex)) - var extensions = map[config.ComponentID]component.Extension{} + var extensions = map[component.ID]component.Extension{} for i := 0; i < tC.numStorages; i++ { - extensions[config.NewComponentIDWithName("file_storage", strconv.Itoa(i))] = &mockStorageExtension{GetClientError: tC.getClientError} + extensions[component.NewIDWithName("file_storage", strconv.Itoa(i))] = &mockStorageExtension{GetClientError: tC.getClientError} } host := &mockHost{ext: extensions} - ownerID := config.NewComponentID("foo_exporter") + ownerID := component.NewID("foo_exporter") // execute - client, err := toStorageClient(context.Background(), storageID, host, ownerID, config.TracesDataType) + client, err := toStorageClient(context.Background(), storageID, host, ownerID, component.TracesDataType) // verify if tC.expectedError != nil { @@ -448,7 +447,7 @@ func TestGetRetrySettings(t *testing.T) { } func TestInvalidStorageExtensionType(t *testing.T) { - storageID := config.NewComponentIDWithName("extension", "extension") + storageID := component.NewIDWithName("extension", "extension") // make a test extension factory := componenttest.NewNopExtensionFactory() @@ -456,14 +455,14 @@ func TestInvalidStorageExtensionType(t *testing.T) { settings := componenttest.NewNopExtensionCreateSettings() extension, err := factory.CreateExtension(context.Background(), settings, extConfig) assert.NoError(t, err) - var extensions = map[config.ComponentID]component.Extension{ + var extensions = map[component.ID]component.Extension{ storageID: extension, } host := &mockHost{ext: extensions} - ownerID := config.NewComponentID("foo_exporter") + ownerID := component.NewID("foo_exporter") // execute - client, err := toStorageClient(context.Background(), storageID, host, ownerID, config.TracesDataType) + client, err := toStorageClient(context.Background(), storageID, host, ownerID, component.TracesDataType) // we should get an error about the extension type assert.ErrorIs(t, err, errWrongExtensionType) @@ -527,12 +526,12 @@ func TestQueuedRetryPersistenceEnabled(t *testing.T) { t.Cleanup(func() { require.NoError(t, tt.Shutdown(context.Background())) }) qCfg := NewDefaultQueueSettings() - storageID := config.NewComponentIDWithName("file_storage", "storage") + storageID := component.NewIDWithName("file_storage", "storage") qCfg.StorageID = &storageID // enable persistence rCfg := NewDefaultRetrySettings() be := newBaseExporter(&defaultExporterCfg, tt.ToExporterCreateSettings(), fromOptions(WithRetry(rCfg), WithQueue(qCfg)), "", nopRequestUnmarshaler()) - var extensions = map[config.ComponentID]component.Extension{ + var extensions = map[component.ID]component.Extension{ storageID: &mockStorageExtension{}, } host := &mockHost{ext: extensions} @@ -549,12 +548,12 @@ func TestQueuedRetryPersistenceEnabledStorageError(t *testing.T) { t.Cleanup(func() { require.NoError(t, tt.Shutdown(context.Background())) }) qCfg := NewDefaultQueueSettings() - storageID := config.NewComponentIDWithName("file_storage", "storage") + storageID := component.NewIDWithName("file_storage", "storage") qCfg.StorageID = &storageID // enable persistence rCfg := NewDefaultRetrySettings() be := newBaseExporter(&defaultExporterCfg, tt.ToExporterCreateSettings(), fromOptions(WithRetry(rCfg), WithQueue(qCfg)), "", nopRequestUnmarshaler()) - var extensions = map[config.ComponentID]component.Extension{ + var extensions = map[component.ID]component.Extension{ storageID: &mockStorageExtension{GetClientError: storageError}, } host := &mockHost{ext: extensions} @@ -732,10 +731,10 @@ func tagsMatchLabelKeys(tags []tag.Tag, keys []metricdata.LabelKey, labels []met type mockHost struct { component.Host - ext map[config.ComponentID]component.Extension + ext map[component.ID]component.Extension } -func (nh *mockHost) GetExtensions() map[config.ComponentID]component.Extension { +func (nh *mockHost) GetExtensions() map[component.ID]component.Extension { return nh.ext } @@ -751,7 +750,7 @@ func (mse *mockStorageExtension) Shutdown(_ context.Context) error { return nil } -func (mse *mockStorageExtension) GetClient(_ context.Context, _ component.Kind, _ config.ComponentID, _ string) (storage.Client, error) { +func (mse *mockStorageExtension) GetClient(_ context.Context, _ component.Kind, _ component.ID, _ string) (storage.Client, error) { if mse.GetClientError != nil { return nil, mse.GetClientError } diff --git a/exporter/exporterhelper/traces.go b/exporter/exporterhelper/traces.go index 406978d2142..801b3d35325 100644 --- a/exporter/exporterhelper/traces.go +++ b/exporter/exporterhelper/traces.go @@ -19,7 +19,6 @@ import ( "errors" "go.opentelemetry.io/collector/component" - "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/consumer" "go.opentelemetry.io/collector/consumer/consumererror" "go.opentelemetry.io/collector/exporter/exporterhelper/internal" @@ -83,7 +82,7 @@ type traceExporter struct { func NewTracesExporter( _ context.Context, set component.ExporterCreateSettings, - cfg config.Exporter, + cfg component.ExporterConfig, pusher consumer.ConsumeTracesFunc, options ...Option, ) (component.TracesExporter, error) { @@ -100,7 +99,7 @@ func NewTracesExporter( } bs := fromOptions(options...) - be := newBaseExporter(cfg, set, bs, config.TracesDataType, newTraceRequestUnmarshalerFunc(pusher)) + be := newBaseExporter(cfg, set, bs, component.TracesDataType, newTraceRequestUnmarshalerFunc(pusher)) be.wrapConsumerSender(func(nextSender requestSender) requestSender { return &tracesExporterWithObservability{ obsrep: be.obsrep, diff --git a/exporter/exporterhelper/traces_test.go b/exporter/exporterhelper/traces_test.go index b8c7782185e..d6ea12d0173 100644 --- a/exporter/exporterhelper/traces_test.go +++ b/exporter/exporterhelper/traces_test.go @@ -28,7 +28,6 @@ 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,8 +41,8 @@ const ( ) var ( - fakeTracesExporterName = config.NewComponentIDWithName("fake_traces_exporter", "with_name") - fakeTracesExporterConfig = config.NewExporterSettings(fakeTracesExporterName) + fakeTracesExporterName = component.NewIDWithName("fake_traces_exporter", "with_name") + fakeTracesExporterConfig = component.NewExporterConfigSettings(fakeTracesExporterName) ) func TestTracesRequest(t *testing.T) { diff --git a/exporter/loggingexporter/config.go b/exporter/loggingexporter/config.go index 5741d498cc0..e0131246dc3 100644 --- a/exporter/loggingexporter/config.go +++ b/exporter/loggingexporter/config.go @@ -19,7 +19,7 @@ import ( "go.uber.org/zap/zapcore" - "go.opentelemetry.io/collector/config" + "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/config/configtelemetry" "go.opentelemetry.io/collector/confmap" ) @@ -36,7 +36,7 @@ var ( // Config defines configuration for logging exporter. type Config struct { - config.ExporterSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct + component.ExporterConfigSettings `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. @@ -55,7 +55,7 @@ type Config struct { warnLogLevel bool } -var _ config.Exporter = (*Config)(nil) +var _ component.ExporterConfig = (*Config)(nil) var _ confmap.Unmarshaler = (*Config)(nil) func mapLevel(level zapcore.Level) (configtelemetry.Level, error) { diff --git a/exporter/loggingexporter/config_test.go b/exporter/loggingexporter/config_test.go index d390c1fa2d4..90bfbfbf17b 100644 --- a/exporter/loggingexporter/config_test.go +++ b/exporter/loggingexporter/config_test.go @@ -22,7 +22,7 @@ import ( "github.com/stretchr/testify/require" "go.uber.org/zap/zapcore" - "go.opentelemetry.io/collector/config" + "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/config/configtelemetry" "go.opentelemetry.io/collector/confmap" "go.opentelemetry.io/collector/confmap/confmaptest" @@ -31,7 +31,7 @@ import ( func TestUnmarshalDefaultConfig(t *testing.T) { factory := NewFactory() cfg := factory.CreateDefaultConfig() - assert.NoError(t, config.UnmarshalExporter(confmap.New(), cfg)) + assert.NoError(t, component.UnmarshalExporterConfig(confmap.New(), cfg)) assert.Equal(t, factory.CreateDefaultConfig(), cfg) } @@ -44,33 +44,33 @@ func TestUnmarshalConfig(t *testing.T) { { filename: "config_loglevel.yaml", cfg: &Config{ - ExporterSettings: config.NewExporterSettings(config.NewComponentID(typeStr)), - LogLevel: zapcore.DebugLevel, - Verbosity: configtelemetry.LevelDetailed, - SamplingInitial: 10, - SamplingThereafter: 50, - warnLogLevel: true, + ExporterConfigSettings: component.NewExporterConfigSettings(component.NewID(typeStr)), + LogLevel: zapcore.DebugLevel, + Verbosity: configtelemetry.LevelDetailed, + SamplingInitial: 10, + SamplingThereafter: 50, + warnLogLevel: true, }, }, { filename: "config_verbosity.yaml", cfg: &Config{ - ExporterSettings: config.NewExporterSettings(config.NewComponentID(typeStr)), - LogLevel: zapcore.InfoLevel, - Verbosity: configtelemetry.LevelDetailed, - SamplingInitial: 10, - SamplingThereafter: 50, + ExporterConfigSettings: component.NewExporterConfigSettings(component.NewID(typeStr)), + LogLevel: zapcore.InfoLevel, + Verbosity: configtelemetry.LevelDetailed, + SamplingInitial: 10, + SamplingThereafter: 50, }, }, { filename: "loglevel_info.yaml", cfg: &Config{ - ExporterSettings: config.NewExporterSettings(config.NewComponentID(typeStr)), - LogLevel: zapcore.InfoLevel, - Verbosity: configtelemetry.LevelNormal, - SamplingInitial: 2, - SamplingThereafter: 500, - warnLogLevel: true, + ExporterConfigSettings: component.NewExporterConfigSettings(component.NewID(typeStr)), + LogLevel: zapcore.InfoLevel, + Verbosity: configtelemetry.LevelNormal, + SamplingInitial: 2, + SamplingThereafter: 500, + warnLogLevel: true, }, }, { @@ -85,7 +85,7 @@ func TestUnmarshalConfig(t *testing.T) { require.NoError(t, err) factory := NewFactory() cfg := factory.CreateDefaultConfig() - err = config.UnmarshalExporter(cm, cfg) + err = component.UnmarshalExporterConfig(cm, cfg) if tt.expectedErr != "" { assert.EqualError(t, err, tt.expectedErr) } else { diff --git a/exporter/loggingexporter/factory.go b/exporter/loggingexporter/factory.go index c17ab55fb5c..655b05edb55 100644 --- a/exporter/loggingexporter/factory.go +++ b/exporter/loggingexporter/factory.go @@ -23,7 +23,6 @@ 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" @@ -49,17 +48,17 @@ func NewFactory() component.ExporterFactory { ) } -func createDefaultConfig() config.Exporter { +func createDefaultConfig() component.ExporterConfig { return &Config{ - ExporterSettings: config.NewExporterSettings(config.NewComponentID(typeStr)), - LogLevel: zapcore.InfoLevel, - Verbosity: configtelemetry.LevelNormal, - SamplingInitial: defaultSamplingInitial, - SamplingThereafter: defaultSamplingThereafter, + ExporterConfigSettings: component.NewExporterConfigSettings(component.NewID(typeStr)), + LogLevel: zapcore.InfoLevel, + Verbosity: configtelemetry.LevelNormal, + SamplingInitial: defaultSamplingInitial, + SamplingThereafter: defaultSamplingThereafter, } } -func createTracesExporter(ctx context.Context, set component.ExporterCreateSettings, config config.Exporter) (component.TracesExporter, error) { +func createTracesExporter(ctx context.Context, set component.ExporterCreateSettings, config component.ExporterConfig) (component.TracesExporter, error) { cfg := config.(*Config) exporterLogger := createLogger(cfg, set.TelemetrySettings.Logger) s := newLoggingExporter(exporterLogger, cfg.Verbosity) @@ -74,7 +73,7 @@ func createTracesExporter(ctx context.Context, set component.ExporterCreateSetti ) } -func createMetricsExporter(ctx context.Context, set component.ExporterCreateSettings, config config.Exporter) (component.MetricsExporter, error) { +func createMetricsExporter(ctx context.Context, set component.ExporterCreateSettings, config component.ExporterConfig) (component.MetricsExporter, error) { cfg := config.(*Config) exporterLogger := createLogger(cfg, set.TelemetrySettings.Logger) s := newLoggingExporter(exporterLogger, cfg.Verbosity) @@ -89,7 +88,7 @@ func createMetricsExporter(ctx context.Context, set component.ExporterCreateSett ) } -func createLogsExporter(ctx context.Context, set component.ExporterCreateSettings, config config.Exporter) (component.LogsExporter, error) { +func createLogsExporter(ctx context.Context, set component.ExporterCreateSettings, config component.ExporterConfig) (component.LogsExporter, error) { cfg := config.(*Config) exporterLogger := createLogger(cfg, set.TelemetrySettings.Logger) s := newLoggingExporter(exporterLogger, cfg.Verbosity) diff --git a/exporter/loggingexporter/factory_test.go b/exporter/loggingexporter/factory_test.go index 40fdbcd775e..5dac03d80cb 100644 --- a/exporter/loggingexporter/factory_test.go +++ b/exporter/loggingexporter/factory_test.go @@ -21,14 +21,13 @@ import ( "github.com/stretchr/testify/assert" "go.opentelemetry.io/collector/component/componenttest" - "go.opentelemetry.io/collector/config/configtest" ) func TestCreateDefaultConfig(t *testing.T) { factory := NewFactory() cfg := factory.CreateDefaultConfig() assert.NotNil(t, cfg, "failed to create default config") - assert.NoError(t, configtest.CheckConfigStruct(cfg)) + assert.NoError(t, componenttest.CheckConfigStruct(cfg)) } func TestCreateMetricsExporter(t *testing.T) { diff --git a/exporter/otlpexporter/config.go b/exporter/otlpexporter/config.go index f336c57e4c3..7254feebf76 100644 --- a/exporter/otlpexporter/config.go +++ b/exporter/otlpexporter/config.go @@ -17,22 +17,22 @@ package otlpexporter // import "go.opentelemetry.io/collector/exporter/otlpexpor import ( "fmt" - "go.opentelemetry.io/collector/config" + "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/config/configgrpc" "go.opentelemetry.io/collector/exporter/exporterhelper" ) // Config defines configuration for OpenCensus exporter. type Config struct { - 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"` + 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"` configgrpc.GRPCClientSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct. } -var _ config.Exporter = (*Config)(nil) +var _ component.ExporterConfig = (*Config)(nil) // Validate checks if the exporter configuration is valid func (cfg *Config) Validate() error { diff --git a/exporter/otlpexporter/config_test.go b/exporter/otlpexporter/config_test.go index 6bd76301aba..d9295356dac 100644 --- a/exporter/otlpexporter/config_test.go +++ b/exporter/otlpexporter/config_test.go @@ -22,7 +22,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "go.opentelemetry.io/collector/config" + "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/config/configauth" "go.opentelemetry.io/collector/config/configgrpc" "go.opentelemetry.io/collector/config/configtls" @@ -34,7 +34,7 @@ import ( func TestUnmarshalDefaultConfig(t *testing.T) { factory := NewFactory() cfg := factory.CreateDefaultConfig() - assert.NoError(t, config.UnmarshalExporter(confmap.New(), cfg)) + assert.NoError(t, component.UnmarshalExporterConfig(confmap.New(), cfg)) assert.Equal(t, factory.CreateDefaultConfig(), cfg) } @@ -43,10 +43,10 @@ func TestUnmarshalConfig(t *testing.T) { require.NoError(t, err) factory := NewFactory() cfg := factory.CreateDefaultConfig() - assert.NoError(t, config.UnmarshalExporter(cm, cfg)) + assert.NoError(t, component.UnmarshalExporterConfig(cm, cfg)) assert.Equal(t, &Config{ - ExporterSettings: config.NewExporterSettings(config.NewComponentID(typeStr)), + ExporterConfigSettings: component.NewExporterConfigSettings(component.NewID(typeStr)), TimeoutSettings: exporterhelper.TimeoutSettings{ Timeout: 10 * time.Second, }, @@ -82,7 +82,7 @@ func TestUnmarshalConfig(t *testing.T) { }, WriteBufferSize: 512 * 1024, BalancerName: "round_robin", - Auth: &configauth.Authentication{AuthenticatorID: config.NewComponentID("nop")}, + Auth: &configauth.Authentication{AuthenticatorID: component.NewID("nop")}, }, }, cfg) } diff --git a/exporter/otlpexporter/factory.go b/exporter/otlpexporter/factory.go index 8195a9b4fc6..f2540fcf54a 100644 --- a/exporter/otlpexporter/factory.go +++ b/exporter/otlpexporter/factory.go @@ -18,7 +18,6 @@ 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" @@ -41,12 +40,12 @@ func NewFactory() component.ExporterFactory { ) } -func createDefaultConfig() config.Exporter { +func createDefaultConfig() component.ExporterConfig { return &Config{ - ExporterSettings: config.NewExporterSettings(config.NewComponentID(typeStr)), - TimeoutSettings: exporterhelper.NewDefaultTimeoutSettings(), - RetrySettings: exporterhelper.NewDefaultRetrySettings(), - QueueSettings: exporterhelper.NewDefaultQueueSettings(), + ExporterConfigSettings: component.NewExporterConfigSettings(component.NewID(typeStr)), + TimeoutSettings: exporterhelper.NewDefaultTimeoutSettings(), + RetrySettings: exporterhelper.NewDefaultRetrySettings(), + QueueSettings: exporterhelper.NewDefaultQueueSettings(), GRPCClientSettings: configgrpc.GRPCClientSettings{ Headers: map[string]string{}, // Default to gzip compression @@ -60,7 +59,7 @@ func createDefaultConfig() config.Exporter { func createTracesExporter( ctx context.Context, set component.ExporterCreateSettings, - cfg config.Exporter, + cfg component.ExporterConfig, ) (component.TracesExporter, error) { oce, err := newExporter(cfg, set) if err != nil { @@ -80,7 +79,7 @@ func createTracesExporter( func createMetricsExporter( ctx context.Context, set component.ExporterCreateSettings, - cfg config.Exporter, + cfg component.ExporterConfig, ) (component.MetricsExporter, error) { oce, err := newExporter(cfg, set) if err != nil { @@ -101,7 +100,7 @@ func createMetricsExporter( func createLogsExporter( ctx context.Context, set component.ExporterCreateSettings, - cfg config.Exporter, + cfg component.ExporterConfig, ) (component.LogsExporter, error) { oce, err := newExporter(cfg, set) if err != nil { diff --git a/exporter/otlpexporter/factory_test.go b/exporter/otlpexporter/factory_test.go index dc3356c01a0..b56d6442dab 100644 --- a/exporter/otlpexporter/factory_test.go +++ b/exporter/otlpexporter/factory_test.go @@ -23,11 +23,10 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "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/configtest" "go.opentelemetry.io/collector/config/configtls" "go.opentelemetry.io/collector/exporter/exporterhelper" "go.opentelemetry.io/collector/internal/testutil" @@ -37,7 +36,7 @@ func TestCreateDefaultConfig(t *testing.T) { factory := NewFactory() cfg := factory.CreateDefaultConfig() assert.NotNil(t, cfg, "failed to create default config") - assert.NoError(t, configtest.CheckConfigStruct(cfg)) + assert.NoError(t, componenttest.CheckConfigStruct(cfg)) ocfg, ok := factory.CreateDefaultConfig().(*Config) assert.True(t, ok) assert.Equal(t, ocfg.RetrySettings, exporterhelper.NewDefaultRetrySettings()) @@ -68,7 +67,7 @@ func TestCreateTracesExporter(t *testing.T) { { name: "NoEndpoint", config: Config{ - ExporterSettings: config.NewExporterSettings(config.NewComponentID(typeStr)), + ExporterConfigSettings: component.NewExporterConfigSettings(component.NewID(typeStr)), GRPCClientSettings: configgrpc.GRPCClientSettings{ Endpoint: "", }, @@ -78,7 +77,7 @@ func TestCreateTracesExporter(t *testing.T) { { name: "UseSecure", config: Config{ - ExporterSettings: config.NewExporterSettings(config.NewComponentID(typeStr)), + ExporterConfigSettings: component.NewExporterConfigSettings(component.NewID(typeStr)), GRPCClientSettings: configgrpc.GRPCClientSettings{ Endpoint: endpoint, TLSSetting: configtls.TLSClientSetting{ @@ -90,7 +89,7 @@ func TestCreateTracesExporter(t *testing.T) { { name: "Keepalive", config: Config{ - ExporterSettings: config.NewExporterSettings(config.NewComponentID(typeStr)), + ExporterConfigSettings: component.NewExporterConfigSettings(component.NewID(typeStr)), GRPCClientSettings: configgrpc.GRPCClientSettings{ Endpoint: endpoint, Keepalive: &configgrpc.KeepaliveClientConfig{ @@ -104,7 +103,7 @@ func TestCreateTracesExporter(t *testing.T) { { name: "NoneCompression", config: Config{ - ExporterSettings: config.NewExporterSettings(config.NewComponentID(typeStr)), + ExporterConfigSettings: component.NewExporterConfigSettings(component.NewID(typeStr)), GRPCClientSettings: configgrpc.GRPCClientSettings{ Endpoint: endpoint, Compression: "none", @@ -114,7 +113,7 @@ func TestCreateTracesExporter(t *testing.T) { { name: "GzipCompression", config: Config{ - ExporterSettings: config.NewExporterSettings(config.NewComponentID(typeStr)), + ExporterConfigSettings: component.NewExporterConfigSettings(component.NewID(typeStr)), GRPCClientSettings: configgrpc.GRPCClientSettings{ Endpoint: endpoint, Compression: configcompression.Gzip, @@ -142,7 +141,7 @@ func TestCreateTracesExporter(t *testing.T) { { name: "Headers", config: Config{ - ExporterSettings: config.NewExporterSettings(config.NewComponentID(typeStr)), + ExporterConfigSettings: component.NewExporterConfigSettings(component.NewID(typeStr)), GRPCClientSettings: configgrpc.GRPCClientSettings{ Endpoint: endpoint, Headers: map[string]string{ @@ -155,7 +154,7 @@ func TestCreateTracesExporter(t *testing.T) { { name: "NumConsumers", config: Config{ - ExporterSettings: config.NewExporterSettings(config.NewComponentID(typeStr)), + ExporterConfigSettings: component.NewExporterConfigSettings(component.NewID(typeStr)), GRPCClientSettings: configgrpc.GRPCClientSettings{ Endpoint: endpoint, }, @@ -164,7 +163,7 @@ func TestCreateTracesExporter(t *testing.T) { { name: "CaCert", config: Config{ - ExporterSettings: config.NewExporterSettings(config.NewComponentID(typeStr)), + ExporterConfigSettings: component.NewExporterConfigSettings(component.NewID(typeStr)), GRPCClientSettings: configgrpc.GRPCClientSettings{ Endpoint: endpoint, TLSSetting: configtls.TLSClientSetting{ @@ -178,7 +177,7 @@ func TestCreateTracesExporter(t *testing.T) { { name: "CertPemFileError", config: Config{ - ExporterSettings: config.NewExporterSettings(config.NewComponentID(typeStr)), + ExporterConfigSettings: component.NewExporterConfigSettings(component.NewID(typeStr)), GRPCClientSettings: configgrpc.GRPCClientSettings{ Endpoint: endpoint, TLSSetting: configtls.TLSClientSetting{ diff --git a/exporter/otlpexporter/otlp.go b/exporter/otlpexporter/otlp.go index 11e55f19ef7..5f9682e179a 100644 --- a/exporter/otlpexporter/otlp.go +++ b/exporter/otlpexporter/otlp.go @@ -28,7 +28,6 @@ import ( "google.golang.org/grpc/status" "go.opentelemetry.io/collector/component" - "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/consumer/consumererror" "go.opentelemetry.io/collector/exporter/exporterhelper" "go.opentelemetry.io/collector/pdata/plog" @@ -59,7 +58,7 @@ type exporter struct { // Crete new exporter and start it. The exporter will begin connecting but // this function may return before the connection is established. -func newExporter(cfg config.Exporter, set component.ExporterCreateSettings) (*exporter, error) { +func newExporter(cfg component.ExporterConfig, set component.ExporterCreateSettings) (*exporter, error) { oCfg := cfg.(*Config) if oCfg.Endpoint == "" { diff --git a/exporter/otlphttpexporter/config.go b/exporter/otlphttpexporter/config.go index 2aa650a9667..2db393e1c10 100644 --- a/exporter/otlphttpexporter/config.go +++ b/exporter/otlphttpexporter/config.go @@ -17,17 +17,17 @@ package otlphttpexporter // import "go.opentelemetry.io/collector/exporter/otlph import ( "errors" - "go.opentelemetry.io/collector/config" + "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/config/confighttp" "go.opentelemetry.io/collector/exporter/exporterhelper" ) // Config defines configuration for OTLP/HTTP exporter. type Config struct { - 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"` + 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"` // The URL to send traces to. If omitted the Endpoint + "/v1/traces" will be used. TracesEndpoint string `mapstructure:"traces_endpoint"` @@ -39,7 +39,7 @@ type Config struct { LogsEndpoint string `mapstructure:"logs_endpoint"` } -var _ config.Exporter = (*Config)(nil) +var _ component.ExporterConfig = (*Config)(nil) // Validate checks if the exporter configuration is valid func (cfg *Config) Validate() error { diff --git a/exporter/otlphttpexporter/config_test.go b/exporter/otlphttpexporter/config_test.go index 8cb9c4ed16e..261ca74a7a9 100644 --- a/exporter/otlphttpexporter/config_test.go +++ b/exporter/otlphttpexporter/config_test.go @@ -22,7 +22,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "go.opentelemetry.io/collector/config" + "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/config/confighttp" "go.opentelemetry.io/collector/config/configtls" "go.opentelemetry.io/collector/confmap" @@ -33,7 +33,7 @@ import ( func TestUnmarshalDefaultConfig(t *testing.T) { factory := NewFactory() cfg := factory.CreateDefaultConfig() - assert.NoError(t, config.UnmarshalExporter(confmap.New(), cfg)) + assert.NoError(t, component.UnmarshalExporterConfig(confmap.New(), cfg)) assert.Equal(t, factory.CreateDefaultConfig(), cfg) // Default/Empty config is invalid. assert.Error(t, cfg.Validate()) @@ -44,10 +44,10 @@ func TestUnmarshalConfig(t *testing.T) { require.NoError(t, err) factory := NewFactory() cfg := factory.CreateDefaultConfig() - assert.NoError(t, config.UnmarshalExporter(cm, cfg)) + assert.NoError(t, component.UnmarshalExporterConfig(cm, cfg)) assert.Equal(t, &Config{ - ExporterSettings: config.NewExporterSettings(config.NewComponentID(typeStr)), + ExporterConfigSettings: component.NewExporterConfigSettings(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 4a96dd89426..ba1926e27c9 100644 --- a/exporter/otlphttpexporter/factory.go +++ b/exporter/otlphttpexporter/factory.go @@ -21,7 +21,6 @@ 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" @@ -44,11 +43,11 @@ func NewFactory() component.ExporterFactory { ) } -func createDefaultConfig() config.Exporter { +func createDefaultConfig() component.ExporterConfig { return &Config{ - ExporterSettings: config.NewExporterSettings(config.NewComponentID(typeStr)), - RetrySettings: exporterhelper.NewDefaultRetrySettings(), - QueueSettings: exporterhelper.NewDefaultQueueSettings(), + ExporterConfigSettings: component.NewExporterConfigSettings(component.NewID(typeStr)), + RetrySettings: exporterhelper.NewDefaultRetrySettings(), + QueueSettings: exporterhelper.NewDefaultQueueSettings(), HTTPClientSettings: confighttp.HTTPClientSettings{ Endpoint: "", Timeout: 30 * time.Second, @@ -79,7 +78,7 @@ func composeSignalURL(oCfg *Config, signalOverrideURL string, signalName string) func createTracesExporter( ctx context.Context, set component.ExporterCreateSettings, - cfg config.Exporter, + cfg component.ExporterConfig, ) (component.TracesExporter, error) { oce, err := newExporter(cfg, set) if err != nil { @@ -105,7 +104,7 @@ func createTracesExporter( func createMetricsExporter( ctx context.Context, set component.ExporterCreateSettings, - cfg config.Exporter, + cfg component.ExporterConfig, ) (component.MetricsExporter, error) { oce, err := newExporter(cfg, set) if err != nil { @@ -131,7 +130,7 @@ func createMetricsExporter( func createLogsExporter( ctx context.Context, set component.ExporterCreateSettings, - cfg config.Exporter, + cfg component.ExporterConfig, ) (component.LogsExporter, error) { oce, err := newExporter(cfg, set) if err != nil { diff --git a/exporter/otlphttpexporter/factory_test.go b/exporter/otlphttpexporter/factory_test.go index 28eaa3f8d8c..7529899855c 100644 --- a/exporter/otlphttpexporter/factory_test.go +++ b/exporter/otlphttpexporter/factory_test.go @@ -23,11 +23,10 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "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/configtest" "go.opentelemetry.io/collector/config/configtls" "go.opentelemetry.io/collector/internal/testutil" ) @@ -36,7 +35,7 @@ func TestCreateDefaultConfig(t *testing.T) { factory := NewFactory() cfg := factory.CreateDefaultConfig() assert.NotNil(t, cfg, "failed to create default config") - assert.NoError(t, configtest.CheckConfigStruct(cfg)) + assert.NoError(t, componenttest.CheckConfigStruct(cfg)) ocfg, ok := factory.CreateDefaultConfig().(*Config) assert.True(t, ok) assert.Equal(t, ocfg.HTTPClientSettings.Endpoint, "") @@ -72,7 +71,7 @@ func TestCreateTracesExporter(t *testing.T) { { name: "NoEndpoint", config: Config{ - ExporterSettings: config.NewExporterSettings(config.NewComponentID(typeStr)), + ExporterConfigSettings: component.NewExporterConfigSettings(component.NewID(typeStr)), HTTPClientSettings: confighttp.HTTPClientSettings{ Endpoint: "", }, @@ -82,7 +81,7 @@ func TestCreateTracesExporter(t *testing.T) { { name: "UseSecure", config: Config{ - ExporterSettings: config.NewExporterSettings(config.NewComponentID(typeStr)), + ExporterConfigSettings: component.NewExporterConfigSettings(component.NewID(typeStr)), HTTPClientSettings: confighttp.HTTPClientSettings{ Endpoint: endpoint, TLSSetting: configtls.TLSClientSetting{ @@ -94,7 +93,7 @@ func TestCreateTracesExporter(t *testing.T) { { name: "Headers", config: Config{ - ExporterSettings: config.NewExporterSettings(config.NewComponentID(typeStr)), + ExporterConfigSettings: component.NewExporterConfigSettings(component.NewID(typeStr)), HTTPClientSettings: confighttp.HTTPClientSettings{ Endpoint: endpoint, Headers: map[string]string{ @@ -107,7 +106,7 @@ func TestCreateTracesExporter(t *testing.T) { { name: "CaCert", config: Config{ - ExporterSettings: config.NewExporterSettings(config.NewComponentID(typeStr)), + ExporterConfigSettings: component.NewExporterConfigSettings(component.NewID(typeStr)), HTTPClientSettings: confighttp.HTTPClientSettings{ Endpoint: endpoint, TLSSetting: configtls.TLSClientSetting{ @@ -121,7 +120,7 @@ func TestCreateTracesExporter(t *testing.T) { { name: "CertPemFileError", config: Config{ - ExporterSettings: config.NewExporterSettings(config.NewComponentID(typeStr)), + ExporterConfigSettings: component.NewExporterConfigSettings(component.NewID(typeStr)), HTTPClientSettings: confighttp.HTTPClientSettings{ Endpoint: endpoint, TLSSetting: configtls.TLSClientSetting{ @@ -137,7 +136,7 @@ func TestCreateTracesExporter(t *testing.T) { { name: "NoneCompression", config: Config{ - ExporterSettings: config.NewExporterSettings(config.NewComponentID(typeStr)), + ExporterConfigSettings: component.NewExporterConfigSettings(component.NewID(typeStr)), HTTPClientSettings: confighttp.HTTPClientSettings{ Endpoint: endpoint, Compression: "none", @@ -147,7 +146,7 @@ func TestCreateTracesExporter(t *testing.T) { { name: "GzipCompression", config: Config{ - ExporterSettings: config.NewExporterSettings(config.NewComponentID(typeStr)), + ExporterConfigSettings: component.NewExporterConfigSettings(component.NewID(typeStr)), HTTPClientSettings: confighttp.HTTPClientSettings{ Endpoint: endpoint, Compression: configcompression.Gzip, @@ -157,7 +156,7 @@ func TestCreateTracesExporter(t *testing.T) { { name: "SnappyCompression", config: Config{ - ExporterSettings: config.NewExporterSettings(config.NewComponentID(typeStr)), + ExporterConfigSettings: component.NewExporterConfigSettings(component.NewID(typeStr)), HTTPClientSettings: confighttp.HTTPClientSettings{ Endpoint: endpoint, Compression: configcompression.Snappy, @@ -167,7 +166,7 @@ func TestCreateTracesExporter(t *testing.T) { { name: "ZstdCompression", config: Config{ - ExporterSettings: config.NewExporterSettings(config.NewComponentID(typeStr)), + ExporterConfigSettings: component.NewExporterConfigSettings(component.NewID(typeStr)), HTTPClientSettings: confighttp.HTTPClientSettings{ Endpoint: endpoint, Compression: configcompression.Zstd, diff --git a/exporter/otlphttpexporter/otlp.go b/exporter/otlphttpexporter/otlp.go index d940b6825c8..95ea2c4118b 100644 --- a/exporter/otlphttpexporter/otlp.go +++ b/exporter/otlphttpexporter/otlp.go @@ -31,7 +31,6 @@ import ( "google.golang.org/protobuf/proto" "go.opentelemetry.io/collector/component" - "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/consumer/consumererror" "go.opentelemetry.io/collector/exporter/exporterhelper" "go.opentelemetry.io/collector/pdata/plog" @@ -61,7 +60,7 @@ const ( ) // Create new exporter. -func newExporter(cfg config.Exporter, set component.ExporterCreateSettings) (*exporter, error) { +func newExporter(cfg component.ExporterConfig, set component.ExporterCreateSettings) (*exporter, error) { oCfg := cfg.(*Config) if oCfg.Endpoint != "" { diff --git a/exporter/otlphttpexporter/otlp_test.go b/exporter/otlphttpexporter/otlp_test.go index a29cfc1a3f0..c1a15b43f70 100644 --- a/exporter/otlphttpexporter/otlp_test.go +++ b/exporter/otlphttpexporter/otlp_test.go @@ -37,7 +37,6 @@ 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" @@ -328,7 +327,7 @@ func startLogsExporter(t *testing.T, baseURL string, overrideURL string) compone return exp } -func createExporterConfig(baseURL string, defaultCfg config.Exporter) *Config { +func createExporterConfig(baseURL string, defaultCfg component.ExporterConfig) *Config { cfg := defaultCfg.(*Config) cfg.Endpoint = baseURL cfg.QueueSettings.Enabled = false @@ -360,7 +359,7 @@ func startLogsReceiver(t *testing.T, addr string, next consumer.Logs) { startAndCleanup(t, recv) } -func createReceiverConfig(addr string, defaultCfg config.Receiver) *otlpreceiver.Config { +func createReceiverConfig(addr string, defaultCfg component.ReceiverConfig) *otlpreceiver.Config { cfg := defaultCfg.(*otlpreceiver.Config) cfg.HTTP.Endpoint = addr cfg.GRPC = nil @@ -481,8 +480,8 @@ func TestErrorResponses(t *testing.T) { }() cfg := &Config{ - ExporterSettings: config.NewExporterSettings(config.NewComponentID(typeStr)), - TracesEndpoint: fmt.Sprintf("http://%s/v1/traces", addr), + ExporterConfigSettings: component.NewExporterConfigSettings(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. } @@ -558,8 +557,8 @@ func TestUserAgent(t *testing.T) { }() cfg := &Config{ - ExporterSettings: config.NewExporterSettings(config.NewComponentID(typeStr)), - TracesEndpoint: fmt.Sprintf("http://%s/v1/traces", addr), + ExporterConfigSettings: component.NewExporterConfigSettings(component.NewID(typeStr)), + TracesEndpoint: fmt.Sprintf("http://%s/v1/traces", addr), HTTPClientSettings: confighttp.HTTPClientSettings{ Headers: test.headers, }, @@ -603,8 +602,8 @@ func TestUserAgent(t *testing.T) { }() cfg := &Config{ - ExporterSettings: config.NewExporterSettings(config.NewComponentID(typeStr)), - MetricsEndpoint: fmt.Sprintf("http://%s/v1/metrics", addr), + ExporterConfigSettings: component.NewExporterConfigSettings(component.NewID(typeStr)), + MetricsEndpoint: fmt.Sprintf("http://%s/v1/metrics", addr), HTTPClientSettings: confighttp.HTTPClientSettings{ Headers: test.headers, }, @@ -648,8 +647,8 @@ func TestUserAgent(t *testing.T) { }() cfg := &Config{ - ExporterSettings: config.NewExporterSettings(config.NewComponentID(typeStr)), - LogsEndpoint: fmt.Sprintf("http://%s/v1/logs", addr), + ExporterConfigSettings: component.NewExporterConfigSettings(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 52063e4f795..89c0a4bb444 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/config" + "go.opentelemetry.io/collector/component" ) // Config has the configuration for the ballast extension. type Config struct { - config.ExtensionSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct + component.ExtensionConfigSettings `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 ca87d7c1cfc..01b93ef4f4f 100644 --- a/extension/ballastextension/config_test.go +++ b/extension/ballastextension/config_test.go @@ -21,7 +21,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "go.opentelemetry.io/collector/config" + "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/confmap" "go.opentelemetry.io/collector/confmap/confmaptest" ) @@ -29,7 +29,7 @@ import ( func TestUnmarshalDefaultConfig(t *testing.T) { factory := NewFactory() cfg := factory.CreateDefaultConfig() - assert.NoError(t, config.UnmarshalExtension(confmap.New(), cfg)) + assert.NoError(t, component.UnmarshalExtensionConfig(confmap.New(), cfg)) assert.Equal(t, factory.CreateDefaultConfig(), cfg) } @@ -38,12 +38,12 @@ func TestUnmarshalConfig(t *testing.T) { require.NoError(t, err) factory := NewFactory() cfg := factory.CreateDefaultConfig() - assert.NoError(t, config.UnmarshalExtension(cm, cfg)) + assert.NoError(t, component.UnmarshalExtensionConfig(cm, cfg)) assert.Equal(t, &Config{ - ExtensionSettings: config.NewExtensionSettings(config.NewComponentID(typeStr)), - SizeMiB: 123, - SizeInPercentage: 20, + ExtensionConfigSettings: component.NewExtensionConfigSettings(component.NewID(typeStr)), + SizeMiB: 123, + SizeInPercentage: 20, }, cfg) } diff --git a/extension/ballastextension/factory.go b/extension/ballastextension/factory.go index e19dbee50f5..3a244aa3e5e 100644 --- a/extension/ballastextension/factory.go +++ b/extension/ballastextension/factory.go @@ -18,7 +18,6 @@ import ( "context" "go.opentelemetry.io/collector/component" - "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/internal/iruntime" ) @@ -35,12 +34,12 @@ func NewFactory() component.ExtensionFactory { return component.NewExtensionFactory(typeStr, createDefaultConfig, createExtension, component.StabilityLevelBeta) } -func createDefaultConfig() config.Extension { +func createDefaultConfig() component.ExtensionConfig { return &Config{ - ExtensionSettings: config.NewExtensionSettings(config.NewComponentID(typeStr)), + ExtensionConfigSettings: component.NewExtensionConfigSettings(component.NewID(typeStr)), } } -func createExtension(_ context.Context, set component.ExtensionCreateSettings, cfg config.Extension) (component.Extension, error) { +func createExtension(_ context.Context, set component.ExtensionCreateSettings, cfg component.ExtensionConfig) (component.Extension, error) { return newMemoryBallast(cfg.(*Config), set.Logger, memHandler), nil } diff --git a/extension/ballastextension/factory_test.go b/extension/ballastextension/factory_test.go index 3025d3968df..8ced4d6b274 100644 --- a/extension/ballastextension/factory_test.go +++ b/extension/ballastextension/factory_test.go @@ -21,16 +21,15 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/component/componenttest" - "go.opentelemetry.io/collector/config" - "go.opentelemetry.io/collector/config/configtest" ) func TestFactory_CreateDefaultConfig(t *testing.T) { cfg := createDefaultConfig() - assert.Equal(t, &Config{ExtensionSettings: config.NewExtensionSettings(config.NewComponentID(typeStr))}, cfg) + assert.Equal(t, &Config{ExtensionConfigSettings: component.NewExtensionConfigSettings(component.NewID(typeStr))}, cfg) - assert.NoError(t, configtest.CheckConfigStruct(cfg)) + assert.NoError(t, componenttest.CheckConfigStruct(cfg)) ext, err := createExtension(context.Background(), componenttest.NewNopExtensionCreateSettings(), cfg) require.NoError(t, err) require.NotNil(t, ext) diff --git a/extension/experimental/storage/README.md b/extension/experimental/storage/README.md index 2214994ad14..442b1a2dd44 100644 --- a/extension/experimental/storage/README.md +++ b/extension/experimental/storage/README.md @@ -6,7 +6,7 @@ A storage extension persists state beyond the collector process. Other component The `storage.Extension` interface extends `component.Extension` by adding the following method: ``` -GetClient(context.Context, component.Kind, config.ComponentID, string) (Client, error) +GetClient(context.Context, component.Kind, component.ID, string) (Client, error) ``` The `storage.Client` interface contains the following methods: diff --git a/extension/experimental/storage/storage.go b/extension/experimental/storage/storage.go index 6e1c3c92814..9d23ee476c7 100644 --- a/extension/experimental/storage/storage.go +++ b/extension/experimental/storage/storage.go @@ -18,7 +18,6 @@ import ( "context" "go.opentelemetry.io/collector/component" - "go.opentelemetry.io/collector/config" ) // Extension is the interface that storage extensions must implement @@ -29,7 +28,7 @@ type Extension interface { // Each component can have multiple storages (e.g. one for each signal), // which can be identified using storageName parameter. // The component can use the client to manage state - GetClient(ctx context.Context, kind component.Kind, id config.ComponentID, storageName string) (Client, error) + GetClient(ctx context.Context, kind component.Kind, id component.ID, storageName string) (Client, error) } // Client is the interface that storage clients must implement diff --git a/extension/zpagesextension/config.go b/extension/zpagesextension/config.go index 519e27fd12c..1fb47523e21 100644 --- a/extension/zpagesextension/config.go +++ b/extension/zpagesextension/config.go @@ -17,13 +17,13 @@ package zpagesextension // import "go.opentelemetry.io/collector/extension/zpage import ( "errors" - "go.opentelemetry.io/collector/config" + "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/config/confignet" ) // Config has the configuration for the extension enabling the zPages extension. type Config struct { - config.ExtensionSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct + component.ExtensionConfigSettings `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 @@ -31,7 +31,7 @@ type Config struct { TCPAddr confignet.TCPAddr `mapstructure:",squash"` } -var _ config.Extension = (*Config)(nil) +var _ component.ExtensionConfig = (*Config)(nil) // Validate checks if the extension configuration is valid func (cfg *Config) Validate() error { diff --git a/extension/zpagesextension/config_test.go b/extension/zpagesextension/config_test.go index 109783b7463..a9af78689ad 100644 --- a/extension/zpagesextension/config_test.go +++ b/extension/zpagesextension/config_test.go @@ -21,7 +21,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "go.opentelemetry.io/collector/config" + "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/config/confignet" "go.opentelemetry.io/collector/confmap" "go.opentelemetry.io/collector/confmap/confmaptest" @@ -30,7 +30,7 @@ import ( func TestUnmarshalDefaultConfig(t *testing.T) { factory := NewFactory() cfg := factory.CreateDefaultConfig() - assert.NoError(t, config.UnmarshalExtension(confmap.New(), cfg)) + assert.NoError(t, component.UnmarshalExtensionConfig(confmap.New(), cfg)) assert.Equal(t, factory.CreateDefaultConfig(), cfg) } @@ -39,10 +39,10 @@ func TestUnmarshalConfig(t *testing.T) { require.NoError(t, err) factory := NewFactory() cfg := factory.CreateDefaultConfig() - assert.NoError(t, config.UnmarshalExtension(cm, cfg)) + assert.NoError(t, component.UnmarshalExtensionConfig(cm, cfg)) assert.Equal(t, &Config{ - ExtensionSettings: config.NewExtensionSettings(config.NewComponentID(typeStr)), + ExtensionConfigSettings: component.NewExtensionConfigSettings(component.NewID(typeStr)), TCPAddr: confignet.TCPAddr{ Endpoint: "localhost:56888", }, diff --git a/extension/zpagesextension/factory.go b/extension/zpagesextension/factory.go index 00119108eae..88815952fcd 100644 --- a/extension/zpagesextension/factory.go +++ b/extension/zpagesextension/factory.go @@ -18,7 +18,6 @@ import ( "context" "go.opentelemetry.io/collector/component" - "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/config/confignet" ) @@ -34,9 +33,9 @@ func NewFactory() component.ExtensionFactory { return component.NewExtensionFactory(typeStr, createDefaultConfig, createExtension, component.StabilityLevelBeta) } -func createDefaultConfig() config.Extension { +func createDefaultConfig() component.ExtensionConfig { return &Config{ - ExtensionSettings: config.NewExtensionSettings(config.NewComponentID(typeStr)), + ExtensionConfigSettings: component.NewExtensionConfigSettings(component.NewID(typeStr)), TCPAddr: confignet.TCPAddr{ Endpoint: defaultEndpoint, }, @@ -44,6 +43,6 @@ func createDefaultConfig() config.Extension { } // createExtension creates the extension based on this config. -func createExtension(_ context.Context, set component.ExtensionCreateSettings, cfg config.Extension) (component.Extension, error) { +func createExtension(_ context.Context, set component.ExtensionCreateSettings, cfg component.ExtensionConfig) (component.Extension, error) { return newServer(cfg.(*Config), set.TelemetrySettings), nil } diff --git a/extension/zpagesextension/factory_test.go b/extension/zpagesextension/factory_test.go index 068a4ffcbe9..8afb574d763 100644 --- a/extension/zpagesextension/factory_test.go +++ b/extension/zpagesextension/factory_test.go @@ -21,24 +21,23 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "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/config/configtest" "go.opentelemetry.io/collector/internal/testutil" ) func TestFactory_CreateDefaultConfig(t *testing.T) { cfg := createDefaultConfig() assert.Equal(t, &Config{ - ExtensionSettings: config.NewExtensionSettings(config.NewComponentID(typeStr)), + ExtensionConfigSettings: component.NewExtensionConfigSettings(component.NewID(typeStr)), TCPAddr: confignet.TCPAddr{ Endpoint: "localhost:55679", }, }, cfg) - assert.NoError(t, configtest.CheckConfigStruct(cfg)) + assert.NoError(t, componenttest.CheckConfigStruct(cfg)) ext, err := createExtension(context.Background(), componenttest.NewNopExtensionCreateSettings(), cfg) require.NoError(t, err) require.NotNil(t, ext) diff --git a/internal/sharedcomponent/sharedcomponent_test.go b/internal/sharedcomponent/sharedcomponent_test.go index 5b8a7e57c41..2e42de07455 100644 --- a/internal/sharedcomponent/sharedcomponent_test.go +++ b/internal/sharedcomponent/sharedcomponent_test.go @@ -23,10 +23,9 @@ import ( "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/component/componenttest" - "go.opentelemetry.io/collector/config" ) -var id = config.NewComponentID("test") +var id = component.NewID("test") type baseComponent struct { component.StartFunc diff --git a/obsreport/obsreport_exporter.go b/obsreport/obsreport_exporter.go index 8a8bddfd6ae..f999f649588 100644 --- a/obsreport/obsreport_exporter.go +++ b/obsreport/obsreport_exporter.go @@ -23,7 +23,6 @@ import ( "go.opentelemetry.io/otel/trace" "go.opentelemetry.io/collector/component" - "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/config/configtelemetry" "go.opentelemetry.io/collector/internal/obsreportconfig/obsmetrics" ) @@ -38,7 +37,7 @@ type Exporter struct { // ExporterSettings are settings for creating an Exporter. type ExporterSettings struct { - ExporterID config.ComponentID + ExporterID component.ID ExporterCreateSettings component.ExporterCreateSettings } diff --git a/obsreport/obsreport_processor.go b/obsreport/obsreport_processor.go index fdc492211a8..d48f5e28ece 100644 --- a/obsreport/obsreport_processor.go +++ b/obsreport/obsreport_processor.go @@ -22,7 +22,6 @@ import ( "go.opencensus.io/tag" "go.opentelemetry.io/collector/component" - "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/config/configtelemetry" "go.opentelemetry.io/collector/internal/obsreportconfig/obsmetrics" ) @@ -49,7 +48,7 @@ type Processor struct { // ProcessorSettings are settings for creating a Processor. type ProcessorSettings struct { - ProcessorID config.ComponentID + ProcessorID component.ID ProcessorCreateSettings component.ProcessorCreateSettings } diff --git a/obsreport/obsreport_receiver.go b/obsreport/obsreport_receiver.go index c2fdbb76749..04e15920721 100644 --- a/obsreport/obsreport_receiver.go +++ b/obsreport/obsreport_receiver.go @@ -28,7 +28,6 @@ import ( "go.uber.org/zap" "go.opentelemetry.io/collector/component" - "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/config/configtelemetry" "go.opentelemetry.io/collector/featuregate" "go.opentelemetry.io/collector/internal/obsreportconfig" @@ -65,7 +64,7 @@ type Receiver struct { // ReceiverSettings are settings for creating an Receiver. type ReceiverSettings struct { - ReceiverID config.ComponentID + ReceiverID component.ID Transport string // LongLivedCtx when true indicates that the context passed in the call // outlives the individual receive operation. @@ -177,7 +176,7 @@ func (rec *Receiver) EndTracesOp( numReceivedSpans int, err error, ) { - rec.endOp(receiverCtx, format, numReceivedSpans, err, config.TracesDataType) + rec.endOp(receiverCtx, format, numReceivedSpans, err, component.TracesDataType) } // StartLogsOp is called when a request is received from a client. @@ -195,7 +194,7 @@ func (rec *Receiver) EndLogsOp( numReceivedLogRecords int, err error, ) { - rec.endOp(receiverCtx, format, numReceivedLogRecords, err, config.LogsDataType) + rec.endOp(receiverCtx, format, numReceivedLogRecords, err, component.LogsDataType) } // StartMetricsOp is called when a request is received from a client. @@ -213,7 +212,7 @@ func (rec *Receiver) EndMetricsOp( numReceivedPoints int, err error, ) { - rec.endOp(receiverCtx, format, numReceivedPoints, err, config.MetricsDataType) + rec.endOp(receiverCtx, format, numReceivedPoints, err, component.MetricsDataType) } // startOp creates the span used to trace the operation. Returning @@ -247,7 +246,7 @@ func (rec *Receiver) endOp( format string, numReceivedItems int, err error, - dataType config.DataType, + dataType component.DataType, ) { numAccepted := numReceivedItems numRefused := 0 @@ -266,13 +265,13 @@ func (rec *Receiver) endOp( if span.IsRecording() { var acceptedItemsKey, refusedItemsKey string switch dataType { - case config.TracesDataType: + case component.TracesDataType: acceptedItemsKey = obsmetrics.AcceptedSpansKey refusedItemsKey = obsmetrics.RefusedSpansKey - case config.MetricsDataType: + case component.MetricsDataType: acceptedItemsKey = obsmetrics.AcceptedMetricPointsKey refusedItemsKey = obsmetrics.RefusedMetricPointsKey - case config.LogsDataType: + case component.LogsDataType: acceptedItemsKey = obsmetrics.AcceptedLogRecordsKey refusedItemsKey = obsmetrics.RefusedLogRecordsKey } @@ -287,7 +286,7 @@ func (rec *Receiver) endOp( span.End() } -func (rec *Receiver) recordMetrics(receiverCtx context.Context, dataType config.DataType, numAccepted, numRefused int) { +func (rec *Receiver) recordMetrics(receiverCtx context.Context, dataType component.DataType, numAccepted, numRefused int) { if rec.useOtelForMetrics { rec.recordWithOtel(receiverCtx, dataType, numAccepted, numRefused) } else { @@ -295,16 +294,16 @@ func (rec *Receiver) recordMetrics(receiverCtx context.Context, dataType config. } } -func (rec *Receiver) recordWithOtel(receiverCtx context.Context, dataType config.DataType, numAccepted, numRefused int) { +func (rec *Receiver) recordWithOtel(receiverCtx context.Context, dataType component.DataType, numAccepted, numRefused int) { var acceptedMeasure, refusedMeasure syncint64.Counter switch dataType { - case config.TracesDataType: + case component.TracesDataType: acceptedMeasure = rec.acceptedSpansCounter refusedMeasure = rec.refusedSpansCounter - case config.MetricsDataType: + case component.MetricsDataType: acceptedMeasure = rec.acceptedMetricPointsCounter refusedMeasure = rec.refusedMetricPointsCounter - case config.LogsDataType: + case component.LogsDataType: acceptedMeasure = rec.acceptedLogRecordsCounter refusedMeasure = rec.refusedLogRecordsCounter } @@ -313,16 +312,16 @@ func (rec *Receiver) recordWithOtel(receiverCtx context.Context, dataType config refusedMeasure.Add(receiverCtx, int64(numRefused), rec.otelAttrs...) } -func (rec *Receiver) recordWithOC(receiverCtx context.Context, dataType config.DataType, numAccepted, numRefused int) { +func (rec *Receiver) recordWithOC(receiverCtx context.Context, dataType component.DataType, numAccepted, numRefused int) { var acceptedMeasure, refusedMeasure *stats.Int64Measure switch dataType { - case config.TracesDataType: + case component.TracesDataType: acceptedMeasure = obsmetrics.ReceiverAcceptedSpans refusedMeasure = obsmetrics.ReceiverRefusedSpans - case config.MetricsDataType: + case component.MetricsDataType: acceptedMeasure = obsmetrics.ReceiverAcceptedMetricPoints refusedMeasure = obsmetrics.ReceiverRefusedMetricPoints - case config.LogsDataType: + case component.LogsDataType: acceptedMeasure = obsmetrics.ReceiverAcceptedLogRecords refusedMeasure = obsmetrics.ReceiverRefusedLogRecords } diff --git a/obsreport/obsreport_scraper.go b/obsreport/obsreport_scraper.go index fe70977b6be..ba8e868217e 100644 --- a/obsreport/obsreport_scraper.go +++ b/obsreport/obsreport_scraper.go @@ -24,7 +24,6 @@ import ( "go.opentelemetry.io/otel/trace" "go.opentelemetry.io/collector/component" - "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/config/configtelemetry" "go.opentelemetry.io/collector/internal/obsreportconfig/obsmetrics" "go.opentelemetry.io/collector/receiver/scrapererror" @@ -33,16 +32,16 @@ import ( // Scraper is a helper to add observability to a component.Scraper. type Scraper struct { level configtelemetry.Level - receiverID config.ComponentID - scraper config.ComponentID + receiverID component.ID + scraper component.ID mutators []tag.Mutator tracer trace.Tracer } // ScraperSettings are settings for creating a Scraper. type ScraperSettings struct { - ReceiverID config.ComponentID - Scraper config.ComponentID + ReceiverID component.ID + Scraper component.ID ReceiverCreateSettings component.ReceiverCreateSettings } @@ -100,7 +99,7 @@ func (s *Scraper) EndMetricsOp( // end span according to errors if span.IsRecording() { span.SetAttributes( - attribute.String(obsmetrics.FormatKey, string(config.MetricsDataType)), + attribute.String(obsmetrics.FormatKey, string(component.MetricsDataType)), attribute.Int64(obsmetrics.ScrapedMetricPointsKey, int64(numScrapedMetrics)), attribute.Int64(obsmetrics.ErroredMetricPointsKey, int64(numErroredMetrics)), ) diff --git a/obsreport/obsreport_test.go b/obsreport/obsreport_test.go index 69dbbc250b6..95dc85f3f7a 100644 --- a/obsreport/obsreport_test.go +++ b/obsreport/obsreport_test.go @@ -24,7 +24,7 @@ import ( "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/codes" - "go.opentelemetry.io/collector/config" + "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/featuregate" "go.opentelemetry.io/collector/internal/obsreportconfig" "go.opentelemetry.io/collector/internal/obsreportconfig/obsmetrics" @@ -38,10 +38,10 @@ const ( ) var ( - receiver = config.NewComponentID("fakeReceiver") - scraper = config.NewComponentID("fakeScraper") - processor = config.NewComponentID("fakeProcessor") - exporter = config.NewComponentID("fakeExporter") + receiver = component.NewID("fakeReceiver") + scraper = component.NewID("fakeScraper") + processor = component.NewID("fakeProcessor") + exporter = component.NewID("fakeExporter") errFake = errors.New("errFake") partialErrFake = scrapererror.NewPartialScrapeError(errFake, 1) diff --git a/obsreport/obsreporttest/obsreporttest.go b/obsreport/obsreporttest/obsreporttest.go index c506535ec18..e2049044737 100644 --- a/obsreport/obsreporttest/obsreporttest.go +++ b/obsreport/obsreporttest/obsreporttest.go @@ -33,7 +33,6 @@ 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/internal/obsreportconfig" ) @@ -140,7 +139,7 @@ func SetupTelemetry() (TestTelemetry, error) { // CheckExporterTraces checks that for the current exported values for trace exporter metrics match given values. // When this function is called it is required to also call SetupTelemetry as first thing. -func CheckExporterTraces(_ TestTelemetry, exporter config.ComponentID, sentSpans, sendFailedSpans int64) error { +func CheckExporterTraces(_ TestTelemetry, exporter component.ID, sentSpans, sendFailedSpans int64) error { exporterTags := tagsForExporterView(exporter) if sendFailedSpans > 0 { return multierr.Combine( @@ -152,7 +151,7 @@ func CheckExporterTraces(_ TestTelemetry, exporter config.ComponentID, sentSpans // CheckExporterMetrics checks that for the current exported values for metrics exporter metrics match given values. // When this function is called it is required to also call SetupTelemetry as first thing. -func CheckExporterMetrics(_ TestTelemetry, exporter config.ComponentID, sentMetricsPoints, sendFailedMetricsPoints int64) error { +func CheckExporterMetrics(_ TestTelemetry, exporter component.ID, sentMetricsPoints, sendFailedMetricsPoints int64) error { exporterTags := tagsForExporterView(exporter) if sendFailedMetricsPoints > 0 { return multierr.Combine( @@ -164,7 +163,7 @@ func CheckExporterMetrics(_ TestTelemetry, exporter config.ComponentID, sentMetr // CheckExporterLogs checks that for the current exported values for logs exporter metrics match given values. // When this function is called it is required to also call SetupTelemetry as first thing. -func CheckExporterLogs(_ TestTelemetry, exporter config.ComponentID, sentLogRecords, sendFailedLogRecords int64) error { +func CheckExporterLogs(_ TestTelemetry, exporter component.ID, sentLogRecords, sendFailedLogRecords int64) error { exporterTags := tagsForExporterView(exporter) if sendFailedLogRecords > 0 { return multierr.Combine( @@ -176,7 +175,7 @@ func CheckExporterLogs(_ TestTelemetry, exporter config.ComponentID, sentLogReco // CheckProcessorTraces checks that for the current exported values for trace exporter metrics match given values. // When this function is called it is required to also call SetupTelemetry as first thing. -func CheckProcessorTraces(_ TestTelemetry, processor config.ComponentID, acceptedSpans, refusedSpans, droppedSpans int64) error { +func CheckProcessorTraces(_ TestTelemetry, processor component.ID, acceptedSpans, refusedSpans, droppedSpans int64) error { processorTags := tagsForProcessorView(processor) return multierr.Combine( checkValueForView(processorTags, acceptedSpans, "processor/accepted_spans"), @@ -186,7 +185,7 @@ func CheckProcessorTraces(_ TestTelemetry, processor config.ComponentID, accepte // CheckProcessorMetrics checks that for the current exported values for metrics exporter metrics match given values. // When this function is called it is required to also call SetupTelemetry as first thing. -func CheckProcessorMetrics(_ TestTelemetry, processor config.ComponentID, acceptedMetricPoints, refusedMetricPoints, droppedMetricPoints int64) error { +func CheckProcessorMetrics(_ TestTelemetry, processor component.ID, acceptedMetricPoints, refusedMetricPoints, droppedMetricPoints int64) error { processorTags := tagsForProcessorView(processor) return multierr.Combine( checkValueForView(processorTags, acceptedMetricPoints, "processor/accepted_metric_points"), @@ -196,7 +195,7 @@ func CheckProcessorMetrics(_ TestTelemetry, processor config.ComponentID, accept // CheckProcessorLogs checks that for the current exported values for logs exporter metrics match given values. // When this function is called it is required to also call SetupTelemetry as first thing. -func CheckProcessorLogs(_ TestTelemetry, processor config.ComponentID, acceptedLogRecords, refusedLogRecords, droppedLogRecords int64) error { +func CheckProcessorLogs(_ TestTelemetry, processor component.ID, acceptedLogRecords, refusedLogRecords, droppedLogRecords int64) error { processorTags := tagsForProcessorView(processor) return multierr.Combine( checkValueForView(processorTags, acceptedLogRecords, "processor/accepted_log_records"), @@ -206,25 +205,25 @@ func CheckProcessorLogs(_ TestTelemetry, processor config.ComponentID, acceptedL // CheckReceiverTraces checks that for the current exported values for trace receiver metrics match given values. // When this function is called it is required to also call SetupTelemetry as first thing. -func CheckReceiverTraces(tts TestTelemetry, receiver config.ComponentID, protocol string, acceptedSpans, droppedSpans int64) error { +func CheckReceiverTraces(tts TestTelemetry, receiver component.ID, protocol string, acceptedSpans, droppedSpans int64) error { return tts.otelPrometheusChecker.checkReceiverTraces(receiver, protocol, acceptedSpans, droppedSpans) } // CheckReceiverLogs checks that for the current exported values for logs receiver metrics match given values. // When this function is called it is required to also call SetupTelemetry as first thing. -func CheckReceiverLogs(tts TestTelemetry, receiver config.ComponentID, protocol string, acceptedLogRecords, droppedLogRecords int64) error { +func CheckReceiverLogs(tts TestTelemetry, receiver component.ID, protocol string, acceptedLogRecords, droppedLogRecords int64) error { return tts.otelPrometheusChecker.checkReceiverLogs(receiver, protocol, acceptedLogRecords, droppedLogRecords) } // CheckReceiverMetrics checks that for the current exported values for metrics receiver metrics match given values. // When this function is called it is required to also call SetupTelemetry as first thing. -func CheckReceiverMetrics(tts TestTelemetry, receiver config.ComponentID, protocol string, acceptedMetricPoints, droppedMetricPoints int64) error { +func CheckReceiverMetrics(tts TestTelemetry, receiver component.ID, protocol string, acceptedMetricPoints, droppedMetricPoints int64) error { return tts.otelPrometheusChecker.checkReceiverMetrics(receiver, protocol, acceptedMetricPoints, droppedMetricPoints) } // CheckScraperMetrics checks that for the current exported values for metrics scraper metrics match given values. // When this function is called it is required to also call SetupTelemetry as first thing. -func CheckScraperMetrics(_ TestTelemetry, receiver config.ComponentID, scraper config.ComponentID, scrapedMetricPoints, erroredMetricPoints int64) error { +func CheckScraperMetrics(_ TestTelemetry, receiver component.ID, scraper component.ID, scrapedMetricPoints, erroredMetricPoints int64) error { scraperTags := tagsForScraperView(receiver, scraper) return multierr.Combine( checkValueForView(scraperTags, scrapedMetricPoints, "scraper/scraped_metric_points"), @@ -257,7 +256,7 @@ func checkValueForView(wantTags []tag.Tag, value int64, vName string) error { } // tagsForScraperView returns the tags that are needed for the scraper views. -func tagsForScraperView(receiver config.ComponentID, scraper config.ComponentID) []tag.Tag { +func tagsForScraperView(receiver component.ID, scraper component.ID) []tag.Tag { return []tag.Tag{ {Key: receiverTag, Value: receiver.String()}, {Key: scraperTag, Value: scraper.String()}, @@ -265,14 +264,14 @@ func tagsForScraperView(receiver config.ComponentID, scraper config.ComponentID) } // tagsForProcessorView returns the tags that are needed for the processor views. -func tagsForProcessorView(processor config.ComponentID) []tag.Tag { +func tagsForProcessorView(processor component.ID) []tag.Tag { return []tag.Tag{ {Key: processorTag, Value: processor.String()}, } } // tagsForExporterView returns the tags that are needed for the exporter views. -func tagsForExporterView(exporter config.ComponentID) []tag.Tag { +func tagsForExporterView(exporter component.ID) []tag.Tag { return []tag.Tag{ {Key: exporterTag, Value: exporter.String()}, } diff --git a/obsreport/obsreporttest/obsreporttest_test.go b/obsreport/obsreporttest/obsreporttest_test.go index fe3f5108ec1..fa1f435366b 100644 --- a/obsreport/obsreporttest/obsreporttest_test.go +++ b/obsreport/obsreporttest/obsreporttest_test.go @@ -21,7 +21,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "go.opentelemetry.io/collector/config" + "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/obsreport" "go.opentelemetry.io/collector/obsreport/obsreporttest" ) @@ -32,8 +32,8 @@ const ( ) var ( - receiver = config.NewComponentID("fakeReicever") - exporter = config.NewComponentID("fakeExporter") + receiver = component.NewID("fakeReicever") + exporter = component.NewID("fakeExporter") ) func TestCheckReceiverTracesViews(t *testing.T) { diff --git a/obsreport/obsreporttest/otelprometheuschecker.go b/obsreport/obsreporttest/otelprometheuschecker.go index 9c6586de998..fe0d780c6c0 100644 --- a/obsreport/obsreporttest/otelprometheuschecker.go +++ b/obsreport/obsreporttest/otelprometheuschecker.go @@ -26,7 +26,7 @@ import ( "go.opentelemetry.io/otel/attribute" "go.uber.org/multierr" - "go.opentelemetry.io/collector/config" + "go.opentelemetry.io/collector/component" ) // prometheusChecker is used to assert exported metrics from a prometheus handler. @@ -34,21 +34,21 @@ type prometheusChecker struct { promHandler http.Handler } -func (pc *prometheusChecker) checkReceiverTraces(receiver config.ComponentID, protocol string, acceptedSpans, droppedSpans int64) error { +func (pc *prometheusChecker) checkReceiverTraces(receiver component.ID, protocol string, acceptedSpans, droppedSpans int64) error { receiverAttrs := attributesForReceiverMetrics(receiver, protocol) return multierr.Combine( pc.checkCounter("receiver_accepted_spans", acceptedSpans, receiverAttrs), pc.checkCounter("receiver_refused_spans", droppedSpans, receiverAttrs)) } -func (pc *prometheusChecker) checkReceiverLogs(receiver config.ComponentID, protocol string, acceptedLogRecords, droppedLogRecords int64) error { +func (pc *prometheusChecker) checkReceiverLogs(receiver component.ID, protocol string, acceptedLogRecords, droppedLogRecords int64) error { receiverAttrs := attributesForReceiverMetrics(receiver, protocol) return multierr.Combine( pc.checkCounter("receiver_accepted_log_records", acceptedLogRecords, receiverAttrs), pc.checkCounter("receiver_refused_log_records", droppedLogRecords, receiverAttrs)) } -func (pc *prometheusChecker) checkReceiverMetrics(receiver config.ComponentID, protocol string, acceptedMetricPoints, droppedMetricPoints int64) error { +func (pc *prometheusChecker) checkReceiverMetrics(receiver component.ID, protocol string, acceptedMetricPoints, droppedMetricPoints int64) error { receiverAttrs := attributesForReceiverMetrics(receiver, protocol) return multierr.Combine( pc.checkCounter("receiver_accepted_metric_points", acceptedMetricPoints, receiverAttrs), @@ -125,7 +125,7 @@ func fetchPrometheusMetrics(handler http.Handler) (map[string]*io_prometheus_cli } // attributesForReceiverMetrics returns the attributes that are needed for the receiver metrics. -func attributesForReceiverMetrics(receiver config.ComponentID, transport string) []attribute.KeyValue { +func attributesForReceiverMetrics(receiver component.ID, transport string) []attribute.KeyValue { return []attribute.KeyValue{ attribute.String(receiverTag.Name(), receiver.String()), attribute.String(transportTag.Name(), transport), diff --git a/obsreport/obsreporttest/otelprometheuschecker_test.go b/obsreport/obsreporttest/otelprometheuschecker_test.go index 7c1615ccb32..dc36c3b2e1b 100644 --- a/obsreport/obsreporttest/otelprometheuschecker_test.go +++ b/obsreport/obsreporttest/otelprometheuschecker_test.go @@ -21,7 +21,7 @@ import ( "github.com/stretchr/testify/assert" "go.opentelemetry.io/otel/attribute" - "go.opentelemetry.io/collector/config" + "go.opentelemetry.io/collector/component" ) func newStubPromChecker() prometheusChecker { @@ -56,7 +56,7 @@ gauge_metric 49 func TestPromChecker(t *testing.T) { pc := newStubPromChecker() - receiver := config.NewComponentID("fakeReceiver") + receiver := component.NewID("fakeReceiver") transport := "fakeTransport" assert.NoError(t, diff --git a/processor/batchprocessor/batch_processor_test.go b/processor/batchprocessor/batch_processor_test.go index ee406106777..09eb064347c 100644 --- a/processor/batchprocessor/batch_processor_test.go +++ b/processor/batchprocessor/batch_processor_test.go @@ -26,8 +26,8 @@ import ( "github.com/stretchr/testify/require" "go.opencensus.io/stats/view" + "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 +285,9 @@ func TestBatchProcessorSentByTimeout(t *testing.T) { func TestBatchProcessorTraceSendWhenClosing(t *testing.T) { cfg := Config{ - ProcessorSettings: config.NewProcessorSettings(config.NewComponentID(typeStr)), - Timeout: 3 * time.Second, - SendBatchSize: 1000, + ProcessorConfigSettings: component.NewProcessorConfigSettings(component.NewID(typeStr)), + Timeout: 3 * time.Second, + SendBatchSize: 1000, } sink := new(consumertest.TracesSink) @@ -313,9 +313,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{ - ProcessorSettings: config.NewProcessorSettings(config.NewComponentID(typeStr)), - Timeout: 200 * time.Millisecond, - SendBatchSize: 50, + ProcessorConfigSettings: component.NewProcessorConfigSettings(component.NewID(typeStr)), + Timeout: 200 * time.Millisecond, + SendBatchSize: 50, } requestCount := 100 @@ -367,9 +367,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{ - ProcessorSettings: config.NewProcessorSettings(config.NewComponentID(typeStr)), - Timeout: 100 * time.Millisecond, - SendBatchSize: 50, + ProcessorConfigSettings: component.NewProcessorConfigSettings(component.NewID(typeStr)), + Timeout: 100 * time.Millisecond, + SendBatchSize: 50, } requestCount := 100 @@ -446,9 +446,9 @@ func TestBatchMetrics_UnevenBatchMaxSize(t *testing.T) { func TestBatchMetricsProcessor_Timeout(t *testing.T) { cfg := Config{ - ProcessorSettings: config.NewProcessorSettings(config.NewComponentID(typeStr)), - Timeout: 100 * time.Millisecond, - SendBatchSize: 101, + ProcessorConfigSettings: component.NewProcessorConfigSettings(component.NewID(typeStr)), + Timeout: 100 * time.Millisecond, + SendBatchSize: 101, } requestCount := 5 metricsPerRequest := 10 @@ -495,9 +495,9 @@ func TestBatchMetricsProcessor_Timeout(t *testing.T) { func TestBatchMetricProcessor_Shutdown(t *testing.T) { cfg := Config{ - ProcessorSettings: config.NewProcessorSettings(config.NewComponentID(typeStr)), - Timeout: 3 * time.Second, - SendBatchSize: 1000, + ProcessorConfigSettings: component.NewProcessorConfigSettings(component.NewID(typeStr)), + Timeout: 3 * time.Second, + SendBatchSize: 1000, } requestCount := 5 metricsPerRequest := 10 @@ -581,9 +581,9 @@ func BenchmarkTraceSizeSpanCount(b *testing.B) { func BenchmarkBatchMetricProcessor(b *testing.B) { b.StopTimer() cfg := Config{ - ProcessorSettings: config.NewProcessorSettings(config.NewComponentID(typeStr)), - Timeout: 100 * time.Millisecond, - SendBatchSize: 2000, + ProcessorConfigSettings: component.NewProcessorConfigSettings(component.NewID(typeStr)), + Timeout: 100 * time.Millisecond, + SendBatchSize: 2000, } ctx := context.Background() sink := new(metricsSink) @@ -631,9 +631,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{ - ProcessorSettings: config.NewProcessorSettings(config.NewComponentID(typeStr)), - Timeout: 200 * time.Millisecond, - SendBatchSize: 50, + ProcessorConfigSettings: component.NewProcessorConfigSettings(component.NewID(typeStr)), + Timeout: 200 * time.Millisecond, + SendBatchSize: 50, } requestCount := 100 @@ -685,9 +685,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{ - ProcessorSettings: config.NewProcessorSettings(config.NewComponentID(typeStr)), - Timeout: 100 * time.Millisecond, - SendBatchSize: 50, + ProcessorConfigSettings: component.NewProcessorConfigSettings(component.NewID(typeStr)), + Timeout: 100 * time.Millisecond, + SendBatchSize: 50, } requestCount := 100 @@ -743,9 +743,9 @@ func TestBatchLogProcessor_BatchSize(t *testing.T) { func TestBatchLogsProcessor_Timeout(t *testing.T) { cfg := Config{ - ProcessorSettings: config.NewProcessorSettings(config.NewComponentID(typeStr)), - Timeout: 100 * time.Millisecond, - SendBatchSize: 100, + ProcessorConfigSettings: component.NewProcessorConfigSettings(component.NewID(typeStr)), + Timeout: 100 * time.Millisecond, + SendBatchSize: 100, } requestCount := 5 logsPerRequest := 10 @@ -792,9 +792,9 @@ func TestBatchLogsProcessor_Timeout(t *testing.T) { func TestBatchLogProcessor_Shutdown(t *testing.T) { cfg := Config{ - ProcessorSettings: config.NewProcessorSettings(config.NewComponentID(typeStr)), - Timeout: 3 * time.Second, - SendBatchSize: 1000, + ProcessorConfigSettings: component.NewProcessorConfigSettings(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 ef8ba20d79f..7f24259d032 100644 --- a/processor/batchprocessor/config.go +++ b/processor/batchprocessor/config.go @@ -18,12 +18,12 @@ import ( "errors" "time" - "go.opentelemetry.io/collector/config" + "go.opentelemetry.io/collector/component" ) // Config defines configuration for batch processor. type Config struct { - config.ProcessorSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct + component.ProcessorConfigSettings `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"` @@ -37,7 +37,7 @@ type Config struct { SendBatchMaxSize uint32 `mapstructure:"send_batch_max_size"` } -var _ config.Processor = (*Config)(nil) +var _ component.ProcessorConfig = (*Config)(nil) // Validate checks if the processor configuration is valid func (cfg *Config) Validate() error { diff --git a/processor/batchprocessor/config_test.go b/processor/batchprocessor/config_test.go index d3414fc05eb..fe1f9f40b08 100644 --- a/processor/batchprocessor/config_test.go +++ b/processor/batchprocessor/config_test.go @@ -22,7 +22,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "go.opentelemetry.io/collector/config" + "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/confmap" "go.opentelemetry.io/collector/confmap/confmaptest" ) @@ -30,7 +30,7 @@ import ( func TestUnmarshalDefaultConfig(t *testing.T) { factory := NewFactory() cfg := factory.CreateDefaultConfig() - assert.NoError(t, config.UnmarshalProcessor(confmap.New(), cfg)) + assert.NoError(t, component.UnmarshalProcessorConfig(confmap.New(), cfg)) assert.Equal(t, factory.CreateDefaultConfig(), cfg) } @@ -39,30 +39,30 @@ func TestUnmarshalConfig(t *testing.T) { require.NoError(t, err) factory := NewFactory() cfg := factory.CreateDefaultConfig() - assert.NoError(t, config.UnmarshalProcessor(cm, cfg)) + assert.NoError(t, component.UnmarshalProcessorConfig(cm, cfg)) assert.Equal(t, &Config{ - ProcessorSettings: config.NewProcessorSettings(config.NewComponentID(typeStr)), - SendBatchSize: uint32(10000), - SendBatchMaxSize: uint32(11000), - Timeout: time.Second * 10, + ProcessorConfigSettings: component.NewProcessorConfigSettings(component.NewID(typeStr)), + SendBatchSize: uint32(10000), + SendBatchMaxSize: uint32(11000), + Timeout: time.Second * 10, }, cfg) } func TestValidateConfig_DefaultBatchMaxSize(t *testing.T) { cfg := &Config{ - ProcessorSettings: config.NewProcessorSettings(config.NewComponentIDWithName(typeStr, "2")), - SendBatchSize: 100, - SendBatchMaxSize: 0, + ProcessorConfigSettings: component.NewProcessorConfigSettings(component.NewIDWithName(typeStr, "2")), + SendBatchSize: 100, + SendBatchMaxSize: 0, } assert.NoError(t, cfg.Validate()) } func TestValidateConfig_ValidBatchSizes(t *testing.T) { cfg := &Config{ - ProcessorSettings: config.NewProcessorSettings(config.NewComponentIDWithName(typeStr, "2")), - SendBatchSize: 100, - SendBatchMaxSize: 1000, + ProcessorConfigSettings: component.NewProcessorConfigSettings(component.NewIDWithName(typeStr, "2")), + SendBatchSize: 100, + SendBatchMaxSize: 1000, } assert.NoError(t, cfg.Validate()) @@ -70,9 +70,9 @@ func TestValidateConfig_ValidBatchSizes(t *testing.T) { func TestValidateConfig_InvalidBatchSize(t *testing.T) { cfg := &Config{ - ProcessorSettings: config.NewProcessorSettings(config.NewComponentIDWithName(typeStr, "2")), - SendBatchSize: 1000, - SendBatchMaxSize: 100, + ProcessorConfigSettings: component.NewProcessorConfigSettings(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 8316b928ecc..2ba5253a288 100644 --- a/processor/batchprocessor/factory.go +++ b/processor/batchprocessor/factory.go @@ -19,7 +19,6 @@ import ( "time" "go.opentelemetry.io/collector/component" - "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/consumer" ) @@ -41,18 +40,18 @@ func NewFactory() component.ProcessorFactory { component.WithLogsProcessor(createLogsProcessor, component.StabilityLevelStable)) } -func createDefaultConfig() config.Processor { +func createDefaultConfig() component.ProcessorConfig { return &Config{ - ProcessorSettings: config.NewProcessorSettings(config.NewComponentID(typeStr)), - SendBatchSize: defaultSendBatchSize, - Timeout: defaultTimeout, + ProcessorConfigSettings: component.NewProcessorConfigSettings(component.NewID(typeStr)), + SendBatchSize: defaultSendBatchSize, + Timeout: defaultTimeout, } } func createTracesProcessor( _ context.Context, set component.ProcessorCreateSettings, - cfg config.Processor, + cfg component.ProcessorConfig, nextConsumer consumer.Traces, ) (component.TracesProcessor, error) { level := set.MetricsLevel @@ -62,7 +61,7 @@ func createTracesProcessor( func createMetricsProcessor( _ context.Context, set component.ProcessorCreateSettings, - cfg config.Processor, + cfg component.ProcessorConfig, nextConsumer consumer.Metrics, ) (component.MetricsProcessor, error) { level := set.MetricsLevel @@ -72,7 +71,7 @@ func createMetricsProcessor( func createLogsProcessor( _ context.Context, set component.ProcessorCreateSettings, - cfg config.Processor, + cfg component.ProcessorConfig, nextConsumer consumer.Logs, ) (component.LogsProcessor, error) { level := set.MetricsLevel diff --git a/processor/batchprocessor/factory_test.go b/processor/batchprocessor/factory_test.go index 91e53f0f26e..b02504fe4f6 100644 --- a/processor/batchprocessor/factory_test.go +++ b/processor/batchprocessor/factory_test.go @@ -21,7 +21,6 @@ import ( "github.com/stretchr/testify/assert" "go.opentelemetry.io/collector/component/componenttest" - "go.opentelemetry.io/collector/config/configtest" ) func TestCreateDefaultConfig(t *testing.T) { @@ -29,7 +28,7 @@ func TestCreateDefaultConfig(t *testing.T) { cfg := factory.CreateDefaultConfig() assert.NotNil(t, cfg, "failed to create default config") - assert.NoError(t, configtest.CheckConfigStruct(cfg)) + assert.NoError(t, componenttest.CheckConfigStruct(cfg)) } func TestCreateProcessor(t *testing.T) { diff --git a/processor/memorylimiterprocessor/config.go b/processor/memorylimiterprocessor/config.go index 6f597161ac3..372dd951802 100644 --- a/processor/memorylimiterprocessor/config.go +++ b/processor/memorylimiterprocessor/config.go @@ -20,12 +20,12 @@ package memorylimiterprocessor // import "go.opentelemetry.io/collector/processo import ( "time" - "go.opentelemetry.io/collector/config" + "go.opentelemetry.io/collector/component" ) // Config defines configuration for memory memoryLimiter processor. type Config struct { - config.ProcessorSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct + component.ProcessorConfigSettings `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 @@ -49,7 +49,7 @@ type Config struct { MemorySpikePercentage uint32 `mapstructure:"spike_limit_percentage"` } -var _ config.Processor = (*Config)(nil) +var _ component.ProcessorConfig = (*Config)(nil) // Validate checks if the processor configuration is valid func (cfg *Config) Validate() error { diff --git a/processor/memorylimiterprocessor/config_test.go b/processor/memorylimiterprocessor/config_test.go index c1aa79f99a3..6d0c137caf1 100644 --- a/processor/memorylimiterprocessor/config_test.go +++ b/processor/memorylimiterprocessor/config_test.go @@ -22,7 +22,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "go.opentelemetry.io/collector/config" + "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/confmap" "go.opentelemetry.io/collector/confmap/confmaptest" ) @@ -30,7 +30,7 @@ import ( func TestUnmarshalDefaultConfig(t *testing.T) { factory := NewFactory() cfg := factory.CreateDefaultConfig() - assert.NoError(t, config.UnmarshalProcessor(confmap.New(), cfg)) + assert.NoError(t, component.UnmarshalProcessorConfig(confmap.New(), cfg)) assert.Equal(t, factory.CreateDefaultConfig(), cfg) } @@ -39,12 +39,12 @@ func TestUnmarshalConfig(t *testing.T) { require.NoError(t, err) factory := NewFactory() cfg := factory.CreateDefaultConfig() - assert.NoError(t, config.UnmarshalProcessor(cm, cfg)) + assert.NoError(t, component.UnmarshalProcessorConfig(cm, cfg)) assert.Equal(t, &Config{ - ProcessorSettings: config.NewProcessorSettings(config.NewComponentID(typeStr)), - CheckInterval: 5 * time.Second, - MemoryLimitMiB: 4000, - MemorySpikeLimitMiB: 500, + ProcessorConfigSettings: component.NewProcessorConfigSettings(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 31de08cd094..0d634f2163c 100644 --- a/processor/memorylimiterprocessor/factory.go +++ b/processor/memorylimiterprocessor/factory.go @@ -19,7 +19,6 @@ import ( "sync" "go.opentelemetry.io/collector/component" - "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/consumer" "go.opentelemetry.io/collector/processor/processorhelper" ) @@ -34,14 +33,14 @@ var processorCapabilities = consumer.Capabilities{MutatesData: false} type factory struct { // memoryLimiters stores memoryLimiter instances with unique configs that multiple processors can reuse. // This avoids running multiple memory checks (ie: GC) for every processor using the same processor config. - memoryLimiters map[config.Processor]*memoryLimiter + memoryLimiters map[component.ProcessorConfig]*memoryLimiter lock sync.Mutex } // NewFactory returns a new factory for the Memory Limiter processor. func NewFactory() component.ProcessorFactory { f := &factory{ - memoryLimiters: map[config.Processor]*memoryLimiter{}, + memoryLimiters: map[component.ProcessorConfig]*memoryLimiter{}, } return component.NewProcessorFactory( typeStr, @@ -53,16 +52,16 @@ func NewFactory() component.ProcessorFactory { // CreateDefaultConfig creates the default configuration for processor. Notice // that the default configuration is expected to fail for this processor. -func createDefaultConfig() config.Processor { +func createDefaultConfig() component.ProcessorConfig { return &Config{ - ProcessorSettings: config.NewProcessorSettings(config.NewComponentID(typeStr)), + ProcessorConfigSettings: component.NewProcessorConfigSettings(component.NewID(typeStr)), } } func (f *factory) createTracesProcessor( ctx context.Context, set component.ProcessorCreateSettings, - cfg config.Processor, + cfg component.ProcessorConfig, nextConsumer consumer.Traces, ) (component.TracesProcessor, error) { memLimiter, err := f.getMemoryLimiter(set, cfg) @@ -79,7 +78,7 @@ func (f *factory) createTracesProcessor( func (f *factory) createMetricsProcessor( ctx context.Context, set component.ProcessorCreateSettings, - cfg config.Processor, + cfg component.ProcessorConfig, nextConsumer consumer.Metrics, ) (component.MetricsProcessor, error) { memLimiter, err := f.getMemoryLimiter(set, cfg) @@ -96,7 +95,7 @@ func (f *factory) createMetricsProcessor( func (f *factory) createLogsProcessor( ctx context.Context, set component.ProcessorCreateSettings, - cfg config.Processor, + cfg component.ProcessorConfig, nextConsumer consumer.Logs, ) (component.LogsProcessor, error) { memLimiter, err := f.getMemoryLimiter(set, cfg) @@ -112,7 +111,7 @@ func (f *factory) createLogsProcessor( // getMemoryLimiter checks if we have a cached memoryLimiter with a specific config, // otherwise initialize and add one to the store. -func (f *factory) getMemoryLimiter(set component.ProcessorCreateSettings, cfg config.Processor) (*memoryLimiter, error) { +func (f *factory) getMemoryLimiter(set component.ProcessorCreateSettings, cfg component.ProcessorConfig) (*memoryLimiter, error) { f.lock.Lock() defer f.lock.Unlock() diff --git a/processor/memorylimiterprocessor/factory_test.go b/processor/memorylimiterprocessor/factory_test.go index 7016bc9a1c3..627a8ae226c 100644 --- a/processor/memorylimiterprocessor/factory_test.go +++ b/processor/memorylimiterprocessor/factory_test.go @@ -23,7 +23,6 @@ import ( "github.com/stretchr/testify/require" "go.opentelemetry.io/collector/component/componenttest" - "go.opentelemetry.io/collector/config/configtest" "go.opentelemetry.io/collector/consumer/consumertest" ) @@ -33,7 +32,7 @@ func TestCreateDefaultConfig(t *testing.T) { cfg := factory.CreateDefaultConfig() assert.NotNil(t, cfg, "failed to create default config") - assert.NoError(t, configtest.CheckConfigStruct(cfg)) + assert.NoError(t, componenttest.CheckConfigStruct(cfg)) } func TestCreateProcessor(t *testing.T) { diff --git a/processor/memorylimiterprocessor/memorylimiter_test.go b/processor/memorylimiterprocessor/memorylimiter_test.go index 181193c02f5..6103a934f67 100644 --- a/processor/memorylimiterprocessor/memorylimiter_test.go +++ b/processor/memorylimiterprocessor/memorylimiter_test.go @@ -25,8 +25,8 @@ import ( "go.uber.org/atomic" "go.uber.org/zap" + "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" @@ -123,7 +123,7 @@ func TestMetricsMemoryPressureResponse(t *testing.T) { context.Background(), componenttest.NewNopProcessorCreateSettings(), &Config{ - ProcessorSettings: config.NewProcessorSettings(config.NewComponentID(typeStr)), + ProcessorConfigSettings: component.NewProcessorConfigSettings(component.NewID(typeStr)), }, consumertest.NewNop(), ml.processMetrics, @@ -194,7 +194,7 @@ func TestTraceMemoryPressureResponse(t *testing.T) { context.Background(), componenttest.NewNopProcessorCreateSettings(), &Config{ - ProcessorSettings: config.NewProcessorSettings(config.NewComponentID(typeStr)), + ProcessorConfigSettings: component.NewProcessorConfigSettings(component.NewID(typeStr)), }, consumertest.NewNop(), ml.processTraces, @@ -265,7 +265,7 @@ func TestLogMemoryPressureResponse(t *testing.T) { context.Background(), componenttest.NewNopProcessorCreateSettings(), &Config{ - ProcessorSettings: config.NewProcessorSettings(config.NewComponentID(typeStr)), + ProcessorConfigSettings: component.NewProcessorConfigSettings(component.NewID(typeStr)), }, consumertest.NewNop(), ml.processLogs, @@ -453,7 +453,7 @@ func TestBallastSizeMiB(t *testing.T) { func newObsReport() *obsreport.Processor { set := obsreport.ProcessorSettings{ - ProcessorID: config.NewComponentID(typeStr), + ProcessorID: component.NewID(typeStr), ProcessorCreateSettings: componenttest.NewNopProcessorCreateSettings(), } set.ProcessorCreateSettings.MetricsLevel = configtelemetry.LevelNone diff --git a/processor/processorhelper/logs.go b/processor/processorhelper/logs.go index 0d4928e8942..67463784d24 100644 --- a/processor/processorhelper/logs.go +++ b/processor/processorhelper/logs.go @@ -21,7 +21,6 @@ import ( "go.opentelemetry.io/otel/trace" "go.opentelemetry.io/collector/component" - "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/consumer" "go.opentelemetry.io/collector/pdata/plog" ) @@ -40,7 +39,7 @@ type logProcessor struct { func NewLogsProcessor( _ context.Context, _ component.ProcessorCreateSettings, - cfg config.Processor, + cfg component.ProcessorConfig, nextConsumer consumer.Logs, logsFunc ProcessLogsFunc, options ...Option, diff --git a/processor/processorhelper/logs_test.go b/processor/processorhelper/logs_test.go index e68431e14f4..ee0f570109c 100644 --- a/processor/processorhelper/logs_test.go +++ b/processor/processorhelper/logs_test.go @@ -24,13 +24,12 @@ 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 = config.NewProcessorSettings(config.NewComponentID("test")) +var testLogsCfg = component.NewProcessorConfigSettings(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.go b/processor/processorhelper/metrics.go index 28f2d8a6569..24ec2456f6b 100644 --- a/processor/processorhelper/metrics.go +++ b/processor/processorhelper/metrics.go @@ -21,7 +21,6 @@ import ( "go.opentelemetry.io/otel/trace" "go.opentelemetry.io/collector/component" - "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/consumer" "go.opentelemetry.io/collector/pdata/pmetric" ) @@ -40,7 +39,7 @@ type metricsProcessor struct { func NewMetricsProcessor( _ context.Context, _ component.ProcessorCreateSettings, - cfg config.Processor, + cfg component.ProcessorConfig, nextConsumer consumer.Metrics, metricsFunc ProcessMetricsFunc, options ...Option, diff --git a/processor/processorhelper/metrics_test.go b/processor/processorhelper/metrics_test.go index 363ce273414..cfe3be03d4e 100644 --- a/processor/processorhelper/metrics_test.go +++ b/processor/processorhelper/metrics_test.go @@ -24,13 +24,12 @@ 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 = config.NewProcessorSettings(config.NewComponentID("test")) +var testMetricsCfg = component.NewProcessorConfigSettings(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/processor.go b/processor/processorhelper/processor.go index 1797692bdc6..281db20c3a6 100644 --- a/processor/processorhelper/processor.go +++ b/processor/processorhelper/processor.go @@ -21,7 +21,6 @@ import ( "go.opentelemetry.io/otel/trace" "go.opentelemetry.io/collector/component" - "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/consumer" "go.opentelemetry.io/collector/internal/obsreportconfig/obsmetrics" ) @@ -78,6 +77,6 @@ func fromOptions(options []Option) *baseSettings { return opts } -func spanAttributes(id config.ComponentID) trace.EventOption { +func spanAttributes(id component.ID) trace.EventOption { return trace.WithAttributes(attribute.String(obsmetrics.ProcessorKey, id.String())) } diff --git a/processor/processorhelper/traces.go b/processor/processorhelper/traces.go index 30c0bd4f027..8bfbb8864c3 100644 --- a/processor/processorhelper/traces.go +++ b/processor/processorhelper/traces.go @@ -21,7 +21,6 @@ import ( "go.opentelemetry.io/otel/trace" "go.opentelemetry.io/collector/component" - "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/consumer" "go.opentelemetry.io/collector/pdata/ptrace" ) @@ -40,7 +39,7 @@ type tracesProcessor struct { func NewTracesProcessor( _ context.Context, _ component.ProcessorCreateSettings, - cfg config.Processor, + cfg component.ProcessorConfig, nextConsumer consumer.Traces, tracesFunc ProcessTracesFunc, options ...Option, diff --git a/processor/processorhelper/traces_test.go b/processor/processorhelper/traces_test.go index df5808c13a1..8aaf81adc20 100644 --- a/processor/processorhelper/traces_test.go +++ b/processor/processorhelper/traces_test.go @@ -24,13 +24,12 @@ 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 = config.NewProcessorSettings(config.NewComponentID("test")) +var testTracesCfg = component.NewProcessorConfigSettings(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 3953bc98584..911d61e4a78 100644 --- a/receiver/otlpreceiver/config.go +++ b/receiver/otlpreceiver/config.go @@ -17,7 +17,7 @@ package otlpreceiver // import "go.opentelemetry.io/collector/receiver/otlprecei import ( "errors" - "go.opentelemetry.io/collector/config" + "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/config/configgrpc" "go.opentelemetry.io/collector/config/confighttp" "go.opentelemetry.io/collector/confmap" @@ -38,12 +38,12 @@ type Protocols struct { // Config defines configuration for OTLP receiver. type Config struct { - config.ReceiverSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct + component.ReceiverConfigSettings `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"` } -var _ config.Receiver = (*Config)(nil) +var _ component.ReceiverConfig = (*Config)(nil) var _ confmap.Unmarshaler = (*Config)(nil) // Validate checks the receiver configuration is valid diff --git a/receiver/otlpreceiver/config_test.go b/receiver/otlpreceiver/config_test.go index 57817925fd1..e72518faf08 100644 --- a/receiver/otlpreceiver/config_test.go +++ b/receiver/otlpreceiver/config_test.go @@ -22,7 +22,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "go.opentelemetry.io/collector/config" + "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/config/configgrpc" "go.opentelemetry.io/collector/config/confighttp" "go.opentelemetry.io/collector/config/confignet" @@ -36,7 +36,7 @@ func TestUnmarshalDefaultConfig(t *testing.T) { require.NoError(t, err) factory := NewFactory() cfg := factory.CreateDefaultConfig() - assert.NoError(t, config.UnmarshalReceiver(cm, cfg)) + assert.NoError(t, component.UnmarshalReceiverConfig(cm, cfg)) assert.Equal(t, factory.CreateDefaultConfig(), cfg) } @@ -45,7 +45,7 @@ func TestUnmarshalConfigOnlyGRPC(t *testing.T) { require.NoError(t, err) factory := NewFactory() cfg := factory.CreateDefaultConfig() - assert.NoError(t, config.UnmarshalReceiver(cm, cfg)) + assert.NoError(t, component.UnmarshalReceiverConfig(cm, cfg)) defaultOnlyGRPC := factory.CreateDefaultConfig().(*Config) defaultOnlyGRPC.HTTP = nil @@ -57,7 +57,7 @@ func TestUnmarshalConfigOnlyHTTP(t *testing.T) { require.NoError(t, err) factory := NewFactory() cfg := factory.CreateDefaultConfig() - assert.NoError(t, config.UnmarshalReceiver(cm, cfg)) + assert.NoError(t, component.UnmarshalReceiverConfig(cm, cfg)) defaultOnlyHTTP := factory.CreateDefaultConfig().(*Config) defaultOnlyHTTP.GRPC = nil @@ -69,7 +69,7 @@ func TestUnmarshalConfigOnlyHTTPNull(t *testing.T) { require.NoError(t, err) factory := NewFactory() cfg := factory.CreateDefaultConfig() - assert.NoError(t, config.UnmarshalReceiver(cm, cfg)) + assert.NoError(t, component.UnmarshalReceiverConfig(cm, cfg)) defaultOnlyHTTP := factory.CreateDefaultConfig().(*Config) defaultOnlyHTTP.GRPC = nil @@ -81,7 +81,7 @@ func TestUnmarshalConfigOnlyHTTPEmptyMap(t *testing.T) { require.NoError(t, err) factory := NewFactory() cfg := factory.CreateDefaultConfig() - assert.NoError(t, config.UnmarshalReceiver(cm, cfg)) + assert.NoError(t, component.UnmarshalReceiverConfig(cm, cfg)) defaultOnlyHTTP := factory.CreateDefaultConfig().(*Config) defaultOnlyHTTP.GRPC = nil @@ -93,10 +93,10 @@ func TestUnmarshalConfig(t *testing.T) { require.NoError(t, err) factory := NewFactory() cfg := factory.CreateDefaultConfig() - assert.NoError(t, config.UnmarshalReceiver(cm, cfg)) + assert.NoError(t, component.UnmarshalReceiverConfig(cm, cfg)) assert.Equal(t, &Config{ - ReceiverSettings: config.NewReceiverSettings(config.NewComponentID(typeStr)), + ReceiverConfigSettings: component.NewReceiverConfigSettings(component.NewID(typeStr)), Protocols: Protocols{ GRPC: &configgrpc.GRPCServerSettings{ NetAddr: confignet.NetAddr{ @@ -150,10 +150,10 @@ func TestUnmarshalConfigUnix(t *testing.T) { require.NoError(t, err) factory := NewFactory() cfg := factory.CreateDefaultConfig() - assert.NoError(t, config.UnmarshalReceiver(cm, cfg)) + assert.NoError(t, component.UnmarshalReceiverConfig(cm, cfg)) assert.Equal(t, &Config{ - ReceiverSettings: config.NewReceiverSettings(config.NewComponentID(typeStr)), + ReceiverConfigSettings: component.NewReceiverConfigSettings(component.NewID(typeStr)), Protocols: Protocols{ GRPC: &configgrpc.GRPCServerSettings{ NetAddr: confignet.NetAddr{ @@ -175,7 +175,7 @@ func TestUnmarshalConfigTypoDefaultProtocol(t *testing.T) { require.NoError(t, err) factory := NewFactory() cfg := factory.CreateDefaultConfig() - assert.EqualError(t, config.UnmarshalReceiver(cm, cfg), "1 error(s) decoding:\n\n* 'protocols' has invalid keys: htttp") + assert.EqualError(t, component.UnmarshalReceiverConfig(cm, cfg), "1 error(s) decoding:\n\n* 'protocols' has invalid keys: htttp") } func TestUnmarshalConfigInvalidProtocol(t *testing.T) { @@ -183,7 +183,7 @@ func TestUnmarshalConfigInvalidProtocol(t *testing.T) { require.NoError(t, err) factory := NewFactory() cfg := factory.CreateDefaultConfig() - assert.EqualError(t, config.UnmarshalReceiver(cm, cfg), "1 error(s) decoding:\n\n* 'protocols' has invalid keys: thrift") + assert.EqualError(t, component.UnmarshalReceiverConfig(cm, cfg), "1 error(s) decoding:\n\n* 'protocols' has invalid keys: thrift") } func TestUnmarshalConfigEmptyProtocols(t *testing.T) { @@ -191,13 +191,13 @@ func TestUnmarshalConfigEmptyProtocols(t *testing.T) { require.NoError(t, err) factory := NewFactory() cfg := factory.CreateDefaultConfig() - assert.NoError(t, config.UnmarshalReceiver(cm, cfg)) + assert.NoError(t, component.UnmarshalReceiverConfig(cm, cfg)) assert.EqualError(t, cfg.Validate(), "must specify at least one protocol when using the OTLP receiver") } func TestUnmarshalConfigEmpty(t *testing.T) { factory := NewFactory() cfg := factory.CreateDefaultConfig() - assert.NoError(t, config.UnmarshalReceiver(confmap.New(), cfg)) + assert.NoError(t, component.UnmarshalReceiverConfig(confmap.New(), cfg)) assert.EqualError(t, cfg.Validate(), "must specify at least one protocol when using the OTLP receiver") } diff --git a/receiver/otlpreceiver/factory.go b/receiver/otlpreceiver/factory.go index 171034b4f05..9d78608e515 100644 --- a/receiver/otlpreceiver/factory.go +++ b/receiver/otlpreceiver/factory.go @@ -18,7 +18,6 @@ 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" @@ -44,9 +43,9 @@ func NewFactory() component.ReceiverFactory { } // createDefaultConfig creates the default configuration for receiver. -func createDefaultConfig() config.Receiver { +func createDefaultConfig() component.ReceiverConfig { return &Config{ - ReceiverSettings: config.NewReceiverSettings(config.NewComponentID(typeStr)), + ReceiverConfigSettings: component.NewReceiverConfigSettings(component.NewID(typeStr)), Protocols: Protocols{ GRPC: &configgrpc.GRPCServerSettings{ NetAddr: confignet.NetAddr{ @@ -67,7 +66,7 @@ func createDefaultConfig() config.Receiver { func createTracesReceiver( _ context.Context, set component.ReceiverCreateSettings, - cfg config.Receiver, + cfg component.ReceiverConfig, nextConsumer consumer.Traces, ) (component.TracesReceiver, error) { r := receivers.GetOrAdd(cfg, func() component.Component { @@ -84,7 +83,7 @@ func createTracesReceiver( func createMetricsReceiver( _ context.Context, set component.ReceiverCreateSettings, - cfg config.Receiver, + cfg component.ReceiverConfig, consumer consumer.Metrics, ) (component.MetricsReceiver, error) { r := receivers.GetOrAdd(cfg, func() component.Component { @@ -101,7 +100,7 @@ func createMetricsReceiver( func createLogReceiver( _ context.Context, set component.ReceiverCreateSettings, - cfg config.Receiver, + cfg component.ReceiverConfig, consumer consumer.Logs, ) (component.LogsReceiver, error) { r := receivers.GetOrAdd(cfg, func() component.Component { diff --git a/receiver/otlpreceiver/factory_test.go b/receiver/otlpreceiver/factory_test.go index 3b28ce12b42..142a12d3a61 100644 --- a/receiver/otlpreceiver/factory_test.go +++ b/receiver/otlpreceiver/factory_test.go @@ -21,12 +21,11 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "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" - "go.opentelemetry.io/collector/config/configtest" "go.opentelemetry.io/collector/consumer" "go.opentelemetry.io/collector/consumer/consumertest" "go.opentelemetry.io/collector/internal/testutil" @@ -36,7 +35,7 @@ func TestCreateDefaultConfig(t *testing.T) { factory := NewFactory() cfg := factory.CreateDefaultConfig() assert.NotNil(t, cfg, "failed to create default config") - assert.NoError(t, configtest.CheckConfigStruct(cfg)) + assert.NoError(t, componenttest.CheckConfigStruct(cfg)) } func TestCreateReceiver(t *testing.T) { @@ -75,7 +74,7 @@ func TestCreateTracesReceiver(t *testing.T) { { name: "default", cfg: &Config{ - ReceiverSettings: config.NewReceiverSettings(config.NewComponentID(typeStr)), + ReceiverConfigSettings: component.NewReceiverConfigSettings(component.NewID(typeStr)), Protocols: Protocols{ GRPC: defaultGRPCSettings, HTTP: defaultHTTPSettings, @@ -85,7 +84,7 @@ func TestCreateTracesReceiver(t *testing.T) { { name: "invalid_grpc_port", cfg: &Config{ - ReceiverSettings: config.NewReceiverSettings(config.NewComponentID(typeStr)), + ReceiverConfigSettings: component.NewReceiverConfigSettings(component.NewID(typeStr)), Protocols: Protocols{ GRPC: &configgrpc.GRPCServerSettings{ NetAddr: confignet.NetAddr{ @@ -101,7 +100,7 @@ func TestCreateTracesReceiver(t *testing.T) { { name: "invalid_http_port", cfg: &Config{ - ReceiverSettings: config.NewReceiverSettings(config.NewComponentID(typeStr)), + ReceiverConfigSettings: component.NewReceiverConfigSettings(component.NewID(typeStr)), Protocols: Protocols{ GRPC: defaultGRPCSettings, HTTP: &confighttp.HTTPServerSettings{ @@ -151,7 +150,7 @@ func TestCreateMetricReceiver(t *testing.T) { { name: "default", cfg: &Config{ - ReceiverSettings: config.NewReceiverSettings(config.NewComponentID(typeStr)), + ReceiverConfigSettings: component.NewReceiverConfigSettings(component.NewID(typeStr)), Protocols: Protocols{ GRPC: defaultGRPCSettings, HTTP: defaultHTTPSettings, @@ -161,7 +160,7 @@ func TestCreateMetricReceiver(t *testing.T) { { name: "invalid_grpc_address", cfg: &Config{ - ReceiverSettings: config.NewReceiverSettings(config.NewComponentID(typeStr)), + ReceiverConfigSettings: component.NewReceiverConfigSettings(component.NewID(typeStr)), Protocols: Protocols{ GRPC: &configgrpc.GRPCServerSettings{ NetAddr: confignet.NetAddr{ @@ -177,7 +176,7 @@ func TestCreateMetricReceiver(t *testing.T) { { name: "invalid_http_address", cfg: &Config{ - ReceiverSettings: config.NewReceiverSettings(config.NewComponentID(typeStr)), + ReceiverConfigSettings: component.NewReceiverConfigSettings(component.NewID(typeStr)), Protocols: Protocols{ GRPC: defaultGRPCSettings, HTTP: &confighttp.HTTPServerSettings{ @@ -228,7 +227,7 @@ func TestCreateLogReceiver(t *testing.T) { { name: "default", cfg: &Config{ - ReceiverSettings: config.NewReceiverSettings(config.NewComponentID(typeStr)), + ReceiverConfigSettings: component.NewReceiverConfigSettings(component.NewID(typeStr)), Protocols: Protocols{ GRPC: defaultGRPCSettings, HTTP: defaultHTTPSettings, @@ -239,7 +238,7 @@ func TestCreateLogReceiver(t *testing.T) { { name: "invalid_grpc_address", cfg: &Config{ - ReceiverSettings: config.NewReceiverSettings(config.NewComponentID(typeStr)), + ReceiverConfigSettings: component.NewReceiverConfigSettings(component.NewID(typeStr)), Protocols: Protocols{ GRPC: &configgrpc.GRPCServerSettings{ NetAddr: confignet.NetAddr{ @@ -256,7 +255,7 @@ func TestCreateLogReceiver(t *testing.T) { { name: "invalid_http_address", cfg: &Config{ - ReceiverSettings: config.NewReceiverSettings(config.NewComponentID(typeStr)), + ReceiverConfigSettings: component.NewReceiverConfigSettings(component.NewID(typeStr)), Protocols: Protocols{ GRPC: defaultGRPCSettings, HTTP: &confighttp.HTTPServerSettings{ @@ -270,7 +269,7 @@ func TestCreateLogReceiver(t *testing.T) { { name: "no_next_consumer", cfg: &Config{ - ReceiverSettings: config.NewReceiverSettings(config.NewComponentID(typeStr)), + ReceiverConfigSettings: component.NewReceiverConfigSettings(component.NewID(typeStr)), Protocols: Protocols{ GRPC: defaultGRPCSettings, HTTP: &confighttp.HTTPServerSettings{ @@ -284,8 +283,8 @@ func TestCreateLogReceiver(t *testing.T) { { name: "no_http_or_grcp_config", cfg: &Config{ - ReceiverSettings: config.NewReceiverSettings(config.NewComponentID(typeStr)), - Protocols: Protocols{}, + ReceiverConfigSettings: component.NewReceiverConfigSettings(component.NewID(typeStr)), + Protocols: Protocols{}, }, wantErr: false, sink: new(consumertest.LogsSink), diff --git a/receiver/otlpreceiver/internal/logs/otlp.go b/receiver/otlpreceiver/internal/logs/otlp.go index fa02b048f5f..f1c66192c41 100644 --- a/receiver/otlpreceiver/internal/logs/otlp.go +++ b/receiver/otlpreceiver/internal/logs/otlp.go @@ -18,7 +18,6 @@ import ( "context" "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/plog/plogotlp" @@ -36,7 +35,7 @@ type Receiver struct { } // New creates a new Receiver reference. -func New(id config.ComponentID, nextConsumer consumer.Logs, set component.ReceiverCreateSettings) *Receiver { +func New(id component.ID, nextConsumer consumer.Logs, set component.ReceiverCreateSettings) *Receiver { return &Receiver{ nextConsumer: nextConsumer, obsrecv: obsreport.NewReceiver(obsreport.ReceiverSettings{ diff --git a/receiver/otlpreceiver/internal/logs/otlp_test.go b/receiver/otlpreceiver/internal/logs/otlp_test.go index 592dd36fdd2..9733743dae6 100644 --- a/receiver/otlpreceiver/internal/logs/otlp_test.go +++ b/receiver/otlpreceiver/internal/logs/otlp_test.go @@ -25,8 +25,8 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/credentials/insecure" + "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/internal/testdata" @@ -86,7 +86,7 @@ func otlpReceiverOnGRPCServer(t *testing.T, lc consumer.Logs) net.Addr { require.NoError(t, ln.Close()) }) - r := New(config.NewComponentIDWithName("otlp", "log"), lc, componenttest.NewNopReceiverCreateSettings()) + r := New(component.NewIDWithName("otlp", "log"), lc, componenttest.NewNopReceiverCreateSettings()) // Now run it as a gRPC server srv := grpc.NewServer() plogotlp.RegisterGRPCServer(srv, r) diff --git a/receiver/otlpreceiver/internal/metrics/otlp.go b/receiver/otlpreceiver/internal/metrics/otlp.go index 9e5abc2578c..12942fe5e04 100644 --- a/receiver/otlpreceiver/internal/metrics/otlp.go +++ b/receiver/otlpreceiver/internal/metrics/otlp.go @@ -18,7 +18,6 @@ import ( "context" "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/pmetricotlp" @@ -36,7 +35,7 @@ type Receiver struct { } // New creates a new Receiver reference. -func New(id config.ComponentID, nextConsumer consumer.Metrics, set component.ReceiverCreateSettings) *Receiver { +func New(id component.ID, nextConsumer consumer.Metrics, set component.ReceiverCreateSettings) *Receiver { return &Receiver{ nextConsumer: nextConsumer, obsrecv: obsreport.NewReceiver(obsreport.ReceiverSettings{ diff --git a/receiver/otlpreceiver/internal/metrics/otlp_test.go b/receiver/otlpreceiver/internal/metrics/otlp_test.go index 0539c4bc339..163e9dba41e 100644 --- a/receiver/otlpreceiver/internal/metrics/otlp_test.go +++ b/receiver/otlpreceiver/internal/metrics/otlp_test.go @@ -25,8 +25,8 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/credentials/insecure" + "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/internal/testdata" @@ -87,7 +87,7 @@ func otlpReceiverOnGRPCServer(t *testing.T, mc consumer.Metrics) net.Addr { require.NoError(t, ln.Close()) }) - r := New(config.NewComponentIDWithName("otlp", "metrics"), mc, componenttest.NewNopReceiverCreateSettings()) + r := New(component.NewIDWithName("otlp", "metrics"), mc, componenttest.NewNopReceiverCreateSettings()) // Now run it as a gRPC server srv := grpc.NewServer() pmetricotlp.RegisterGRPCServer(srv, r) diff --git a/receiver/otlpreceiver/internal/trace/otlp.go b/receiver/otlpreceiver/internal/trace/otlp.go index d35c5d19d2a..5614e580d44 100644 --- a/receiver/otlpreceiver/internal/trace/otlp.go +++ b/receiver/otlpreceiver/internal/trace/otlp.go @@ -18,7 +18,6 @@ import ( "context" "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/ptrace/ptraceotlp" @@ -36,7 +35,7 @@ type Receiver struct { } // New creates a new Receiver reference. -func New(id config.ComponentID, nextConsumer consumer.Traces, set component.ReceiverCreateSettings) *Receiver { +func New(id component.ID, nextConsumer consumer.Traces, set component.ReceiverCreateSettings) *Receiver { return &Receiver{ nextConsumer: nextConsumer, obsrecv: obsreport.NewReceiver(obsreport.ReceiverSettings{ diff --git a/receiver/otlpreceiver/internal/trace/otlp_test.go b/receiver/otlpreceiver/internal/trace/otlp_test.go index cb26a1eca7f..b53809459f7 100644 --- a/receiver/otlpreceiver/internal/trace/otlp_test.go +++ b/receiver/otlpreceiver/internal/trace/otlp_test.go @@ -25,8 +25,8 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/credentials/insecure" + "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/internal/testdata" @@ -84,7 +84,7 @@ func otlpReceiverOnGRPCServer(t *testing.T, tc consumer.Traces) net.Addr { require.NoError(t, ln.Close()) }) - r := New(config.NewComponentIDWithName("otlp", "trace"), tc, componenttest.NewNopReceiverCreateSettings()) + r := New(component.NewIDWithName("otlp", "trace"), tc, componenttest.NewNopReceiverCreateSettings()) // Now run it as a gRPC server srv := grpc.NewServer() ptraceotlp.RegisterGRPCServer(srv, r) diff --git a/receiver/otlpreceiver/otlp_test.go b/receiver/otlpreceiver/otlp_test.go index 58fee0fffe7..687a1ea8f73 100644 --- a/receiver/otlpreceiver/otlp_test.go +++ b/receiver/otlpreceiver/otlp_test.go @@ -39,7 +39,6 @@ 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" @@ -184,8 +183,8 @@ func TestJsonHttp(t *testing.T) { func TestHandleInvalidRequests(t *testing.T) { endpoint := testutil.GetAvailableLocalAddress(t) cfg := &Config{ - ReceiverSettings: config.NewReceiverSettings(config.NewComponentID(typeStr)), - Protocols: Protocols{HTTP: &confighttp.HTTPServerSettings{Endpoint: endpoint}}, + ReceiverConfigSettings: component.NewReceiverConfigSettings(component.NewID(typeStr)), + Protocols: Protocols{HTTP: &confighttp.HTTPServerSettings{Endpoint: endpoint}}, } // Traces @@ -700,7 +699,7 @@ func TestOTLPReceiverTrace_HandleNextConsumerResponse(t *testing.T) { require.Equal(t, test.expectedReceivedBatches, len(sink.AllTraces())) - require.NoError(t, obsreporttest.CheckReceiverTraces(tt, config.NewComponentIDWithName(typeStr, exporter.receiverTag), "grpc", int64(test.expectedReceivedBatches), int64(test.expectedIngestionBlockedRPCs))) + require.NoError(t, obsreporttest.CheckReceiverTraces(tt, component.NewIDWithName(typeStr, exporter.receiverTag), "grpc", int64(test.expectedReceivedBatches), int64(test.expectedIngestionBlockedRPCs))) }) } } @@ -708,7 +707,7 @@ func TestOTLPReceiverTrace_HandleNextConsumerResponse(t *testing.T) { func TestGRPCInvalidTLSCredentials(t *testing.T) { cfg := &Config{ - ReceiverSettings: config.NewReceiverSettings(config.NewComponentID(typeStr)), + ReceiverConfigSettings: component.NewReceiverConfigSettings(component.NewID(typeStr)), Protocols: Protocols{ GRPC: &configgrpc.GRPCServerSettings{ NetAddr: confignet.NetAddr{ @@ -779,7 +778,7 @@ func TestGRPCMaxRecvSize(t *testing.T) { func TestHTTPInvalidTLSCredentials(t *testing.T) { cfg := &Config{ - ReceiverSettings: config.NewReceiverSettings(config.NewComponentID(typeStr)), + ReceiverConfigSettings: component.NewReceiverConfigSettings(component.NewID(typeStr)), Protocols: Protocols{ HTTP: &confighttp.HTTPServerSettings{ Endpoint: testutil.GetAvailableLocalAddress(t), @@ -808,7 +807,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{ - ReceiverSettings: config.NewReceiverSettings(config.NewComponentID(typeStr)), + ReceiverConfigSettings: component.NewReceiverConfigSettings(component.NewID(typeStr)), Protocols: Protocols{ HTTP: &confighttp.HTTPServerSettings{ Endpoint: endpoint, diff --git a/receiver/scraperhelper/scraper.go b/receiver/scraperhelper/scraper.go index 8b16e63514b..0923386e2cb 100644 --- a/receiver/scraperhelper/scraper.go +++ b/receiver/scraperhelper/scraper.go @@ -19,7 +19,6 @@ import ( "errors" "go.opentelemetry.io/collector/component" - "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/pdata/pmetric" ) @@ -37,7 +36,7 @@ type Scraper interface { component.Component // ID returns the scraper id. - ID() config.ComponentID + ID() component.ID Scrape(context.Context) (pmetric.Metrics, error) } @@ -64,10 +63,10 @@ type baseScraper struct { component.StartFunc component.ShutdownFunc ScrapeFunc - id config.ComponentID + id component.ID } -func (b *baseScraper) ID() config.ComponentID { +func (b *baseScraper) ID() component.ID { return b.id } @@ -79,7 +78,7 @@ func NewScraper(name string, scrape ScrapeFunc, options ...ScraperOption) (Scrap } bs := &baseScraper{ ScrapeFunc: scrape, - id: config.NewComponentID(config.Type(name)), + id: component.NewID(component.Type(name)), } for _, op := range options { op(bs) diff --git a/receiver/scraperhelper/scrapercontroller.go b/receiver/scraperhelper/scrapercontroller.go index c2c63a329df..fe1d89e9b77 100644 --- a/receiver/scraperhelper/scrapercontroller.go +++ b/receiver/scraperhelper/scrapercontroller.go @@ -23,7 +23,6 @@ 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" @@ -32,18 +31,18 @@ import ( // ScraperControllerSettings defines common settings for a scraper controller // configuration. Scraper controller receivers can embed this struct, instead -// of config.ReceiverSettings, and extend it with more fields if needed. +// of component.ReceiverConfigSettings, and extend it with more fields if needed. type ScraperControllerSettings struct { - config.ReceiverSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct - CollectionInterval time.Duration `mapstructure:"collection_interval"` + component.ReceiverConfigSettings `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 config.Type) ScraperControllerSettings { +func NewDefaultScraperControllerSettings(cfgType component.Type) ScraperControllerSettings { return ScraperControllerSettings{ - ReceiverSettings: config.NewReceiverSettings(config.NewComponentID(cfgType)), - CollectionInterval: time.Minute, + ReceiverConfigSettings: component.NewReceiverConfigSettings(component.NewID(cfgType)), + CollectionInterval: time.Minute, } } @@ -71,7 +70,7 @@ func WithTickerChannel(tickerCh <-chan time.Time) ScraperControllerOption { } type controller struct { - id config.ComponentID + id component.ID logger *zap.Logger collectionInterval time.Duration nextConsumer consumer.Metrics diff --git a/receiver/scraperhelper/scrapercontroller_test.go b/receiver/scraperhelper/scrapercontroller_test.go index ff9903d2d45..60a2c4b239c 100644 --- a/receiver/scraperhelper/scrapercontroller_test.go +++ b/receiver/scraperhelper/scrapercontroller_test.go @@ -28,7 +28,6 @@ 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/obsreport/obsreporttest" @@ -288,7 +287,7 @@ func assertReceiverViews(t *testing.T, tt obsreporttest.TestTelemetry, sink *con for _, md := range sink.AllMetrics() { dataPointCount += md.DataPointCount() } - require.NoError(t, obsreporttest.CheckReceiverMetrics(tt, config.NewComponentID("receiver"), "", int64(dataPointCount), 0)) + require.NoError(t, obsreporttest.CheckReceiverMetrics(tt, component.NewID("receiver"), "", int64(dataPointCount), 0)) } func assertScraperSpan(t *testing.T, expectedErr error, spans []sdktrace.ReadOnlySpan) { @@ -324,7 +323,7 @@ func assertScraperViews(t *testing.T, tt obsreporttest.TestTelemetry, expectedEr } } - require.NoError(t, obsreporttest.CheckScraperMetrics(tt, config.NewComponentID("receiver"), config.NewComponentID("scraper"), expectedScraped, expectedErrored)) + require.NoError(t, obsreporttest.CheckScraperMetrics(tt, component.NewID("receiver"), component.NewID("scraper"), expectedScraped, expectedErrored)) } func TestSingleScrapePerTick(t *testing.T) { diff --git a/service/config.go b/service/config.go index a96c415864b..8dda7138b6b 100644 --- a/service/config.go +++ b/service/config.go @@ -18,6 +18,7 @@ import ( "errors" "fmt" + "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/service/telemetry" ) @@ -31,16 +32,16 @@ var ( // Config defines the configuration for the various elements of collector or agent. type Config struct { // Receivers is a map of ComponentID to Receivers. - Receivers map[config.ComponentID]config.Receiver + Receivers map[component.ID]component.ReceiverConfig // Exporters is a map of ComponentID to Exporters. - Exporters map[config.ComponentID]config.Exporter + Exporters map[component.ID]component.ExporterConfig // Processors is a map of ComponentID to Processors. - Processors map[config.ComponentID]config.Processor + Processors map[component.ID]component.ProcessorConfig // Extensions is a map of ComponentID to extensions. - Extensions map[config.ComponentID]config.Extension + Extensions map[component.ID]component.ExtensionConfig Service ConfigService } @@ -111,7 +112,7 @@ func (cfg *Config) validateService() error { // Check that all pipelines have at least one receiver and one exporter, and they reference // only configured components. for pipelineID, pipeline := range cfg.Service.Pipelines { - if pipelineID.Type() != config.TracesDataType && pipelineID.Type() != config.MetricsDataType && pipelineID.Type() != config.LogsDataType { + if pipelineID.Type() != component.TracesDataType && pipelineID.Type() != component.MetricsDataType && pipelineID.Type() != component.LogsDataType { return fmt.Errorf("unknown pipeline datatype %q for %v", pipelineID.Type(), pipelineID) } @@ -158,10 +159,10 @@ type ConfigService struct { Telemetry telemetry.Config `mapstructure:"telemetry"` // Extensions are the ordered list of extensions configured for the service. - Extensions []config.ComponentID `mapstructure:"extensions"` + Extensions []component.ID `mapstructure:"extensions"` // Pipelines are the set of data pipelines configured for the service. - Pipelines map[config.ComponentID]*ConfigServicePipeline `mapstructure:"pipelines"` + Pipelines map[component.ID]*ConfigServicePipeline `mapstructure:"pipelines"` } type ConfigServicePipeline = config.Pipeline diff --git a/service/config_provider_test.go b/service/config_provider_test.go index 1adce1cc358..b852453ccb2 100644 --- a/service/config_provider_test.go +++ b/service/config_provider_test.go @@ -24,8 +24,8 @@ import ( "github.com/stretchr/testify/require" "go.uber.org/zap/zapcore" + "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/confmap" "go.opentelemetry.io/collector/confmap/provider/fileprovider" @@ -34,27 +34,27 @@ import ( ) var configNop = &Config{ - Receivers: map[config.ComponentID]config.Receiver{config.NewComponentID("nop"): componenttest.NewNopReceiverFactory().CreateDefaultConfig()}, - Processors: map[config.ComponentID]config.Processor{config.NewComponentID("nop"): componenttest.NewNopProcessorFactory().CreateDefaultConfig()}, - Exporters: map[config.ComponentID]config.Exporter{config.NewComponentID("nop"): componenttest.NewNopExporterFactory().CreateDefaultConfig()}, - Extensions: map[config.ComponentID]config.Extension{config.NewComponentID("nop"): componenttest.NewNopExtensionFactory().CreateDefaultConfig()}, + Receivers: map[component.ID]component.ReceiverConfig{component.NewID("nop"): componenttest.NewNopReceiverFactory().CreateDefaultConfig()}, + Processors: map[component.ID]component.ProcessorConfig{component.NewID("nop"): componenttest.NewNopProcessorFactory().CreateDefaultConfig()}, + Exporters: map[component.ID]component.ExporterConfig{component.NewID("nop"): componenttest.NewNopExporterFactory().CreateDefaultConfig()}, + Extensions: map[component.ID]component.ExtensionConfig{component.NewID("nop"): componenttest.NewNopExtensionFactory().CreateDefaultConfig()}, Service: ConfigService{ - Extensions: []config.ComponentID{config.NewComponentID("nop")}, - Pipelines: map[config.ComponentID]*ConfigServicePipeline{ - config.NewComponentID("traces"): { - Receivers: []config.ComponentID{config.NewComponentID("nop")}, - Processors: []config.ComponentID{config.NewComponentID("nop")}, - Exporters: []config.ComponentID{config.NewComponentID("nop")}, + Extensions: []component.ID{component.NewID("nop")}, + Pipelines: map[component.ID]*ConfigServicePipeline{ + component.NewID("traces"): { + Receivers: []component.ID{component.NewID("nop")}, + Processors: []component.ID{component.NewID("nop")}, + Exporters: []component.ID{component.NewID("nop")}, }, - config.NewComponentID("metrics"): { - Receivers: []config.ComponentID{config.NewComponentID("nop")}, - Processors: []config.ComponentID{config.NewComponentID("nop")}, - Exporters: []config.ComponentID{config.NewComponentID("nop")}, + component.NewID("metrics"): { + Receivers: []component.ID{component.NewID("nop")}, + Processors: []component.ID{component.NewID("nop")}, + Exporters: []component.ID{component.NewID("nop")}, }, - config.NewComponentID("logs"): { - Receivers: []config.ComponentID{config.NewComponentID("nop")}, - Processors: []config.ComponentID{config.NewComponentID("nop")}, - Exporters: []config.ComponentID{config.NewComponentID("nop")}, + component.NewID("logs"): { + Receivers: []component.ID{component.NewID("nop")}, + Processors: []component.ID{component.NewID("nop")}, + Exporters: []component.ID{component.NewID("nop")}, }, }, Telemetry: telemetry.Config{ diff --git a/service/config_test.go b/service/config_test.go index 367110f4e04..1463c5771ad 100644 --- a/service/config_test.go +++ b/service/config_test.go @@ -22,7 +22,7 @@ import ( "github.com/stretchr/testify/assert" "go.uber.org/zap/zapcore" - "go.opentelemetry.io/collector/config" + "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/config/configtelemetry" "go.opentelemetry.io/collector/service/telemetry" ) @@ -35,7 +35,7 @@ var ( ) type nopRecvConfig struct { - config.ReceiverSettings + component.ReceiverConfigSettings validateErr error } @@ -44,7 +44,7 @@ func (nc *nopRecvConfig) Validate() error { } type nopExpConfig struct { - config.ExporterSettings + component.ExporterConfigSettings validateErr error } @@ -53,7 +53,7 @@ func (nc *nopExpConfig) Validate() error { } type nopProcConfig struct { - config.ProcessorSettings + component.ProcessorConfigSettings validateErr error } @@ -62,7 +62,7 @@ func (nc *nopProcConfig) Validate() error { } type nopExtConfig struct { - config.ExtensionSettings + component.ExtensionConfigSettings validateErr error } @@ -112,7 +112,7 @@ func TestConfigValidate(t *testing.T) { name: "invalid-extension-reference", cfgFn: func() *Config { cfg := generateConfig() - cfg.Service.Extensions = append(cfg.Service.Extensions, config.NewComponentIDWithName("nop", "2")) + cfg.Service.Extensions = append(cfg.Service.Extensions, component.NewIDWithName("nop", "2")) return cfg }, expected: errors.New(`service references extension "nop/2" which does not exist`), @@ -121,8 +121,8 @@ func TestConfigValidate(t *testing.T) { name: "invalid-receiver-reference", cfgFn: func() *Config { cfg := generateConfig() - pipe := cfg.Service.Pipelines[config.NewComponentID("traces")] - pipe.Receivers = append(pipe.Receivers, config.NewComponentIDWithName("nop", "2")) + pipe := cfg.Service.Pipelines[component.NewID("traces")] + pipe.Receivers = append(pipe.Receivers, component.NewIDWithName("nop", "2")) return cfg }, expected: errors.New(`pipeline "traces" references receiver "nop/2" which does not exist`), @@ -131,8 +131,8 @@ func TestConfigValidate(t *testing.T) { name: "invalid-processor-reference", cfgFn: func() *Config { cfg := generateConfig() - pipe := cfg.Service.Pipelines[config.NewComponentID("traces")] - pipe.Processors = append(pipe.Processors, config.NewComponentIDWithName("nop", "2")) + pipe := cfg.Service.Pipelines[component.NewID("traces")] + pipe.Processors = append(pipe.Processors, component.NewIDWithName("nop", "2")) return cfg }, expected: errors.New(`pipeline "traces" references processor "nop/2" which does not exist`), @@ -141,8 +141,8 @@ func TestConfigValidate(t *testing.T) { name: "invalid-exporter-reference", cfgFn: func() *Config { cfg := generateConfig() - pipe := cfg.Service.Pipelines[config.NewComponentID("traces")] - pipe.Exporters = append(pipe.Exporters, config.NewComponentIDWithName("nop", "2")) + pipe := cfg.Service.Pipelines[component.NewID("traces")] + pipe.Exporters = append(pipe.Exporters, component.NewIDWithName("nop", "2")) return cfg }, expected: errors.New(`pipeline "traces" references exporter "nop/2" which does not exist`), @@ -151,7 +151,7 @@ func TestConfigValidate(t *testing.T) { name: "missing-pipeline-receivers", cfgFn: func() *Config { cfg := generateConfig() - pipe := cfg.Service.Pipelines[config.NewComponentID("traces")] + pipe := cfg.Service.Pipelines[component.NewID("traces")] pipe.Receivers = nil return cfg }, @@ -161,7 +161,7 @@ func TestConfigValidate(t *testing.T) { name: "missing-pipeline-exporters", cfgFn: func() *Config { cfg := generateConfig() - pipe := cfg.Service.Pipelines[config.NewComponentID("traces")] + pipe := cfg.Service.Pipelines[component.NewID("traces")] pipe.Exporters = nil return cfg }, @@ -180,9 +180,9 @@ func TestConfigValidate(t *testing.T) { name: "invalid-receiver-config", cfgFn: func() *Config { cfg := generateConfig() - cfg.Receivers[config.NewComponentID("nop")] = &nopRecvConfig{ - ReceiverSettings: config.NewReceiverSettings(config.NewComponentID("nop")), - validateErr: errInvalidRecvConfig, + cfg.Receivers[component.NewID("nop")] = &nopRecvConfig{ + ReceiverConfigSettings: component.NewReceiverConfigSettings(component.NewID("nop")), + validateErr: errInvalidRecvConfig, } return cfg }, @@ -192,9 +192,9 @@ func TestConfigValidate(t *testing.T) { name: "invalid-exporter-config", cfgFn: func() *Config { cfg := generateConfig() - cfg.Exporters[config.NewComponentID("nop")] = &nopExpConfig{ - ExporterSettings: config.NewExporterSettings(config.NewComponentID("nop")), - validateErr: errInvalidExpConfig, + cfg.Exporters[component.NewID("nop")] = &nopExpConfig{ + ExporterConfigSettings: component.NewExporterConfigSettings(component.NewID("nop")), + validateErr: errInvalidExpConfig, } return cfg }, @@ -204,9 +204,9 @@ func TestConfigValidate(t *testing.T) { name: "invalid-processor-config", cfgFn: func() *Config { cfg := generateConfig() - cfg.Processors[config.NewComponentID("nop")] = &nopProcConfig{ - ProcessorSettings: config.NewProcessorSettings(config.NewComponentID("nop")), - validateErr: errInvalidProcConfig, + cfg.Processors[component.NewID("nop")] = &nopProcConfig{ + ProcessorConfigSettings: component.NewProcessorConfigSettings(component.NewID("nop")), + validateErr: errInvalidProcConfig, } return cfg }, @@ -216,9 +216,9 @@ func TestConfigValidate(t *testing.T) { name: "invalid-extension-config", cfgFn: func() *Config { cfg := generateConfig() - cfg.Extensions[config.NewComponentID("nop")] = &nopExtConfig{ - ExtensionSettings: config.NewExtensionSettings(config.NewComponentID("nop")), - validateErr: errInvalidExtConfig, + cfg.Extensions[component.NewID("nop")] = &nopExtConfig{ + ExtensionConfigSettings: component.NewExtensionConfigSettings(component.NewID("nop")), + validateErr: errInvalidExtConfig, } return cfg }, @@ -228,10 +228,10 @@ func TestConfigValidate(t *testing.T) { name: "invalid-service-pipeline-type", cfgFn: func() *Config { cfg := generateConfig() - cfg.Service.Pipelines[config.NewComponentID("wrongtype")] = &ConfigServicePipeline{ - Receivers: []config.ComponentID{config.NewComponentID("nop")}, - Processors: []config.ComponentID{config.NewComponentID("nop")}, - Exporters: []config.ComponentID{config.NewComponentID("nop")}, + cfg.Service.Pipelines[component.NewID("wrongtype")] = &ConfigServicePipeline{ + Receivers: []component.ID{component.NewID("nop")}, + Processors: []component.ID{component.NewID("nop")}, + Exporters: []component.ID{component.NewID("nop")}, } return cfg }, @@ -249,24 +249,24 @@ func TestConfigValidate(t *testing.T) { func generateConfig() *Config { return &Config{ - Receivers: map[config.ComponentID]config.Receiver{ - config.NewComponentID("nop"): &nopRecvConfig{ - ReceiverSettings: config.NewReceiverSettings(config.NewComponentID("nop")), + Receivers: map[component.ID]component.ReceiverConfig{ + component.NewID("nop"): &nopRecvConfig{ + ReceiverConfigSettings: component.NewReceiverConfigSettings(component.NewID("nop")), }, }, - Exporters: map[config.ComponentID]config.Exporter{ - config.NewComponentID("nop"): &nopExpConfig{ - ExporterSettings: config.NewExporterSettings(config.NewComponentID("nop")), + Exporters: map[component.ID]component.ExporterConfig{ + component.NewID("nop"): &nopExpConfig{ + ExporterConfigSettings: component.NewExporterConfigSettings(component.NewID("nop")), }, }, - Processors: map[config.ComponentID]config.Processor{ - config.NewComponentID("nop"): &nopProcConfig{ - ProcessorSettings: config.NewProcessorSettings(config.NewComponentID("nop")), + Processors: map[component.ID]component.ProcessorConfig{ + component.NewID("nop"): &nopProcConfig{ + ProcessorConfigSettings: component.NewProcessorConfigSettings(component.NewID("nop")), }, }, - Extensions: map[config.ComponentID]config.Extension{ - config.NewComponentID("nop"): &nopExtConfig{ - ExtensionSettings: config.NewExtensionSettings(config.NewComponentID("nop")), + Extensions: map[component.ID]component.ExtensionConfig{ + component.NewID("nop"): &nopExtConfig{ + ExtensionConfigSettings: component.NewExtensionConfigSettings(component.NewID("nop")), }, }, Service: ConfigService{ @@ -286,12 +286,12 @@ func generateConfig() *Config { Address: ":8080", }, }, - Extensions: []config.ComponentID{config.NewComponentID("nop")}, - Pipelines: map[config.ComponentID]*ConfigServicePipeline{ - config.NewComponentID("traces"): { - Receivers: []config.ComponentID{config.NewComponentID("nop")}, - Processors: []config.ComponentID{config.NewComponentID("nop")}, - Exporters: []config.ComponentID{config.NewComponentID("nop")}, + Extensions: []component.ID{component.NewID("nop")}, + Pipelines: map[component.ID]*ConfigServicePipeline{ + component.NewID("traces"): { + Receivers: []component.ID{component.NewID("nop")}, + Processors: []component.ID{component.NewID("nop")}, + Exporters: []component.ID{component.NewID("nop")}, }, }, }, diff --git a/service/extensions/config.go b/service/extensions/config.go index 44c75b23905..da7b851ee70 100644 --- a/service/extensions/config.go +++ b/service/extensions/config.go @@ -14,9 +14,7 @@ package extensions // import "go.opentelemetry.io/collector/service/extensions" -import ( - "go.opentelemetry.io/collector/config" -) +import "go.opentelemetry.io/collector/component" // Config represents the ordered list of extensions configured for the service. -type Config []config.ComponentID +type Config []component.ID diff --git a/service/extensions/extensions.go b/service/extensions/extensions.go index d69cc84392b..1e20f430290 100644 --- a/service/extensions/extensions.go +++ b/service/extensions/extensions.go @@ -24,7 +24,6 @@ import ( "go.uber.org/zap" "go.opentelemetry.io/collector/component" - "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/service/internal/components" "go.opentelemetry.io/collector/service/internal/zpages" ) @@ -34,7 +33,7 @@ const zExtensionName = "zextensionname" // Extensions is a map of extensions created from extension configs. type Extensions struct { telemetry component.TelemetrySettings - extMap map[config.ComponentID]component.Extension + extMap map[component.ID]component.Extension } // Start starts all extensions. @@ -84,8 +83,8 @@ func (bes *Extensions) NotifyPipelineNotReady() error { return errs } -func (bes *Extensions) GetExtensions() map[config.ComponentID]component.Extension { - result := make(map[config.ComponentID]component.Extension, len(bes.extMap)) +func (bes *Extensions) GetExtensions() map[component.ID]component.Extension { + result := make(map[component.ID]component.Extension, len(bes.extMap)) for extID, v := range bes.extMap { result[extID] = v } @@ -123,18 +122,18 @@ type Settings struct { Telemetry component.TelemetrySettings BuildInfo component.BuildInfo - // Configs is a map of config.ComponentID to config.Extension. - Configs map[config.ComponentID]config.Extension + // Configs is a map of component.ID to component.ExtensionConfig. + Configs map[component.ID]component.ExtensionConfig // Factories maps extension type names in the config to the respective component.ExtensionFactory. - Factories map[config.Type]component.ExtensionFactory + Factories map[component.Type]component.ExtensionFactory } // New creates a new Extensions from Config. func New(ctx context.Context, set Settings, cfg Config) (*Extensions, error) { exts := &Extensions{ telemetry: set.Telemetry, - extMap: make(map[config.ComponentID]component.Extension), + extMap: make(map[component.ID]component.Extension), } for _, extID := range cfg { extCfg, existsCfg := set.Configs[extID] @@ -169,7 +168,7 @@ func New(ctx context.Context, set Settings, cfg Config) (*Extensions, error) { return exts, nil } -func extensionLogger(logger *zap.Logger, id config.ComponentID) *zap.Logger { +func extensionLogger(logger *zap.Logger, id component.ID) *zap.Logger { return logger.With( zap.String(components.ZapKindKey, components.ZapKindExtension), zap.String(components.ZapNameKey, id.String())) diff --git a/service/extensions/extensions_test.go b/service/extensions/extensions_test.go index 6c65f2f645d..8691f10c485 100644 --- a/service/extensions/extensions_test.go +++ b/service/extensions/extensions_test.go @@ -24,7 +24,6 @@ import ( "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/component/componenttest" - "go.opentelemetry.io/collector/config" ) func TestBuildExtensions(t *testing.T) { @@ -38,54 +37,54 @@ func TestBuildExtensions(t *testing.T) { tests := []struct { name string factories component.Factories - extensionsConfigs map[config.ComponentID]config.Extension - serviceExtensions []config.ComponentID + extensionsConfigs map[component.ID]component.ExtensionConfig + serviceExtensions []component.ID wantErrMsg string }{ { name: "extension_not_configured", - serviceExtensions: []config.ComponentID{ - config.NewComponentID("myextension"), + serviceExtensions: []component.ID{ + component.NewID("myextension"), }, wantErrMsg: "extension \"myextension\" is not configured", }, { name: "missing_extension_factory", - extensionsConfigs: map[config.ComponentID]config.Extension{ - config.NewComponentID("unknown"): nopExtensionConfig, + extensionsConfigs: map[component.ID]component.ExtensionConfig{ + component.NewID("unknown"): nopExtensionConfig, }, - serviceExtensions: []config.ComponentID{ - config.NewComponentID("unknown"), + serviceExtensions: []component.ID{ + component.NewID("unknown"), }, wantErrMsg: "extension factory for type \"unknown\" is not configured", }, { name: "error_on_create_extension", factories: component.Factories{ - Extensions: map[config.Type]component.ExtensionFactory{ + Extensions: map[component.Type]component.ExtensionFactory{ errExtensionFactory.Type(): errExtensionFactory, }, }, - extensionsConfigs: map[config.ComponentID]config.Extension{ - config.NewComponentID(errExtensionFactory.Type()): errExtensionConfig, + extensionsConfigs: map[component.ID]component.ExtensionConfig{ + component.NewID(errExtensionFactory.Type()): errExtensionConfig, }, - serviceExtensions: []config.ComponentID{ - config.NewComponentID(errExtensionFactory.Type()), + serviceExtensions: []component.ID{ + component.NewID(errExtensionFactory.Type()), }, wantErrMsg: "failed to create extension \"err\": cannot create \"err\" extension type", }, { name: "bad_factory", factories: component.Factories{ - Extensions: map[config.Type]component.ExtensionFactory{ + Extensions: map[component.Type]component.ExtensionFactory{ badExtensionFactory.Type(): badExtensionFactory, }, }, - extensionsConfigs: map[config.ComponentID]config.Extension{ - config.NewComponentID(badExtensionFactory.Type()): badExtensionCfg, + extensionsConfigs: map[component.ID]component.ExtensionConfig{ + component.NewID(badExtensionFactory.Type()): badExtensionCfg, }, - serviceExtensions: []config.ComponentID{ - config.NewComponentID(badExtensionFactory.Type()), + serviceExtensions: []component.ID{ + component.NewID(badExtensionFactory.Type()), }, wantErrMsg: "factory for \"bf\" produced a nil extension", }, @@ -108,14 +107,14 @@ func TestBuildExtensions(t *testing.T) { func newBadExtensionFactory() component.ExtensionFactory { return component.NewExtensionFactory( "bf", - func() config.Extension { + func() component.ExtensionConfig { return &struct { - config.ExtensionSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct + component.ExtensionConfigSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct }{ - ExtensionSettings: config.NewExtensionSettings(config.NewComponentID("bf")), + ExtensionConfigSettings: component.NewExtensionConfigSettings(component.NewID("bf")), } }, - func(ctx context.Context, set component.ExtensionCreateSettings, extension config.Extension) (component.Extension, error) { + func(ctx context.Context, set component.ExtensionCreateSettings, extension component.ExtensionConfig) (component.Extension, error) { return nil, nil }, component.StabilityLevelInDevelopment, @@ -125,14 +124,14 @@ func newBadExtensionFactory() component.ExtensionFactory { func newCreateErrorExtensionFactory() component.ExtensionFactory { return component.NewExtensionFactory( "err", - func() config.Extension { + func() component.ExtensionConfig { return &struct { - config.ExtensionSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct + component.ExtensionConfigSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct }{ - ExtensionSettings: config.NewExtensionSettings(config.NewComponentID("err")), + ExtensionConfigSettings: component.NewExtensionConfigSettings(component.NewID("err")), } }, - func(ctx context.Context, set component.ExtensionCreateSettings, extension config.Extension) (component.Extension, error) { + func(ctx context.Context, set component.ExtensionCreateSettings, extension component.ExtensionConfig) (component.Extension, error) { return nil, errors.New("cannot create \"err\" extension type") }, component.StabilityLevelInDevelopment, diff --git a/service/host.go b/service/host.go index f43a55d172c..31be010608d 100644 --- a/service/host.go +++ b/service/host.go @@ -16,7 +16,6 @@ package service // import "go.opentelemetry.io/collector/service" import ( "go.opentelemetry.io/collector/component" - "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/service/extensions" "go.opentelemetry.io/collector/service/internal/pipelines" ) @@ -39,7 +38,7 @@ func (host *serviceHost) ReportFatalError(err error) { host.asyncErrorChannel <- err } -func (host *serviceHost) GetFactory(kind component.Kind, componentType config.Type) component.Factory { +func (host *serviceHost) GetFactory(kind component.Kind, componentType component.Type) component.Factory { switch kind { case component.KindReceiver: return host.factories.Receivers[componentType] @@ -53,10 +52,10 @@ func (host *serviceHost) GetFactory(kind component.Kind, componentType config.Ty return nil } -func (host *serviceHost) GetExtensions() map[config.ComponentID]component.Extension { +func (host *serviceHost) GetExtensions() map[component.ID]component.Extension { return host.extensions.GetExtensions() } -func (host *serviceHost) GetExporters() map[config.DataType]map[config.ComponentID]component.Exporter { +func (host *serviceHost) GetExporters() map[component.DataType]map[component.ID]component.Exporter { return host.pipelines.GetExporters() } diff --git a/service/internal/configunmarshaler/error.go b/service/internal/configunmarshaler/error.go index 102c21851d5..3518fbde12a 100644 --- a/service/internal/configunmarshaler/error.go +++ b/service/internal/configunmarshaler/error.go @@ -18,13 +18,13 @@ import ( "fmt" "reflect" - "go.opentelemetry.io/collector/config" + "go.opentelemetry.io/collector/component" ) -func errorUnknownType(component string, id config.ComponentID, factories []reflect.Value) error { +func errorUnknownType(component string, id component.ID, factories []reflect.Value) error { return fmt.Errorf("unknown %s type: %q for id: %q (valid values: %v)", component, id.Type(), id, factories) } -func errorUnmarshalError(component string, id config.ComponentID, err error) error { +func errorUnmarshalError(component string, id component.ID, err error) error { return fmt.Errorf("error reading %s configuration for %q: %w", component, id, err) } diff --git a/service/internal/configunmarshaler/exporters.go b/service/internal/configunmarshaler/exporters.go index 143b241e2fa..e4064dfb028 100644 --- a/service/internal/configunmarshaler/exporters.go +++ b/service/internal/configunmarshaler/exporters.go @@ -18,7 +18,6 @@ import ( "reflect" "go.opentelemetry.io/collector/component" - "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/confmap" ) @@ -26,23 +25,23 @@ import ( const exportersKeyName = "exporters" type Exporters struct { - exps map[config.ComponentID]config.Exporter + exps map[component.ID]component.ExporterConfig - factories map[config.Type]component.ExporterFactory + factories map[component.Type]component.ExporterFactory } -func NewExporters(factories map[config.Type]component.ExporterFactory) *Exporters { +func NewExporters(factories map[component.Type]component.ExporterFactory) *Exporters { return &Exporters{factories: factories} } func (e *Exporters) Unmarshal(conf *confmap.Conf) error { - rawExps := make(map[config.ComponentID]map[string]interface{}) + rawExps := make(map[component.ID]map[string]interface{}) if err := conf.Unmarshal(&rawExps, confmap.WithErrorUnused()); err != nil { return err } // Prepare resulting map. - e.exps = make(map[config.ComponentID]config.Exporter) + e.exps = make(map[component.ID]component.ExporterConfig) // Iterate over Exporters and create a config for each. for id, value := range rawExps { @@ -58,7 +57,7 @@ func (e *Exporters) Unmarshal(conf *confmap.Conf) error { // Now that the default config struct is created we can Unmarshal into it, // and it will apply user-defined config on top of the default. - if err := config.UnmarshalExporter(confmap.NewFromStringMap(value), exporterCfg); err != nil { + if err := component.UnmarshalExporterConfig(confmap.NewFromStringMap(value), exporterCfg); err != nil { return errorUnmarshalError(exportersKeyName, id, err) } @@ -68,6 +67,6 @@ func (e *Exporters) Unmarshal(conf *confmap.Conf) error { return nil } -func (e *Exporters) GetExporters() map[config.ComponentID]config.Exporter { +func (e *Exporters) GetExporters() map[component.ID]component.ExporterConfig { return e.exps } diff --git a/service/internal/configunmarshaler/exporters_test.go b/service/internal/configunmarshaler/exporters_test.go index cbeee6f344b..5f8ba6caad5 100644 --- a/service/internal/configunmarshaler/exporters_test.go +++ b/service/internal/configunmarshaler/exporters_test.go @@ -20,8 +20,8 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/component/componenttest" - "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/confmap" ) @@ -38,9 +38,9 @@ func TestExportersUnmarshal(t *testing.T) { cfgWithName := factories.Exporters["nop"].CreateDefaultConfig() cfgWithName.SetIDName("myexporter") - assert.Equal(t, map[config.ComponentID]config.Exporter{ - config.NewComponentID("nop"): factories.Exporters["nop"].CreateDefaultConfig(), - config.NewComponentIDWithName("nop", "myexporter"): cfgWithName, + assert.Equal(t, map[component.ID]component.ExporterConfig{ + component.NewID("nop"): factories.Exporters["nop"].CreateDefaultConfig(), + component.NewIDWithName("nop", "myexporter"): cfgWithName, }, exps.GetExporters()) } diff --git a/service/internal/configunmarshaler/extensions.go b/service/internal/configunmarshaler/extensions.go index a0e49b5194b..cb3478a7725 100644 --- a/service/internal/configunmarshaler/extensions.go +++ b/service/internal/configunmarshaler/extensions.go @@ -18,7 +18,6 @@ import ( "reflect" "go.opentelemetry.io/collector/component" - "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/confmap" ) @@ -26,23 +25,23 @@ import ( const extensionsKeyName = "extensions" type Extensions struct { - exts map[config.ComponentID]config.Extension + exts map[component.ID]component.ExtensionConfig - factories map[config.Type]component.ExtensionFactory + factories map[component.Type]component.ExtensionFactory } -func NewExtensions(factories map[config.Type]component.ExtensionFactory) *Extensions { +func NewExtensions(factories map[component.Type]component.ExtensionFactory) *Extensions { return &Extensions{factories: factories} } func (e *Extensions) Unmarshal(conf *confmap.Conf) error { - rawExts := make(map[config.ComponentID]map[string]interface{}) + rawExts := make(map[component.ID]map[string]interface{}) if err := conf.Unmarshal(&rawExts, confmap.WithErrorUnused()); err != nil { return err } // Prepare resulting map. - e.exts = make(map[config.ComponentID]config.Extension) + e.exts = make(map[component.ID]component.ExtensionConfig) // Iterate over extensions and create a config for each. for id, value := range rawExts { @@ -58,7 +57,7 @@ func (e *Extensions) Unmarshal(conf *confmap.Conf) error { // Now that the default config struct is created we can Unmarshal into it, // and it will apply user-defined config on top of the default. - if err := config.UnmarshalExtension(confmap.NewFromStringMap(value), extensionCfg); err != nil { + if err := component.UnmarshalExtensionConfig(confmap.NewFromStringMap(value), extensionCfg); err != nil { return errorUnmarshalError(extensionsKeyName, id, err) } @@ -68,6 +67,6 @@ func (e *Extensions) Unmarshal(conf *confmap.Conf) error { return nil } -func (e *Extensions) GetExtensions() map[config.ComponentID]config.Extension { +func (e *Extensions) GetExtensions() map[component.ID]component.ExtensionConfig { return e.exts } diff --git a/service/internal/configunmarshaler/extensions_test.go b/service/internal/configunmarshaler/extensions_test.go index 6af6f761b3d..3f6a7e57eee 100644 --- a/service/internal/configunmarshaler/extensions_test.go +++ b/service/internal/configunmarshaler/extensions_test.go @@ -20,8 +20,8 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/component/componenttest" - "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/confmap" ) @@ -38,9 +38,9 @@ func TestExtensionsUnmarshal(t *testing.T) { cfgWithName := factories.Extensions["nop"].CreateDefaultConfig() cfgWithName.SetIDName("myextension") - assert.Equal(t, map[config.ComponentID]config.Extension{ - config.NewComponentID("nop"): factories.Extensions["nop"].CreateDefaultConfig(), - config.NewComponentIDWithName("nop", "myextension"): cfgWithName, + assert.Equal(t, map[component.ID]component.ExtensionConfig{ + component.NewID("nop"): factories.Extensions["nop"].CreateDefaultConfig(), + component.NewIDWithName("nop", "myextension"): cfgWithName, }, exts.GetExtensions()) } diff --git a/service/internal/configunmarshaler/processors.go b/service/internal/configunmarshaler/processors.go index fb33af43333..920876d7781 100644 --- a/service/internal/configunmarshaler/processors.go +++ b/service/internal/configunmarshaler/processors.go @@ -18,7 +18,6 @@ import ( "reflect" "go.opentelemetry.io/collector/component" - "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/confmap" ) @@ -26,23 +25,23 @@ import ( const processorsKeyName = "processors" type Processors struct { - procs map[config.ComponentID]config.Processor + procs map[component.ID]component.ProcessorConfig - factories map[config.Type]component.ProcessorFactory + factories map[component.Type]component.ProcessorFactory } -func NewProcessors(factories map[config.Type]component.ProcessorFactory) *Processors { +func NewProcessors(factories map[component.Type]component.ProcessorFactory) *Processors { return &Processors{factories: factories} } func (p *Processors) Unmarshal(conf *confmap.Conf) error { - rawProcs := make(map[config.ComponentID]map[string]interface{}) + rawProcs := make(map[component.ID]map[string]interface{}) if err := conf.Unmarshal(&rawProcs, confmap.WithErrorUnused()); err != nil { return err } // Prepare resulting map. - p.procs = make(map[config.ComponentID]config.Processor) + p.procs = make(map[component.ID]component.ProcessorConfig) // Iterate over processors and create a config for each. for id, value := range rawProcs { // Find processor factory based on "type" that we read from config source. @@ -57,7 +56,7 @@ func (p *Processors) Unmarshal(conf *confmap.Conf) error { // Now that the default config struct is created we can Unmarshal into it, // and it will apply user-defined config on top of the default. - if err := config.UnmarshalProcessor(confmap.NewFromStringMap(value), processorCfg); err != nil { + if err := component.UnmarshalProcessorConfig(confmap.NewFromStringMap(value), processorCfg); err != nil { return errorUnmarshalError(processorsKeyName, id, err) } @@ -67,6 +66,6 @@ func (p *Processors) Unmarshal(conf *confmap.Conf) error { return nil } -func (p *Processors) GetProcessors() map[config.ComponentID]config.Processor { +func (p *Processors) GetProcessors() map[component.ID]component.ProcessorConfig { return p.procs } diff --git a/service/internal/configunmarshaler/processors_test.go b/service/internal/configunmarshaler/processors_test.go index d172009a596..58583251053 100644 --- a/service/internal/configunmarshaler/processors_test.go +++ b/service/internal/configunmarshaler/processors_test.go @@ -20,8 +20,8 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/component/componenttest" - "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/confmap" ) @@ -38,9 +38,9 @@ func TestProcessorsUnmarshal(t *testing.T) { cfgWithName := factories.Processors["nop"].CreateDefaultConfig() cfgWithName.SetIDName("myprocessor") - assert.Equal(t, map[config.ComponentID]config.Processor{ - config.NewComponentID("nop"): factories.Processors["nop"].CreateDefaultConfig(), - config.NewComponentIDWithName("nop", "myprocessor"): cfgWithName, + assert.Equal(t, map[component.ID]component.ProcessorConfig{ + component.NewID("nop"): factories.Processors["nop"].CreateDefaultConfig(), + component.NewIDWithName("nop", "myprocessor"): cfgWithName, }, procs.procs) } diff --git a/service/internal/configunmarshaler/receivers.go b/service/internal/configunmarshaler/receivers.go index 0db56700266..a6affc72167 100644 --- a/service/internal/configunmarshaler/receivers.go +++ b/service/internal/configunmarshaler/receivers.go @@ -18,7 +18,6 @@ import ( "reflect" "go.opentelemetry.io/collector/component" - "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/confmap" ) @@ -26,23 +25,23 @@ import ( const receiversKeyName = "receivers" type Receivers struct { - recvs map[config.ComponentID]config.Receiver + recvs map[component.ID]component.ReceiverConfig - factories map[config.Type]component.ReceiverFactory + factories map[component.Type]component.ReceiverFactory } -func NewReceivers(factories map[config.Type]component.ReceiverFactory) *Receivers { +func NewReceivers(factories map[component.Type]component.ReceiverFactory) *Receivers { return &Receivers{factories: factories} } func (r *Receivers) Unmarshal(conf *confmap.Conf) error { - rawRecvs := make(map[config.ComponentID]map[string]interface{}) + rawRecvs := make(map[component.ID]map[string]interface{}) if err := conf.Unmarshal(&rawRecvs, confmap.WithErrorUnused()); err != nil { return err } // Prepare resulting map. - r.recvs = make(map[config.ComponentID]config.Receiver) + r.recvs = make(map[component.ID]component.ReceiverConfig) // Iterate over input map and create a config for each. for id, value := range rawRecvs { @@ -58,7 +57,7 @@ func (r *Receivers) Unmarshal(conf *confmap.Conf) error { // Now that the default config struct is created we can Unmarshal into it, // and it will apply user-defined config on top of the default. - if err := config.UnmarshalReceiver(confmap.NewFromStringMap(value), receiverCfg); err != nil { + if err := component.UnmarshalReceiverConfig(confmap.NewFromStringMap(value), receiverCfg); err != nil { return errorUnmarshalError(receiversKeyName, id, err) } @@ -68,6 +67,6 @@ func (r *Receivers) Unmarshal(conf *confmap.Conf) error { return nil } -func (r *Receivers) GetReceivers() map[config.ComponentID]config.Receiver { +func (r *Receivers) GetReceivers() map[component.ID]component.ReceiverConfig { return r.recvs } diff --git a/service/internal/configunmarshaler/receivers_test.go b/service/internal/configunmarshaler/receivers_test.go index a6445d8767a..41255118ba4 100644 --- a/service/internal/configunmarshaler/receivers_test.go +++ b/service/internal/configunmarshaler/receivers_test.go @@ -20,8 +20,8 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/component/componenttest" - "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/confmap" ) @@ -38,9 +38,9 @@ func TestReceiversUnmarshal(t *testing.T) { cfgWithName := factories.Receivers["nop"].CreateDefaultConfig() cfgWithName.SetIDName("myreceiver") - assert.Equal(t, map[config.ComponentID]config.Receiver{ - config.NewComponentID("nop"): factories.Receivers["nop"].CreateDefaultConfig(), - config.NewComponentIDWithName("nop", "myreceiver"): cfgWithName, + assert.Equal(t, map[component.ID]component.ReceiverConfig{ + component.NewID("nop"): factories.Receivers["nop"].CreateDefaultConfig(), + component.NewIDWithName("nop", "myreceiver"): cfgWithName, }, recvs.GetReceivers()) } diff --git a/service/internal/pipelines/pipelines.go b/service/internal/pipelines/pipelines.go index 0dc0ca091e1..2d0e1e4537b 100644 --- a/service/internal/pipelines/pipelines.go +++ b/service/internal/pipelines/pipelines.go @@ -43,7 +43,7 @@ type baseConsumer interface { } type builtComponent struct { - id config.ComponentID + id component.ID comp component.Component } @@ -59,10 +59,10 @@ type builtPipeline struct { type Pipelines struct { telemetry component.TelemetrySettings - allReceivers map[config.DataType]map[config.ComponentID]component.Receiver - allExporters map[config.DataType]map[config.ComponentID]component.Exporter + allReceivers map[component.DataType]map[component.ID]component.Receiver + allExporters map[component.DataType]map[component.ID]component.Exporter - pipelines map[config.ComponentID]*builtPipeline + pipelines map[component.ID]*builtPipeline } // StartAll starts all pipelines. @@ -139,12 +139,12 @@ func (bps *Pipelines) ShutdownAll(ctx context.Context) error { return errs } -func (bps *Pipelines) GetExporters() map[config.DataType]map[config.ComponentID]component.Exporter { - exportersMap := make(map[config.DataType]map[config.ComponentID]component.Exporter) +func (bps *Pipelines) GetExporters() map[component.DataType]map[component.ID]component.Exporter { + exportersMap := make(map[component.DataType]map[component.ID]component.Exporter) - exportersMap[config.TracesDataType] = make(map[config.ComponentID]component.Exporter, len(bps.allExporters[config.TracesDataType])) - exportersMap[config.MetricsDataType] = make(map[config.ComponentID]component.Exporter, len(bps.allExporters[config.MetricsDataType])) - exportersMap[config.LogsDataType] = make(map[config.ComponentID]component.Exporter, len(bps.allExporters[config.LogsDataType])) + exportersMap[component.TracesDataType] = make(map[component.ID]component.Exporter, len(bps.allExporters[component.TracesDataType])) + exportersMap[component.MetricsDataType] = make(map[component.ID]component.Exporter, len(bps.allExporters[component.MetricsDataType])) + exportersMap[component.LogsDataType] = make(map[component.ID]component.Exporter, len(bps.allExporters[component.LogsDataType])) for dt, expByID := range bps.allExporters { for expID, exp := range expByID { @@ -183,37 +183,37 @@ type Settings struct { BuildInfo component.BuildInfo // ReceiverFactories maps receiver type names in the config to the respective component.ReceiverFactory. - ReceiverFactories map[config.Type]component.ReceiverFactory + ReceiverFactories map[component.Type]component.ReceiverFactory - // ReceiverConfigs is a map of config.ComponentID to config.Receiver. - ReceiverConfigs map[config.ComponentID]config.Receiver + // ReceiverConfigs is a map of component.ID to component.ReceiverConfig. + ReceiverConfigs map[component.ID]component.ReceiverConfig // ProcessorFactories maps processor type names in the config to the respective component.ProcessorFactory. - ProcessorFactories map[config.Type]component.ProcessorFactory + ProcessorFactories map[component.Type]component.ProcessorFactory - // ProcessorConfigs is a map of config.ComponentID to config.Processor. - ProcessorConfigs map[config.ComponentID]config.Processor + // ProcessorConfigs is a map of component.ID to component.ProcessorConfig. + ProcessorConfigs map[component.ID]component.ProcessorConfig // ExporterFactories maps exporter type names in the config to the respective component.ExporterFactory. - ExporterFactories map[config.Type]component.ExporterFactory + ExporterFactories map[component.Type]component.ExporterFactory - // ExporterConfigs is a map of config.ComponentID to config.Exporter. - ExporterConfigs map[config.ComponentID]config.Exporter + // ExporterConfigs is a map of component.ID to component.ExporterConfig. + ExporterConfigs map[component.ID]component.ExporterConfig - // PipelineConfigs is a map of config.ComponentID to config.Pipeline. - PipelineConfigs map[config.ComponentID]*config.Pipeline + // PipelineConfigs is a map of component.ID to config.Pipeline. + PipelineConfigs map[component.ID]*config.Pipeline } // Build builds all pipelines from config. func Build(ctx context.Context, set Settings) (*Pipelines, error) { exps := &Pipelines{ telemetry: set.Telemetry, - allReceivers: make(map[config.DataType]map[config.ComponentID]component.Receiver), - allExporters: make(map[config.DataType]map[config.ComponentID]component.Exporter), - pipelines: make(map[config.ComponentID]*builtPipeline, len(set.PipelineConfigs)), + allReceivers: make(map[component.DataType]map[component.ID]component.Receiver), + allExporters: make(map[component.DataType]map[component.ID]component.Exporter), + pipelines: make(map[component.ID]*builtPipeline, len(set.PipelineConfigs)), } - receiversConsumers := make(map[config.DataType]map[config.ComponentID][]baseConsumer) + receiversConsumers := make(map[component.DataType]map[component.ID][]baseConsumer) // Iterate over all pipelines, and create exporters, then processors. // Receivers cannot be created since we need to know all consumers, a.k.a. we need all pipelines build up to the @@ -221,7 +221,7 @@ func Build(ctx context.Context, set Settings) (*Pipelines, error) { for pipelineID, pipeline := range set.PipelineConfigs { // The data type of the pipeline defines what data type each exporter is expected to receive. if _, ok := exps.allExporters[pipelineID.Type()]; !ok { - exps.allExporters[pipelineID.Type()] = make(map[config.ComponentID]component.Exporter) + exps.allExporters[pipelineID.Type()] = make(map[component.ID]component.Exporter) } expByID := exps.allExporters[pipelineID.Type()] @@ -251,11 +251,11 @@ func Build(ctx context.Context, set Settings) (*Pipelines, error) { // Build a fan out consumer to all exporters. switch pipelineID.Type() { - case config.TracesDataType: + case component.TracesDataType: bp.lastConsumer = buildFanOutExportersTracesConsumer(bp.exporters) - case config.MetricsDataType: + case component.MetricsDataType: bp.lastConsumer = buildFanOutExportersMetricsConsumer(bp.exporters) - case config.LogsDataType: + case component.LogsDataType: bp.lastConsumer = buildFanOutExportersLogsConsumer(bp.exporters) default: return nil, fmt.Errorf("create fan-out exporter in pipeline %q, data type %q is not supported", pipelineID, pipelineID.Type()) @@ -281,11 +281,11 @@ func Build(ctx context.Context, set Settings) (*Pipelines, error) { // Some consumers may not correctly implement the Capabilities, and ignore the next consumer when calculated the Capabilities. // Because of this wrap the first consumer if any consumers in the pipeline mutate the data and the first says that it doesn't. switch pipelineID.Type() { - case config.TracesDataType: + case component.TracesDataType: bp.lastConsumer = capTraces{Traces: bp.lastConsumer.(consumer.Traces), cap: consumer.Capabilities{MutatesData: mutatesConsumedData}} - case config.MetricsDataType: + case component.MetricsDataType: bp.lastConsumer = capMetrics{Metrics: bp.lastConsumer.(consumer.Metrics), cap: consumer.Capabilities{MutatesData: mutatesConsumedData}} - case config.LogsDataType: + case component.LogsDataType: bp.lastConsumer = capLogs{Logs: bp.lastConsumer.(consumer.Logs), cap: consumer.Capabilities{MutatesData: mutatesConsumedData}} default: return nil, fmt.Errorf("create cap consumer in pipeline %q, data type %q is not supported", pipelineID, pipelineID.Type()) @@ -293,7 +293,7 @@ func Build(ctx context.Context, set Settings) (*Pipelines, error) { // The data type of the pipeline defines what data type each exporter is expected to receive. if _, ok := receiversConsumers[pipelineID.Type()]; !ok { - receiversConsumers[pipelineID.Type()] = make(map[config.ComponentID][]baseConsumer) + receiversConsumers[pipelineID.Type()] = make(map[component.ID][]baseConsumer) } recvConsByID := receiversConsumers[pipelineID.Type()] // Iterate over all Receivers for this pipeline and just append the lastConsumer as a consumer for the receiver. @@ -306,7 +306,7 @@ func Build(ctx context.Context, set Settings) (*Pipelines, error) { for pipelineID, pipeline := range set.PipelineConfigs { // The data type of the pipeline defines what data type each exporter is expected to receive. if _, ok := exps.allReceivers[pipelineID.Type()]; !ok { - exps.allReceivers[pipelineID.Type()] = make(map[config.ComponentID]component.Receiver) + exps.allReceivers[pipelineID.Type()] = make(map[component.ID]component.Receiver) } recvByID := exps.allReceivers[pipelineID.Type()] bp := exps.pipelines[pipelineID] @@ -335,10 +335,10 @@ func buildExporter( ctx context.Context, settings component.TelemetrySettings, buildInfo component.BuildInfo, - cfgs map[config.ComponentID]config.Exporter, - factories map[config.Type]component.ExporterFactory, - id config.ComponentID, - pipelineID config.ComponentID, + cfgs map[component.ID]component.ExporterConfig, + factories map[component.Type]component.ExporterFactory, + id component.ID, + pipelineID component.ID, ) (component.Exporter, error) { cfg, existsCfg := cfgs[id] if !existsCfg { @@ -365,15 +365,15 @@ func buildExporter( return exp, nil } -func createExporter(ctx context.Context, set component.ExporterCreateSettings, cfg config.Exporter, id config.ComponentID, pipelineID config.ComponentID, factory component.ExporterFactory) (component.Exporter, error) { +func createExporter(ctx context.Context, set component.ExporterCreateSettings, cfg component.ExporterConfig, id component.ID, pipelineID component.ID, factory component.ExporterFactory) (component.Exporter, error) { switch pipelineID.Type() { - case config.TracesDataType: + case component.TracesDataType: return factory.CreateTracesExporter(ctx, set, cfg) - case config.MetricsDataType: + case component.MetricsDataType: return factory.CreateMetricsExporter(ctx, set, cfg) - case config.LogsDataType: + case component.LogsDataType: return factory.CreateLogsExporter(ctx, set, cfg) } return nil, fmt.Errorf("error creating exporter %q in pipeline %q, data type %q is not supported", id, pipelineID, pipelineID.Type()) @@ -406,20 +406,20 @@ func buildFanOutExportersLogsConsumer(exporters []builtComponent) consumer.Logs return fanoutconsumer.NewLogs(consumers) } -func exporterLogger(logger *zap.Logger, id config.ComponentID, dt config.DataType) *zap.Logger { +func exporterLogger(logger *zap.Logger, id component.ID, dt component.DataType) *zap.Logger { return logger.With( zap.String(components.ZapKindKey, components.ZapKindExporter), zap.String(components.ZapDataTypeKey, string(dt)), zap.String(components.ZapNameKey, id.String())) } -func getExporterStabilityLevel(factory component.ExporterFactory, dt config.DataType) component.StabilityLevel { +func getExporterStabilityLevel(factory component.ExporterFactory, dt component.DataType) component.StabilityLevel { switch dt { - case config.TracesDataType: + case component.TracesDataType: return factory.TracesExporterStability() - case config.MetricsDataType: + case component.MetricsDataType: return factory.MetricsExporterStability() - case config.LogsDataType: + case component.LogsDataType: return factory.LogsExporterStability() } return component.StabilityLevelUndefined @@ -428,10 +428,10 @@ func getExporterStabilityLevel(factory component.ExporterFactory, dt config.Data func buildProcessor(ctx context.Context, settings component.TelemetrySettings, buildInfo component.BuildInfo, - cfgs map[config.ComponentID]config.Processor, - factories map[config.Type]component.ProcessorFactory, - id config.ComponentID, - pipelineID config.ComponentID, + cfgs map[component.ID]component.ProcessorConfig, + factories map[component.Type]component.ProcessorFactory, + id component.ID, + pipelineID component.ID, next baseConsumer, ) (component.Processor, error) { procCfg, existsCfg := cfgs[id] @@ -458,34 +458,34 @@ func buildProcessor(ctx context.Context, return proc, nil } -func createProcessor(ctx context.Context, set component.ProcessorCreateSettings, cfg config.Processor, id config.ComponentID, pipelineID config.ComponentID, next baseConsumer, factory component.ProcessorFactory) (component.Processor, error) { +func createProcessor(ctx context.Context, set component.ProcessorCreateSettings, cfg component.ProcessorConfig, id component.ID, pipelineID component.ID, next baseConsumer, factory component.ProcessorFactory) (component.Processor, error) { switch pipelineID.Type() { - case config.TracesDataType: + case component.TracesDataType: return factory.CreateTracesProcessor(ctx, set, cfg, next.(consumer.Traces)) - case config.MetricsDataType: + case component.MetricsDataType: return factory.CreateMetricsProcessor(ctx, set, cfg, next.(consumer.Metrics)) - case config.LogsDataType: + case component.LogsDataType: return factory.CreateLogsProcessor(ctx, set, cfg, next.(consumer.Logs)) } return nil, fmt.Errorf("error creating processor %q in pipeline %q, data type %q is not supported", id, pipelineID, pipelineID.Type()) } -func processorLogger(logger *zap.Logger, procID config.ComponentID, pipelineID config.ComponentID) *zap.Logger { +func processorLogger(logger *zap.Logger, procID component.ID, pipelineID component.ID) *zap.Logger { return logger.With( zap.String(components.ZapKindKey, components.ZapKindProcessor), zap.String(components.ZapNameKey, procID.String()), zap.String(components.ZapKindPipeline, pipelineID.String())) } -func getProcessorStabilityLevel(factory component.ProcessorFactory, dt config.DataType) component.StabilityLevel { +func getProcessorStabilityLevel(factory component.ProcessorFactory, dt component.DataType) component.StabilityLevel { switch dt { - case config.TracesDataType: + case component.TracesDataType: return factory.TracesProcessorStability() - case config.MetricsDataType: + case component.MetricsDataType: return factory.MetricsProcessorStability() - case config.LogsDataType: + case component.LogsDataType: return factory.LogsProcessorStability() } return component.StabilityLevelUndefined @@ -494,10 +494,10 @@ func getProcessorStabilityLevel(factory component.ProcessorFactory, dt config.Da func buildReceiver(ctx context.Context, settings component.TelemetrySettings, buildInfo component.BuildInfo, - cfgs map[config.ComponentID]config.Receiver, - factories map[config.Type]component.ReceiverFactory, - id config.ComponentID, - pipelineID config.ComponentID, + cfgs map[component.ID]component.ReceiverConfig, + factories map[component.Type]component.ReceiverFactory, + id component.ID, + pipelineID component.ID, nexts []baseConsumer, ) (component.Receiver, error) { cfg, existsCfg := cfgs[id] @@ -525,21 +525,21 @@ func buildReceiver(ctx context.Context, return recv, nil } -func createReceiver(ctx context.Context, set component.ReceiverCreateSettings, cfg config.Receiver, id config.ComponentID, pipelineID config.ComponentID, nexts []baseConsumer, factory component.ReceiverFactory) (component.Receiver, error) { +func createReceiver(ctx context.Context, set component.ReceiverCreateSettings, cfg component.ReceiverConfig, id component.ID, pipelineID component.ID, nexts []baseConsumer, factory component.ReceiverFactory) (component.Receiver, error) { switch pipelineID.Type() { - case config.TracesDataType: + case component.TracesDataType: var consumers []consumer.Traces for _, next := range nexts { consumers = append(consumers, next.(consumer.Traces)) } return factory.CreateTracesReceiver(ctx, set, cfg, fanoutconsumer.NewTraces(consumers)) - case config.MetricsDataType: + case component.MetricsDataType: var consumers []consumer.Metrics for _, next := range nexts { consumers = append(consumers, next.(consumer.Metrics)) } return factory.CreateMetricsReceiver(ctx, set, cfg, fanoutconsumer.NewMetrics(consumers)) - case config.LogsDataType: + case component.LogsDataType: var consumers []consumer.Logs for _, next := range nexts { consumers = append(consumers, next.(consumer.Logs)) @@ -549,20 +549,20 @@ func createReceiver(ctx context.Context, set component.ReceiverCreateSettings, c return nil, fmt.Errorf("error creating receiver %q in pipeline %q, data type %q is not supported", id, pipelineID, pipelineID.Type()) } -func receiverLogger(logger *zap.Logger, id config.ComponentID, dt config.DataType) *zap.Logger { +func receiverLogger(logger *zap.Logger, id component.ID, dt component.DataType) *zap.Logger { return logger.With( zap.String(components.ZapKindKey, components.ZapKindReceiver), zap.String(components.ZapNameKey, id.String()), zap.String(components.ZapKindPipeline, string(dt))) } -func getReceiverStabilityLevel(factory component.ReceiverFactory, dt config.DataType) component.StabilityLevel { +func getReceiverStabilityLevel(factory component.ReceiverFactory, dt component.DataType) component.StabilityLevel { switch dt { - case config.TracesDataType: + case component.TracesDataType: return factory.TracesReceiverStability() - case config.MetricsDataType: + case component.MetricsDataType: return factory.MetricsReceiverStability() - case config.LogsDataType: + case component.LogsDataType: return factory.LogsReceiverStability() } return component.StabilityLevelUndefined diff --git a/service/internal/pipelines/pipelines_test.go b/service/internal/pipelines/pipelines_test.go index 858d05c04dd..4f991ead2c7 100644 --- a/service/internal/pipelines/pipelines_test.go +++ b/service/internal/pipelines/pipelines_test.go @@ -38,48 +38,48 @@ import ( func TestBuild(t *testing.T) { tests := []struct { name string - receiverIDs []config.ComponentID - processorIDs []config.ComponentID - exporterIDs []config.ComponentID + receiverIDs []component.ID + processorIDs []component.ID + exporterIDs []component.ID expectedRequests int }{ { name: "pipelines_simple.yaml", - receiverIDs: []config.ComponentID{config.NewComponentID("examplereceiver")}, - processorIDs: []config.ComponentID{config.NewComponentID("exampleprocessor")}, - exporterIDs: []config.ComponentID{config.NewComponentID("exampleexporter")}, + receiverIDs: []component.ID{component.NewID("examplereceiver")}, + processorIDs: []component.ID{component.NewID("exampleprocessor")}, + exporterIDs: []component.ID{component.NewID("exampleexporter")}, expectedRequests: 1, }, { name: "pipelines_simple_multi_proc.yaml", - receiverIDs: []config.ComponentID{config.NewComponentID("examplereceiver")}, - processorIDs: []config.ComponentID{config.NewComponentID("exampleprocessor"), config.NewComponentID("exampleprocessor")}, - exporterIDs: []config.ComponentID{config.NewComponentID("exampleexporter")}, + receiverIDs: []component.ID{component.NewID("examplereceiver")}, + processorIDs: []component.ID{component.NewID("exampleprocessor"), component.NewID("exampleprocessor")}, + exporterIDs: []component.ID{component.NewID("exampleexporter")}, expectedRequests: 1, }, { name: "pipelines_simple_no_proc.yaml", - receiverIDs: []config.ComponentID{config.NewComponentID("examplereceiver")}, - exporterIDs: []config.ComponentID{config.NewComponentID("exampleexporter")}, + receiverIDs: []component.ID{component.NewID("examplereceiver")}, + exporterIDs: []component.ID{component.NewID("exampleexporter")}, expectedRequests: 1, }, { name: "pipelines_multi.yaml", - receiverIDs: []config.ComponentID{config.NewComponentID("examplereceiver"), config.NewComponentIDWithName("examplereceiver", "1")}, - processorIDs: []config.ComponentID{config.NewComponentID("exampleprocessor"), config.NewComponentIDWithName("exampleprocessor", "1")}, - exporterIDs: []config.ComponentID{config.NewComponentID("exampleexporter"), config.NewComponentIDWithName("exampleexporter", "1")}, + receiverIDs: []component.ID{component.NewID("examplereceiver"), component.NewIDWithName("examplereceiver", "1")}, + processorIDs: []component.ID{component.NewID("exampleprocessor"), component.NewIDWithName("exampleprocessor", "1")}, + exporterIDs: []component.ID{component.NewID("exampleexporter"), component.NewIDWithName("exampleexporter", "1")}, expectedRequests: 2, }, { name: "pipelines_multi_no_proc.yaml", - receiverIDs: []config.ComponentID{config.NewComponentID("examplereceiver"), config.NewComponentIDWithName("examplereceiver", "1")}, - exporterIDs: []config.ComponentID{config.NewComponentID("exampleexporter"), config.NewComponentIDWithName("exampleexporter", "1")}, + receiverIDs: []component.ID{component.NewID("examplereceiver"), component.NewIDWithName("examplereceiver", "1")}, + exporterIDs: []component.ID{component.NewID("exampleexporter"), component.NewIDWithName("exampleexporter", "1")}, expectedRequests: 2, }, { name: "pipelines_exporter_multi_pipeline.yaml", - receiverIDs: []config.ComponentID{config.NewComponentID("examplereceiver")}, - exporterIDs: []config.ComponentID{config.NewComponentID("exampleexporter")}, + receiverIDs: []component.ID{component.NewID("examplereceiver")}, + exporterIDs: []component.ID{component.NewID("exampleexporter")}, expectedRequests: 2, }, } @@ -99,51 +99,51 @@ func TestBuild(t *testing.T) { // Verify exporters created, started and empty. for _, expID := range test.exporterIDs { - traceExporter := pipelines.GetExporters()[config.TracesDataType][expID].(*testcomponents.ExampleExporter) + traceExporter := pipelines.GetExporters()[component.TracesDataType][expID].(*testcomponents.ExampleExporter) assert.True(t, traceExporter.Started) assert.Equal(t, len(traceExporter.Traces), 0) // Validate metrics. - metricsExporter := pipelines.GetExporters()[config.MetricsDataType][expID].(*testcomponents.ExampleExporter) + metricsExporter := pipelines.GetExporters()[component.MetricsDataType][expID].(*testcomponents.ExampleExporter) assert.True(t, metricsExporter.Started) assert.Zero(t, len(metricsExporter.Traces)) // Validate logs. - logsExporter := pipelines.GetExporters()[config.LogsDataType][expID].(*testcomponents.ExampleExporter) + logsExporter := pipelines.GetExporters()[component.LogsDataType][expID].(*testcomponents.ExampleExporter) assert.True(t, logsExporter.Started) assert.Zero(t, len(logsExporter.Traces)) } // Verify processors created in the given order and started. for i, procID := range test.processorIDs { - traceProcessor := pipelines.pipelines[config.NewComponentID(config.TracesDataType)].processors[i] + traceProcessor := pipelines.pipelines[component.NewID(component.TracesDataType)].processors[i] assert.Equal(t, procID, traceProcessor.id) assert.True(t, traceProcessor.comp.(*testcomponents.ExampleProcessor).Started) // Validate metrics. - metricsProcessor := pipelines.pipelines[config.NewComponentID(config.MetricsDataType)].processors[i] + metricsProcessor := pipelines.pipelines[component.NewID(component.MetricsDataType)].processors[i] assert.Equal(t, procID, metricsProcessor.id) assert.True(t, metricsProcessor.comp.(*testcomponents.ExampleProcessor).Started) // Validate logs. - logsProcessor := pipelines.pipelines[config.NewComponentID(config.LogsDataType)].processors[i] + logsProcessor := pipelines.pipelines[component.NewID(component.LogsDataType)].processors[i] assert.Equal(t, procID, logsProcessor.id) assert.True(t, logsProcessor.comp.(*testcomponents.ExampleProcessor).Started) } // Verify receivers created, started and send data to confirm pipelines correctly connected. for _, recvID := range test.receiverIDs { - traceReceiver := pipelines.allReceivers[config.TracesDataType][recvID].(*testcomponents.ExampleReceiver) + traceReceiver := pipelines.allReceivers[component.TracesDataType][recvID].(*testcomponents.ExampleReceiver) assert.True(t, traceReceiver.Started) // Send traces. assert.NoError(t, traceReceiver.ConsumeTraces(context.Background(), testdata.GenerateTraces(1))) - metricsReceiver := pipelines.allReceivers[config.MetricsDataType][recvID].(*testcomponents.ExampleReceiver) + metricsReceiver := pipelines.allReceivers[component.MetricsDataType][recvID].(*testcomponents.ExampleReceiver) assert.True(t, metricsReceiver.Started) // Send metrics. assert.NoError(t, metricsReceiver.ConsumeMetrics(context.Background(), testdata.GenerateMetrics(1))) - logsReceiver := pipelines.allReceivers[config.LogsDataType][recvID].(*testcomponents.ExampleReceiver) + logsReceiver := pipelines.allReceivers[component.LogsDataType][recvID].(*testcomponents.ExampleReceiver) assert.True(t, logsReceiver.Started) // Send logs. assert.NoError(t, logsReceiver.ConsumeLogs(context.Background(), testdata.GenerateLogs(1))) @@ -153,46 +153,46 @@ func TestBuild(t *testing.T) { // Verify receivers shutdown. for _, recvID := range test.receiverIDs { - traceReceiver := pipelines.allReceivers[config.TracesDataType][recvID].(*testcomponents.ExampleReceiver) + traceReceiver := pipelines.allReceivers[component.TracesDataType][recvID].(*testcomponents.ExampleReceiver) assert.True(t, traceReceiver.Stopped) - metricsReceiver := pipelines.allReceivers[config.MetricsDataType][recvID].(*testcomponents.ExampleReceiver) + metricsReceiver := pipelines.allReceivers[component.MetricsDataType][recvID].(*testcomponents.ExampleReceiver) assert.True(t, metricsReceiver.Stopped) - logsReceiver := pipelines.allReceivers[config.LogsDataType][recvID].(*testcomponents.ExampleReceiver) + logsReceiver := pipelines.allReceivers[component.LogsDataType][recvID].(*testcomponents.ExampleReceiver) assert.True(t, logsReceiver.Stopped) } // Verify processors shutdown. for i := range test.processorIDs { - traceProcessor := pipelines.pipelines[config.NewComponentID(config.TracesDataType)].processors[i] + traceProcessor := pipelines.pipelines[component.NewID(component.TracesDataType)].processors[i] assert.True(t, traceProcessor.comp.(*testcomponents.ExampleProcessor).Stopped) // Validate metrics. - metricsProcessor := pipelines.pipelines[config.NewComponentID(config.MetricsDataType)].processors[i] + metricsProcessor := pipelines.pipelines[component.NewID(component.MetricsDataType)].processors[i] assert.True(t, metricsProcessor.comp.(*testcomponents.ExampleProcessor).Stopped) // Validate logs. - logsProcessor := pipelines.pipelines[config.NewComponentID(config.LogsDataType)].processors[i] + logsProcessor := pipelines.pipelines[component.NewID(component.LogsDataType)].processors[i] assert.True(t, logsProcessor.comp.(*testcomponents.ExampleProcessor).Stopped) } // Now verify that exporters received data, and are shutdown. for _, expID := range test.exporterIDs { // Validate traces. - traceExporter := pipelines.GetExporters()[config.TracesDataType][expID].(*testcomponents.ExampleExporter) + traceExporter := pipelines.GetExporters()[component.TracesDataType][expID].(*testcomponents.ExampleExporter) require.Len(t, traceExporter.Traces, test.expectedRequests) assert.EqualValues(t, testdata.GenerateTraces(1), traceExporter.Traces[0]) assert.True(t, traceExporter.Stopped) // Validate metrics. - metricsExporter := pipelines.GetExporters()[config.MetricsDataType][expID].(*testcomponents.ExampleExporter) + metricsExporter := pipelines.GetExporters()[component.MetricsDataType][expID].(*testcomponents.ExampleExporter) require.Len(t, metricsExporter.Metrics, test.expectedRequests) assert.EqualValues(t, testdata.GenerateMetrics(1), metricsExporter.Metrics[0]) assert.True(t, metricsExporter.Stopped) // Validate logs. - logsExporter := pipelines.GetExporters()[config.LogsDataType][expID].(*testcomponents.ExampleExporter) + logsExporter := pipelines.GetExporters()[component.LogsDataType][expID].(*testcomponents.ExampleExporter) require.Len(t, logsExporter.Logs, test.expectedRequests) assert.EqualValues(t, testdata.GenerateLogs(1), logsExporter.Logs[0]) assert.True(t, logsExporter.Stopped) @@ -232,17 +232,17 @@ func TestBuildErrors(t *testing.T) { for _, test := range tests { t.Run(test.configFile, func(t *testing.T) { factories := component.Factories{ - Receivers: map[config.Type]component.ReceiverFactory{ + Receivers: map[component.Type]component.ReceiverFactory{ nopReceiverFactory.Type(): nopReceiverFactory, "unknown": nopReceiverFactory, badReceiverFactory.Type(): badReceiverFactory, }, - Processors: map[config.Type]component.ProcessorFactory{ + Processors: map[component.Type]component.ProcessorFactory{ nopProcessorFactory.Type(): nopProcessorFactory, "unknown": nopProcessorFactory, badProcessorFactory.Type(): badProcessorFactory, }, - Exporters: map[config.Type]component.ExporterFactory{ + Exporters: map[component.Type]component.ExporterFactory{ nopExporterFactory.Type(): nopExporterFactory, "unknown": nopExporterFactory, badExporterFactory.Type(): badExporterFactory, @@ -274,39 +274,39 @@ func TestFailToStartAndShutdown(t *testing.T) { set := Settings{ Telemetry: componenttest.NewNopTelemetrySettings(), BuildInfo: component.NewDefaultBuildInfo(), - ReceiverFactories: map[config.Type]component.ReceiverFactory{ + ReceiverFactories: map[component.Type]component.ReceiverFactory{ nopReceiverFactory.Type(): nopReceiverFactory, errReceiverFactory.Type(): errReceiverFactory, }, - ReceiverConfigs: map[config.ComponentID]config.Receiver{ - config.NewComponentID(nopReceiverFactory.Type()): nopReceiverFactory.CreateDefaultConfig(), - config.NewComponentID(errReceiverFactory.Type()): errReceiverFactory.CreateDefaultConfig(), + ReceiverConfigs: map[component.ID]component.ReceiverConfig{ + component.NewID(nopReceiverFactory.Type()): nopReceiverFactory.CreateDefaultConfig(), + component.NewID(errReceiverFactory.Type()): errReceiverFactory.CreateDefaultConfig(), }, - ProcessorFactories: map[config.Type]component.ProcessorFactory{ + ProcessorFactories: map[component.Type]component.ProcessorFactory{ nopProcessorFactory.Type(): nopProcessorFactory, errProcessorFactory.Type(): errProcessorFactory, }, - ProcessorConfigs: map[config.ComponentID]config.Processor{ - config.NewComponentID(nopProcessorFactory.Type()): nopProcessorFactory.CreateDefaultConfig(), - config.NewComponentID(errProcessorFactory.Type()): errProcessorFactory.CreateDefaultConfig(), + ProcessorConfigs: map[component.ID]component.ProcessorConfig{ + component.NewID(nopProcessorFactory.Type()): nopProcessorFactory.CreateDefaultConfig(), + component.NewID(errProcessorFactory.Type()): errProcessorFactory.CreateDefaultConfig(), }, - ExporterFactories: map[config.Type]component.ExporterFactory{ + ExporterFactories: map[component.Type]component.ExporterFactory{ nopExporterFactory.Type(): nopExporterFactory, errExporterFactory.Type(): errExporterFactory, }, - ExporterConfigs: map[config.ComponentID]config.Exporter{ - config.NewComponentID(nopExporterFactory.Type()): nopExporterFactory.CreateDefaultConfig(), - config.NewComponentID(errExporterFactory.Type()): errExporterFactory.CreateDefaultConfig(), + ExporterConfigs: map[component.ID]component.ExporterConfig{ + component.NewID(nopExporterFactory.Type()): nopExporterFactory.CreateDefaultConfig(), + component.NewID(errExporterFactory.Type()): errExporterFactory.CreateDefaultConfig(), }, } - for _, dt := range []config.DataType{config.TracesDataType, config.MetricsDataType, config.LogsDataType} { + for _, dt := range []component.DataType{component.TracesDataType, component.MetricsDataType, component.LogsDataType} { t.Run(string(dt)+"/receiver", func(t *testing.T) { - set.PipelineConfigs = map[config.ComponentID]*config.Pipeline{ - config.NewComponentID(dt): { - Receivers: []config.ComponentID{config.NewComponentID("nop"), config.NewComponentID("err")}, - Processors: []config.ComponentID{config.NewComponentID("nop")}, - Exporters: []config.ComponentID{config.NewComponentID("nop")}, + set.PipelineConfigs = map[component.ID]*config.Pipeline{ + component.NewID(dt): { + Receivers: []component.ID{component.NewID("nop"), component.NewID("err")}, + Processors: []component.ID{component.NewID("nop")}, + Exporters: []component.ID{component.NewID("nop")}, }, } pipelines, err := Build(context.Background(), set) @@ -316,11 +316,11 @@ func TestFailToStartAndShutdown(t *testing.T) { }) t.Run(string(dt)+"/processor", func(t *testing.T) { - set.PipelineConfigs = map[config.ComponentID]*config.Pipeline{ - config.NewComponentID(dt): { - Receivers: []config.ComponentID{config.NewComponentID("nop")}, - Processors: []config.ComponentID{config.NewComponentID("nop"), config.NewComponentID("err")}, - Exporters: []config.ComponentID{config.NewComponentID("nop")}, + set.PipelineConfigs = map[component.ID]*config.Pipeline{ + component.NewID(dt): { + Receivers: []component.ID{component.NewID("nop")}, + Processors: []component.ID{component.NewID("nop"), component.NewID("err")}, + Exporters: []component.ID{component.NewID("nop")}, }, } pipelines, err := Build(context.Background(), set) @@ -330,11 +330,11 @@ func TestFailToStartAndShutdown(t *testing.T) { }) t.Run(string(dt)+"/exporter", func(t *testing.T) { - set.PipelineConfigs = map[config.ComponentID]*config.Pipeline{ - config.NewComponentID(dt): { - Receivers: []config.ComponentID{config.NewComponentID("nop")}, - Processors: []config.ComponentID{config.NewComponentID("nop")}, - Exporters: []config.ComponentID{config.NewComponentID("nop"), config.NewComponentID("err")}, + set.PipelineConfigs = map[component.ID]*config.Pipeline{ + component.NewID(dt): { + Receivers: []component.ID{component.NewID("nop")}, + Processors: []component.ID{component.NewID("nop")}, + Exporters: []component.ID{component.NewID("nop"), component.NewID("err")}, }, } pipelines, err := Build(context.Background(), set) @@ -346,90 +346,90 @@ func TestFailToStartAndShutdown(t *testing.T) { } func newBadReceiverFactory() component.ReceiverFactory { - return component.NewReceiverFactory("bf", func() config.Receiver { + return component.NewReceiverFactory("bf", func() component.ReceiverConfig { return &struct { - config.ReceiverSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct + component.ReceiverConfigSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct }{ - ReceiverSettings: config.NewReceiverSettings(config.NewComponentID("bf")), + ReceiverConfigSettings: component.NewReceiverConfigSettings(component.NewID("bf")), } }) } func newBadProcessorFactory() component.ProcessorFactory { - return component.NewProcessorFactory("bf", func() config.Processor { + return component.NewProcessorFactory("bf", func() component.ProcessorConfig { return &struct { - config.ProcessorSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct + component.ProcessorConfigSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct }{ - ProcessorSettings: config.NewProcessorSettings(config.NewComponentID("bf")), + ProcessorConfigSettings: component.NewProcessorConfigSettings(component.NewID("bf")), } }) } func newBadExporterFactory() component.ExporterFactory { - return component.NewExporterFactory("bf", func() config.Exporter { + return component.NewExporterFactory("bf", func() component.ExporterConfig { return &struct { - config.ExporterSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct + component.ExporterConfigSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct }{ - ExporterSettings: config.NewExporterSettings(config.NewComponentID("bf")), + ExporterConfigSettings: component.NewExporterConfigSettings(component.NewID("bf")), } }) } func newErrReceiverFactory() component.ReceiverFactory { - return component.NewReceiverFactory("err", func() config.Receiver { + return component.NewReceiverFactory("err", func() component.ReceiverConfig { return &struct { - config.ReceiverSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct + component.ReceiverConfigSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct }{ - ReceiverSettings: config.NewReceiverSettings(config.NewComponentID("bf")), + ReceiverConfigSettings: component.NewReceiverConfigSettings(component.NewID("bf")), } }, - component.WithTracesReceiver(func(context.Context, component.ReceiverCreateSettings, config.Receiver, consumer.Traces) (component.TracesReceiver, error) { + component.WithTracesReceiver(func(context.Context, component.ReceiverCreateSettings, component.ReceiverConfig, consumer.Traces) (component.TracesReceiver, error) { return &errComponent{}, nil }, component.StabilityLevelUndefined), - component.WithLogsReceiver(func(context.Context, component.ReceiverCreateSettings, config.Receiver, consumer.Logs) (component.LogsReceiver, error) { + component.WithLogsReceiver(func(context.Context, component.ReceiverCreateSettings, component.ReceiverConfig, consumer.Logs) (component.LogsReceiver, error) { return &errComponent{}, nil }, component.StabilityLevelUndefined), - component.WithMetricsReceiver(func(context.Context, component.ReceiverCreateSettings, config.Receiver, consumer.Metrics) (component.MetricsReceiver, error) { + component.WithMetricsReceiver(func(context.Context, component.ReceiverCreateSettings, component.ReceiverConfig, consumer.Metrics) (component.MetricsReceiver, error) { return &errComponent{}, nil }, component.StabilityLevelUndefined), ) } func newErrProcessorFactory() component.ProcessorFactory { - return component.NewProcessorFactory("err", func() config.Processor { + return component.NewProcessorFactory("err", func() component.ProcessorConfig { return &struct { - config.ProcessorSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct + component.ProcessorConfigSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct }{ - ProcessorSettings: config.NewProcessorSettings(config.NewComponentID("bf")), + ProcessorConfigSettings: component.NewProcessorConfigSettings(component.NewID("bf")), } }, - component.WithTracesProcessor(func(context.Context, component.ProcessorCreateSettings, config.Processor, consumer.Traces) (component.TracesProcessor, error) { + component.WithTracesProcessor(func(context.Context, component.ProcessorCreateSettings, component.ProcessorConfig, consumer.Traces) (component.TracesProcessor, error) { return &errComponent{}, nil }, component.StabilityLevelUndefined), - component.WithLogsProcessor(func(context.Context, component.ProcessorCreateSettings, config.Processor, consumer.Logs) (component.LogsProcessor, error) { + component.WithLogsProcessor(func(context.Context, component.ProcessorCreateSettings, component.ProcessorConfig, consumer.Logs) (component.LogsProcessor, error) { return &errComponent{}, nil }, component.StabilityLevelUndefined), - component.WithMetricsProcessor(func(context.Context, component.ProcessorCreateSettings, config.Processor, consumer.Metrics) (component.MetricsProcessor, error) { + component.WithMetricsProcessor(func(context.Context, component.ProcessorCreateSettings, component.ProcessorConfig, consumer.Metrics) (component.MetricsProcessor, error) { return &errComponent{}, nil }, component.StabilityLevelUndefined), ) } func newErrExporterFactory() component.ExporterFactory { - return component.NewExporterFactory("err", func() config.Exporter { + return component.NewExporterFactory("err", func() component.ExporterConfig { return &struct { - config.ExporterSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct + component.ExporterConfigSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct }{ - ExporterSettings: config.NewExporterSettings(config.NewComponentID("bf")), + ExporterConfigSettings: component.NewExporterConfigSettings(component.NewID("bf")), } }, - component.WithTracesExporter(func(context.Context, component.ExporterCreateSettings, config.Exporter) (component.TracesExporter, error) { + component.WithTracesExporter(func(context.Context, component.ExporterCreateSettings, component.ExporterConfig) (component.TracesExporter, error) { return &errComponent{}, nil }, component.StabilityLevelUndefined), - component.WithLogsExporter(func(context.Context, component.ExporterCreateSettings, config.Exporter) (component.LogsExporter, error) { + component.WithLogsExporter(func(context.Context, component.ExporterCreateSettings, component.ExporterConfig) (component.LogsExporter, error) { return &errComponent{}, nil }, component.StabilityLevelUndefined), - component.WithMetricsExporter(func(context.Context, component.ExporterCreateSettings, config.Exporter) (component.MetricsExporter, error) { + component.WithMetricsExporter(func(context.Context, component.ExporterCreateSettings, component.ExporterConfig) (component.MetricsExporter, error) { return &errComponent{}, nil }, component.StabilityLevelUndefined), ) @@ -474,7 +474,7 @@ type configSettings struct { } type serviceSettings struct { - Pipelines map[config.ComponentID]*config.Pipeline `mapstructure:"pipelines"` + Pipelines map[component.ID]*config.Pipeline `mapstructure:"pipelines"` } func loadConfig(t *testing.T, fileName string, factories component.Factories) *configSettings { diff --git a/service/internal/testcomponents/example_exporter.go b/service/internal/testcomponents/example_exporter.go index 37e4709b78d..c44d666f6d5 100644 --- a/service/internal/testcomponents/example_exporter.go +++ b/service/internal/testcomponents/example_exporter.go @@ -18,7 +18,6 @@ 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" @@ -32,7 +31,7 @@ const ( // ExampleExporterConfig config for ExampleExporter. type ExampleExporterConfig struct { - config.ExporterSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct + component.ExporterConfigSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct } // ExampleExporterFactory is factory for ExampleExporter. @@ -44,21 +43,21 @@ var ExampleExporterFactory = component.NewExporterFactory( component.WithLogsExporter(createLogsExporter, stability), ) -func createExporterDefaultConfig() config.Exporter { +func createExporterDefaultConfig() component.ExporterConfig { return &ExampleExporterConfig{ - ExporterSettings: config.NewExporterSettings(config.NewComponentID(typeStr)), + ExporterConfigSettings: component.NewExporterConfigSettings(component.NewID(typeStr)), } } -func createTracesExporter(context.Context, component.ExporterCreateSettings, config.Exporter) (component.TracesExporter, error) { +func createTracesExporter(context.Context, component.ExporterCreateSettings, component.ExporterConfig) (component.TracesExporter, error) { return &ExampleExporter{}, nil } -func createMetricsExporter(context.Context, component.ExporterCreateSettings, config.Exporter) (component.MetricsExporter, error) { +func createMetricsExporter(context.Context, component.ExporterCreateSettings, component.ExporterConfig) (component.MetricsExporter, error) { return &ExampleExporter{}, nil } -func createLogsExporter(context.Context, component.ExporterCreateSettings, config.Exporter) (component.LogsExporter, error) { +func createLogsExporter(context.Context, component.ExporterCreateSettings, component.ExporterConfig) (component.LogsExporter, error) { return &ExampleExporter{}, nil } diff --git a/service/internal/testcomponents/example_factories.go b/service/internal/testcomponents/example_factories.go index 19133436980..ac5f21f433f 100644 --- a/service/internal/testcomponents/example_factories.go +++ b/service/internal/testcomponents/example_factories.go @@ -16,19 +16,18 @@ package testcomponents // import "go.opentelemetry.io/collector/service/internal import ( "go.opentelemetry.io/collector/component" - "go.opentelemetry.io/collector/config" ) // ExampleComponents registers example factories. This is only used by tests. func ExampleComponents() (component.Factories, error) { return component.Factories{ - Receivers: map[config.Type]component.ReceiverFactory{ + Receivers: map[component.Type]component.ReceiverFactory{ ExampleReceiverFactory.Type(): ExampleReceiverFactory, }, - Processors: map[config.Type]component.ProcessorFactory{ + Processors: map[component.Type]component.ProcessorFactory{ ExampleProcessorFactory.Type(): ExampleProcessorFactory, }, - Exporters: map[config.Type]component.ExporterFactory{ + Exporters: map[component.Type]component.ExporterFactory{ ExampleExporterFactory.Type(): ExampleExporterFactory, }, }, nil diff --git a/service/internal/testcomponents/example_processor.go b/service/internal/testcomponents/example_processor.go index 660059168c6..bf32030daf5 100644 --- a/service/internal/testcomponents/example_processor.go +++ b/service/internal/testcomponents/example_processor.go @@ -18,7 +18,6 @@ import ( "context" "go.opentelemetry.io/collector/component" - "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/consumer" ) @@ -26,7 +25,7 @@ const procType = "exampleprocessor" // ExampleProcessorConfig config for ExampleProcessor. type ExampleProcessorConfig struct { - config.ProcessorSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct + component.ProcessorConfigSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct } // ExampleProcessorFactory is factory for ExampleProcessor. @@ -38,21 +37,21 @@ var ExampleProcessorFactory = component.NewProcessorFactory( component.WithLogsProcessor(createLogsProcessor, component.StabilityLevelInDevelopment)) // CreateDefaultConfig creates the default configuration for the Processor. -func createDefaultConfig() config.Processor { +func createDefaultConfig() component.ProcessorConfig { return &ExampleProcessorConfig{ - ProcessorSettings: config.NewProcessorSettings(config.NewComponentID(procType)), + ProcessorConfigSettings: component.NewProcessorConfigSettings(component.NewID(procType)), } } -func createTracesProcessor(_ context.Context, _ component.ProcessorCreateSettings, _ config.Processor, nextConsumer consumer.Traces) (component.TracesProcessor, error) { +func createTracesProcessor(_ context.Context, _ component.ProcessorCreateSettings, _ component.ProcessorConfig, nextConsumer consumer.Traces) (component.TracesProcessor, error) { return &ExampleProcessor{Traces: nextConsumer}, nil } -func createMetricsProcessor(_ context.Context, _ component.ProcessorCreateSettings, _ config.Processor, nextConsumer consumer.Metrics) (component.MetricsProcessor, error) { +func createMetricsProcessor(_ context.Context, _ component.ProcessorCreateSettings, _ component.ProcessorConfig, nextConsumer consumer.Metrics) (component.MetricsProcessor, error) { return &ExampleProcessor{Metrics: nextConsumer}, nil } -func createLogsProcessor(_ context.Context, _ component.ProcessorCreateSettings, _ config.Processor, nextConsumer consumer.Logs) (component.LogsProcessor, error) { +func createLogsProcessor(_ context.Context, _ component.ProcessorCreateSettings, _ component.ProcessorConfig, nextConsumer consumer.Logs) (component.LogsProcessor, error) { return &ExampleProcessor{Logs: nextConsumer}, nil } diff --git a/service/internal/testcomponents/example_receiver.go b/service/internal/testcomponents/example_receiver.go index 847dc00c411..7a1b4cc2c9d 100644 --- a/service/internal/testcomponents/example_receiver.go +++ b/service/internal/testcomponents/example_receiver.go @@ -18,15 +18,14 @@ import ( "context" "go.opentelemetry.io/collector/component" - "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/consumer" ) -const receiverType = config.Type("examplereceiver") +const receiverType = component.Type("examplereceiver") // ExampleReceiverConfig config for ExampleReceiver. type ExampleReceiverConfig struct { - config.ReceiverSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct + component.ReceiverConfigSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct } // ExampleReceiverFactory is factory for ExampleReceiver. @@ -37,9 +36,9 @@ var ExampleReceiverFactory = component.NewReceiverFactory( component.WithMetricsReceiver(createMetricsReceiver, component.StabilityLevelInDevelopment), component.WithLogsReceiver(createLogsReceiver, component.StabilityLevelInDevelopment)) -func createReceiverDefaultConfig() config.Receiver { +func createReceiverDefaultConfig() component.ReceiverConfig { return &ExampleReceiverConfig{ - ReceiverSettings: config.NewReceiverSettings(config.NewComponentID(receiverType)), + ReceiverConfigSettings: component.NewReceiverConfigSettings(component.NewID(receiverType)), } } @@ -47,7 +46,7 @@ func createReceiverDefaultConfig() config.Receiver { func createTracesReceiver( _ context.Context, _ component.ReceiverCreateSettings, - cfg config.Receiver, + cfg component.ReceiverConfig, nextConsumer consumer.Traces, ) (component.TracesReceiver, error) { receiver := createReceiver(cfg) @@ -59,7 +58,7 @@ func createTracesReceiver( func createMetricsReceiver( _ context.Context, _ component.ReceiverCreateSettings, - cfg config.Receiver, + cfg component.ReceiverConfig, nextConsumer consumer.Metrics, ) (component.MetricsReceiver, error) { receiver := createReceiver(cfg) @@ -70,7 +69,7 @@ func createMetricsReceiver( func createLogsReceiver( _ context.Context, _ component.ReceiverCreateSettings, - cfg config.Receiver, + cfg component.ReceiverConfig, nextConsumer consumer.Logs, ) (component.LogsReceiver, error) { receiver := createReceiver(cfg) @@ -78,7 +77,7 @@ func createLogsReceiver( return receiver, nil } -func createReceiver(cfg config.Receiver) *ExampleReceiver { +func createReceiver(cfg component.ReceiverConfig) *ExampleReceiver { // There must be one receiver for all data types. We maintain a map of // receivers per config. @@ -118,4 +117,4 @@ func (erp *ExampleReceiver) Shutdown(context.Context) error { // We maintain this map because the ReceiverFactory is asked trace and metric receivers separately // when it gets CreateTracesReceiver() and CreateMetricsReceiver() but they must not // create separate objects, they must use one Receiver object per configuration. -var exampleReceivers = map[config.Receiver]*ExampleReceiver{} +var exampleReceivers = map[component.ReceiverConfig]*ExampleReceiver{} diff --git a/service/service_test.go b/service/service_test.go index 59ac56b000f..ab70b155198 100644 --- a/service/service_test.go +++ b/service/service_test.go @@ -26,7 +26,6 @@ import ( "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/component/componenttest" - "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/featuregate" ) @@ -69,7 +68,7 @@ func TestServiceGetExtensions(t *testing.T) { extMap := srv.host.GetExtensions() assert.Len(t, extMap, 1) - assert.Contains(t, extMap, config.NewComponentID("nop")) + assert.Contains(t, extMap, component.NewID("nop")) } func TestServiceGetExporters(t *testing.T) { @@ -84,12 +83,12 @@ func TestServiceGetExporters(t *testing.T) { expMap := srv.host.GetExporters() assert.Len(t, expMap, 3) - assert.Len(t, expMap[config.TracesDataType], 1) - assert.Contains(t, expMap[config.TracesDataType], config.NewComponentID("nop")) - assert.Len(t, expMap[config.MetricsDataType], 1) - assert.Contains(t, expMap[config.MetricsDataType], config.NewComponentID("nop")) - assert.Len(t, expMap[config.LogsDataType], 1) - assert.Contains(t, expMap[config.LogsDataType], config.NewComponentID("nop")) + assert.Len(t, expMap[component.TracesDataType], 1) + assert.Contains(t, expMap[component.TracesDataType], component.NewID("nop")) + assert.Len(t, expMap[component.MetricsDataType], 1) + assert.Contains(t, expMap[component.MetricsDataType], component.NewID("nop")) + assert.Len(t, expMap[component.LogsDataType], 1) + assert.Contains(t, expMap[component.LogsDataType], component.NewID("nop")) } // TestServiceTelemetryCleanupOnError tests that if newService errors due to an invalid config telemetry is cleaned up diff --git a/service/servicetest/configprovider_test.go b/service/servicetest/configprovider_test.go index 4194500ab3e..e022eb76c14 100644 --- a/service/servicetest/configprovider_test.go +++ b/service/servicetest/configprovider_test.go @@ -21,6 +21,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/component/componenttest" "go.opentelemetry.io/collector/config" ) @@ -34,35 +35,35 @@ func TestLoadConfig(t *testing.T) { // Verify extensions. require.Len(t, cfg.Extensions, 2) - assert.Contains(t, cfg.Extensions, config.NewComponentID("nop")) - assert.Contains(t, cfg.Extensions, config.NewComponentIDWithName("nop", "myextension")) + assert.Contains(t, cfg.Extensions, component.NewID("nop")) + assert.Contains(t, cfg.Extensions, component.NewIDWithName("nop", "myextension")) // Verify receivers require.Len(t, cfg.Receivers, 2) - assert.Contains(t, cfg.Receivers, config.NewComponentID("nop")) - assert.Contains(t, cfg.Receivers, config.NewComponentIDWithName("nop", "myreceiver")) + assert.Contains(t, cfg.Receivers, component.NewID("nop")) + assert.Contains(t, cfg.Receivers, component.NewIDWithName("nop", "myreceiver")) // Verify exporters assert.Len(t, cfg.Exporters, 2) - assert.Contains(t, cfg.Exporters, config.NewComponentID("nop")) - assert.Contains(t, cfg.Exporters, config.NewComponentIDWithName("nop", "myexporter")) + assert.Contains(t, cfg.Exporters, component.NewID("nop")) + assert.Contains(t, cfg.Exporters, component.NewIDWithName("nop", "myexporter")) // Verify procs assert.Len(t, cfg.Processors, 2) - assert.Contains(t, cfg.Processors, config.NewComponentID("nop")) - assert.Contains(t, cfg.Processors, config.NewComponentIDWithName("nop", "myprocessor")) + assert.Contains(t, cfg.Processors, component.NewID("nop")) + assert.Contains(t, cfg.Processors, component.NewIDWithName("nop", "myprocessor")) // Verify service. require.Len(t, cfg.Service.Extensions, 1) - assert.Contains(t, cfg.Service.Extensions, config.NewComponentID("nop")) + assert.Contains(t, cfg.Service.Extensions, component.NewID("nop")) require.Len(t, cfg.Service.Pipelines, 1) assert.Equal(t, &config.Pipeline{ - Receivers: []config.ComponentID{config.NewComponentID("nop")}, - Processors: []config.ComponentID{config.NewComponentID("nop")}, - Exporters: []config.ComponentID{config.NewComponentID("nop")}, + Receivers: []component.ID{component.NewID("nop")}, + Processors: []component.ID{component.NewID("nop")}, + Exporters: []component.ID{component.NewID("nop")}, }, - cfg.Service.Pipelines[config.NewComponentID("traces")], + cfg.Service.Pipelines[component.NewID("traces")], "Did not load pipeline config correctly") } diff --git a/service/unmarshaler_test.go b/service/unmarshaler_test.go index 1f385047bdc..c973c53685e 100644 --- a/service/unmarshaler_test.go +++ b/service/unmarshaler_test.go @@ -21,8 +21,8 @@ import ( "github.com/stretchr/testify/require" "go.uber.org/zap" + "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/component/componenttest" - "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/confmap" "go.opentelemetry.io/collector/service/telemetry" ) @@ -137,7 +137,7 @@ func TestConfigServicePipelineUnmarshalError(t *testing.T) { for _, tt := range testCases { t.Run(tt.name, func(t *testing.T) { - pipelines := make(map[config.ComponentID]ConfigServicePipeline) + pipelines := make(map[component.ID]ConfigServicePipeline) err := tt.conf.Unmarshal(&pipelines, confmap.WithErrorUnused()) require.Error(t, err) assert.Contains(t, err.Error(), tt.expectError)