Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate special Configs for each component type, use a standard opaque Config #6617

Merged
merged 1 commit into from
Nov 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .chloggen/rmconfig.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: deprecation

# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver)
component: component

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Deprecate `component.[Exporter|Extension|Processor|Receiver]Config` in favor of `component.Config`

# One or more tracking issues or pull requests related to the change
issues: [6578]
20 changes: 19 additions & 1 deletion component/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,19 +161,37 @@ func (sl StabilityLevel) LogMessage() string {
return "Stability level of component is undefined"
}

// Factory is implemented by all component factories.
// Factory is implemented by all Component factories.
//
// This interface cannot be directly implemented. Implementations must
// use the factory helpers for the appropriate component type.
type Factory interface {
// Type gets the type of the component created by this factory.
Type() Type

// CreateDefaultConfig creates the default configuration for the Component.
// 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 Component.
// 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

unexportedFactoryFunc()
}

// CreateDefaultConfigFunc is the equivalent of Factory.CreateDefaultConfig().
type CreateDefaultConfigFunc func() Config

// CreateDefaultConfig implements Factory.CreateDefaultConfig().
func (f CreateDefaultConfigFunc) CreateDefaultConfig() Config {
return f()
}

type baseFactory struct {
cfgType Type
CreateDefaultConfigFunc
}

