From c8835faf52a91d1939b7476f0bc98d4ad3b603f0 Mon Sep 17 00:00:00 2001 From: Bogdan Drutu Date: Tue, 15 Nov 2022 12:57:50 -0800 Subject: [PATCH] Draft changes to show how we can split component Signed-off-by: Bogdan Drutu --- CHANGELOG.md | 2 +- cmd/otelcorecol/components.go | 38 +-- component/component.go | 4 +- component/component_test.go | 2 +- component/componenttest/nop_exporter.go | 23 +- component/componenttest/nop_extension.go | 15 +- component/componenttest/nop_factories.go | 22 +- component/componenttest/nop_host.go | 8 +- component/config.go | 24 +- component/exporter.go | 225 ------------------ component/host.go | 4 +- component/processor.go | 7 +- component/receiver.go | 7 +- config/configauth/clientauth.go | 4 +- config/configauth/configauth.go | 5 +- config/configauth/configauth_test.go | 13 +- config/configauth/serverauth.go | 4 +- config/configgrpc/configgrpc_test.go | 15 +- config/confighttp/confighttp_test.go | 25 +- config/exporter.go | 5 +- config/extension.go | 5 +- exporter/exporter.go | 220 +++++++++++++++++ {component => exporter}/exporter_test.go | 39 +-- exporter/exporterhelper/common.go | 3 +- exporter/exporterhelper/logs.go | 7 +- exporter/exporterhelper/logs_test.go | 9 +- exporter/exporterhelper/metrics.go | 7 +- exporter/exporterhelper/metrics_test.go | 9 +- exporter/exporterhelper/queued_retry.go | 3 +- exporter/exporterhelper/queued_retry_test.go | 13 +- exporter/exporterhelper/traces.go | 7 +- exporter/exporterhelper/traces_test.go | 9 +- exporter/loggingexporter/config.go | 4 +- exporter/loggingexporter/config_test.go | 5 +- exporter/loggingexporter/factory.go | 19 +- exporter/otlpexporter/config.go | 4 +- exporter/otlpexporter/config_test.go | 5 +- exporter/otlpexporter/factory.go | 31 +-- exporter/otlpexporter/otlp.go | 3 +- exporter/otlpexporter/otlp_test.go | 4 +- exporter/otlphttpexporter/config.go | 4 +- exporter/otlphttpexporter/config_test.go | 5 +- exporter/otlphttpexporter/factory.go | 31 +-- exporter/otlphttpexporter/otlp.go | 3 +- exporter/otlphttpexporter/otlp_test.go | 9 +- extension/ballastextension/config_test.go | 5 +- extension/ballastextension/factory.go | 9 +- extension/experimental/storage/storage.go | 3 +- {component => extension}/extension.go | 92 +++---- {component => extension}/extension_test.go | 11 +- extension/zpagesextension/config.go | 4 +- extension/zpagesextension/config_test.go | 5 +- extension/zpagesextension/factory.go | 9 +- obsreport/obsreport_exporter.go | 9 +- obsreport/obsreporttest/obsreporttest.go | 3 +- .../memorylimiter_test.go | 5 +- service/config.go | 6 +- service/config_provider.go | 5 +- service/config_provider_test.go | 6 +- service/config_test.go | 6 +- service/extensions/extensions.go | 23 +- service/extensions/extensions_test.go | 36 +-- {component => service}/factories.go | 30 ++- {component => service}/factories_test.go | 62 ++--- service/host.go | 10 +- .../internal/configunmarshaler/exporters.go | 13 +- .../configunmarshaler/exporters_test.go | 3 +- .../internal/configunmarshaler/extensions.go | 13 +- .../configunmarshaler/extensions_test.go | 3 +- service/internal/pipelines/pipelines.go | 39 +-- service/internal/pipelines/pipelines_test.go | 28 ++- .../testcomponents/example_exporter.go | 17 +- .../testcomponents/example_factories.go | 8 +- service/service_test.go | 2 +- service/servicetest/configprovider.go | 5 +- service/settings.go | 4 +- service/unmarshaler.go | 3 +- 77 files changed, 727 insertions(+), 660 deletions(-) delete mode 100644 component/exporter.go create mode 100644 exporter/exporter.go rename {component => exporter}/exporter_test.go (51%) rename {component => extension}/extension.go (54%) rename {component => extension}/extension_test.go (79%) rename {component => service}/factories.go (70%) rename {component => service}/factories_test.go (62%) diff --git a/CHANGELOG.md b/CHANGELOG.md index a5466919731..fa4eb549e86 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -917,7 +917,7 @@ There isn't a valid core binary for this release. Use v0.57.2 instead. - Deprecated `exporterhelper.WithTraces` in favour of `component.WithTracesExporter` - Deprecated `exporterhelper.WithMetrics` in favour of `component.WithMetricsExporter` - Deprecated `exporterhelper.WithLogs` in favour of `component.WithLogsExporter` - - Deprecated `exporterhelper.NewFactory` in favour of `component.NewExporterFactory` + - Deprecated `exporterhelper.NewFactory` in favour of `component.NewFactory` - Move helpers from receiverhelper to component (#4891) - Deprecated `receiverhelper.CreateDefaultConfig` in favour of `component.ReceiverDefaultConfigFunc` - Deprecated `receiverhelper.WithTraces` in favour of `component.WithTracesReceiver` diff --git a/cmd/otelcorecol/components.go b/cmd/otelcorecol/components.go index 9156edaad1a..3ece3203c68 100644 --- a/cmd/otelcorecol/components.go +++ b/cmd/otelcorecol/components.go @@ -3,51 +3,51 @@ package main import ( - "go.opentelemetry.io/collector/component" - loggingexporter "go.opentelemetry.io/collector/exporter/loggingexporter" - otlpexporter "go.opentelemetry.io/collector/exporter/otlpexporter" - otlphttpexporter "go.opentelemetry.io/collector/exporter/otlphttpexporter" - ballastextension "go.opentelemetry.io/collector/extension/ballastextension" - zpagesextension "go.opentelemetry.io/collector/extension/zpagesextension" - batchprocessor "go.opentelemetry.io/collector/processor/batchprocessor" - memorylimiterprocessor "go.opentelemetry.io/collector/processor/memorylimiterprocessor" - otlpreceiver "go.opentelemetry.io/collector/receiver/otlpreceiver" + "go.opentelemetry.io/collector/exporter/loggingexporter" + "go.opentelemetry.io/collector/exporter/otlpexporter" + "go.opentelemetry.io/collector/exporter/otlphttpexporter" + "go.opentelemetry.io/collector/extension/ballastextension" + "go.opentelemetry.io/collector/extension/zpagesextension" + "go.opentelemetry.io/collector/processor/batchprocessor" + "go.opentelemetry.io/collector/processor/memorylimiterprocessor" + "go.opentelemetry.io/collector/receiver/otlpreceiver" + "go.opentelemetry.io/collector/service" ) -func components() (component.Factories, error) { +func components() (service.Factories, error) { var err error - factories := component.Factories{} + factories := service.Factories{} - factories.Extensions, err = component.MakeExtensionFactoryMap( + factories.Extensions, err = service.MakeExtensionFactoryMap( ballastextension.NewFactory(), zpagesextension.NewFactory(), ) if err != nil { - return component.Factories{}, err + return service.Factories{}, err } - factories.Receivers, err = component.MakeReceiverFactoryMap( + factories.Receivers, err = service.MakeReceiverFactoryMap( otlpreceiver.NewFactory(), ) if err != nil { - return component.Factories{}, err + return service.Factories{}, err } - factories.Exporters, err = component.MakeExporterFactoryMap( + factories.Exporters, err = service.MakeExporterFactoryMap( loggingexporter.NewFactory(), otlpexporter.NewFactory(), otlphttpexporter.NewFactory(), ) if err != nil { - return component.Factories{}, err + return service.Factories{}, err } - factories.Processors, err = component.MakeProcessorFactoryMap( + factories.Processors, err = service.MakeProcessorFactoryMap( batchprocessor.NewFactory(), memorylimiterprocessor.NewFactory(), ) if err != nil { - return component.Factories{}, err + return service.Factories{}, err } return factories, nil diff --git a/component/component.go b/component/component.go index 277bf938fa8..0953e64df08 100644 --- a/component/component.go +++ b/component/component.go @@ -161,15 +161,13 @@ func (sl StabilityLevel) LogMessage() string { type Factory interface { // Type gets the type of the component created by this factory. Type() Type - - unexportedFactoryFunc() } type baseFactory struct { cfgType Type } -func (baseFactory) unexportedFactoryFunc() {} +func (baseFactory) unexportedFunc() {} func (bf baseFactory) Type() Type { return bf.cfgType diff --git a/component/component_test.go b/component/component_test.go index 7f59fbc1319..dd6839d5a40 100644 --- a/component/component_test.go +++ b/component/component_test.go @@ -22,5 +22,5 @@ import ( func TestBaseInternal(t *testing.T) { base := baseFactory{} - assert.NotPanics(t, base.unexportedFactoryFunc) + assert.NotPanics(t, base.unexportedFunc) } diff --git a/component/componenttest/nop_exporter.go b/component/componenttest/nop_exporter.go index 2617d7c29d1..e1468943d47 100644 --- a/component/componenttest/nop_exporter.go +++ b/component/componenttest/nop_exporter.go @@ -20,11 +20,12 @@ import ( "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/consumer/consumertest" + "go.opentelemetry.io/collector/exporter" ) // NewNopExporterCreateSettings returns a new nop settings for Create*Exporter functions. -func NewNopExporterCreateSettings() component.ExporterCreateSettings { - return component.ExporterCreateSettings{ +func NewNopExporterCreateSettings() exporter.CreateSettings { + return exporter.CreateSettings{ TelemetrySettings: NewNopTelemetrySettings(), BuildInfo: component.NewDefaultBuildInfo(), } @@ -35,29 +36,29 @@ type nopExporterConfig struct { } // NewNopExporterFactory returns a component.ExporterFactory that constructs nop exporters. -func NewNopExporterFactory() component.ExporterFactory { - return component.NewExporterFactory( +func NewNopExporterFactory() exporter.Factory { + return exporter.NewFactory( "nop", - func() component.ExporterConfig { + func() exporter.Config { return &nopExporterConfig{ ExporterSettings: config.NewExporterSettings(component.NewID("nop")), } }, - component.WithTracesExporter(createTracesExporter, component.StabilityLevelStable), - component.WithMetricsExporter(createMetricsExporter, component.StabilityLevelStable), - component.WithLogsExporter(createLogsExporter, component.StabilityLevelStable), + exporter.WithTracesExporter(createTracesExporter, component.StabilityLevelStable), + exporter.WithMetricsExporter(createMetricsExporter, component.StabilityLevelStable), + exporter.WithLogsExporter(createLogsExporter, component.StabilityLevelStable), ) } -func createTracesExporter(context.Context, component.ExporterCreateSettings, component.ExporterConfig) (component.TracesExporter, error) { +func createTracesExporter(context.Context, exporter.CreateSettings, exporter.Config) (exporter.TracesExporter, error) { return nopExporterInstance, nil } -func createMetricsExporter(context.Context, component.ExporterCreateSettings, component.ExporterConfig) (component.MetricsExporter, error) { +func createMetricsExporter(context.Context, exporter.CreateSettings, exporter.Config) (exporter.MetricsExporter, error) { return nopExporterInstance, nil } -func createLogsExporter(context.Context, component.ExporterCreateSettings, component.ExporterConfig) (component.LogsExporter, error) { +func createLogsExporter(context.Context, exporter.CreateSettings, exporter.Config) (exporter.LogsExporter, error) { return nopExporterInstance, nil } diff --git a/component/componenttest/nop_extension.go b/component/componenttest/nop_extension.go index 8960e530012..12f28f887c8 100644 --- a/component/componenttest/nop_extension.go +++ b/component/componenttest/nop_extension.go @@ -19,11 +19,12 @@ import ( "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/config" + "go.opentelemetry.io/collector/extension" ) // NewNopExtensionCreateSettings returns a new nop settings for Create*Extension functions. -func NewNopExtensionCreateSettings() component.ExtensionCreateSettings { - return component.ExtensionCreateSettings{ +func NewNopExtensionCreateSettings() extension.CreateSettings { + return extension.CreateSettings{ TelemetrySettings: NewNopTelemetrySettings(), BuildInfo: component.NewDefaultBuildInfo(), } @@ -33,16 +34,16 @@ type nopExtensionConfig struct { config.ExtensionSettings `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( +// NewNopExtensionFactory returns a component.Factory that constructs nop extensions. +func NewNopExtensionFactory() extension.Factory { + return extension.NewExtensionFactory( "nop", - func() component.ExtensionConfig { + func() extension.Config { return &nopExtensionConfig{ ExtensionSettings: config.NewExtensionSettings(component.NewID("nop")), } }, - func(context.Context, component.ExtensionCreateSettings, component.ExtensionConfig) (component.Extension, error) { + func(context.Context, extension.CreateSettings, extension.Config) (extension.Extension, error) { return nopExtensionInstance, nil }, component.StabilityLevelStable) diff --git a/component/componenttest/nop_factories.go b/component/componenttest/nop_factories.go index 03b026cc699..14073ba3b2e 100644 --- a/component/componenttest/nop_factories.go +++ b/component/componenttest/nop_factories.go @@ -15,28 +15,28 @@ package componenttest // import "go.opentelemetry.io/collector/component/componenttest" import ( - "go.opentelemetry.io/collector/component" + "go.opentelemetry.io/collector/service" ) // NopFactories returns a component.Factories with all nop factories. -func NopFactories() (component.Factories, error) { - var factories component.Factories +func NopFactories() (service.Factories, error) { + var factories service.Factories var err error - if factories.Extensions, err = component.MakeExtensionFactoryMap(NewNopExtensionFactory()); err != nil { - return component.Factories{}, err + if factories.Extensions, err = service.MakeExtensionFactoryMap(NewNopExtensionFactory()); err != nil { + return service.Factories{}, err } - if factories.Receivers, err = component.MakeReceiverFactoryMap(NewNopReceiverFactory()); err != nil { - return component.Factories{}, err + if factories.Receivers, err = service.MakeReceiverFactoryMap(NewNopReceiverFactory()); err != nil { + return service.Factories{}, err } - if factories.Exporters, err = component.MakeExporterFactoryMap(NewNopExporterFactory()); err != nil { - return component.Factories{}, err + if factories.Exporters, err = service.MakeExporterFactoryMap(NewNopExporterFactory()); err != nil { + return service.Factories{}, err } - if factories.Processors, err = component.MakeProcessorFactoryMap(NewNopProcessorFactory()); err != nil { - return component.Factories{}, err + if factories.Processors, err = service.MakeProcessorFactoryMap(NewNopProcessorFactory()); err != nil { + return service.Factories{}, err } return factories, err diff --git a/component/componenttest/nop_host.go b/component/componenttest/nop_host.go index b535b674af6..1adb43784bc 100644 --- a/component/componenttest/nop_host.go +++ b/component/componenttest/nop_host.go @@ -16,6 +16,8 @@ package componenttest // import "go.opentelemetry.io/collector/component/compone import ( "go.opentelemetry.io/collector/component" + "go.opentelemetry.io/collector/exporter" + "go.opentelemetry.io/collector/extension" ) // nopHost mocks a receiver.ReceiverHost for test purposes. @@ -32,10 +34,10 @@ func (nh *nopHost) GetFactory(_ component.Kind, _ component.Type) component.Fact return nil } -func (nh *nopHost) GetExtensions() map[component.ID]component.Extension { +func (nh *nopHost) GetExtensions() map[component.ID]extension.Extension { return nil } -func (nh *nopHost) GetExporters() map[component.DataType]map[component.ID]component.Exporter { - return nil +func (nh *nopHost) GetExporters() map[component.DataType]map[component.ID]exporter. { +return nil } diff --git a/component/config.go b/component/config.go index 3fb147b78e1..9d06b0e8913 100644 --- a/component/config.go +++ b/component/config.go @@ -21,6 +21,22 @@ import ( // Type is the component type as it is used in the config. type Type string +type Config interface { + identifiable + validatable +} + +// UnmarshalConfig helper function to unmarshal a Config. +// It checks if the config implements confmap.Unmarshaler and uses that if available, +// otherwise uses Map.UnmarshalExact, erroring if a field is nonexistent. +func UnmarshalConfig(conf *confmap.Conf, cfg Config) error { + if cu, ok := cfg.(confmap.Unmarshaler); ok { + return cu.Unmarshal(conf) + } + + return conf.Unmarshal(cfg, confmap.WithErrorUnused()) +} + // validatable defines the interface for the configuration validation. type validatable interface { // Validate validates the configuration and returns an error if invalid. @@ -42,11 +58,3 @@ const ( // DataTypeLogs is the data type tag for logs. DataTypeLogs DataType = "logs" ) - -func unmarshal(componentSection *confmap.Conf, intoCfg interface{}) error { - if cu, ok := intoCfg.(confmap.Unmarshaler); ok { - return cu.Unmarshal(componentSection) - } - - return componentSection.Unmarshal(intoCfg, confmap.WithErrorUnused()) -} diff --git a/component/exporter.go b/component/exporter.go deleted file mode 100644 index d0e1c595a8e..00000000000 --- a/component/exporter.go +++ /dev/null @@ -1,225 +0,0 @@ -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package component // import "go.opentelemetry.io/collector/component" - -import ( - "context" - - "go.opentelemetry.io/collector/confmap" - "go.opentelemetry.io/collector/consumer" -) - -// ExporterConfig is the configuration of a component.Exporter. Specific Exporter must implement -// this interface and must embed config.ExporterSettings struct or a struct that extends it. -type ExporterConfig interface { - identifiable - validatable - - privateConfigExporter() -} - -// UnmarshalExporterConfig helper function to unmarshal an ExporterConfig. -// It checks if the config implements confmap.Unmarshaler and uses that if available, -// otherwise uses Map.UnmarshalExact, erroring if a field is nonexistent. -func UnmarshalExporterConfig(conf *confmap.Conf, cfg ExporterConfig) error { - return unmarshal(conf, cfg) -} - -// Exporter exports telemetry data from the collector to a destination. -type Exporter interface { - Component -} - -// TracesExporter is an Exporter that can consume traces. -type TracesExporter interface { - Exporter - consumer.Traces -} - -// MetricsExporter is an Exporter that can consume metrics. -type MetricsExporter interface { - Exporter - consumer.Metrics -} - -// LogsExporter is an Exporter that can consume logs. -type LogsExporter interface { - Exporter - consumer.Logs -} - -// ExporterCreateSettings configures Exporter creators. -type ExporterCreateSettings struct { - TelemetrySettings - - // BuildInfo can be used by components for informational purposes - BuildInfo BuildInfo -} - -// ExporterFactory is factory interface for exporters. -// -// This interface cannot be directly implemented. Implementations must -// use the NewExporterFactory to implement it. -type ExporterFactory interface { - Factory - - // CreateDefaultConfig creates the default configuration for the Exporter. - // This method can be called multiple times depending on the pipeline - // 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 - // 'componenttest.CheckConfigStruct'. It is recommended to have these checks in the - // tests of any implementation of the Factory interface. - 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 ExporterConfig) (TracesExporter, error) - - // TracesExporterStability gets the stability level of the TracesExporter. - TracesExporterStability() StabilityLevel - - // 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 ExporterConfig) (MetricsExporter, error) - - // MetricsExporterStability gets the stability level of the MetricsExporter. - MetricsExporterStability() StabilityLevel - - // 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 ExporterConfig) (LogsExporter, error) - - // LogsExporterStability gets the stability level of the LogsExporter. - LogsExporterStability() StabilityLevel -} - -// ExporterFactoryOption apply changes to ExporterOptions. -type ExporterFactoryOption interface { - // applyExporterFactoryOption applies the option. - applyExporterFactoryOption(o *exporterFactory) -} - -var _ ExporterFactoryOption = (*exporterFactoryOptionFunc)(nil) - -// exporterFactoryOptionFunc is an ExporterFactoryOption created through a function. -type exporterFactoryOptionFunc func(*exporterFactory) - -func (f exporterFactoryOptionFunc) applyExporterFactoryOption(o *exporterFactory) { - f(o) -} - -// ExporterCreateDefaultConfigFunc is the equivalent of ExporterFactory.CreateDefaultConfig(). -type ExporterCreateDefaultConfigFunc func() ExporterConfig - -// CreateDefaultConfig implements ExporterFactory.CreateDefaultConfig(). -func (f ExporterCreateDefaultConfigFunc) CreateDefaultConfig() ExporterConfig { - return f() -} - -// CreateTracesExporterFunc is the equivalent of ExporterFactory.CreateTracesExporter(). -type CreateTracesExporterFunc func(context.Context, ExporterCreateSettings, ExporterConfig) (TracesExporter, error) - -// CreateTracesExporter implements ExporterFactory.CreateTracesExporter(). -func (f CreateTracesExporterFunc) CreateTracesExporter(ctx context.Context, set ExporterCreateSettings, cfg ExporterConfig) (TracesExporter, error) { - if f == nil { - return nil, ErrDataTypeIsNotSupported - } - return f(ctx, set, cfg) -} - -// CreateMetricsExporterFunc is the equivalent of ExporterFactory.CreateMetricsExporter(). -type CreateMetricsExporterFunc func(context.Context, ExporterCreateSettings, ExporterConfig) (MetricsExporter, error) - -// CreateMetricsExporter implements ExporterFactory.CreateMetricsExporter(). -func (f CreateMetricsExporterFunc) CreateMetricsExporter(ctx context.Context, set ExporterCreateSettings, cfg ExporterConfig) (MetricsExporter, error) { - if f == nil { - return nil, ErrDataTypeIsNotSupported - } - return f(ctx, set, cfg) -} - -// CreateLogsExporterFunc is the equivalent of ExporterFactory.CreateLogsExporter(). -type CreateLogsExporterFunc func(context.Context, ExporterCreateSettings, ExporterConfig) (LogsExporter, error) - -// CreateLogsExporter implements ExporterFactory.CreateLogsExporter(). -func (f CreateLogsExporterFunc) CreateLogsExporter(ctx context.Context, set ExporterCreateSettings, cfg ExporterConfig) (LogsExporter, error) { - if f == nil { - return nil, ErrDataTypeIsNotSupported - } - return f(ctx, set, cfg) -} - -type exporterFactory struct { - baseFactory - ExporterCreateDefaultConfigFunc - CreateTracesExporterFunc - tracesStabilityLevel StabilityLevel - CreateMetricsExporterFunc - metricsStabilityLevel StabilityLevel - CreateLogsExporterFunc - logsStabilityLevel StabilityLevel -} - -func (e exporterFactory) TracesExporterStability() StabilityLevel { - return e.tracesStabilityLevel -} - -func (e exporterFactory) MetricsExporterStability() StabilityLevel { - return e.metricsStabilityLevel -} - -func (e exporterFactory) LogsExporterStability() StabilityLevel { - return e.logsStabilityLevel -} - -// WithTracesExporter overrides the default "error not supported" implementation for CreateTracesExporter and the default "undefined" stability level. -func WithTracesExporter(createTracesExporter CreateTracesExporterFunc, sl StabilityLevel) ExporterFactoryOption { - return exporterFactoryOptionFunc(func(o *exporterFactory) { - o.tracesStabilityLevel = sl - o.CreateTracesExporterFunc = createTracesExporter - }) -} - -// WithMetricsExporter overrides the default "error not supported" implementation for CreateMetricsExporter and the default "undefined" stability level. -func WithMetricsExporter(createMetricsExporter CreateMetricsExporterFunc, sl StabilityLevel) ExporterFactoryOption { - return exporterFactoryOptionFunc(func(o *exporterFactory) { - o.metricsStabilityLevel = sl - o.CreateMetricsExporterFunc = createMetricsExporter - }) -} - -// WithLogsExporter overrides the default "error not supported" implementation for CreateLogsExporter and the default "undefined" stability level. -func WithLogsExporter(createLogsExporter CreateLogsExporterFunc, sl StabilityLevel) ExporterFactoryOption { - return exporterFactoryOptionFunc(func(o *exporterFactory) { - o.logsStabilityLevel = sl - o.CreateLogsExporterFunc = createLogsExporter - }) -} - -// NewExporterFactory returns a ExporterFactory. -func NewExporterFactory(cfgType Type, createDefaultConfig ExporterCreateDefaultConfigFunc, options ...ExporterFactoryOption) ExporterFactory { - f := &exporterFactory{ - baseFactory: baseFactory{cfgType: cfgType}, - ExporterCreateDefaultConfigFunc: createDefaultConfig, - } - for _, opt := range options { - opt.applyExporterFactoryOption(f) - } - return f -} diff --git a/component/host.go b/component/host.go index 92c395b0306..9cff1172315 100644 --- a/component/host.go +++ b/component/host.go @@ -45,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[ID]Extension + GetExtensions() map[ID]Component // 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 @@ -58,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[DataType]map[ID]Exporter + GetExporters() map[DataType]map[ID]Component } diff --git a/component/processor.go b/component/processor.go index 0424c4106ad..9146376f5ae 100644 --- a/component/processor.go +++ b/component/processor.go @@ -24,8 +24,7 @@ import ( // ProcessorConfig is the configuration of a component.Processor. Specific Processor must implement // this interface and must embed ProcessorSettings struct or a struct that extends it. type ProcessorConfig interface { - identifiable - validatable + Config privateConfigProcessor() } @@ -34,7 +33,7 @@ type ProcessorConfig interface { // It checks if the config implements confmap.Unmarshaler and uses that if available, // otherwise uses Map.UnmarshalExact, erroring if a field is nonexistent. func UnmarshalProcessorConfig(conf *confmap.Conf, cfg ProcessorConfig) error { - return unmarshal(conf, cfg) + return UnmarshalConfig(conf, cfg) } // Processor defines the common functions that must be implemented by TracesProcessor @@ -108,6 +107,8 @@ type ProcessorFactory interface { // LogsProcessorStability gets the stability level of the LogsProcessor. LogsProcessorStability() StabilityLevel + + unexportedFunc() } // ProcessorCreateDefaultConfigFunc is the equivalent of ProcessorFactory.CreateDefaultConfig(). diff --git a/component/receiver.go b/component/receiver.go index c61f4024e8d..633799144a1 100644 --- a/component/receiver.go +++ b/component/receiver.go @@ -24,8 +24,7 @@ import ( // ReceiverConfig is the configuration of a component.Receiver. Specific Extension must implement // this interface and must embed ReceiverSettings struct or a struct that extends it. type ReceiverConfig interface { - identifiable - validatable + Config privateConfigReceiver() } @@ -34,7 +33,7 @@ type ReceiverConfig interface { // It checks if the config implements confmap.Unmarshaler and uses that if available, // otherwise uses Map.UnmarshalExact, erroring if a field is nonexistent. func UnmarshalReceiverConfig(conf *confmap.Conf, cfg ReceiverConfig) error { - return unmarshal(conf, cfg) + return UnmarshalConfig(conf, cfg) } // Receiver allows the collector to receive metrics, traces and logs. @@ -153,6 +152,8 @@ type ReceiverFactory interface { // LogsReceiverStability gets the stability level of the LogsReceiver. LogsReceiverStability() StabilityLevel + + unexportedFunc() } // ReceiverFactoryOption apply changes to ReceiverOptions. diff --git a/config/configauth/clientauth.go b/config/configauth/clientauth.go index c8944737fe1..661053da952 100644 --- a/config/configauth/clientauth.go +++ b/config/configauth/clientauth.go @@ -19,14 +19,14 @@ import ( "google.golang.org/grpc/credentials" - "go.opentelemetry.io/collector/component" + "go.opentelemetry.io/collector/extension" ) // ClientAuthenticator is an Extension that can be used as an authenticator for the configauth.Authentication option. // Authenticators are then included as part of OpenTelemetry Collector builds and can be referenced by their // names from the Authentication configuration. type ClientAuthenticator interface { - component.Extension + extension.Extension // RoundTripper returns a RoundTripper that can be used to authenticate HTTP requests. RoundTripper(base http.RoundTripper) (http.RoundTripper, error) diff --git a/config/configauth/configauth.go b/config/configauth/configauth.go index 30a440497b5..d48544b1ee1 100644 --- a/config/configauth/configauth.go +++ b/config/configauth/configauth.go @@ -19,6 +19,7 @@ import ( "fmt" "go.opentelemetry.io/collector/component" + "go.opentelemetry.io/collector/extension" ) var ( @@ -35,7 +36,7 @@ type Authentication struct { // 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[component.ID]component.Extension) (ServerAuthenticator, error) { +func (a Authentication) GetServerAuthenticator(extensions map[component.ID]extension.Extension) (ServerAuthenticator, error) { if ext, found := extensions[a.AuthenticatorID]; found { if auth, ok := ext.(ServerAuthenticator); ok { return auth, nil @@ -49,7 +50,7 @@ func (a Authentication) GetServerAuthenticator(extensions map[component.ID]compo // 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[component.ID]component.Extension) (ClientAuthenticator, error) { +func (a Authentication) GetClientAuthenticator(extensions map[component.ID]extension.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 04707e699ef..5c2e65cae3c 100644 --- a/config/configauth/configauth_test.go +++ b/config/configauth/configauth_test.go @@ -18,6 +18,7 @@ import ( "testing" "github.com/stretchr/testify/assert" + "go.opentelemetry.io/collector/extension" "go.opentelemetry.io/collector/component" ) @@ -25,7 +26,7 @@ import ( func TestGetServerAuthenticator(t *testing.T) { testCases := []struct { desc string - authenticator component.Extension + authenticator extension.Extension expected error }{ { @@ -45,7 +46,7 @@ func TestGetServerAuthenticator(t *testing.T) { cfg := &Authentication{ AuthenticatorID: component.NewID("mock"), } - ext := map[component.ID]component.Extension{ + ext := map[component.ID]extension.Extension{ component.NewID("mock"): tC.authenticator, } @@ -68,7 +69,7 @@ func TestGetServerAuthenticatorFails(t *testing.T) { AuthenticatorID: component.NewID("does-not-exist"), } - authenticator, err := cfg.GetServerAuthenticator(map[component.ID]component.Extension{}) + authenticator, err := cfg.GetServerAuthenticator(map[component.ID]extension.Extension{}) assert.ErrorIs(t, err, errAuthenticatorNotFound) assert.Nil(t, authenticator) } @@ -76,7 +77,7 @@ func TestGetServerAuthenticatorFails(t *testing.T) { func TestGetClientAuthenticator(t *testing.T) { testCases := []struct { desc string - authenticator component.Extension + authenticator extension.Extension expected error }{ { @@ -96,7 +97,7 @@ func TestGetClientAuthenticator(t *testing.T) { cfg := &Authentication{ AuthenticatorID: component.NewID("mock"), } - ext := map[component.ID]component.Extension{ + ext := map[component.ID]extension.Extension{ component.NewID("mock"): tC.authenticator, } @@ -118,7 +119,7 @@ func TestGetClientAuthenticatorFails(t *testing.T) { cfg := &Authentication{ AuthenticatorID: component.NewID("does-not-exist"), } - authenticator, err := cfg.GetClientAuthenticator(map[component.ID]component.Extension{}) + authenticator, err := cfg.GetClientAuthenticator(map[component.ID]extension.Extension{}) assert.ErrorIs(t, err, errAuthenticatorNotFound) assert.Nil(t, authenticator) } diff --git a/config/configauth/serverauth.go b/config/configauth/serverauth.go index e1d32620fbc..9b937891d4a 100644 --- a/config/configauth/serverauth.go +++ b/config/configauth/serverauth.go @@ -17,7 +17,7 @@ package configauth // import "go.opentelemetry.io/collector/config/configauth" import ( "context" - "go.opentelemetry.io/collector/component" + "go.opentelemetry.io/collector/extension" ) // ServerAuthenticator is an Extension that can be used as an authenticator for the configauth.Authentication option. @@ -26,7 +26,7 @@ import ( // but note that the expectations that come as part of Extensions exist here as well. For instance, multiple instances of the same // authenticator should be possible to exist under different names. type ServerAuthenticator interface { - component.Extension + extension.Extension // Authenticate checks whether the given headers map contains valid auth data. Successfully authenticated calls will always return a nil error. // When the authentication fails, an error must be returned and the caller must not retry. This function is typically called from interceptors, diff --git a/config/configgrpc/configgrpc_test.go b/config/configgrpc/configgrpc_test.go index eeaa93bf4af..6e520767124 100644 --- a/config/configgrpc/configgrpc_test.go +++ b/config/configgrpc/configgrpc_test.go @@ -39,6 +39,7 @@ import ( "go.opentelemetry.io/collector/config/configcompression" "go.opentelemetry.io/collector/config/confignet" "go.opentelemetry.io/collector/config/configtls" + "go.opentelemetry.io/collector/extension" "go.opentelemetry.io/collector/obsreport/obsreporttest" "go.opentelemetry.io/collector/pdata/ptrace/ptraceotlp" ) @@ -91,7 +92,7 @@ func TestAllGrpcClientSettings(t *testing.T) { Auth: &configauth.Authentication{AuthenticatorID: component.NewID("testauth")}, }, host: &mockHost{ - ext: map[component.ID]component.Extension{ + ext: map[component.ID]extension.Extension{ component.NewID("testauth"): &configauth.MockClientAuthenticator{}, }, }, @@ -119,7 +120,7 @@ func TestAllGrpcClientSettings(t *testing.T) { Auth: &configauth.Authentication{AuthenticatorID: component.NewID("testauth")}, }, host: &mockHost{ - ext: map[component.ID]component.Extension{ + ext: map[component.ID]extension.Extension{ component.NewID("testauth"): &configauth.MockClientAuthenticator{}, }, }, @@ -147,7 +148,7 @@ func TestAllGrpcClientSettings(t *testing.T) { Auth: &configauth.Authentication{AuthenticatorID: component.NewID("testauth")}, }, host: &mockHost{ - ext: map[component.ID]component.Extension{ + ext: map[component.ID]extension.Extension{ component.NewID("testauth"): &configauth.MockClientAuthenticator{}, }, }, @@ -216,7 +217,7 @@ func TestGrpcServerAuthSettings(t *testing.T) { AuthenticatorID: component.NewID("mock"), } host := &mockHost{ - ext: map[component.ID]component.Extension{ + ext: map[component.ID]extension.Extension{ component.NewID("mock"): configauth.NewServerAuthenticator(), }, } @@ -295,7 +296,7 @@ func TestGRPCClientSettingsError(t *testing.T) { Endpoint: "localhost:1234", Auth: &configauth.Authentication{AuthenticatorID: component.NewID("doesntexist")}, }, - host: &mockHost{ext: map[component.ID]component.Extension{}}, + host: &mockHost{ext: map[component.ID]extension.Extension{}}, }, { err: "no extensions configuration available", @@ -1075,9 +1076,9 @@ func tempSocketName(t *testing.T) string { type mockHost struct { component.Host - ext map[component.ID]component.Extension + ext map[component.ID]extension.Extension } -func (nh *mockHost) GetExtensions() map[component.ID]component.Extension { +func (nh *mockHost) GetExtensions() map[component.ID]extension.Extension { return nh.ext } diff --git a/config/confighttp/confighttp_test.go b/config/confighttp/confighttp_test.go index 26cbd24e0aa..3dd2eacb040 100644 --- a/config/confighttp/confighttp_test.go +++ b/config/confighttp/confighttp_test.go @@ -37,6 +37,7 @@ import ( "go.opentelemetry.io/collector/component/componenttest" "go.opentelemetry.io/collector/config/configauth" "go.opentelemetry.io/collector/config/configtls" + "go.opentelemetry.io/collector/extension" ) type customRoundTripper struct { @@ -50,7 +51,7 @@ func (c *customRoundTripper) RoundTrip(request *http.Request) (*http.Response, e func TestAllHTTPClientSettings(t *testing.T) { host := &mockHost{ - ext: map[component.ID]component.Extension{ + ext: map[component.ID]extension.Extension{ component.NewID("testauth"): &configauth.MockClientAuthenticator{ResultRoundTripper: &customRoundTripper{}}, }, } @@ -160,7 +161,7 @@ func TestAllHTTPClientSettings(t *testing.T) { func TestPartialHTTPClientSettings(t *testing.T) { host := &mockHost{ - ext: map[component.ID]component.Extension{ + ext: map[component.ID]extension.Extension{ component.NewID("testauth"): &configauth.MockClientAuthenticator{ResultRoundTripper: &customRoundTripper{}}, }, } @@ -211,7 +212,7 @@ func TestDefaultHTTPClientSettings(t *testing.T) { func TestHTTPClientSettingsError(t *testing.T) { host := &mockHost{ - ext: map[component.ID]component.Extension{}, + ext: map[component.ID]extension.Extension{}, } tests := []struct { settings HTTPClientSettings @@ -274,7 +275,7 @@ func TestHTTPClientSettingWithAuthConfig(t *testing.T) { }, shouldErr: false, host: &mockHost{ - ext: map[component.ID]component.Extension{ + ext: map[component.ID]extension.Extension{ component.NewID("mock"): &configauth.MockClientAuthenticator{ ResultRoundTripper: &customRoundTripper{}, }, @@ -289,7 +290,7 @@ func TestHTTPClientSettingWithAuthConfig(t *testing.T) { }, shouldErr: true, host: &mockHost{ - ext: map[component.ID]component.Extension{ + ext: map[component.ID]extension.Extension{ component.NewID("mock"): &configauth.MockClientAuthenticator{ResultRoundTripper: &customRoundTripper{}}, }, }, @@ -311,7 +312,7 @@ func TestHTTPClientSettingWithAuthConfig(t *testing.T) { }, shouldErr: false, host: &mockHost{ - ext: map[component.ID]component.Extension{ + ext: map[component.ID]extension.Extension{ component.NewID("mock"): &configauth.MockClientAuthenticator{ResultRoundTripper: &customRoundTripper{}}, }, }, @@ -324,7 +325,7 @@ func TestHTTPClientSettingWithAuthConfig(t *testing.T) { }, shouldErr: true, host: &mockHost{ - ext: map[component.ID]component.Extension{ + ext: map[component.ID]extension.Extension{ component.NewID("mock"): &configauth.MockClientAuthenticator{ ResultRoundTripper: &customRoundTripper{}, MustError: true}, }, @@ -737,7 +738,7 @@ func TestHttpCorsWithAuthentication(t *testing.T) { } host := &mockHost{ - ext: map[component.ID]component.Extension{ + ext: map[component.ID]extension.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") @@ -932,7 +933,7 @@ func TestServerAuth(t *testing.T) { } host := &mockHost{ - ext: map[component.ID]component.Extension{ + ext: map[component.ID]extension.Extension{ component.NewID("mock"): configauth.NewServerAuthenticator( configauth.WithAuthenticate(func(ctx context.Context, headers map[string][]string) (context.Context, error) { authCalled = true @@ -979,7 +980,7 @@ func TestFailedServerAuth(t *testing.T) { }, } host := &mockHost{ - ext: map[component.ID]component.Extension{ + ext: map[component.ID]extension.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") @@ -1002,10 +1003,10 @@ func TestFailedServerAuth(t *testing.T) { type mockHost struct { component.Host - ext map[component.ID]component.Extension + ext map[component.ID]extension.Extension } -func (nh *mockHost) GetExtensions() map[component.ID]component.Extension { +func (nh *mockHost) GetExtensions() map[component.ID]extension.Extension { return nh.ext } diff --git a/config/exporter.go b/config/exporter.go index eb7c5b9460b..c6f2e441e2e 100644 --- a/config/exporter.go +++ b/config/exporter.go @@ -15,6 +15,7 @@ package config // import "go.opentelemetry.io/collector/config" import ( "go.opentelemetry.io/collector/component" + "go.opentelemetry.io/collector/exporter" ) // ExporterSettings defines common settings for a component.Exporter configuration. @@ -25,7 +26,7 @@ import ( // When embedded in the exporter config, it must be with `mapstructure:",squash"` tag. type ExporterSettings struct { id component.ID `mapstructure:"-"` - component.ExporterConfig + exporter.Config } // NewExporterSettings return a new ExporterSettings with the given ComponentID. @@ -33,7 +34,7 @@ func NewExporterSettings(id component.ID) ExporterSettings { return ExporterSettings{id: id} } -var _ component.ExporterConfig = (*ExporterSettings)(nil) +var _ exporter.Config = (*ExporterSettings)(nil) // ID returns the receiver component.ID. func (es *ExporterSettings) ID() component.ID { diff --git a/config/extension.go b/config/extension.go index 9addb5169fe..3415cf4aa02 100644 --- a/config/extension.go +++ b/config/extension.go @@ -15,6 +15,7 @@ package config // import "go.opentelemetry.io/collector/config" import ( "go.opentelemetry.io/collector/component" + "go.opentelemetry.io/collector/extension" ) // ExtensionSettings defines common settings for a component.Extension configuration. @@ -25,7 +26,7 @@ import ( // When embedded in the extension config, it must be with `mapstructure:",squash"` tag. type ExtensionSettings struct { id component.ID `mapstructure:"-"` - component.ExtensionConfig + extension.Config } // NewExtensionSettings return a new ExtensionSettings with the given ID. @@ -33,7 +34,7 @@ func NewExtensionSettings(id component.ID) ExtensionSettings { return ExtensionSettings{id: id} } -var _ component.ExtensionConfig = (*ExtensionSettings)(nil) +var _ extension.Config = (*ExtensionSettings)(nil) // ID returns the receiver ID. func (es *ExtensionSettings) ID() component.ID { diff --git a/exporter/exporter.go b/exporter/exporter.go new file mode 100644 index 00000000000..20fb8d5ef5d --- /dev/null +++ b/exporter/exporter.go @@ -0,0 +1,220 @@ +// 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 exporter // import "go.opentelemetry.io/collector/component" + +import ( + "context" + + "go.opentelemetry.io/collector/component" + "go.opentelemetry.io/collector/consumer" +) + +// Config is the configuration of any exporter. Specific exporters must implement +// this interface and must embed config.ExporterSettings struct or a struct that extends it. +type Config interface { + component.Config + + privateConfigExporter() +} + +// Traces is an exporter that can consume traces. +type Traces interface { + component.Component + consumer.Traces +} + +// Metrics is an exporter that can consume metrics. +type Metrics interface { + component.Component + consumer.Metrics +} + +// Logs is an exporter that can consume logs. +type Logs interface { + component.Component + consumer.Logs +} + +// CreateSettings configures exporter creators. +type CreateSettings struct { + TelemetrySettings component.TelemetrySettings + + // BuildInfo can be used by components for informational purposes + BuildInfo component.BuildInfo +} + +// Factory is factory interface for exporters. +// +// This interface cannot be directly implemented. Implementations must +// use the NewFactory to implement it. +type Factory interface { + component.Factory + + // CreateDefaultConfig creates the default configuration for the exporter. + // This method can be called multiple times depending on the pipeline + // 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 + // 'componenttest.CheckConfigStruct'. It is recommended to have these checks in the + // tests of any implementation of the Factory interface. + CreateDefaultConfig() Config + + // CreateTracesExporter creates an exporter.Traces 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 CreateSettings, cfg Config) (Traces, error) + + // TracesExporterStability gets the stability level of the exporter.Traces. + TracesExporterStability() component.StabilityLevel + + // CreateMetricsExporter creates an exporter.Metrics 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 CreateSettings, cfg Config) (Metrics, error) + + // MetricsExporterStability gets the stability level of the exporter.Metrics. + MetricsExporterStability() component.StabilityLevel + + // CreateLogsExporter creates an exporter.Logs 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 CreateSettings, cfg Config) (Logs, error) + + // LogsExporterStability gets the stability level of the exporter.Logs. + LogsExporterStability() component.StabilityLevel + + unexportedFunc() +} + +// FactoryOption apply changes to NewFactory. +type FactoryOption interface { + // apply the option. + apply(o *factory) +} + +var _ FactoryOption = (*factoryOptionFunc)(nil) + +// factoryOptionFunc is an FactoryOption created through a function. +type factoryOptionFunc func(*factory) + +func (f factoryOptionFunc) apply(o *factory) { + f(o) +} + +// CreateDefaultConfigFunc is the equivalent of Factory.CreateDefaultConfig(). +type CreateDefaultConfigFunc func() Config + +// CreateDefaultConfig implements Factory.CreateDefaultConfig(). +func (f CreateDefaultConfigFunc) CreateDefaultConfig() Config { + return f() +} + +// CreateTracesFunc is the equivalent of Factory.CreateTracesExporter(). +type CreateTracesFunc func(context.Context, CreateSettings, Config) (Traces, error) + +// CreateTracesExporter implements Factory.CreateTracesExporter(). +func (f CreateTracesFunc) CreateTracesExporter(ctx context.Context, set CreateSettings, cfg Config) (Traces, error) { + if f == nil { + return nil, component.ErrDataTypeIsNotSupported + } + return f(ctx, set, cfg) +} + +// CreateMetricsFunc is the equivalent of Factory.CreateMetricsExporter(). +type CreateMetricsFunc func(context.Context, CreateSettings, Config) (Metrics, error) + +// CreateMetricsExporter implements Factory.CreateMetricsExporter(). +func (f CreateMetricsFunc) CreateMetricsExporter(ctx context.Context, set CreateSettings, cfg Config) (Metrics, error) { + if f == nil { + return nil, component.ErrDataTypeIsNotSupported + } + return f(ctx, set, cfg) +} + +// CreateLogsFunc is the equivalent of Factory.CreateLogsExporter(). +type CreateLogsFunc func(context.Context, CreateSettings, Config) (Logs, error) + +// CreateLogsExporter implements Factory.CreateLogsExporter(). +func (f CreateLogsFunc) CreateLogsExporter(ctx context.Context, set CreateSettings, cfg Config) (Logs, error) { + if f == nil { + return nil, component.ErrDataTypeIsNotSupported + } + return f(ctx, set, cfg) +} + +type factory struct { + cfgType component.Type + CreateDefaultConfigFunc + CreateTracesFunc + tracesStabilityLevel component.StabilityLevel + CreateMetricsFunc + metricsStabilityLevel component.StabilityLevel + CreateLogsFunc + logsStabilityLevel component.StabilityLevel +} + +func (f factory) Type() component.Type { + return f.cfgType +} + +func (f factory) unexportedFunc() {} + +func (f factory) TracesExporterStability() component.StabilityLevel { + return f.tracesStabilityLevel +} + +func (f factory) MetricsExporterStability() component.StabilityLevel { + return f.metricsStabilityLevel +} + +func (f factory) LogsExporterStability() component.StabilityLevel { + return f.logsStabilityLevel +} + +// WithTraces overrides the default "error not supported" implementation for CreateTracesExporter and the default "undefined" stability level. +func WithTraces(createTraces CreateTracesFunc, sl component.StabilityLevel) FactoryOption { + return factoryOptionFunc(func(o *factory) { + o.tracesStabilityLevel = sl + o.CreateTracesFunc = createTraces + }) +} + +// WithMetrics overrides the default "error not supported" implementation for CreateMetricsExporter and the default "undefined" stability level. +func WithMetrics(createMetrics CreateMetricsFunc, sl component.StabilityLevel) FactoryOption { + return factoryOptionFunc(func(o *factory) { + o.metricsStabilityLevel = sl + o.CreateMetricsFunc = createMetrics + }) +} + +// WithLogs overrides the default "error not supported" implementation for CreateLogsExporter and the default "undefined" stability level. +func WithLogs(createLogs CreateLogsFunc, sl component.StabilityLevel) FactoryOption { + return factoryOptionFunc(func(o *factory) { + o.logsStabilityLevel = sl + o.CreateLogsFunc = createLogs + }) +} + +// NewFactory returns a Factory. +func NewFactory(cfgType component.Type, createDefaultConfig CreateDefaultConfigFunc, options ...FactoryOption) Factory { + f := &factory{ + cfgType: cfgType, + CreateDefaultConfigFunc: createDefaultConfig, + } + for _, opt := range options { + opt.apply(f) + } + return f +} diff --git a/component/exporter_test.go b/exporter/exporter_test.go similarity index 51% rename from component/exporter_test.go rename to exporter/exporter_test.go index ef541cec19b..0b47fbae5be 100644 --- a/component/exporter_test.go +++ b/exporter/exporter_test.go @@ -14,7 +14,7 @@ // TODO: Move tests back to component package after config.*Settings are removed. -package component_test +package exporter_test import ( "context" @@ -24,57 +24,58 @@ import ( "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/config" + "go.opentelemetry.io/collector/exporter" ) -func TestNewExporterFactory(t *testing.T) { +func TestNewFactory(t *testing.T) { const typeStr = "test" defaultCfg := config.NewExporterSettings(component.NewID(typeStr)) - factory := component.NewExporterFactory( + factory := exporter.NewFactory( typeStr, - func() component.ExporterConfig { return &defaultCfg }) + func() exporter.Config { return &defaultCfg }) assert.EqualValues(t, typeStr, factory.Type()) assert.EqualValues(t, &defaultCfg, factory.CreateDefaultConfig()) - _, err := factory.CreateTracesExporter(context.Background(), component.ExporterCreateSettings{}, &defaultCfg) + _, err := factory.CreateTracesExporter(context.Background(), exporter.CreateSettings{}, &defaultCfg) assert.Error(t, err) - _, err = factory.CreateMetricsExporter(context.Background(), component.ExporterCreateSettings{}, &defaultCfg) + _, err = factory.CreateMetricsExporter(context.Background(), exporter.CreateSettings{}, &defaultCfg) assert.Error(t, err) - _, err = factory.CreateLogsExporter(context.Background(), component.ExporterCreateSettings{}, &defaultCfg) + _, err = factory.CreateLogsExporter(context.Background(), exporter.CreateSettings{}, &defaultCfg) assert.Error(t, err) } -func TestNewExporterFactory_WithOptions(t *testing.T) { +func TestNewFactory_WithOptions(t *testing.T) { const typeStr = "test" defaultCfg := config.NewExporterSettings(component.NewID(typeStr)) - factory := component.NewExporterFactory( + factory := exporter.NewFactory( typeStr, - func() component.ExporterConfig { return &defaultCfg }, - component.WithTracesExporter(createTracesExporter, component.StabilityLevelInDevelopment), - component.WithMetricsExporter(createMetricsExporter, component.StabilityLevelAlpha), - component.WithLogsExporter(createLogsExporter, component.StabilityLevelDeprecated)) + func() exporter.Config { return &defaultCfg }, + exporter.WithTraces(createTracesExporter, component.StabilityLevelInDevelopment), + exporter.WithMetrics(createMetricsExporter, component.StabilityLevelAlpha), + exporter.WithLogs(createLogsExporter, component.StabilityLevelDeprecated)) assert.EqualValues(t, typeStr, factory.Type()) assert.EqualValues(t, &defaultCfg, factory.CreateDefaultConfig()) assert.Equal(t, component.StabilityLevelInDevelopment, factory.TracesExporterStability()) - _, err := factory.CreateTracesExporter(context.Background(), component.ExporterCreateSettings{}, &defaultCfg) + _, err := factory.CreateTracesExporter(context.Background(), exporter.CreateSettings{}, &defaultCfg) assert.NoError(t, err) assert.Equal(t, component.StabilityLevelAlpha, factory.MetricsExporterStability()) - _, err = factory.CreateMetricsExporter(context.Background(), component.ExporterCreateSettings{}, &defaultCfg) + _, err = factory.CreateMetricsExporter(context.Background(), exporter.CreateSettings{}, &defaultCfg) assert.NoError(t, err) assert.Equal(t, component.StabilityLevelDeprecated, factory.LogsExporterStability()) - _, err = factory.CreateLogsExporter(context.Background(), component.ExporterCreateSettings{}, &defaultCfg) + _, err = factory.CreateLogsExporter(context.Background(), exporter.CreateSettings{}, &defaultCfg) assert.NoError(t, err) } -func createTracesExporter(context.Context, component.ExporterCreateSettings, component.ExporterConfig) (component.TracesExporter, error) { +func createTracesExporter(context.Context, exporter.CreateSettings, exporter.Config) (exporter.Traces, error) { return nil, nil } -func createMetricsExporter(context.Context, component.ExporterCreateSettings, component.ExporterConfig) (component.MetricsExporter, error) { +func createMetricsExporter(context.Context, exporter.CreateSettings, exporter.Config) (exporter.Metrics, error) { return nil, nil } -func createLogsExporter(context.Context, component.ExporterCreateSettings, component.ExporterConfig) (component.LogsExporter, error) { +func createLogsExporter(context.Context, exporter.CreateSettings, exporter.Config) (exporter.Logs, error) { return nil, nil } diff --git a/exporter/exporterhelper/common.go b/exporter/exporterhelper/common.go index 68d32750462..681e2c21076 100644 --- a/exporter/exporterhelper/common.go +++ b/exporter/exporterhelper/common.go @@ -20,6 +20,7 @@ import ( "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/consumer" + "go.opentelemetry.io/collector/exporter" "go.opentelemetry.io/collector/exporter/exporterhelper/internal" "go.opentelemetry.io/collector/obsreport" ) @@ -155,7 +156,7 @@ type baseExporter struct { qrSender *queuedRetrySender } -func newBaseExporter(cfg component.ExporterConfig, set component.ExporterCreateSettings, bs *baseSettings, signal component.DataType, reqUnmarshaler internal.RequestUnmarshaler) (*baseExporter, error) { +func newBaseExporter(cfg exporter.Config, set exporter.CreateSettings, bs *baseSettings, signal component.DataType, reqUnmarshaler internal.RequestUnmarshaler) (*baseExporter, error) { be := &baseExporter{} var err error diff --git a/exporter/exporterhelper/logs.go b/exporter/exporterhelper/logs.go index 29a558520e0..0ca6d52b40d 100644 --- a/exporter/exporterhelper/logs.go +++ b/exporter/exporterhelper/logs.go @@ -21,6 +21,7 @@ import ( "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/consumer" "go.opentelemetry.io/collector/consumer/consumererror" + "go.opentelemetry.io/collector/exporter" "go.opentelemetry.io/collector/exporter/exporterhelper/internal" "go.opentelemetry.io/collector/pdata/plog" ) @@ -80,11 +81,11 @@ type logsExporter struct { // NewLogsExporter creates a component.LogsExporter that records observability metrics and wraps every request with a Span. func NewLogsExporter( _ context.Context, - set component.ExporterCreateSettings, - cfg component.ExporterConfig, + set exporter.CreateSettings, + cfg exporter.Config, pusher consumer.ConsumeLogsFunc, options ...Option, -) (component.LogsExporter, error) { +) (exporter.LogsExporter, error) { if cfg == nil { return nil, errNilConfig } diff --git a/exporter/exporterhelper/logs_test.go b/exporter/exporterhelper/logs_test.go index 1b496d17880..39c54bd12d2 100644 --- a/exporter/exporterhelper/logs_test.go +++ b/exporter/exporterhelper/logs_test.go @@ -31,6 +31,7 @@ import ( "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/consumer" "go.opentelemetry.io/collector/consumer/consumererror" + "go.opentelemetry.io/collector/exporter" "go.opentelemetry.io/collector/internal/obsreportconfig/obsmetrics" "go.opentelemetry.io/collector/internal/testdata" "go.opentelemetry.io/collector/obsreport/obsreporttest" @@ -65,7 +66,7 @@ func TestLogsExporter_InvalidName(t *testing.T) { } func TestLogsExporter_NilLogger(t *testing.T) { - le, err := NewLogsExporter(context.Background(), component.ExporterCreateSettings{}, &fakeLogsExporterConfig, newPushLogsData(nil)) + le, err := NewLogsExporter(context.Background(), exporter.CreateSettings{}, &fakeLogsExporterConfig, newPushLogsData(nil)) require.Nil(t, le) require.Equal(t, errNilLogger, err) } @@ -212,7 +213,7 @@ func newPushLogsData(retError error) consumer.ConsumeLogsFunc { } } -func checkRecordedMetricsForLogsExporter(t *testing.T, tt obsreporttest.TestTelemetry, le component.LogsExporter, wantError error) { +func checkRecordedMetricsForLogsExporter(t *testing.T, tt obsreporttest.TestTelemetry, le exporter.LogsExporter, wantError error) { ld := testdata.GenerateLogs(2) const numBatches = 7 for i := 0; i < numBatches; i++ { @@ -227,7 +228,7 @@ func checkRecordedMetricsForLogsExporter(t *testing.T, tt obsreporttest.TestTele } } -func generateLogsTraffic(t *testing.T, tracer trace.Tracer, le component.LogsExporter, numRequests int, wantError error) { +func generateLogsTraffic(t *testing.T, tracer trace.Tracer, le exporter.LogsExporter, numRequests int, wantError error) { ld := testdata.GenerateLogs(1) ctx, span := tracer.Start(context.Background(), fakeLogsParentSpanName) defer span.End() @@ -236,7 +237,7 @@ func generateLogsTraffic(t *testing.T, tracer trace.Tracer, le component.LogsExp } } -func checkWrapSpanForLogsExporter(t *testing.T, sr *tracetest.SpanRecorder, tracer trace.Tracer, le component.LogsExporter, wantError error, numLogRecords int64) { +func checkWrapSpanForLogsExporter(t *testing.T, sr *tracetest.SpanRecorder, tracer trace.Tracer, le exporter.LogsExporter, wantError error, numLogRecords int64) { const numRequests = 5 generateLogsTraffic(t, tracer, le, numRequests, wantError) diff --git a/exporter/exporterhelper/metrics.go b/exporter/exporterhelper/metrics.go index 33d81d64fa5..2ab458e3775 100644 --- a/exporter/exporterhelper/metrics.go +++ b/exporter/exporterhelper/metrics.go @@ -21,6 +21,7 @@ import ( "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/consumer" "go.opentelemetry.io/collector/consumer/consumererror" + "go.opentelemetry.io/collector/exporter" "go.opentelemetry.io/collector/exporter/exporterhelper/internal" "go.opentelemetry.io/collector/pdata/pmetric" ) @@ -81,11 +82,11 @@ type metricsExporter struct { // NewMetricsExporter creates a component.MetricsExporter that records observability metrics and wraps every request with a Span. func NewMetricsExporter( _ context.Context, - set component.ExporterCreateSettings, - cfg component.ExporterConfig, + set exporter.CreateSettings, + cfg exporter.Config, pusher consumer.ConsumeMetricsFunc, options ...Option, -) (component.MetricsExporter, error) { +) (exporter.MetricsExporter, error) { if cfg == nil { return nil, errNilConfig } diff --git a/exporter/exporterhelper/metrics_test.go b/exporter/exporterhelper/metrics_test.go index 4f7651eb13a..b4914bdfdc9 100644 --- a/exporter/exporterhelper/metrics_test.go +++ b/exporter/exporterhelper/metrics_test.go @@ -31,6 +31,7 @@ import ( "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/consumer" "go.opentelemetry.io/collector/consumer/consumererror" + "go.opentelemetry.io/collector/exporter" "go.opentelemetry.io/collector/internal/obsreportconfig/obsmetrics" "go.opentelemetry.io/collector/internal/testdata" "go.opentelemetry.io/collector/obsreport/obsreporttest" @@ -64,7 +65,7 @@ func TestMetricsExporter_InvalidName(t *testing.T) { } func TestMetricsExporter_NilLogger(t *testing.T) { - me, err := NewMetricsExporter(context.Background(), component.ExporterCreateSettings{}, &fakeMetricsExporterConfig, newPushMetricsData(nil)) + me, err := NewMetricsExporter(context.Background(), exporter.CreateSettings{}, &fakeMetricsExporterConfig, newPushMetricsData(nil)) require.Nil(t, me) require.Equal(t, errNilLogger, err) } @@ -213,7 +214,7 @@ func newPushMetricsData(retError error) consumer.ConsumeMetricsFunc { } } -func checkRecordedMetricsForMetricsExporter(t *testing.T, tt obsreporttest.TestTelemetry, me component.MetricsExporter, wantError error) { +func checkRecordedMetricsForMetricsExporter(t *testing.T, tt obsreporttest.TestTelemetry, me exporter.MetricsExporter, wantError error) { md := testdata.GenerateMetrics(2) const numBatches = 7 for i := 0; i < numBatches; i++ { @@ -229,7 +230,7 @@ func checkRecordedMetricsForMetricsExporter(t *testing.T, tt obsreporttest.TestT } } -func generateMetricsTraffic(t *testing.T, tracer trace.Tracer, me component.MetricsExporter, numRequests int, wantError error) { +func generateMetricsTraffic(t *testing.T, tracer trace.Tracer, me exporter.MetricsExporter, numRequests int, wantError error) { md := testdata.GenerateMetrics(1) ctx, span := tracer.Start(context.Background(), fakeMetricsParentSpanName) defer span.End() @@ -238,7 +239,7 @@ func generateMetricsTraffic(t *testing.T, tracer trace.Tracer, me component.Metr } } -func checkWrapSpanForMetricsExporter(t *testing.T, sr *tracetest.SpanRecorder, tracer trace.Tracer, me component.MetricsExporter, wantError error, numMetricPoints int64) { +func checkWrapSpanForMetricsExporter(t *testing.T, sr *tracetest.SpanRecorder, tracer trace.Tracer, me exporter.MetricsExporter, wantError error, numMetricPoints int64) { const numRequests = 5 generateMetricsTraffic(t, tracer, me, numRequests, wantError) diff --git a/exporter/exporterhelper/queued_retry.go b/exporter/exporterhelper/queued_retry.go index c4a93ce143a..fbfcc965681 100644 --- a/exporter/exporterhelper/queued_retry.go +++ b/exporter/exporterhelper/queued_retry.go @@ -30,6 +30,7 @@ import ( "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/consumer/consumererror" "go.opentelemetry.io/collector/exporter/exporterhelper/internal" + "go.opentelemetry.io/collector/extension" "go.opentelemetry.io/collector/extension/experimental/storage" "go.opentelemetry.io/collector/internal/obsreportconfig/obsmetrics" ) @@ -127,7 +128,7 @@ func newQueuedRetrySender(id component.ID, signal component.DataType, qCfg Queue return qrs } -func getStorageExtension(extensions map[component.ID]component.Extension, storageID component.ID) (storage.Extension, error) { +func getStorageExtension(extensions map[component.ID]extension.Extension, storageID component.ID) (storage.Extension, error) { if ext, found := extensions[storageID]; found { if storageExt, ok := ext.(storage.Extension); ok { return storageExt, nil diff --git a/exporter/exporterhelper/queued_retry_test.go b/exporter/exporterhelper/queued_retry_test.go index 574f088bf4d..5c1c550ff92 100644 --- a/exporter/exporterhelper/queued_retry_test.go +++ b/exporter/exporterhelper/queued_retry_test.go @@ -34,6 +34,7 @@ import ( "go.opentelemetry.io/collector/component/componenttest" "go.opentelemetry.io/collector/consumer/consumererror" "go.opentelemetry.io/collector/exporter/exporterhelper/internal" + "go.opentelemetry.io/collector/extension" "go.opentelemetry.io/collector/extension/experimental/storage" "go.opentelemetry.io/collector/internal/testdata" "go.opentelemetry.io/collector/obsreport/obsreporttest" @@ -435,7 +436,7 @@ func TestGetRetrySettings(t *testing.T) { t.Run(tC.desc, func(t *testing.T) { storageID := component.NewIDWithName("file_storage", strconv.Itoa(tC.storageIndex)) - var extensions = map[component.ID]component.Extension{} + var extensions = map[component.ID]extension.Extension{} for i := 0; i < tC.numStorages; i++ { extensions[component.NewIDWithName("file_storage", strconv.Itoa(i))] = &mockStorageExtension{GetClientError: tC.getClientError} } @@ -466,7 +467,7 @@ func TestInvalidStorageExtensionType(t *testing.T) { settings := componenttest.NewNopExtensionCreateSettings() extension, err := factory.CreateExtension(context.Background(), settings, extConfig) assert.NoError(t, err) - var extensions = map[component.ID]component.Extension{ + var extensions = map[component.ID]extension.Extension{ storageID: extension, } host := &mockHost{ext: extensions} @@ -545,7 +546,7 @@ func TestQueuedRetryPersistenceEnabled(t *testing.T) { be, err := newBaseExporter(&defaultExporterCfg, tt.ToExporterCreateSettings(), fromOptions(WithRetry(rCfg), WithQueue(qCfg)), "", nopRequestUnmarshaler()) require.NoError(t, err) - var extensions = map[component.ID]component.Extension{ + var extensions = map[component.ID]extension.Extension{ storageID: &mockStorageExtension{}, } host := &mockHost{ext: extensions} @@ -568,7 +569,7 @@ func TestQueuedRetryPersistenceEnabledStorageError(t *testing.T) { be, err := newBaseExporter(&defaultExporterCfg, tt.ToExporterCreateSettings(), fromOptions(WithRetry(rCfg), WithQueue(qCfg)), "", nopRequestUnmarshaler()) require.NoError(t, err) - var extensions = map[component.ID]component.Extension{ + var extensions = map[component.ID]extension.Extension{ storageID: &mockStorageExtension{GetClientError: storageError}, } host := &mockHost{ext: extensions} @@ -746,10 +747,10 @@ func tagsMatchLabelKeys(tags []tag.Tag, keys []metricdata.LabelKey, labels []met type mockHost struct { component.Host - ext map[component.ID]component.Extension + ext map[component.ID]extension.Extension } -func (nh *mockHost) GetExtensions() map[component.ID]component.Extension { +func (nh *mockHost) GetExtensions() map[component.ID]extension.Extension { return nh.ext } diff --git a/exporter/exporterhelper/traces.go b/exporter/exporterhelper/traces.go index a2a2c311741..d3cc8ffde24 100644 --- a/exporter/exporterhelper/traces.go +++ b/exporter/exporterhelper/traces.go @@ -21,6 +21,7 @@ import ( "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/consumer" "go.opentelemetry.io/collector/consumer/consumererror" + "go.opentelemetry.io/collector/exporter" "go.opentelemetry.io/collector/exporter/exporterhelper/internal" "go.opentelemetry.io/collector/pdata/ptrace" ) @@ -81,11 +82,11 @@ type traceExporter struct { // NewTracesExporter creates a component.TracesExporter that records observability metrics and wraps every request with a Span. func NewTracesExporter( _ context.Context, - set component.ExporterCreateSettings, - cfg component.ExporterConfig, + set exporter.CreateSettings, + cfg exporter.Config, pusher consumer.ConsumeTracesFunc, options ...Option, -) (component.TracesExporter, error) { +) (exporter.TracesExporter, error) { if cfg == nil { return nil, errNilConfig } diff --git a/exporter/exporterhelper/traces_test.go b/exporter/exporterhelper/traces_test.go index c27973aa709..0cef747f1cd 100644 --- a/exporter/exporterhelper/traces_test.go +++ b/exporter/exporterhelper/traces_test.go @@ -31,6 +31,7 @@ import ( "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/consumer" "go.opentelemetry.io/collector/consumer/consumererror" + "go.opentelemetry.io/collector/exporter" "go.opentelemetry.io/collector/internal/obsreportconfig/obsmetrics" "go.opentelemetry.io/collector/internal/testdata" "go.opentelemetry.io/collector/obsreport/obsreporttest" @@ -60,7 +61,7 @@ func TestTracesExporter_InvalidName(t *testing.T) { } func TestTracesExporter_NilLogger(t *testing.T) { - te, err := NewTracesExporter(context.Background(), component.ExporterCreateSettings{}, &fakeTracesExporterConfig, newTraceDataPusher(nil)) + te, err := NewTracesExporter(context.Background(), exporter.CreateSettings{}, &fakeTracesExporterConfig, newTraceDataPusher(nil)) require.Nil(t, te) require.Equal(t, errNilLogger, err) } @@ -213,7 +214,7 @@ func newTraceDataPusher(retError error) consumer.ConsumeTracesFunc { } } -func checkRecordedMetricsForTracesExporter(t *testing.T, tt obsreporttest.TestTelemetry, te component.TracesExporter, wantError error) { +func checkRecordedMetricsForTracesExporter(t *testing.T, tt obsreporttest.TestTelemetry, te exporter.TracesExporter, wantError error) { td := testdata.GenerateTraces(2) const numBatches = 7 for i := 0; i < numBatches; i++ { @@ -228,7 +229,7 @@ func checkRecordedMetricsForTracesExporter(t *testing.T, tt obsreporttest.TestTe } } -func generateTraceTraffic(t *testing.T, tracer trace.Tracer, te component.TracesExporter, numRequests int, wantError error) { +func generateTraceTraffic(t *testing.T, tracer trace.Tracer, te exporter.TracesExporter, numRequests int, wantError error) { td := ptrace.NewTraces() td.ResourceSpans().AppendEmpty().ScopeSpans().AppendEmpty().Spans().AppendEmpty() ctx, span := tracer.Start(context.Background(), fakeTraceParentSpanName) @@ -238,7 +239,7 @@ func generateTraceTraffic(t *testing.T, tracer trace.Tracer, te component.Traces } } -func checkWrapSpanForTracesExporter(t *testing.T, sr *tracetest.SpanRecorder, tracer trace.Tracer, te component.TracesExporter, wantError error, numSpans int64) { +func checkWrapSpanForTracesExporter(t *testing.T, sr *tracetest.SpanRecorder, tracer trace.Tracer, te exporter.TracesExporter, wantError error, numSpans int64) { const numRequests = 5 generateTraceTraffic(t, tracer, te, numRequests, wantError) diff --git a/exporter/loggingexporter/config.go b/exporter/loggingexporter/config.go index 7dbff1bba25..e956c062fcc 100644 --- a/exporter/loggingexporter/config.go +++ b/exporter/loggingexporter/config.go @@ -19,10 +19,10 @@ import ( "go.uber.org/zap/zapcore" - "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/config/configtelemetry" "go.opentelemetry.io/collector/confmap" + "go.opentelemetry.io/collector/exporter" ) var ( @@ -56,7 +56,7 @@ type Config struct { warnLogLevel bool } -var _ component.ExporterConfig = (*Config)(nil) +var _ exporter.Config = (*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 71822c5cce9..4226d4715a3 100644 --- a/exporter/loggingexporter/config_test.go +++ b/exporter/loggingexporter/config_test.go @@ -27,12 +27,13 @@ import ( "go.opentelemetry.io/collector/config/configtelemetry" "go.opentelemetry.io/collector/confmap" "go.opentelemetry.io/collector/confmap/confmaptest" + "go.opentelemetry.io/collector/exporter" ) func TestUnmarshalDefaultConfig(t *testing.T) { factory := NewFactory() cfg := factory.CreateDefaultConfig() - assert.NoError(t, component.UnmarshalExporterConfig(confmap.New(), cfg)) + assert.NoError(t, exporter.UnmarshalExporterConfig(confmap.New(), cfg)) assert.Equal(t, factory.CreateDefaultConfig(), cfg) } @@ -86,7 +87,7 @@ func TestUnmarshalConfig(t *testing.T) { require.NoError(t, err) factory := NewFactory() cfg := factory.CreateDefaultConfig() - err = component.UnmarshalExporterConfig(cm, cfg) + err = exporter.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 a87c7cec2d5..711917dde4e 100644 --- a/exporter/loggingexporter/factory.go +++ b/exporter/loggingexporter/factory.go @@ -26,6 +26,7 @@ import ( "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/config/configtelemetry" "go.opentelemetry.io/collector/consumer" + "go.opentelemetry.io/collector/exporter" "go.opentelemetry.io/collector/exporter/exporterhelper" ) @@ -39,17 +40,17 @@ const ( var onceWarnLogLevel sync.Once // NewFactory creates a factory for Logging exporter -func NewFactory() component.ExporterFactory { - return component.NewExporterFactory( +func NewFactory() exporter.Factory { + return exporter.NewFactory( typeStr, createDefaultConfig, - component.WithTracesExporter(createTracesExporter, component.StabilityLevelInDevelopment), - component.WithMetricsExporter(createMetricsExporter, component.StabilityLevelInDevelopment), - component.WithLogsExporter(createLogsExporter, component.StabilityLevelInDevelopment), + exporter.WithTracesExporter(createTracesExporter, component.StabilityLevelInDevelopment), + exporter.WithMetricsExporter(createMetricsExporter, component.StabilityLevelInDevelopment), + exporter.WithLogsExporter(createLogsExporter, component.StabilityLevelInDevelopment), ) } -func createDefaultConfig() component.ExporterConfig { +func createDefaultConfig() exporter.Config { return &Config{ ExporterSettings: config.NewExporterSettings(component.NewID(typeStr)), LogLevel: zapcore.InfoLevel, @@ -59,7 +60,7 @@ func createDefaultConfig() component.ExporterConfig { } } -func createTracesExporter(ctx context.Context, set component.ExporterCreateSettings, config component.ExporterConfig) (component.TracesExporter, error) { +func createTracesExporter(ctx context.Context, set exporter.CreateSettings, config exporter.Config) (exporter.TracesExporter, error) { cfg := config.(*Config) exporterLogger := createLogger(cfg, set.TelemetrySettings.Logger) s := newLoggingExporter(exporterLogger, cfg.Verbosity) @@ -74,7 +75,7 @@ func createTracesExporter(ctx context.Context, set component.ExporterCreateSetti ) } -func createMetricsExporter(ctx context.Context, set component.ExporterCreateSettings, config component.ExporterConfig) (component.MetricsExporter, error) { +func createMetricsExporter(ctx context.Context, set exporter.CreateSettings, config exporter.Config) (exporter.MetricsExporter, error) { cfg := config.(*Config) exporterLogger := createLogger(cfg, set.TelemetrySettings.Logger) s := newLoggingExporter(exporterLogger, cfg.Verbosity) @@ -89,7 +90,7 @@ func createMetricsExporter(ctx context.Context, set component.ExporterCreateSett ) } -func createLogsExporter(ctx context.Context, set component.ExporterCreateSettings, config component.ExporterConfig) (component.LogsExporter, error) { +func createLogsExporter(ctx context.Context, set exporter.CreateSettings, config exporter.Config) (exporter.LogsExporter, error) { cfg := config.(*Config) exporterLogger := createLogger(cfg, set.TelemetrySettings.Logger) s := newLoggingExporter(exporterLogger, cfg.Verbosity) diff --git a/exporter/otlpexporter/config.go b/exporter/otlpexporter/config.go index c15770fa9eb..114b8a18290 100644 --- a/exporter/otlpexporter/config.go +++ b/exporter/otlpexporter/config.go @@ -17,9 +17,9 @@ package otlpexporter // import "go.opentelemetry.io/collector/exporter/otlpexpor import ( "fmt" - "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/config/configgrpc" + exporter2 "go.opentelemetry.io/collector/exporter" "go.opentelemetry.io/collector/exporter/exporterhelper" ) @@ -33,7 +33,7 @@ type Config struct { configgrpc.GRPCClientSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct. } -var _ component.ExporterConfig = (*Config)(nil) +var _ exporter2.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 6679a42a4dc..5592f177fd0 100644 --- a/exporter/otlpexporter/config_test.go +++ b/exporter/otlpexporter/config_test.go @@ -29,13 +29,14 @@ import ( "go.opentelemetry.io/collector/config/configtls" "go.opentelemetry.io/collector/confmap" "go.opentelemetry.io/collector/confmap/confmaptest" + exporter2 "go.opentelemetry.io/collector/exporter" "go.opentelemetry.io/collector/exporter/exporterhelper" ) func TestUnmarshalDefaultConfig(t *testing.T) { factory := NewFactory() cfg := factory.CreateDefaultConfig() - assert.NoError(t, component.UnmarshalExporterConfig(confmap.New(), cfg)) + assert.NoError(t, exporter2.UnmarshalExporterConfig(confmap.New(), cfg)) assert.Equal(t, factory.CreateDefaultConfig(), cfg) } @@ -44,7 +45,7 @@ func TestUnmarshalConfig(t *testing.T) { require.NoError(t, err) factory := NewFactory() cfg := factory.CreateDefaultConfig() - assert.NoError(t, component.UnmarshalExporterConfig(cm, cfg)) + assert.NoError(t, exporter2.UnmarshalExporterConfig(cm, cfg)) assert.Equal(t, &Config{ ExporterSettings: config.NewExporterSettings(component.NewID(typeStr)), diff --git a/exporter/otlpexporter/factory.go b/exporter/otlpexporter/factory.go index 3a140974375..a2e724b12b1 100644 --- a/exporter/otlpexporter/factory.go +++ b/exporter/otlpexporter/factory.go @@ -22,6 +22,7 @@ import ( "go.opentelemetry.io/collector/config/configcompression" "go.opentelemetry.io/collector/config/configgrpc" "go.opentelemetry.io/collector/consumer" + exporter2 "go.opentelemetry.io/collector/exporter" "go.opentelemetry.io/collector/exporter/exporterhelper" ) @@ -31,17 +32,17 @@ const ( ) // NewFactory creates a factory for OTLP exporter. -func NewFactory() component.ExporterFactory { - return component.NewExporterFactory( +func NewFactory() exporter2.ExporterFactory { + return exporter2.NewFactory( typeStr, createDefaultConfig, - component.WithTracesExporter(createTracesExporter, component.StabilityLevelStable), - component.WithMetricsExporter(createMetricsExporter, component.StabilityLevelStable), - component.WithLogsExporter(createLogsExporter, component.StabilityLevelBeta), + exporter2.WithTracesExporter(createTracesExporter, component.StabilityLevelStable), + exporter2.WithMetricsExporter(createMetricsExporter, component.StabilityLevelStable), + exporter2.WithLogsExporter(createLogsExporter, component.StabilityLevelBeta), ) } -func createDefaultConfig() component.ExporterConfig { +func createDefaultConfig() exporter2.ExporterConfig { return &Config{ ExporterSettings: config.NewExporterSettings(component.NewID(typeStr)), TimeoutSettings: exporterhelper.NewDefaultTimeoutSettings(), @@ -59,9 +60,9 @@ func createDefaultConfig() component.ExporterConfig { func createTracesExporter( ctx context.Context, - set component.ExporterCreateSettings, - cfg component.ExporterConfig, -) (component.TracesExporter, error) { + set exporter2.ExporterCreateSettings, + cfg exporter2.ExporterConfig, +) (exporter2.TracesExporter, error) { oce, err := newExporter(cfg, set) if err != nil { return nil, err @@ -79,9 +80,9 @@ func createTracesExporter( func createMetricsExporter( ctx context.Context, - set component.ExporterCreateSettings, - cfg component.ExporterConfig, -) (component.MetricsExporter, error) { + set exporter2.ExporterCreateSettings, + cfg exporter2.ExporterConfig, +) (exporter2.MetricsExporter, error) { oce, err := newExporter(cfg, set) if err != nil { return nil, err @@ -100,9 +101,9 @@ func createMetricsExporter( func createLogsExporter( ctx context.Context, - set component.ExporterCreateSettings, - cfg component.ExporterConfig, -) (component.LogsExporter, error) { + set exporter2.ExporterCreateSettings, + cfg exporter2.ExporterConfig, +) (exporter2.LogsExporter, error) { oce, err := newExporter(cfg, set) if err != nil { return nil, err diff --git a/exporter/otlpexporter/otlp.go b/exporter/otlpexporter/otlp.go index ea619888940..390daa54353 100644 --- a/exporter/otlpexporter/otlp.go +++ b/exporter/otlpexporter/otlp.go @@ -29,6 +29,7 @@ import ( "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/consumer/consumererror" + exporter2 "go.opentelemetry.io/collector/exporter" "go.opentelemetry.io/collector/exporter/exporterhelper" "go.opentelemetry.io/collector/pdata/plog" "go.opentelemetry.io/collector/pdata/plog/plogotlp" @@ -58,7 +59,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 component.ExporterConfig, set component.ExporterCreateSettings) (*exporter, error) { +func newExporter(cfg exporter2.ExporterConfig, set exporter2.ExporterCreateSettings) (*exporter, error) { oCfg := cfg.(*Config) if oCfg.Endpoint == "" { diff --git a/exporter/otlpexporter/otlp_test.go b/exporter/otlpexporter/otlp_test.go index e5899e63b7b..c90b61c291c 100644 --- a/exporter/otlpexporter/otlp_test.go +++ b/exporter/otlpexporter/otlp_test.go @@ -34,10 +34,10 @@ import ( "google.golang.org/grpc/status" "google.golang.org/protobuf/types/known/durationpb" - "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/component/componenttest" "go.opentelemetry.io/collector/config/configgrpc" "go.opentelemetry.io/collector/config/configtls" + exporter2 "go.opentelemetry.io/collector/exporter" "go.opentelemetry.io/collector/internal/testdata" "go.opentelemetry.io/collector/pdata/plog" "go.opentelemetry.io/collector/pdata/plog/plogotlp" @@ -586,7 +586,7 @@ func TestSendTracesOnResourceExhaustion(t *testing.T) { }, 10*time.Second, 5*time.Millisecond, "Should retry if RetryInfo is included into status details by the server.") } -func startServerAndMakeRequest(t *testing.T, exp component.TracesExporter, td ptrace.Traces, ln net.Listener) { +func startServerAndMakeRequest(t *testing.T, exp exporter2.TracesExporter, td ptrace.Traces, ln net.Listener) { rcv, _ := otlpTracesReceiverOnGRPCServer(ln, false) defer rcv.srv.GracefulStop() // Ensure that initially there is no data in the receiver. diff --git a/exporter/otlphttpexporter/config.go b/exporter/otlphttpexporter/config.go index 04fbf7d4bc4..06c6995316e 100644 --- a/exporter/otlphttpexporter/config.go +++ b/exporter/otlphttpexporter/config.go @@ -17,9 +17,9 @@ package otlphttpexporter // import "go.opentelemetry.io/collector/exporter/otlph import ( "errors" - "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/config/confighttp" + exporter2 "go.opentelemetry.io/collector/exporter" "go.opentelemetry.io/collector/exporter/exporterhelper" ) @@ -40,7 +40,7 @@ type Config struct { LogsEndpoint string `mapstructure:"logs_endpoint"` } -var _ component.ExporterConfig = (*Config)(nil) +var _ exporter2.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 9f37c110149..0b97d488e9b 100644 --- a/exporter/otlphttpexporter/config_test.go +++ b/exporter/otlphttpexporter/config_test.go @@ -28,13 +28,14 @@ import ( "go.opentelemetry.io/collector/config/configtls" "go.opentelemetry.io/collector/confmap" "go.opentelemetry.io/collector/confmap/confmaptest" + exporter2 "go.opentelemetry.io/collector/exporter" "go.opentelemetry.io/collector/exporter/exporterhelper" ) func TestUnmarshalDefaultConfig(t *testing.T) { factory := NewFactory() cfg := factory.CreateDefaultConfig() - assert.NoError(t, component.UnmarshalExporterConfig(confmap.New(), cfg)) + assert.NoError(t, exporter2.UnmarshalExporterConfig(confmap.New(), cfg)) assert.Equal(t, factory.CreateDefaultConfig(), cfg) // Default/Empty config is invalid. assert.Error(t, cfg.Validate()) @@ -45,7 +46,7 @@ func TestUnmarshalConfig(t *testing.T) { require.NoError(t, err) factory := NewFactory() cfg := factory.CreateDefaultConfig() - assert.NoError(t, component.UnmarshalExporterConfig(cm, cfg)) + assert.NoError(t, exporter2.UnmarshalExporterConfig(cm, cfg)) assert.Equal(t, &Config{ ExporterSettings: config.NewExporterSettings(component.NewID(typeStr)), diff --git a/exporter/otlphttpexporter/factory.go b/exporter/otlphttpexporter/factory.go index 5048d920f0d..4f8fb8b1627 100644 --- a/exporter/otlphttpexporter/factory.go +++ b/exporter/otlphttpexporter/factory.go @@ -25,6 +25,7 @@ import ( "go.opentelemetry.io/collector/config/configcompression" "go.opentelemetry.io/collector/config/confighttp" "go.opentelemetry.io/collector/consumer" + exporter2 "go.opentelemetry.io/collector/exporter" "go.opentelemetry.io/collector/exporter/exporterhelper" ) @@ -34,17 +35,17 @@ const ( ) // NewFactory creates a factory for OTLP exporter. -func NewFactory() component.ExporterFactory { - return component.NewExporterFactory( +func NewFactory() exporter2.ExporterFactory { + return exporter2.NewFactory( typeStr, createDefaultConfig, - component.WithTracesExporter(createTracesExporter, component.StabilityLevelStable), - component.WithMetricsExporter(createMetricsExporter, component.StabilityLevelStable), - component.WithLogsExporter(createLogsExporter, component.StabilityLevelBeta), + exporter2.WithTracesExporter(createTracesExporter, component.StabilityLevelStable), + exporter2.WithMetricsExporter(createMetricsExporter, component.StabilityLevelStable), + exporter2.WithLogsExporter(createLogsExporter, component.StabilityLevelBeta), ) } -func createDefaultConfig() component.ExporterConfig { +func createDefaultConfig() exporter2.ExporterConfig { return &Config{ ExporterSettings: config.NewExporterSettings(component.NewID(typeStr)), RetrySettings: exporterhelper.NewDefaultRetrySettings(), @@ -78,9 +79,9 @@ func composeSignalURL(oCfg *Config, signalOverrideURL string, signalName string) func createTracesExporter( ctx context.Context, - set component.ExporterCreateSettings, - cfg component.ExporterConfig, -) (component.TracesExporter, error) { + set exporter2.ExporterCreateSettings, + cfg exporter2.ExporterConfig, +) (exporter2.TracesExporter, error) { oce, err := newExporter(cfg, set) if err != nil { return nil, err @@ -104,9 +105,9 @@ func createTracesExporter( func createMetricsExporter( ctx context.Context, - set component.ExporterCreateSettings, - cfg component.ExporterConfig, -) (component.MetricsExporter, error) { + set exporter2.ExporterCreateSettings, + cfg exporter2.ExporterConfig, +) (exporter2.MetricsExporter, error) { oce, err := newExporter(cfg, set) if err != nil { return nil, err @@ -130,9 +131,9 @@ func createMetricsExporter( func createLogsExporter( ctx context.Context, - set component.ExporterCreateSettings, - cfg component.ExporterConfig, -) (component.LogsExporter, error) { + set exporter2.ExporterCreateSettings, + cfg exporter2.ExporterConfig, +) (exporter2.LogsExporter, error) { oce, err := newExporter(cfg, set) if err != nil { return nil, err diff --git a/exporter/otlphttpexporter/otlp.go b/exporter/otlphttpexporter/otlp.go index 95ea2c4118b..11a129070c3 100644 --- a/exporter/otlphttpexporter/otlp.go +++ b/exporter/otlphttpexporter/otlp.go @@ -32,6 +32,7 @@ import ( "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/consumer/consumererror" + exporter2 "go.opentelemetry.io/collector/exporter" "go.opentelemetry.io/collector/exporter/exporterhelper" "go.opentelemetry.io/collector/pdata/plog" "go.opentelemetry.io/collector/pdata/plog/plogotlp" @@ -60,7 +61,7 @@ const ( ) // Create new exporter. -func newExporter(cfg component.ExporterConfig, set component.ExporterCreateSettings) (*exporter, error) { +func newExporter(cfg exporter2.ExporterConfig, set exporter2.ExporterCreateSettings) (*exporter, error) { oCfg := cfg.(*Config) if oCfg.Endpoint != "" { diff --git a/exporter/otlphttpexporter/otlp_test.go b/exporter/otlphttpexporter/otlp_test.go index 83361af35f2..1f5ec6e535a 100644 --- a/exporter/otlphttpexporter/otlp_test.go +++ b/exporter/otlphttpexporter/otlp_test.go @@ -42,6 +42,7 @@ import ( "go.opentelemetry.io/collector/consumer" "go.opentelemetry.io/collector/consumer/consumererror" "go.opentelemetry.io/collector/consumer/consumertest" + exporter2 "go.opentelemetry.io/collector/exporter" "go.opentelemetry.io/collector/exporter/exporterhelper" "go.opentelemetry.io/collector/internal/testdata" "go.opentelemetry.io/collector/internal/testutil" @@ -302,7 +303,7 @@ func TestIssue_4221(t *testing.T) { assert.NoError(t, exp.ConsumeTraces(context.Background(), md)) } -func startTracesExporter(t *testing.T, baseURL string, overrideURL string) component.TracesExporter { +func startTracesExporter(t *testing.T, baseURL string, overrideURL string) exporter2.TracesExporter { factory := NewFactory() cfg := createExporterConfig(baseURL, factory.CreateDefaultConfig()) cfg.TracesEndpoint = overrideURL @@ -312,7 +313,7 @@ func startTracesExporter(t *testing.T, baseURL string, overrideURL string) compo return exp } -func startMetricsExporter(t *testing.T, baseURL string, overrideURL string) component.MetricsExporter { +func startMetricsExporter(t *testing.T, baseURL string, overrideURL string) exporter2.MetricsExporter { factory := NewFactory() cfg := createExporterConfig(baseURL, factory.CreateDefaultConfig()) cfg.MetricsEndpoint = overrideURL @@ -322,7 +323,7 @@ func startMetricsExporter(t *testing.T, baseURL string, overrideURL string) comp return exp } -func startLogsExporter(t *testing.T, baseURL string, overrideURL string) component.LogsExporter { +func startLogsExporter(t *testing.T, baseURL string, overrideURL string) exporter2.LogsExporter { factory := NewFactory() cfg := createExporterConfig(baseURL, factory.CreateDefaultConfig()) cfg.LogsEndpoint = overrideURL @@ -332,7 +333,7 @@ func startLogsExporter(t *testing.T, baseURL string, overrideURL string) compone return exp } -func createExporterConfig(baseURL string, defaultCfg component.ExporterConfig) *Config { +func createExporterConfig(baseURL string, defaultCfg exporter2.ExporterConfig) *Config { cfg := defaultCfg.(*Config) cfg.Endpoint = baseURL cfg.QueueSettings.Enabled = false diff --git a/extension/ballastextension/config_test.go b/extension/ballastextension/config_test.go index f61e15524cf..5e9ace3561e 100644 --- a/extension/ballastextension/config_test.go +++ b/extension/ballastextension/config_test.go @@ -25,12 +25,13 @@ import ( "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/confmap" "go.opentelemetry.io/collector/confmap/confmaptest" + "go.opentelemetry.io/collector/extension" ) func TestUnmarshalDefaultConfig(t *testing.T) { factory := NewFactory() cfg := factory.CreateDefaultConfig() - assert.NoError(t, component.UnmarshalExtensionConfig(confmap.New(), cfg)) + assert.NoError(t, extension.UnmarshalExtensionConfig(confmap.New(), cfg)) assert.Equal(t, factory.CreateDefaultConfig(), cfg) } @@ -39,7 +40,7 @@ func TestUnmarshalConfig(t *testing.T) { require.NoError(t, err) factory := NewFactory() cfg := factory.CreateDefaultConfig() - assert.NoError(t, component.UnmarshalExtensionConfig(cm, cfg)) + assert.NoError(t, extension.UnmarshalExtensionConfig(cm, cfg)) assert.Equal(t, &Config{ ExtensionSettings: config.NewExtensionSettings(component.NewID(typeStr)), diff --git a/extension/ballastextension/factory.go b/extension/ballastextension/factory.go index 6d5687c3286..61ef6d894b3 100644 --- a/extension/ballastextension/factory.go +++ b/extension/ballastextension/factory.go @@ -19,6 +19,7 @@ import ( "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/config" + "go.opentelemetry.io/collector/extension" "go.opentelemetry.io/collector/internal/iruntime" ) @@ -31,16 +32,16 @@ const ( var memHandler = iruntime.TotalMemory // NewFactory creates a factory for FluentBit extension. -func NewFactory() component.ExtensionFactory { - return component.NewExtensionFactory(typeStr, createDefaultConfig, createExtension, component.StabilityLevelBeta) +func NewFactory() extension.Factory { + return extension.NewExtensionFactory(typeStr, createDefaultConfig, createExtension, component.StabilityLevelBeta) } -func createDefaultConfig() component.ExtensionConfig { +func createDefaultConfig() extension.Config { return &Config{ ExtensionSettings: config.NewExtensionSettings(component.NewID(typeStr)), } } -func createExtension(_ context.Context, set component.ExtensionCreateSettings, cfg component.ExtensionConfig) (component.Extension, error) { +func createExtension(_ context.Context, set extension.CreateSettings, cfg extension.Config) (extension.Extension, error) { return newMemoryBallast(cfg.(*Config), set.Logger, memHandler), nil } diff --git a/extension/experimental/storage/storage.go b/extension/experimental/storage/storage.go index 9d23ee476c7..854554c2098 100644 --- a/extension/experimental/storage/storage.go +++ b/extension/experimental/storage/storage.go @@ -18,11 +18,12 @@ import ( "context" "go.opentelemetry.io/collector/component" + "go.opentelemetry.io/collector/extension" ) // Extension is the interface that storage extensions must implement type Extension interface { - component.Extension + extension.Extension // GetClient will create a client for use by the specified component. // Each component can have multiple storages (e.g. one for each signal), diff --git a/component/extension.go b/extension/extension.go similarity index 54% rename from component/extension.go rename to extension/extension.go index 09477006a47..859009a6bd8 100644 --- a/component/extension.go +++ b/extension/extension.go @@ -12,35 +12,27 @@ // See the License for the specific language governing permissions and // limitations under the License. -package component // import "go.opentelemetry.io/collector/component" +package extension // import "go.opentelemetry.io/collector/component" import ( "context" - "go.opentelemetry.io/collector/confmap" + "go.opentelemetry.io/collector/component" ) -// ExtensionConfig is the configuration of a component.Extension. Specific Extension must implement +// Config is the configuration of a component.Extension. Specific Extension must implement // this interface and must embed config.ExtensionSettings struct or a struct that extends it. -type ExtensionConfig interface { - identifiable - validatable +type Config interface { + component.Config privateConfigExtension() } -// UnmarshalExtensionConfig helper function to unmarshal an ExtensionConfig. -// It checks if the config implements confmap.Unmarshaler and uses that if available, -// otherwise uses Map.UnmarshalExact, erroring if a field is nonexistent. -func UnmarshalExtensionConfig(conf *confmap.Conf, cfg ExtensionConfig) error { - return unmarshal(conf, cfg) -} - // Extension is the interface for objects hosted by the OpenTelemetry Collector that // don't participate directly on data pipelines but provide some functionality // to the service, examples: health check endpoint, z-pages, etc. type Extension interface { - Component + component.Component } // PipelineWatcher is an extra interface for Extension hosted by the OpenTelemetry @@ -60,33 +52,33 @@ type PipelineWatcher interface { NotReady() error } -// ExtensionCreateSettings is passed to ExtensionFactory.Create* functions. -type ExtensionCreateSettings struct { - TelemetrySettings +// CreateSettings is passed to Factory.Create* functions. +type CreateSettings struct { + Telemetry component.TelemetrySettings // BuildInfo can be used by components for informational purposes - BuildInfo BuildInfo + BuildInfo component.BuildInfo } -// ExtensionCreateDefaultConfigFunc is the equivalent of ExtensionFactory.CreateDefaultConfig() -type ExtensionCreateDefaultConfigFunc func() ExtensionConfig +// CreateDefaultConfigFunc is the equivalent of Factory.CreateDefaultConfig() +type CreateDefaultConfigFunc func() Config -// CreateDefaultConfig implements ExtensionFactory.CreateDefaultConfig() -func (f ExtensionCreateDefaultConfigFunc) CreateDefaultConfig() ExtensionConfig { +// CreateDefaultConfig implements Factory.CreateDefaultConfig() +func (f CreateDefaultConfigFunc) CreateDefaultConfig() Config { return f() } -// CreateExtensionFunc is the equivalent of ExtensionFactory.CreateExtension() -type CreateExtensionFunc func(context.Context, ExtensionCreateSettings, ExtensionConfig) (Extension, error) +// CreateExtensionFunc is the equivalent of Factory.CreateExtension() +type CreateExtensionFunc func(context.Context, CreateSettings, Config) (Extension, error) -// CreateExtension implements ExtensionFactory.CreateExtension. -func (f CreateExtensionFunc) CreateExtension(ctx context.Context, set ExtensionCreateSettings, cfg ExtensionConfig) (Extension, error) { +// CreateExtension implements Factory.CreateExtension. +func (f CreateExtensionFunc) CreateExtension(ctx context.Context, set CreateSettings, cfg Config) (Extension, error) { return f(ctx, set, cfg) } -// ExtensionFactory is a factory for extensions to the service. -type ExtensionFactory interface { - Factory +// Factory is a factory for extensions to the service. +type Factory interface { + component.Factory // CreateDefaultConfig creates the default configuration for the Extension. // This method can be called multiple times depending on the pipeline @@ -95,36 +87,44 @@ type ExtensionFactory interface { // The object returned by this method needs to pass the checks implemented by // 'componenttest.CheckConfigStruct'. It is recommended to have these checks in the // tests of any implementation of the Factory interface. - CreateDefaultConfig() ExtensionConfig + CreateDefaultConfig() Config // CreateExtension creates an extension based on the given config. - CreateExtension(ctx context.Context, set ExtensionCreateSettings, cfg ExtensionConfig) (Extension, error) + CreateExtension(ctx context.Context, set CreateSettings, cfg Config) (Extension, error) // ExtensionStability gets the stability level of the Extension. - ExtensionStability() StabilityLevel + ExtensionStability() component.StabilityLevel + + unexportedFunc() } -type extensionFactory struct { - baseFactory - ExtensionCreateDefaultConfigFunc +type factory struct { + cfgType component.Type + CreateDefaultConfigFunc CreateExtensionFunc - extensionStability StabilityLevel + extensionStability component.StabilityLevel } -func (ef *extensionFactory) ExtensionStability() StabilityLevel { +func (f factory) Type() component.Type { + return f.cfgType +} + +func (f factory) unexportedFunc() {} + +func (ef *factory) ExtensionStability() component.StabilityLevel { return ef.extensionStability } -// NewExtensionFactory returns a new ExtensionFactory based on this configuration. +// NewExtensionFactory returns a new Factory based on this configuration. func NewExtensionFactory( - cfgType Type, - createDefaultConfig ExtensionCreateDefaultConfigFunc, + cfgType component.Type, + createDefaultConfig CreateDefaultConfigFunc, createServiceExtension CreateExtensionFunc, - sl StabilityLevel) ExtensionFactory { - return &extensionFactory{ - baseFactory: baseFactory{cfgType: cfgType}, - ExtensionCreateDefaultConfigFunc: createDefaultConfig, - CreateExtensionFunc: createServiceExtension, - extensionStability: sl, + sl component.StabilityLevel) Factory { + return &factory{ + cfgType: cfgType, + CreateDefaultConfigFunc: createDefaultConfig, + CreateExtensionFunc: createServiceExtension, + extensionStability: sl, } } diff --git a/component/extension_test.go b/extension/extension_test.go similarity index 79% rename from component/extension_test.go rename to extension/extension_test.go index 24c34386c44..7854e0290c3 100644 --- a/component/extension_test.go +++ b/extension/extension_test.go @@ -14,7 +14,7 @@ // TODO: Move tests back to component package after config.*Settings are removed. -package component_test +package extension_test import ( "context" @@ -24,6 +24,7 @@ import ( "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/config" + "go.opentelemetry.io/collector/extension" ) type nopExtension struct { @@ -36,10 +37,10 @@ func TestNewExtensionFactory(t *testing.T) { defaultCfg := config.NewExtensionSettings(component.NewID(typeStr)) nopExtensionInstance := new(nopExtension) - factory := component.NewExtensionFactory( + factory := extension.NewExtensionFactory( typeStr, - func() component.ExtensionConfig { return &defaultCfg }, - func(ctx context.Context, settings component.ExtensionCreateSettings, extension component.ExtensionConfig) (component.Extension, error) { + func() extension.Config { return &defaultCfg }, + func(ctx context.Context, settings extension.CreateSettings, extension extension.Config) (extension.Extension, error) { return nopExtensionInstance, nil }, component.StabilityLevelInDevelopment) @@ -47,7 +48,7 @@ func TestNewExtensionFactory(t *testing.T) { assert.EqualValues(t, &defaultCfg, factory.CreateDefaultConfig()) assert.Equal(t, component.StabilityLevelInDevelopment, factory.ExtensionStability()) - ext, err := factory.CreateExtension(context.Background(), component.ExtensionCreateSettings{}, &defaultCfg) + ext, err := factory.CreateExtension(context.Background(), extension.CreateSettings{}, &defaultCfg) assert.NoError(t, err) assert.Same(t, nopExtensionInstance, ext) } diff --git a/extension/zpagesextension/config.go b/extension/zpagesextension/config.go index 8774f870d79..e74a2b4b9e3 100644 --- a/extension/zpagesextension/config.go +++ b/extension/zpagesextension/config.go @@ -17,9 +17,9 @@ package zpagesextension // import "go.opentelemetry.io/collector/extension/zpage import ( "errors" - "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/config/confignet" + "go.opentelemetry.io/collector/extension" ) // Config has the configuration for the extension enabling the zPages extension. @@ -32,7 +32,7 @@ type Config struct { TCPAddr confignet.TCPAddr `mapstructure:",squash"` } -var _ component.ExtensionConfig = (*Config)(nil) +var _ extension.Config = (*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 d698d4f1da1..f1d9734fb4f 100644 --- a/extension/zpagesextension/config_test.go +++ b/extension/zpagesextension/config_test.go @@ -26,12 +26,13 @@ import ( "go.opentelemetry.io/collector/config/confignet" "go.opentelemetry.io/collector/confmap" "go.opentelemetry.io/collector/confmap/confmaptest" + "go.opentelemetry.io/collector/extension" ) func TestUnmarshalDefaultConfig(t *testing.T) { factory := NewFactory() cfg := factory.CreateDefaultConfig() - assert.NoError(t, component.UnmarshalExtensionConfig(confmap.New(), cfg)) + assert.NoError(t, extension.UnmarshalExtensionConfig(confmap.New(), cfg)) assert.Equal(t, factory.CreateDefaultConfig(), cfg) } @@ -40,7 +41,7 @@ func TestUnmarshalConfig(t *testing.T) { require.NoError(t, err) factory := NewFactory() cfg := factory.CreateDefaultConfig() - assert.NoError(t, component.UnmarshalExtensionConfig(cm, cfg)) + assert.NoError(t, extension.UnmarshalExtensionConfig(cm, cfg)) assert.Equal(t, &Config{ ExtensionSettings: config.NewExtensionSettings(component.NewID(typeStr)), diff --git a/extension/zpagesextension/factory.go b/extension/zpagesextension/factory.go index 5d7a458c5d7..75cac547319 100644 --- a/extension/zpagesextension/factory.go +++ b/extension/zpagesextension/factory.go @@ -20,6 +20,7 @@ import ( "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/config/confignet" + "go.opentelemetry.io/collector/extension" ) const ( @@ -30,11 +31,11 @@ const ( ) // NewFactory creates a factory for Z-Pages extension. -func NewFactory() component.ExtensionFactory { - return component.NewExtensionFactory(typeStr, createDefaultConfig, createExtension, component.StabilityLevelBeta) +func NewFactory() extension.Factory { + return extension.NewExtensionFactory(typeStr, createDefaultConfig, createExtension, component.StabilityLevelBeta) } -func createDefaultConfig() component.ExtensionConfig { +func createDefaultConfig() extension.Config { return &Config{ ExtensionSettings: config.NewExtensionSettings(component.NewID(typeStr)), TCPAddr: confignet.TCPAddr{ @@ -44,6 +45,6 @@ func createDefaultConfig() component.ExtensionConfig { } // createExtension creates the extension based on this config. -func createExtension(_ context.Context, set component.ExtensionCreateSettings, cfg component.ExtensionConfig) (component.Extension, error) { +func createExtension(_ context.Context, set extension.CreateSettings, cfg extension.Config) (extension.Extension, error) { return newServer(cfg.(*Config), set.TelemetrySettings), nil } diff --git a/obsreport/obsreport_exporter.go b/obsreport/obsreport_exporter.go index 245a31b8267..94200bd3d59 100644 --- a/obsreport/obsreport_exporter.go +++ b/obsreport/obsreport_exporter.go @@ -29,6 +29,7 @@ import ( "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/config/configtelemetry" + "go.opentelemetry.io/collector/exporter" "go.opentelemetry.io/collector/featuregate" "go.opentelemetry.io/collector/internal/obsreportconfig" "go.opentelemetry.io/collector/internal/obsreportconfig/obsmetrics" @@ -61,7 +62,7 @@ type Exporter struct { // ExporterSettings are settings for creating an Exporter. type ExporterSettings struct { ExporterID component.ID - ExporterCreateSettings component.ExporterCreateSettings + ExporterCreateSettings exporter.CreateSettings } // NewExporter creates a new Exporter. @@ -84,8 +85,8 @@ func newExporter(cfg ExporterSettings, registry *featuregate.Registry) (*Exporte level: cfg.ExporterCreateSettings.TelemetrySettings.MetricsLevel, spanNamePrefix: obsmetrics.ExporterPrefix + cfg.ExporterID.String(), mutators: []tag.Mutator{tag.Upsert(obsmetrics.TagKeyExporter, cfg.ExporterID.String(), tag.WithTTL(tag.TTLNoPropagation))}, - tracer: cfg.ExporterCreateSettings.TracerProvider.Tracer(cfg.ExporterID.String()), - logger: cfg.ExporterCreateSettings.Logger, + tracer: cfg.ExporterCreateSettings.TelemetrySettings.TracerProvider.Tracer(cfg.ExporterID.String()), + logger: cfg.ExporterCreateSettings.TelemetrySettings.Logger, useOtelForMetrics: registry.IsEnabled(obsreportconfig.UseOtelForInternalMetricsfeatureGateID), otelAttrs: []attribute.KeyValue{ @@ -104,7 +105,7 @@ func (exp *Exporter) createOtelMetrics(cfg ExporterSettings) error { if !exp.useOtelForMetrics { return nil } - meter := cfg.ExporterCreateSettings.MeterProvider.Meter(exporterScope) + meter := cfg.ExporterCreateSettings.TelemetrySettings.MeterProvider.Meter(exporterScope) var errors, err error diff --git a/obsreport/obsreporttest/obsreporttest.go b/obsreport/obsreporttest/obsreporttest.go index 4fcd7185673..aa062ca9d2b 100644 --- a/obsreport/obsreporttest/obsreporttest.go +++ b/obsreport/obsreporttest/obsreporttest.go @@ -34,6 +34,7 @@ import ( "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/component/componenttest" "go.opentelemetry.io/collector/config/configtelemetry" + "go.opentelemetry.io/collector/exporter" "go.opentelemetry.io/collector/internal/obsreportconfig" ) @@ -62,7 +63,7 @@ type TestTelemetry struct { } // ToExporterCreateSettings returns ExporterCreateSettings with configured TelemetrySettings -func (tts *TestTelemetry) ToExporterCreateSettings() component.ExporterCreateSettings { +func (tts *TestTelemetry) ToExporterCreateSettings() exporter.CreateSettings { exporterSettings := componenttest.NewNopExporterCreateSettings() exporterSettings.TelemetrySettings = tts.TelemetrySettings return exporterSettings diff --git a/processor/memorylimiterprocessor/memorylimiter_test.go b/processor/memorylimiterprocessor/memorylimiter_test.go index 0ebe99d4ab2..1b046ae885c 100644 --- a/processor/memorylimiterprocessor/memorylimiter_test.go +++ b/processor/memorylimiterprocessor/memorylimiter_test.go @@ -31,6 +31,7 @@ import ( "go.opentelemetry.io/collector/config/configtelemetry" "go.opentelemetry.io/collector/consumer" "go.opentelemetry.io/collector/consumer/consumertest" + "go.opentelemetry.io/collector/extension" "go.opentelemetry.io/collector/internal/iruntime" "go.opentelemetry.io/collector/obsreport" "go.opentelemetry.io/collector/pdata/plog" @@ -430,8 +431,8 @@ type host struct { component.Host } -func (h *host) GetExtensions() map[component.ID]component.Extension { - ret := make(map[component.ID]component.Extension) +func (h *host) GetExtensions() map[component.ID]extension.Extension { + ret := make(map[component.ID]extension.Extension) ret[component.NewID("ballast")] = &ballastExtension{ballastSize: h.ballastSize} return ret } diff --git a/service/config.go b/service/config.go index 5900012770d..a998a6a8468 100644 --- a/service/config.go +++ b/service/config.go @@ -20,6 +20,8 @@ import ( "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/config" + "go.opentelemetry.io/collector/exporter" + "go.opentelemetry.io/collector/extension" "go.opentelemetry.io/collector/service/telemetry" ) @@ -35,13 +37,13 @@ type Config struct { Receivers map[component.ID]component.ReceiverConfig // Exporters is a map of ComponentID to Exporters. - Exporters map[component.ID]component.ExporterConfig + Exporters map[component.ID]exporter.Config // Processors is a map of ComponentID to Processors. Processors map[component.ID]component.ProcessorConfig // Extensions is a map of ComponentID to extensions. - Extensions map[component.ID]component.ExtensionConfig + Extensions map[component.ID]extension.Config Service ConfigService } diff --git a/service/config_provider.go b/service/config_provider.go index 3feba9741fe..b4b231320f1 100644 --- a/service/config_provider.go +++ b/service/config_provider.go @@ -18,7 +18,6 @@ import ( "context" "fmt" - "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/confmap" "go.opentelemetry.io/collector/confmap/converter/expandconverter" "go.opentelemetry.io/collector/confmap/provider/envprovider" @@ -41,7 +40,7 @@ type ConfigProvider interface { // Get returns the service configuration, or error otherwise. // // Should never be called concurrently with itself, Watch or Shutdown. - Get(ctx context.Context, factories component.Factories) (*Config, error) + Get(ctx context.Context, factories Factories) (*Config, error) // Watch blocks until any configuration change was detected or an unrecoverable error // happened during monitoring the configuration changes. @@ -98,7 +97,7 @@ func NewConfigProvider(set ConfigProviderSettings) (ConfigProvider, error) { }, nil } -func (cm *configProvider) Get(ctx context.Context, factories component.Factories) (*Config, error) { +func (cm *configProvider) Get(ctx context.Context, factories Factories) (*Config, error) { conf, err := cm.mapResolver.Resolve(ctx) if err != nil { return nil, fmt.Errorf("cannot resolve the configuration: %w", err) diff --git a/service/config_provider_test.go b/service/config_provider_test.go index 2bbfba4568a..23a2c5712a8 100644 --- a/service/config_provider_test.go +++ b/service/config_provider_test.go @@ -30,14 +30,16 @@ import ( "go.opentelemetry.io/collector/confmap" "go.opentelemetry.io/collector/confmap/provider/fileprovider" "go.opentelemetry.io/collector/confmap/provider/yamlprovider" + "go.opentelemetry.io/collector/exporter" + "go.opentelemetry.io/collector/extension" "go.opentelemetry.io/collector/service/telemetry" ) var configNop = &Config{ 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()}, + Exporters: map[component.ID]exporter.Config{component.NewID("nop"): componenttest.NewNopExporterFactory().CreateDefaultConfig()}, + Extensions: map[component.ID]extension.Config{component.NewID("nop"): componenttest.NewNopExtensionFactory().CreateDefaultConfig()}, Service: ConfigService{ Extensions: []component.ID{component.NewID("nop")}, Pipelines: map[component.ID]*ConfigServicePipeline{ diff --git a/service/config_test.go b/service/config_test.go index 3718a71701c..e327cac5553 100644 --- a/service/config_test.go +++ b/service/config_test.go @@ -25,6 +25,8 @@ import ( "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/config/configtelemetry" + "go.opentelemetry.io/collector/exporter" + "go.opentelemetry.io/collector/extension" "go.opentelemetry.io/collector/service/telemetry" ) @@ -265,7 +267,7 @@ func generateConfig() *Config { ReceiverSettings: config.NewReceiverSettings(component.NewID("nop")), }, }, - Exporters: map[component.ID]component.ExporterConfig{ + Exporters: map[component.ID]exporter.Config{ component.NewID("nop"): &nopExpConfig{ ExporterSettings: config.NewExporterSettings(component.NewID("nop")), }, @@ -275,7 +277,7 @@ func generateConfig() *Config { ProcessorSettings: config.NewProcessorSettings(component.NewID("nop")), }, }, - Extensions: map[component.ID]component.ExtensionConfig{ + Extensions: map[component.ID]extension.Config{ component.NewID("nop"): &nopExtConfig{ ExtensionSettings: config.NewExtensionSettings(component.NewID("nop")), }, diff --git a/service/extensions/extensions.go b/service/extensions/extensions.go index 1e20f430290..327873cf15c 100644 --- a/service/extensions/extensions.go +++ b/service/extensions/extensions.go @@ -24,6 +24,7 @@ import ( "go.uber.org/zap" "go.opentelemetry.io/collector/component" + "go.opentelemetry.io/collector/extension" "go.opentelemetry.io/collector/service/internal/components" "go.opentelemetry.io/collector/service/internal/zpages" ) @@ -33,7 +34,7 @@ const zExtensionName = "zextensionname" // Extensions is a map of extensions created from extension configs. type Extensions struct { telemetry component.TelemetrySettings - extMap map[component.ID]component.Extension + extMap map[component.ID]extension.Extension } // Start starts all extensions. @@ -63,7 +64,7 @@ func (bes *Extensions) Shutdown(ctx context.Context) error { func (bes *Extensions) NotifyPipelineReady() error { for extID, ext := range bes.extMap { - if pw, ok := ext.(component.PipelineWatcher); ok { + if pw, ok := ext.(extension.PipelineWatcher); ok { if err := pw.Ready(); err != nil { return fmt.Errorf("failed to notify extension %q: %w", extID, err) } @@ -76,15 +77,15 @@ func (bes *Extensions) NotifyPipelineNotReady() error { // Notify extensions in reverse order. var errs error for _, ext := range bes.extMap { - if pw, ok := ext.(component.PipelineWatcher); ok { + if pw, ok := ext.(extension.PipelineWatcher); ok { errs = multierr.Append(errs, pw.NotReady()) } } return errs } -func (bes *Extensions) GetExtensions() map[component.ID]component.Extension { - result := make(map[component.ID]component.Extension, len(bes.extMap)) +func (bes *Extensions) GetExtensions() map[component.ID]extension.Extension { + result := make(map[component.ID]extension.Extension, len(bes.extMap)) for extID, v := range bes.extMap { result[extID] = v } @@ -122,18 +123,18 @@ type Settings struct { Telemetry component.TelemetrySettings BuildInfo component.BuildInfo - // Configs is a map of component.ID to component.ExtensionConfig. - Configs map[component.ID]component.ExtensionConfig + // Configs is a map of component.ID to component.Config. + Configs map[component.ID]extension.Config - // Factories maps extension type names in the config to the respective component.ExtensionFactory. - Factories map[component.Type]component.ExtensionFactory + // Factories maps extension type names in the config to the respective component.Factory. + Factories map[component.Type]extension.Factory } // 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[component.ID]component.Extension), + extMap: make(map[component.ID]extension.Extension), } for _, extID := range cfg { extCfg, existsCfg := set.Configs[extID] @@ -146,7 +147,7 @@ func New(ctx context.Context, set Settings, cfg Config) (*Extensions, error) { return nil, fmt.Errorf("extension factory for type %q is not configured", extID.Type()) } - extSet := component.ExtensionCreateSettings{ + extSet := extension.CreateSettings{ TelemetrySettings: set.Telemetry, BuildInfo: set.BuildInfo, } diff --git a/service/extensions/extensions_test.go b/service/extensions/extensions_test.go index 05e7622951f..5b6e03c12d9 100644 --- a/service/extensions/extensions_test.go +++ b/service/extensions/extensions_test.go @@ -25,6 +25,8 @@ import ( "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/component/componenttest" "go.opentelemetry.io/collector/config" + "go.opentelemetry.io/collector/extension" + "go.opentelemetry.io/collector/service" ) func TestBuildExtensions(t *testing.T) { @@ -37,8 +39,8 @@ func TestBuildExtensions(t *testing.T) { tests := []struct { name string - factories component.Factories - extensionsConfigs map[component.ID]component.ExtensionConfig + factories service.Factories + extensionsConfigs map[component.ID]extension.Config serviceExtensions []component.ID wantErrMsg string }{ @@ -51,7 +53,7 @@ func TestBuildExtensions(t *testing.T) { }, { name: "missing_extension_factory", - extensionsConfigs: map[component.ID]component.ExtensionConfig{ + extensionsConfigs: map[component.ID]extension.Config{ component.NewID("unknown"): nopExtensionConfig, }, serviceExtensions: []component.ID{ @@ -61,12 +63,12 @@ func TestBuildExtensions(t *testing.T) { }, { name: "error_on_create_extension", - factories: component.Factories{ - Extensions: map[component.Type]component.ExtensionFactory{ + factories: service.Factories{ + Extensions: map[component.Type]extension.Factory{ errExtensionFactory.Type(): errExtensionFactory, }, }, - extensionsConfigs: map[component.ID]component.ExtensionConfig{ + extensionsConfigs: map[component.ID]extension.Config{ component.NewID(errExtensionFactory.Type()): errExtensionConfig, }, serviceExtensions: []component.ID{ @@ -76,12 +78,12 @@ func TestBuildExtensions(t *testing.T) { }, { name: "bad_factory", - factories: component.Factories{ - Extensions: map[component.Type]component.ExtensionFactory{ + factories: service.Factories{ + Extensions: map[component.Type]extension.Factory{ badExtensionFactory.Type(): badExtensionFactory, }, }, - extensionsConfigs: map[component.ID]component.ExtensionConfig{ + extensionsConfigs: map[component.ID]extension.Config{ component.NewID(badExtensionFactory.Type()): badExtensionCfg, }, serviceExtensions: []component.ID{ @@ -105,34 +107,34 @@ func TestBuildExtensions(t *testing.T) { } } -func newBadExtensionFactory() component.ExtensionFactory { - return component.NewExtensionFactory( +func newBadExtensionFactory() extension.Factory { + return extension.NewExtensionFactory( "bf", - func() component.ExtensionConfig { + func() extension.Config { return &struct { config.ExtensionSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct }{ ExtensionSettings: config.NewExtensionSettings(component.NewID("bf")), } }, - func(ctx context.Context, set component.ExtensionCreateSettings, extension component.ExtensionConfig) (component.Extension, error) { + func(ctx context.Context, set extension.CreateSettings, extension extension.Config) (extension.Extension, error) { return nil, nil }, component.StabilityLevelInDevelopment, ) } -func newCreateErrorExtensionFactory() component.ExtensionFactory { - return component.NewExtensionFactory( +func newCreateErrorExtensionFactory() extension.Factory { + return extension.NewExtensionFactory( "err", - func() component.ExtensionConfig { + func() extension.Config { return &struct { config.ExtensionSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct }{ ExtensionSettings: config.NewExtensionSettings(component.NewID("err")), } }, - func(ctx context.Context, set component.ExtensionCreateSettings, extension component.ExtensionConfig) (component.Extension, error) { + func(ctx context.Context, set extension.CreateSettings, extension extension.Config) (extension.Extension, error) { return nil, errors.New("cannot create \"err\" extension type") }, component.StabilityLevelInDevelopment, diff --git a/component/factories.go b/service/factories.go similarity index 70% rename from component/factories.go rename to service/factories.go index e666afaf73c..155d889a501 100644 --- a/component/factories.go +++ b/service/factories.go @@ -12,33 +12,37 @@ // See the License for the specific language governing permissions and // limitations under the License. -package component // import "go.opentelemetry.io/collector/component" +package service // import "go.opentelemetry.io/collector/component" import ( "fmt" + + "go.opentelemetry.io/collector/component" + "go.opentelemetry.io/collector/exporter" + "go.opentelemetry.io/collector/extension" ) // 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[Type]ReceiverFactory + Receivers map[component.Type]component.ReceiverFactory // Processors maps processor type names in the config to the respective factory. - Processors map[Type]ProcessorFactory + Processors map[component.Type]component.ProcessorFactory // Exporters maps exporter type names in the config to the respective factory. - Exporters map[Type]ExporterFactory + Exporters map[component.Type]exporter.Factory // Extensions maps extension type names in the config to the respective factory. - Extensions map[Type]ExtensionFactory + Extensions map[component.Type]extension.Factory } // 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[Type]ReceiverFactory, error) { - fMap := map[Type]ReceiverFactory{} +func MakeReceiverFactoryMap(factories ...component.ReceiverFactory) (map[component.Type]component.ReceiverFactory, error) { + fMap := map[component.Type]component.ReceiverFactory{} for _, f := range factories { if _, ok := fMap[f.Type()]; ok { return fMap, fmt.Errorf("duplicate receiver factory %q", f.Type()) @@ -51,8 +55,8 @@ func MakeReceiverFactoryMap(factories ...ReceiverFactory) (map[Type]ReceiverFact // 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[Type]ProcessorFactory, error) { - fMap := map[Type]ProcessorFactory{} +func MakeProcessorFactoryMap(factories ...component.ProcessorFactory) (map[component.Type]component.ProcessorFactory, error) { + fMap := map[component.Type]component.ProcessorFactory{} for _, f := range factories { if _, ok := fMap[f.Type()]; ok { return fMap, fmt.Errorf("duplicate processor factory %q", f.Type()) @@ -65,8 +69,8 @@ func MakeProcessorFactoryMap(factories ...ProcessorFactory) (map[Type]ProcessorF // 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[Type]ExporterFactory, error) { - fMap := map[Type]ExporterFactory{} +func MakeExporterFactoryMap(factories ...exporter.Factory) (map[component.Type]exporter.Factory, error) { + fMap := map[component.Type]exporter.Factory{} for _, f := range factories { if _, ok := fMap[f.Type()]; ok { return fMap, fmt.Errorf("duplicate exporter factory %q", f.Type()) @@ -79,8 +83,8 @@ func MakeExporterFactoryMap(factories ...ExporterFactory) (map[Type]ExporterFact // 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[Type]ExtensionFactory, error) { - fMap := map[Type]ExtensionFactory{} +func MakeExtensionFactoryMap(factories ...extension.Factory) (map[component.Type]extension.Factory, error) { + fMap := map[component.Type]extension.Factory{} 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/service/factories_test.go similarity index 62% rename from component/factories_test.go rename to service/factories_test.go index 7b1972cd34b..374bf5e0add 100644 --- a/component/factories_test.go +++ b/service/factories_test.go @@ -12,35 +12,39 @@ // See the License for the specific language governing permissions and // limitations under the License. -package component +package service import ( "testing" "github.com/stretchr/testify/assert" + + "go.opentelemetry.io/collector/component" + "go.opentelemetry.io/collector/exporter" + "go.opentelemetry.io/collector/extension" ) func TestMakeExtensionFactoryMap(t *testing.T) { type testCase struct { name string - in []ExtensionFactory - out map[Type]ExtensionFactory + in []extension.Factory + out map[component.Type]extension.Factory } - p1 := NewExtensionFactory("p1", nil, nil, StabilityLevelAlpha) - p2 := NewExtensionFactory("p2", nil, nil, StabilityLevelAlpha) + p1 := extension.NewExtensionFactory("p1", nil, nil, component.StabilityLevelAlpha) + p2 := extension.NewExtensionFactory("p2", nil, nil, component.StabilityLevelAlpha) testCases := []testCase{ { name: "different names", - in: []ExtensionFactory{p1, p2}, - out: map[Type]ExtensionFactory{ + in: []extension.Factory{p1, p2}, + out: map[component.Type]extension.Factory{ p1.Type(): p1, p2.Type(): p2, }, }, { name: "same name", - in: []ExtensionFactory{p1, p2, NewExtensionFactory("p1", nil, nil, StabilityLevelAlpha)}, + in: []extension.Factory{p1, p2, extension.NewExtensionFactory("p1", nil, nil, component.StabilityLevelAlpha)}, }, } for i := range testCases { @@ -60,24 +64,24 @@ func TestMakeExtensionFactoryMap(t *testing.T) { func TestMakeReceiverFactoryMap(t *testing.T) { type testCase struct { name string - in []ReceiverFactory - out map[Type]ReceiverFactory + in []component.ReceiverFactory + out map[component.Type]component.ReceiverFactory } - p1 := NewReceiverFactory("p1", nil) - p2 := NewReceiverFactory("p2", nil) + p1 := component.NewReceiverFactory("p1", nil) + p2 := component.NewReceiverFactory("p2", nil) testCases := []testCase{ { name: "different names", - in: []ReceiverFactory{p1, p2}, - out: map[Type]ReceiverFactory{ + in: []component.ReceiverFactory{p1, p2}, + out: map[component.Type]component.ReceiverFactory{ p1.Type(): p1, p2.Type(): p2, }, }, { name: "same name", - in: []ReceiverFactory{p1, p2, NewReceiverFactory("p1", nil)}, + in: []component.ReceiverFactory{p1, p2, component.NewReceiverFactory("p1", nil)}, }, } @@ -98,24 +102,24 @@ func TestMakeReceiverFactoryMap(t *testing.T) { func TestMakeProcessorFactoryMap(t *testing.T) { type testCase struct { name string - in []ProcessorFactory - out map[Type]ProcessorFactory + in []component.ProcessorFactory + out map[component.Type]component.ProcessorFactory } - p1 := NewProcessorFactory("p1", nil) - p2 := NewProcessorFactory("p2", nil) + p1 := component.NewProcessorFactory("p1", nil) + p2 := component.NewProcessorFactory("p2", nil) testCases := []testCase{ { name: "different names", - in: []ProcessorFactory{p1, p2}, - out: map[Type]ProcessorFactory{ + in: []component.ProcessorFactory{p1, p2}, + out: map[component.Type]component.ProcessorFactory{ p1.Type(): p1, p2.Type(): p2, }, }, { name: "same name", - in: []ProcessorFactory{p1, p2, NewProcessorFactory("p1", nil)}, + in: []component.ProcessorFactory{p1, p2, component.NewProcessorFactory("p1", nil)}, }, } @@ -136,24 +140,24 @@ func TestMakeProcessorFactoryMap(t *testing.T) { func TestMakeExporterFactoryMap(t *testing.T) { type testCase struct { name string - in []ExporterFactory - out map[Type]ExporterFactory + in []exporter.Factory + out map[component.Type]exporter.Factory } - p1 := NewExporterFactory("p1", nil) - p2 := NewExporterFactory("p2", nil) + p1 := exporter.NewFactory("p1", nil) + p2 := exporter.NewFactory("p2", nil) testCases := []testCase{ { name: "different names", - in: []ExporterFactory{p1, p2}, - out: map[Type]ExporterFactory{ + in: []exporter.Factory{p1, p2}, + out: map[component.Type]exporter.Factory{ p1.Type(): p1, p2.Type(): p2, }, }, { name: "same name", - in: []ExporterFactory{p1, p2, NewExporterFactory("p1", nil)}, + in: []exporter.Factory{p1, p2, exporter.NewFactory("p1", nil)}, }, } diff --git a/service/host.go b/service/host.go index 31be010608d..109f8ea9e4a 100644 --- a/service/host.go +++ b/service/host.go @@ -16,6 +16,8 @@ package service // import "go.opentelemetry.io/collector/service" import ( "go.opentelemetry.io/collector/component" + "go.opentelemetry.io/collector/exporter" + "go.opentelemetry.io/collector/extension" "go.opentelemetry.io/collector/service/extensions" "go.opentelemetry.io/collector/service/internal/pipelines" ) @@ -24,7 +26,7 @@ var _ component.Host = (*serviceHost)(nil) type serviceHost struct { asyncErrorChannel chan error - factories component.Factories + factories Factories buildInfo component.BuildInfo pipelines *pipelines.Pipelines @@ -52,10 +54,10 @@ func (host *serviceHost) GetFactory(kind component.Kind, componentType component return nil } -func (host *serviceHost) GetExtensions() map[component.ID]component.Extension { +func (host *serviceHost) GetExtensions() map[component.ID]extension.Extension { return host.extensions.GetExtensions() } -func (host *serviceHost) GetExporters() map[component.DataType]map[component.ID]component.Exporter { - return host.pipelines.GetExporters() +func (host *serviceHost) GetExporters() map[component.DataType]map[component.ID]exporter. { +return host.pipelines.GetExporters() } diff --git a/service/internal/configunmarshaler/exporters.go b/service/internal/configunmarshaler/exporters.go index e4064dfb028..9c1bb09824e 100644 --- a/service/internal/configunmarshaler/exporters.go +++ b/service/internal/configunmarshaler/exporters.go @@ -19,18 +19,19 @@ import ( "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/confmap" + "go.opentelemetry.io/collector/exporter" ) // exportersKeyName is the configuration key name for exporters section. const exportersKeyName = "exporters" type Exporters struct { - exps map[component.ID]component.ExporterConfig + exps map[component.ID]exporter.Config - factories map[component.Type]component.ExporterFactory + factories map[component.Type]exporter.Factory } -func NewExporters(factories map[component.Type]component.ExporterFactory) *Exporters { +func NewExporters(factories map[component.Type]exporter.Factory) *Exporters { return &Exporters{factories: factories} } @@ -41,7 +42,7 @@ func (e *Exporters) Unmarshal(conf *confmap.Conf) error { } // Prepare resulting map. - e.exps = make(map[component.ID]component.ExporterConfig) + e.exps = make(map[component.ID]exporter.Config) // Iterate over Exporters and create a config for each. for id, value := range rawExps { @@ -57,7 +58,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 := component.UnmarshalExporterConfig(confmap.NewFromStringMap(value), exporterCfg); err != nil { + if err := component.UnmarshalConfig(confmap.NewFromStringMap(value), exporterCfg); err != nil { return errorUnmarshalError(exportersKeyName, id, err) } @@ -67,6 +68,6 @@ func (e *Exporters) Unmarshal(conf *confmap.Conf) error { return nil } -func (e *Exporters) GetExporters() map[component.ID]component.ExporterConfig { +func (e *Exporters) GetExporters() map[component.ID]exporter.Config { return e.exps } diff --git a/service/internal/configunmarshaler/exporters_test.go b/service/internal/configunmarshaler/exporters_test.go index 5f8ba6caad5..468aa61ced3 100644 --- a/service/internal/configunmarshaler/exporters_test.go +++ b/service/internal/configunmarshaler/exporters_test.go @@ -23,6 +23,7 @@ import ( "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/component/componenttest" "go.opentelemetry.io/collector/confmap" + "go.opentelemetry.io/collector/exporter" ) func TestExportersUnmarshal(t *testing.T) { @@ -38,7 +39,7 @@ func TestExportersUnmarshal(t *testing.T) { cfgWithName := factories.Exporters["nop"].CreateDefaultConfig() cfgWithName.SetIDName("myexporter") - assert.Equal(t, map[component.ID]component.ExporterConfig{ + assert.Equal(t, map[component.ID]exporter.Config{ 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 cb3478a7725..7c5d761f703 100644 --- a/service/internal/configunmarshaler/extensions.go +++ b/service/internal/configunmarshaler/extensions.go @@ -19,18 +19,19 @@ import ( "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/confmap" + "go.opentelemetry.io/collector/extension" ) // extensionsKeyName is the configuration key name for extensions section. const extensionsKeyName = "extensions" type Extensions struct { - exts map[component.ID]component.ExtensionConfig + exts map[component.ID]extension.Config - factories map[component.Type]component.ExtensionFactory + factories map[component.Type]extension.Factory } -func NewExtensions(factories map[component.Type]component.ExtensionFactory) *Extensions { +func NewExtensions(factories map[component.Type]extension.Factory) *Extensions { return &Extensions{factories: factories} } @@ -41,7 +42,7 @@ func (e *Extensions) Unmarshal(conf *confmap.Conf) error { } // Prepare resulting map. - e.exts = make(map[component.ID]component.ExtensionConfig) + e.exts = make(map[component.ID]extension.Config) // Iterate over extensions and create a config for each. for id, value := range rawExts { @@ -57,7 +58,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 := component.UnmarshalExtensionConfig(confmap.NewFromStringMap(value), extensionCfg); err != nil { + if err := component.UnmarshalConfig(confmap.NewFromStringMap(value), extensionCfg); err != nil { return errorUnmarshalError(extensionsKeyName, id, err) } @@ -67,6 +68,6 @@ func (e *Extensions) Unmarshal(conf *confmap.Conf) error { return nil } -func (e *Extensions) GetExtensions() map[component.ID]component.ExtensionConfig { +func (e *Extensions) GetExtensions() map[component.ID]extension.Config { return e.exts } diff --git a/service/internal/configunmarshaler/extensions_test.go b/service/internal/configunmarshaler/extensions_test.go index 3f6a7e57eee..8ab4b11cd29 100644 --- a/service/internal/configunmarshaler/extensions_test.go +++ b/service/internal/configunmarshaler/extensions_test.go @@ -23,6 +23,7 @@ import ( "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/component/componenttest" "go.opentelemetry.io/collector/confmap" + "go.opentelemetry.io/collector/extension" ) func TestExtensionsUnmarshal(t *testing.T) { @@ -38,7 +39,7 @@ func TestExtensionsUnmarshal(t *testing.T) { cfgWithName := factories.Extensions["nop"].CreateDefaultConfig() cfgWithName.SetIDName("myextension") - assert.Equal(t, map[component.ID]component.ExtensionConfig{ + assert.Equal(t, map[component.ID]extension.Config{ component.NewID("nop"): factories.Extensions["nop"].CreateDefaultConfig(), component.NewIDWithName("nop", "myextension"): cfgWithName, }, exts.GetExtensions()) diff --git a/service/internal/pipelines/pipelines.go b/service/internal/pipelines/pipelines.go index 24907012a86..6fda36ffd5a 100644 --- a/service/internal/pipelines/pipelines.go +++ b/service/internal/pipelines/pipelines.go @@ -26,6 +26,7 @@ import ( "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/consumer" + "go.opentelemetry.io/collector/exporter" "go.opentelemetry.io/collector/service/internal/components" "go.opentelemetry.io/collector/service/internal/fanoutconsumer" "go.opentelemetry.io/collector/service/internal/zpages" @@ -59,8 +60,8 @@ type builtPipeline struct { type Pipelines struct { telemetry component.TelemetrySettings - allReceivers map[component.DataType]map[component.ID]component.Receiver - allExporters map[component.DataType]map[component.ID]component.Exporter + allReceivers map[component.DataType]map[component.ID]component.Component + allExporters map[component.DataType]map[component.ID]component.Component pipelines map[component.ID]*builtPipeline } @@ -139,12 +140,12 @@ func (bps *Pipelines) ShutdownAll(ctx context.Context) error { return errs } -func (bps *Pipelines) GetExporters() map[component.DataType]map[component.ID]component.Exporter { - exportersMap := make(map[component.DataType]map[component.ID]component.Exporter) +func (bps *Pipelines) GetExporters() map[component.DataType]map[component.ID]component.Component { + exportersMap := make(map[component.DataType]map[component.ID]component.Component) - exportersMap[component.DataTypeTraces] = make(map[component.ID]component.Exporter, len(bps.allExporters[component.DataTypeTraces])) - exportersMap[component.DataTypeMetrics] = make(map[component.ID]component.Exporter, len(bps.allExporters[component.DataTypeMetrics])) - exportersMap[component.DataTypeLogs] = make(map[component.ID]component.Exporter, len(bps.allExporters[component.DataTypeLogs])) + exportersMap[component.DataTypeTraces] = make(map[component.ID]component.Component, len(bps.allExporters[component.DataTypeTraces])) + exportersMap[component.DataTypeMetrics] = make(map[component.ID]component.Component, len(bps.allExporters[component.DataTypeMetrics])) + exportersMap[component.DataTypeLogs] = make(map[component.ID]component.Component, len(bps.allExporters[component.DataTypeLogs])) for dt, expByID := range bps.allExporters { for expID, exp := range expByID { @@ -195,10 +196,10 @@ type Settings struct { ProcessorConfigs map[component.ID]component.ProcessorConfig // ExporterFactories maps exporter type names in the config to the respective component.ExporterFactory. - ExporterFactories map[component.Type]component.ExporterFactory + ExporterFactories map[component.Type]exporter.Factory // ExporterConfigs is a map of component.ID to component.ExporterConfig. - ExporterConfigs map[component.ID]component.ExporterConfig + ExporterConfigs map[component.ID]exporter.Config // PipelineConfigs is a map of component.ID to config.Pipeline. PipelineConfigs map[component.ID]*config.Pipeline @@ -208,8 +209,8 @@ type Settings struct { func Build(ctx context.Context, set Settings) (*Pipelines, error) { exps := &Pipelines{ telemetry: set.Telemetry, - allReceivers: make(map[component.DataType]map[component.ID]component.Receiver), - allExporters: make(map[component.DataType]map[component.ID]component.Exporter), + allReceivers: make(map[component.DataType]map[component.ID]component.Component), + allExporters: make(map[component.DataType]map[component.ID]component.Component), pipelines: make(map[component.ID]*builtPipeline, len(set.PipelineConfigs)), } @@ -221,7 +222,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[component.ID]component.Exporter) + exps.allExporters[pipelineID.Type()] = make(map[component.ID]component.Component) } expByID := exps.allExporters[pipelineID.Type()] @@ -306,7 +307,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[component.ID]component.Receiver) + exps.allReceivers[pipelineID.Type()] = make(map[component.ID]component.Component) } recvByID := exps.allReceivers[pipelineID.Type()] bp := exps.pipelines[pipelineID] @@ -335,11 +336,11 @@ func buildExporter( ctx context.Context, settings component.TelemetrySettings, buildInfo component.BuildInfo, - cfgs map[component.ID]component.ExporterConfig, - factories map[component.Type]component.ExporterFactory, + cfgs map[component.ID]exporter.Config, + factories map[component.Type]exporter.Factory, id component.ID, pipelineID component.ID, -) (component.Exporter, error) { +) (component.Component, error) { cfg, existsCfg := cfgs[id] if !existsCfg { return nil, fmt.Errorf("exporter %q is not configured", id) @@ -350,7 +351,7 @@ func buildExporter( return nil, fmt.Errorf("exporter factory not available for: %q", id) } - set := component.ExporterCreateSettings{ + set := exporter.CreateSettings{ TelemetrySettings: settings, BuildInfo: buildInfo, } @@ -365,7 +366,7 @@ func buildExporter( return exp, nil } -func createExporter(ctx context.Context, set component.ExporterCreateSettings, cfg component.ExporterConfig, id component.ID, pipelineID component.ID, factory component.ExporterFactory) (component.Exporter, error) { +func createExporter(ctx context.Context, set exporter.CreateSettings, cfg exporter.Config, id component.ID, pipelineID component.ID, factory exporter.Factory) (component.Component, error) { switch pipelineID.Type() { case component.DataTypeTraces: return factory.CreateTracesExporter(ctx, set, cfg) @@ -413,7 +414,7 @@ func exporterLogger(logger *zap.Logger, id component.ID, dt component.DataType) zap.String(components.ZapNameKey, id.String())) } -func getExporterStabilityLevel(factory component.ExporterFactory, dt component.DataType) component.StabilityLevel { +func getExporterStabilityLevel(factory exporter.Factory, dt component.DataType) component.StabilityLevel { switch dt { case component.DataTypeTraces: return factory.TracesExporterStability() diff --git a/service/internal/pipelines/pipelines_test.go b/service/internal/pipelines/pipelines_test.go index 2bc2ed63096..bf80e9ac7b8 100644 --- a/service/internal/pipelines/pipelines_test.go +++ b/service/internal/pipelines/pipelines_test.go @@ -30,7 +30,9 @@ import ( "go.opentelemetry.io/collector/confmap/confmaptest" "go.opentelemetry.io/collector/consumer" "go.opentelemetry.io/collector/consumer/consumertest" + "go.opentelemetry.io/collector/exporter" "go.opentelemetry.io/collector/internal/testdata" + "go.opentelemetry.io/collector/service" "go.opentelemetry.io/collector/service/internal/configunmarshaler" "go.opentelemetry.io/collector/service/internal/testcomponents" ) @@ -231,7 +233,7 @@ func TestBuildErrors(t *testing.T) { for _, test := range tests { t.Run(test.configFile, func(t *testing.T) { - factories := component.Factories{ + factories := service.Factories{ Receivers: map[component.Type]component.ReceiverFactory{ nopReceiverFactory.Type(): nopReceiverFactory, "unknown": nopReceiverFactory, @@ -242,7 +244,7 @@ func TestBuildErrors(t *testing.T) { "unknown": nopProcessorFactory, badProcessorFactory.Type(): badProcessorFactory, }, - Exporters: map[component.Type]component.ExporterFactory{ + Exporters: map[component.Type]exporter.Factory{ nopExporterFactory.Type(): nopExporterFactory, "unknown": nopExporterFactory, badExporterFactory.Type(): badExporterFactory, @@ -290,11 +292,11 @@ func TestFailToStartAndShutdown(t *testing.T) { component.NewID(nopProcessorFactory.Type()): nopProcessorFactory.CreateDefaultConfig(), component.NewID(errProcessorFactory.Type()): errProcessorFactory.CreateDefaultConfig(), }, - ExporterFactories: map[component.Type]component.ExporterFactory{ + ExporterFactories: map[component.Type]exporter.Factory{ nopExporterFactory.Type(): nopExporterFactory, errExporterFactory.Type(): errExporterFactory, }, - ExporterConfigs: map[component.ID]component.ExporterConfig{ + ExporterConfigs: map[component.ID]exporter.Config{ component.NewID(nopExporterFactory.Type()): nopExporterFactory.CreateDefaultConfig(), component.NewID(errExporterFactory.Type()): errExporterFactory.CreateDefaultConfig(), }, @@ -365,8 +367,8 @@ func newBadProcessorFactory() component.ProcessorFactory { }) } -func newBadExporterFactory() component.ExporterFactory { - return component.NewExporterFactory("bf", func() component.ExporterConfig { +func newBadExporterFactory() exporter.Factory { + return exporter.NewFactory("bf", func() exporter.Config { return &struct { config.ExporterSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct }{ @@ -415,27 +417,27 @@ func newErrProcessorFactory() component.ProcessorFactory { ) } -func newErrExporterFactory() component.ExporterFactory { - return component.NewExporterFactory("err", func() component.ExporterConfig { +func newErrExporterFactory() exporter.Factory { + return exporter.NewFactory("err", func() exporter.Config { return &struct { config.ExporterSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct }{ ExporterSettings: config.NewExporterSettings(component.NewID("bf")), } }, - component.WithTracesExporter(func(context.Context, component.ExporterCreateSettings, component.ExporterConfig) (component.TracesExporter, error) { + exporter.WithTracesExporter(func(context.Context, exporter.CreateSettings, exporter.Config) (exporter.TracesExporter, error) { return &errComponent{}, nil }, component.StabilityLevelUndefined), - component.WithLogsExporter(func(context.Context, component.ExporterCreateSettings, component.ExporterConfig) (component.LogsExporter, error) { + exporter.WithLogsExporter(func(context.Context, exporter.CreateSettings, exporter.Config) (exporter.LogsExporter, error) { return &errComponent{}, nil }, component.StabilityLevelUndefined), - component.WithMetricsExporter(func(context.Context, component.ExporterCreateSettings, component.ExporterConfig) (component.MetricsExporter, error) { + exporter.WithMetricsExporter(func(context.Context, exporter.CreateSettings, exporter.Config) (exporter.MetricsExporter, error) { return &errComponent{}, nil }, component.StabilityLevelUndefined), ) } -func toSettings(factories component.Factories, cfg *configSettings) Settings { +func toSettings(factories service.Factories, cfg *configSettings) Settings { return Settings{ Telemetry: componenttest.NewNopTelemetrySettings(), BuildInfo: component.NewDefaultBuildInfo(), @@ -477,7 +479,7 @@ type serviceSettings struct { Pipelines map[component.ID]*config.Pipeline `mapstructure:"pipelines"` } -func loadConfig(t *testing.T, fileName string, factories component.Factories) *configSettings { +func loadConfig(t *testing.T, fileName string, factories service.Factories) *configSettings { // Read yaml config from file conf, err := confmaptest.LoadConf(fileName) require.NoError(t, err) diff --git a/service/internal/testcomponents/example_exporter.go b/service/internal/testcomponents/example_exporter.go index 722dddc9b10..2e9d2e2edab 100644 --- a/service/internal/testcomponents/example_exporter.go +++ b/service/internal/testcomponents/example_exporter.go @@ -20,6 +20,7 @@ import ( "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/consumer" + "go.opentelemetry.io/collector/exporter" "go.opentelemetry.io/collector/pdata/plog" "go.opentelemetry.io/collector/pdata/pmetric" "go.opentelemetry.io/collector/pdata/ptrace" @@ -36,29 +37,29 @@ type ExampleExporterConfig struct { } // ExampleExporterFactory is factory for ExampleExporter. -var ExampleExporterFactory = component.NewExporterFactory( +var ExampleExporterFactory = exporter.NewFactory( typeStr, createExporterDefaultConfig, - component.WithTracesExporter(createTracesExporter, stability), - component.WithMetricsExporter(createMetricsExporter, stability), - component.WithLogsExporter(createLogsExporter, stability), + exporter.WithTracesExporter(createTracesExporter, stability), + exporter.WithMetricsExporter(createMetricsExporter, stability), + exporter.WithLogsExporter(createLogsExporter, stability), ) -func createExporterDefaultConfig() component.ExporterConfig { +func createExporterDefaultConfig() exporter.Config { return &ExampleExporterConfig{ ExporterSettings: config.NewExporterSettings(component.NewID(typeStr)), } } -func createTracesExporter(context.Context, component.ExporterCreateSettings, component.ExporterConfig) (component.TracesExporter, error) { +func createTracesExporter(context.Context, exporter.CreateSettings, exporter.Config) (exporter.TracesExporter, error) { return &ExampleExporter{}, nil } -func createMetricsExporter(context.Context, component.ExporterCreateSettings, component.ExporterConfig) (component.MetricsExporter, error) { +func createMetricsExporter(context.Context, exporter.CreateSettings, exporter.Config) (exporter.MetricsExporter, error) { return &ExampleExporter{}, nil } -func createLogsExporter(context.Context, component.ExporterCreateSettings, component.ExporterConfig) (component.LogsExporter, error) { +func createLogsExporter(context.Context, exporter.CreateSettings, exporter.Config) (exporter.LogsExporter, error) { return &ExampleExporter{}, nil } diff --git a/service/internal/testcomponents/example_factories.go b/service/internal/testcomponents/example_factories.go index ac5f21f433f..4bcffc764a0 100644 --- a/service/internal/testcomponents/example_factories.go +++ b/service/internal/testcomponents/example_factories.go @@ -16,18 +16,20 @@ package testcomponents // import "go.opentelemetry.io/collector/service/internal import ( "go.opentelemetry.io/collector/component" + "go.opentelemetry.io/collector/exporter" + "go.opentelemetry.io/collector/service" ) // ExampleComponents registers example factories. This is only used by tests. -func ExampleComponents() (component.Factories, error) { - return component.Factories{ +func ExampleComponents() (service.Factories, error) { + return service.Factories{ Receivers: map[component.Type]component.ReceiverFactory{ ExampleReceiverFactory.Type(): ExampleReceiverFactory, }, Processors: map[component.Type]component.ProcessorFactory{ ExampleProcessorFactory.Type(): ExampleProcessorFactory, }, - Exporters: map[component.Type]component.ExporterFactory{ + Exporters: map[component.Type]exporter.Factory{ ExampleExporterFactory.Type(): ExampleExporterFactory, }, }, nil diff --git a/service/service_test.go b/service/service_test.go index c65d322a80b..01fc7b17dba 100644 --- a/service/service_test.go +++ b/service/service_test.go @@ -203,7 +203,7 @@ func TestServiceTelemetryReusable(t *testing.T) { require.NoError(t, srvTwo.Shutdown(context.Background())) } -func createExampleService(t *testing.T, factories component.Factories) *service { +func createExampleService(t *testing.T, factories Factories) *service { // Read yaml config from file prov, err := NewConfigProvider(newDefaultConfigProviderSettings([]string{filepath.Join("testdata", "otelcol-nop.yaml")})) require.NoError(t, err) diff --git a/service/servicetest/configprovider.go b/service/servicetest/configprovider.go index 227458ea93b..2fb4e220efb 100644 --- a/service/servicetest/configprovider.go +++ b/service/servicetest/configprovider.go @@ -17,7 +17,6 @@ package servicetest // import "go.opentelemetry.io/collector/service/servicetest import ( "context" - "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/confmap" "go.opentelemetry.io/collector/confmap/converter/expandconverter" "go.opentelemetry.io/collector/confmap/provider/envprovider" @@ -28,7 +27,7 @@ import ( ) // LoadConfig loads a config.Config from file, and does NOT validate the configuration. -func LoadConfig(fileName string, factories component.Factories) (*service.Config, error) { +func LoadConfig(fileName string, factories service.Factories) (*service.Config, error) { // Read yaml config from file provider, err := service.NewConfigProvider(service.ConfigProviderSettings{ ResolverSettings: confmap.ResolverSettings{ @@ -44,7 +43,7 @@ func LoadConfig(fileName string, factories component.Factories) (*service.Config } // LoadConfigAndValidate loads a config from the file, and validates the configuration. -func LoadConfigAndValidate(fileName string, factories component.Factories) (*service.Config, error) { +func LoadConfigAndValidate(fileName string, factories service.Factories) (*service.Config, error) { cfg, err := LoadConfig(fileName, factories) if err != nil { return nil, err diff --git a/service/settings.go b/service/settings.go index 070d6911b0c..368106c47a3 100644 --- a/service/settings.go +++ b/service/settings.go @@ -23,7 +23,7 @@ import ( // settings holds configuration for building a new service. type settings struct { // Factories component factories. - Factories component.Factories + Factories Factories // BuildInfo provides collector start information. BuildInfo component.BuildInfo @@ -44,7 +44,7 @@ type settings struct { // CollectorSettings holds configuration for creating a new Collector. type CollectorSettings struct { // Factories component factories. - Factories component.Factories + Factories Factories // BuildInfo provides collector start information. BuildInfo component.BuildInfo diff --git a/service/unmarshaler.go b/service/unmarshaler.go index c1c78d19a04..9a08b17f697 100644 --- a/service/unmarshaler.go +++ b/service/unmarshaler.go @@ -17,7 +17,6 @@ package service // import "go.opentelemetry.io/collector/service" import ( "go.uber.org/zap/zapcore" - "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/config/configtelemetry" "go.opentelemetry.io/collector/confmap" "go.opentelemetry.io/collector/service/internal/configunmarshaler" @@ -34,7 +33,7 @@ type configSettings struct { // unmarshal the configSettings from a confmap.Conf. // After the config is unmarshalled, `Validate()` must be called to validate. -func unmarshal(v *confmap.Conf, factories component.Factories) (*configSettings, error) { +func unmarshal(v *confmap.Conf, factories Factories) (*configSettings, error) { // Unmarshal top level sections and validate. cfg := &configSettings{ Receivers: configunmarshaler.NewReceivers(factories.Receivers),