func (baseFactory) unexportedFactoryFunc() {}
Expand Down
8 changes: 4 additions & 4 deletions component/componenttest/nop_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ type nopExporterConfig struct {
func NewNopExporterFactory() component.ExporterFactory {
return component.NewExporterFactory(
"nop",
func() component.ExporterConfig {
func() component.Config {
return &nopExporterConfig{
ExporterSettings: config.NewExporterSettings(component.NewID("nop")),
}
Expand All @@ -49,15 +49,15 @@ func NewNopExporterFactory() component.ExporterFactory {
)
}

func createTracesExporter(context.Context, component.ExporterCreateSettings, component.ExporterConfig) (component.TracesExporter, error) {
func createTracesExporter(context.Context, component.ExporterCreateSettings, component.Config) (component.TracesExporter, error) {
return nopExporterInstance, nil
}

func createMetricsExporter(context.Context, component.ExporterCreateSettings, component.ExporterConfig) (component.MetricsExporter, error) {
func createMetricsExporter(context.Context, component.ExporterCreateSettings, component.Config) (component.MetricsExporter, error) {
return nopExporterInstance, nil
}

func createLogsExporter(context.Context, component.ExporterCreateSettings, component.ExporterConfig) (component.LogsExporter, error) {
func createLogsExporter(context.Context, component.ExporterCreateSettings, component.Config) (component.LogsExporter, error) {
return nopExporterInstance, nil
}

Expand Down
4 changes: 2 additions & 2 deletions component/componenttest/nop_extension.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ type nopExtensionConfig struct {
func NewNopExtensionFactory() component.ExtensionFactory {
return component.NewExtensionFactory(
"nop",
func() component.ExtensionConfig {
func() component.Config {
return &nopExtensionConfig{
ExtensionSettings: config.NewExtensionSettings(component.NewID("nop")),
}
},
func(context.Context, component.ExtensionCreateSettings, component.ExtensionConfig) (component.Extension, error) {
func(context.Context, component.ExtensionCreateSettings, component.Config) (component.Extension, error) {
return nopExtensionInstance, nil
},
component.StabilityLevelStable)
Expand Down
8 changes: 4 additions & 4 deletions component/componenttest/nop_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ type nopProcessorConfig struct {
func NewNopProcessorFactory() component.ProcessorFactory {
return component.NewProcessorFactory(
"nop",
func() component.ProcessorConfig {
func() component.Config {
return &nopProcessorConfig{
ProcessorSettings: config.NewProcessorSettings(component.NewID("nop")),
}
Expand All @@ -50,15 +50,15 @@ func NewNopProcessorFactory() component.ProcessorFactory {
)
}

func createTracesProcessor(context.Context, component.ProcessorCreateSettings, component.ProcessorConfig, consumer.Traces) (component.TracesProcessor, error) {
func createTracesProcessor(context.Context, component.ProcessorCreateSettings, component.Config, consumer.Traces) (component.TracesProcessor, error) {
return nopProcessorInstance, nil
}

func createMetricsProcessor(context.Context, component.ProcessorCreateSettings, component.ProcessorConfig, consumer.Metrics) (component.MetricsProcessor, error) {
func createMetricsProcessor(context.Context, component.ProcessorCreateSettings, component.Config, consumer.Metrics) (component.MetricsProcessor, error) {
return nopProcessorInstance, nil
}

func createLogsProcessor(context.Context, component.ProcessorCreateSettings, component.ProcessorConfig, consumer.Logs) (component.LogsProcessor, error) {
func createLogsProcessor(context.Context, component.ProcessorCreateSettings, component.Config, consumer.Logs) (component.LogsProcessor, error) {
return nopProcessorInstance, nil
}

Expand Down
8 changes: 4 additions & 4 deletions component/componenttest/nop_receiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ type nopReceiverConfig struct {
func NewNopReceiverFactory() component.ReceiverFactory {
return component.NewReceiverFactory(
"nop",
func() component.ReceiverConfig {
func() component.Config {
return &nopReceiverConfig{
ReceiverSettings: config.NewReceiverSettings(component.NewID("nop")),
}
Expand All @@ -48,15 +48,15 @@ func NewNopReceiverFactory() component.ReceiverFactory {
component.WithLogsReceiver(createLogsReceiver, component.StabilityLevelStable))
}

func createTracesReceiver(context.Context, component.ReceiverCreateSettings, component.ReceiverConfig, consumer.Traces) (component.TracesReceiver, error) {
func createTracesReceiver(context.Context, component.ReceiverCreateSettings, component.Config, consumer.Traces) (component.TracesReceiver, error) {
return nopReceiverInstance, nil
}

func createMetricsReceiver(context.Context, component.ReceiverCreateSettings, component.ReceiverConfig, consumer.Metrics) (component.MetricsReceiver, error) {
func createMetricsReceiver(context.Context, component.ReceiverCreateSettings, component.Config, consumer.Metrics) (component.MetricsReceiver, error) {
return nopReceiverInstance, nil
}

func createLogsReceiver(context.Context, component.ReceiverCreateSettings, component.ReceiverConfig, consumer.Logs) (component.LogsReceiver, error) {
func createLogsReceiver(context.Context, component.ReceiverCreateSettings, component.Config, consumer.Logs) (component.LogsReceiver, error) {
return nopReceiverInstance, nil
}

Expand Down
4 changes: 2 additions & 2 deletions component/componenttest/shutdown_verifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
"go.opentelemetry.io/collector/internal/testdata"
)

func verifyTracesProcessorDoesntProduceAfterShutdown(t *testing.T, factory component.ProcessorFactory, cfg component.ProcessorConfig) {
func verifyTracesProcessorDoesntProduceAfterShutdown(t *testing.T, factory component.ProcessorFactory, cfg component.Config) {
// Create a processor and output its produce to a sink.
nextSink := new(consumertest.TracesSink)
processor, err := factory.CreateTracesProcessor(
Expand Down Expand Up @@ -61,7 +61,7 @@ func verifyTracesProcessorDoesntProduceAfterShutdown(t *testing.T, factory compo
}

// VerifyProcessorShutdown verifies the processor doesn't produce telemetry data after shutdown.
func VerifyProcessorShutdown(t *testing.T, factory component.ProcessorFactory, cfg component.ProcessorConfig) {
func VerifyProcessorShutdown(t *testing.T, factory component.ProcessorFactory, cfg component.Config) {
verifyTracesProcessorDoesntProduceAfterShutdown(t, factory, cfg)
// TODO: add metrics and logs verification.
// TODO: add other shutdown verifications.
Expand Down
8 changes: 0 additions & 8 deletions component/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,6 @@ type Config interface {
privateConfig()
}

// CreateDefaultConfigFunc is the equivalent of Factory.CreateDefaultConfig().
type CreateDefaultConfigFunc func() Config

// CreateDefaultConfig implements Factory.CreateDefaultConfig().
func (f CreateDefaultConfigFunc) CreateDefaultConfig() Config {
return f()
}

// As interface types are only used for static typing, a common idiom to find the reflection Type
// for an interface type Foo is to use a *Foo value.
var configValidatorType = reflect.TypeOf((*ConfigValidator)(nil)).Elem()
Expand Down
57 changes: 19 additions & 38 deletions component/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,14 @@ 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 {
Config
}
// Deprecated: [v0.67.0] use Config.
type ExporterConfig = Config

// Deprecated: [v0.67.0] use UnmarshalConfig.
func UnmarshalExporterConfig(conf *confmap.Conf, cfg ExporterConfig) error {
return UnmarshalConfig(conf, cfg)
}
var UnmarshalExporterConfig = UnmarshalConfig

// TracesExporter is an Exporter that can consume traces.
type TracesExporter interface {
Expand Down Expand Up @@ -65,35 +59,26 @@ type ExporterCreateSettings struct {
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)
CreateTracesExporter(ctx context.Context, set ExporterCreateSettings, cfg Config) (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)
CreateMetricsExporter(ctx context.Context, set ExporterCreateSettings, cfg Config) (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)
CreateLogsExporter(ctx context.Context, set ExporterCreateSettings, cfg Config) (LogsExporter, error)

// LogsExporterStability gets the stability level of the LogsExporter.
LogsExporterStability() StabilityLevel
Expand All @@ -114,41 +99,36 @@ 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()
}
// Deprecated: [v0.67.0] use CreateDefaultConfigFunc.
type ExporterCreateDefaultConfigFunc = CreateDefaultConfigFunc

// CreateTracesExporterFunc is the equivalent of ExporterFactory.CreateTracesExporter().
type CreateTracesExporterFunc func(context.Context, ExporterCreateSettings, ExporterConfig) (TracesExporter, error)
type CreateTracesExporterFunc func(context.Context, ExporterCreateSettings, Config) (TracesExporter, error)

// CreateTracesExporter implements ExporterFactory.CreateTracesExporter().
func (f CreateTracesExporterFunc) CreateTracesExporter(ctx context.Context, set ExporterCreateSettings, cfg ExporterConfig) (TracesExporter, error) {
func (f CreateTracesExporterFunc) CreateTracesExporter(ctx context.Context, set ExporterCreateSettings, cfg Config) (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)
type CreateMetricsExporterFunc func(context.Context, ExporterCreateSettings, Config) (MetricsExporter, error)

// CreateMetricsExporter implements ExporterFactory.CreateMetricsExporter().
func (f CreateMetricsExporterFunc) CreateMetricsExporter(ctx context.Context, set ExporterCreateSettings, cfg ExporterConfig) (MetricsExporter, error) {
func (f CreateMetricsExporterFunc) CreateMetricsExporter(ctx context.Context, set ExporterCreateSettings, cfg Config) (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)
type CreateLogsExporterFunc func(context.Context, ExporterCreateSettings, Config) (LogsExporter, error)

// CreateLogsExporter implements ExporterFactory.CreateLogsExporter().
func (f CreateLogsExporterFunc) CreateLogsExporter(ctx context.Context, set ExporterCreateSettings, cfg ExporterConfig) (LogsExporter, error) {
func (f CreateLogsExporterFunc) CreateLogsExporter(ctx context.Context, set ExporterCreateSettings, cfg Config) (LogsExporter, error) {
if f == nil {
return nil, ErrDataTypeIsNotSupported
}
Expand All @@ -157,7 +137,6 @@ func (f CreateLogsExporterFunc) CreateLogsExporter(ctx context.Context, set Expo

type exporterFactory struct {
baseFactory
ExporterCreateDefaultConfigFunc
CreateTracesExporterFunc
tracesStabilityLevel StabilityLevel
CreateMetricsExporterFunc
Expand Down Expand Up @@ -203,10 +182,12 @@ func WithLogsExporter(createLogsExporter CreateLogsExporterFunc, sl StabilityLev
}

// NewExporterFactory returns a ExporterFactory.
func NewExporterFactory(cfgType Type, createDefaultConfig ExporterCreateDefaultConfigFunc, options ...ExporterFactoryOption) ExporterFactory {
func NewExporterFactory(cfgType Type, createDefaultConfig CreateDefaultConfigFunc, options ...ExporterFactoryOption) ExporterFactory {
f := &exporterFactory{
baseFactory: baseFactory{cfgType: cfgType},
ExporterCreateDefaultConfigFunc: createDefaultConfig,
baseFactory: baseFactory{
cfgType: cfgType,
CreateDefaultConfigFunc: createDefaultConfig,
},
}
for _, opt := range options {
opt.applyExporterFactoryOption(f)
Expand Down
10 changes: 5 additions & 5 deletions component/exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func TestNewExporterFactory(t *testing.T) {
defaultCfg := config.NewExporterSettings(component.NewID(typeStr))
factory := component.NewExporterFactory(
typeStr,
func() component.ExporterConfig { return &defaultCfg })
func() component.Config { return &defaultCfg })
assert.EqualValues(t, typeStr, factory.Type())
assert.EqualValues(t, &defaultCfg, factory.CreateDefaultConfig())
_, err := factory.CreateTracesExporter(context.Background(), component.ExporterCreateSettings{}, &defaultCfg)
Expand All @@ -47,7 +47,7 @@ func TestNewExporterFactory_WithOptions(t *testing.T) {
defaultCfg := config.NewExporterSettings(component.NewID(typeStr))
factory := component.NewExporterFactory(
typeStr,
func() component.ExporterConfig { return &defaultCfg },
func() component.Config { return &defaultCfg },
component.WithTracesExporter(createTracesExporter, component.StabilityLevelDevelopment),
component.WithMetricsExporter(createMetricsExporter, component.StabilityLevelAlpha),
component.WithLogsExporter(createLogsExporter, component.StabilityLevelDeprecated))
Expand All @@ -67,14 +67,14 @@ func TestNewExporterFactory_WithOptions(t *testing.T) {
assert.NoError(t, err)
}

func createTracesExporter(context.Context, component.ExporterCreateSettings, component.ExporterConfig) (component.TracesExporter, error) {
func createTracesExporter(context.Context, component.ExporterCreateSettings, component.Config) (component.TracesExporter, error) {
return nil, nil
}

func createMetricsExporter(context.Context, component.ExporterCreateSettings, component.ExporterConfig) (component.MetricsExporter, error) {
func createMetricsExporter(context.Context, component.ExporterCreateSettings, component.Config) (component.MetricsExporter, error) {
return nil, nil
}

func createLogsExporter(context.Context, component.ExporterCreateSettings, component.ExporterConfig) (component.LogsExporter, error) {
func createLogsExporter(context.Context, component.ExporterCreateSettings, component.Config) (component.LogsExporter, error) {
return nil, nil
}
Loading