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

add stability level to component factory #5580

Merged
Merged
Show file tree
Hide file tree
Changes from 8 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
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,21 @@
### 🚩 Deprecations 🚩

- Deprecate `service.ConfigServiceTelemetry`, `service.ConfigServiceTelemetryLogs`, and `service.ConfigServiceTelemetryMetrics` (#5565)
- Deprecate the following component functions to ensure a stability level is set (#5580):
- `component.WithTracesExporter` -> `component.WithTracesExporterAndStabilityLevel`
- `component.WithMetricsExporter` -> `component.WithMetricsExporterAndStabilityLevel`
- `component.WithLogsExporter` -> `component.WithLogsExporterAndStabilityLevel`
- `component.WithTracesReceiver` -> `component.WithTracesReceiverAndStabilityLevel`
- `component.WithMetricsReceiver` -> `component.WithMetricsReceiverAndStabilityLevel`
- `component.WithLogsReceiver` -> `component.WithLogsReceiverAndStabilityLevel`
- `component.WithTracesProcessor` -> `component.WithTracesProcessorAndStabilityLevel`
- `component.WithMetricsProcessor` -> `component.WithMetricsProcessorAndStabilityLevel`
- `component.WithLogsProcessor` -> `component.WithLogsProcessorAndStabilityLevel`

### 💡 Enhancements 💡

- Components stability levels are now logged. By default components which haven't defined their stability levels, or which are
unmaintained, deprecated or in development will log a message. (#5580)

### 🧰 Bug fixes 🧰

Expand Down
47 changes: 46 additions & 1 deletion component/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,40 @@ const (
KindExtension
)

// StabilityLevel represents the stability level of the component created by the factory.
mx-psi marked this conversation as resolved.
Show resolved Hide resolved
// The stability level is used to determine if the component should be used in production
// or not. For more details see:
// https://github.com/open-telemetry/opentelemetry-collector#stability-levels
type StabilityLevel int

const (
StabilityLevelUndefined = iota // skip 0, start types from 1.
StabilityLevelUnmaintained
StabilityLevelDeprecated
StabilityLevelInDevelopment
StabilityLevelAlpha
StabilityLevelBeta
StabilityLevelStable
)

func (sl StabilityLevel) String() string {
switch sl {
case StabilityLevelUnmaintained:
return "unmaintained"
case StabilityLevelDeprecated:
return "deprecated"
case StabilityLevelInDevelopment:
return "in development"
case StabilityLevelAlpha:
return "alpha"
case StabilityLevelBeta:
return "beta"
case StabilityLevelStable:
return "stable"
}
return "undefined"
}

// Factory is implemented by all component factories.
//
// This interface cannot be directly implemented. Implementations must
Expand All @@ -112,15 +146,26 @@ type Factory interface {
// Type gets the type of the component created by this factory.
Type() config.Type

// StabilityLevel gets the stability level of the component.
StabilityLevel(config.DataType) StabilityLevel

unexportedFactoryFunc()
}

type baseFactory struct {
cfgType config.Type
cfgType config.Type
stability map[config.Type]StabilityLevel
}

func (baseFactory) unexportedFactoryFunc() {}

func (bf baseFactory) Type() config.Type {
return bf.cfgType
}

func (bf baseFactory) StabilityLevel(dt config.DataType) StabilityLevel {
if val, ok := bf.stability[dt]; ok {
return val
}
return StabilityLevelUndefined
}
7 changes: 4 additions & 3 deletions component/componenttest/nop_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,10 @@ func NewNopExporterFactory() component.ExporterFactory {
ExporterSettings: config.NewExporterSettings(config.NewComponentID("nop")),
}
},
component.WithTracesExporter(createTracesExporter),
component.WithMetricsExporter(createMetricsExporter),
component.WithLogsExporter(createLogsExporter))
component.WithTracesExporterAndStabilityLevel(createTracesExporter, component.StabilityLevelInDevelopment),
component.WithMetricsExporterAndStabilityLevel(createMetricsExporter, component.StabilityLevelInDevelopment),
component.WithLogsExporterAndStabilityLevel(createLogsExporter, component.StabilityLevelInDevelopment),
)
}

func createTracesExporter(context.Context, component.ExporterCreateSettings, config.Exporter) (component.TracesExporter, error) {
Expand Down
6 changes: 3 additions & 3 deletions component/componenttest/nop_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ func NewNopProcessorFactory() component.ProcessorFactory {
ProcessorSettings: config.NewProcessorSettings(config.NewComponentID("nop")),
}
},
component.WithTracesProcessor(createTracesProcessor),
component.WithMetricsProcessor(createMetricsProcessor),
component.WithLogsProcessor(createLogsProcessor),
component.WithTracesProcessorAndStabilityLevel(createTracesProcessor, component.StabilityLevelInDevelopment),
codeboten marked this conversation as resolved.
Show resolved Hide resolved
component.WithMetricsProcessorAndStabilityLevel(createMetricsProcessor, component.StabilityLevelInDevelopment),
component.WithLogsProcessorAndStabilityLevel(createLogsProcessor, component.StabilityLevelInDevelopment),
)
}

Expand Down
6 changes: 3 additions & 3 deletions component/componenttest/nop_receiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ func NewNopReceiverFactory() component.ReceiverFactory {
ReceiverSettings: config.NewReceiverSettings(config.NewComponentID("nop")),
}
},
component.WithTracesReceiver(createTracesReceiver),
component.WithMetricsReceiver(createMetricsReceiver),
component.WithLogsReceiver(createLogsReceiver))
component.WithTracesReceiverAndStabilityLevel(createTracesReceiver, component.StabilityLevelInDevelopment),
component.WithMetricsReceiverAndStabilityLevel(createMetricsReceiver, component.StabilityLevelInDevelopment),
component.WithLogsReceiverAndStabilityLevel(createLogsReceiver, component.StabilityLevelInDevelopment))
}

func createTracesReceiver(context.Context, component.ReceiverCreateSettings, config.Receiver, consumer.Traces) (component.TracesReceiver, error) {
Expand Down
29 changes: 28 additions & 1 deletion component/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,30 +149,57 @@ type exporterFactory struct {
}

// WithTracesExporter overrides the default "error not supported" implementation for CreateTracesExporter.
// Deprecated: [v0.55.0] Use WithTracesExporterAndStabilityLevel instead.
codeboten marked this conversation as resolved.
Show resolved Hide resolved
func WithTracesExporter(createTracesExporter CreateTracesExporterFunc) ExporterFactoryOption {
return exporterFactoryOptionFunc(func(o *exporterFactory) {
o.CreateTracesExporterFunc = createTracesExporter
})
}

// WithTracesExporterAndStabilityLevel overrides the default "error not supported" implementation for CreateTracesExporter and the default "undefined" stability level.
func WithTracesExporterAndStabilityLevel(createTracesExporter CreateTracesExporterFunc, sl StabilityLevel) ExporterFactoryOption {
return exporterFactoryOptionFunc(func(o *exporterFactory) {
o.stability[config.TracesDataType] = sl
o.CreateTracesExporterFunc = createTracesExporter
})
}

// WithMetricsExporter overrides the default "error not supported" implementation for CreateMetricsExporter.
// Deprecated: [v0.55.0] Use WithMetricsExporterAndStabilityLevel instead.
func WithMetricsExporter(createMetricsExporter CreateMetricsExporterFunc) ExporterFactoryOption {
return exporterFactoryOptionFunc(func(o *exporterFactory) {
o.CreateMetricsExporterFunc = createMetricsExporter
})
}

// WithMetricsExporterAndStabilityLevel overrides the default "error not supported" implementation for CreateMetricsExporter and the default "undefined" stability level.
func WithMetricsExporterAndStabilityLevel(createMetricsExporter CreateMetricsExporterFunc, sl StabilityLevel) ExporterFactoryOption {
return exporterFactoryOptionFunc(func(o *exporterFactory) {
o.stability[config.MetricsDataType] = sl
o.CreateMetricsExporterFunc = createMetricsExporter
})
}

// WithLogsExporter overrides the default "error not supported" implementation for CreateLogsExporter.
// Deprecated: [v0.55.0] Use WithLogsExporterAndStabilityLevel instead.
func WithLogsExporter(createLogsExporter CreateLogsExporterFunc) ExporterFactoryOption {
return exporterFactoryOptionFunc(func(o *exporterFactory) {
o.CreateLogsExporterFunc = createLogsExporter
})
}

// WithLogsExporterAndStabilityLevel overrides the default "error not supported" implementation for CreateLogsExporter and the default "undefined" stability level.
func WithLogsExporterAndStabilityLevel(createLogsExporter CreateLogsExporterFunc, sl StabilityLevel) ExporterFactoryOption {
return exporterFactoryOptionFunc(func(o *exporterFactory) {
o.stability[config.LogsDataType] = sl
o.CreateLogsExporterFunc = createLogsExporter
})
}

// NewExporterFactory returns a ExporterFactory.
func NewExporterFactory(cfgType config.Type, createDefaultConfig ExporterCreateDefaultConfigFunc, options ...ExporterFactoryOption) ExporterFactory {
mx-psi marked this conversation as resolved.
Show resolved Hide resolved
f := &exporterFactory{
baseFactory: baseFactory{cfgType: cfgType},
baseFactory: baseFactory{cfgType: cfgType, stability: make(map[config.DataType]StabilityLevel)},
ExporterCreateDefaultConfigFunc: createDefaultConfig,
}
for _, opt := range options {
Expand Down
26 changes: 26 additions & 0 deletions component/exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,32 @@ func TestNewExporterFactory_WithOptions(t *testing.T) {
assert.NoError(t, err)
}

func TestNewExporterFactory_WithStabilityLevel(t *testing.T) {
const typeStr = "test"
defaultCfg := config.NewExporterSettings(config.NewComponentID(typeStr))
factory := NewExporterFactory(
typeStr,
func() config.Exporter { return &defaultCfg },
WithTracesExporterAndStabilityLevel(createTracesExporter, StabilityLevelInDevelopment),
WithMetricsExporterAndStabilityLevel(createMetricsExporter, StabilityLevelAlpha),
WithLogsExporterAndStabilityLevel(createLogsExporter, StabilityLevelDeprecated))

assert.EqualValues(t, typeStr, factory.Type())
assert.EqualValues(t, &defaultCfg, factory.CreateDefaultConfig())

assert.EqualValues(t, StabilityLevelInDevelopment, factory.StabilityLevel(config.TracesDataType))
_, err := factory.CreateTracesExporter(context.Background(), ExporterCreateSettings{}, &defaultCfg)
assert.NoError(t, err)

assert.EqualValues(t, StabilityLevelAlpha, factory.StabilityLevel(config.MetricsDataType))
_, err = factory.CreateMetricsExporter(context.Background(), ExporterCreateSettings{}, &defaultCfg)
assert.NoError(t, err)

assert.EqualValues(t, StabilityLevelDeprecated, factory.StabilityLevel(config.LogsDataType))
_, err = factory.CreateLogsExporter(context.Background(), ExporterCreateSettings{}, &defaultCfg)
assert.NoError(t, err)
}

func createTracesExporter(context.Context, ExporterCreateSettings, config.Exporter) (TracesExporter, error) {
return nil, nil
}
Expand Down
29 changes: 28 additions & 1 deletion component/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,30 +179,57 @@ type processorFactory struct {
}

// WithTracesProcessor overrides the default "error not supported" implementation for CreateTracesProcessor.
// Deprecated: [v0.55.0] Use WithTracesProcessorAndStabilityLevel instead.
func WithTracesProcessor(createTracesProcessor CreateTracesProcessorFunc) ProcessorFactoryOption {
return processorFactoryOptionFunc(func(o *processorFactory) {
o.CreateTracesProcessorFunc = createTracesProcessor
})
}

// WithTracesProcessorAndStabilityLevel overrides the default "error not supported" implementation for CreateTracesProcessor and the default "undefined" stability level.
func WithTracesProcessorAndStabilityLevel(createTracesProcessor CreateTracesProcessorFunc, sl StabilityLevel) ProcessorFactoryOption {
return processorFactoryOptionFunc(func(o *processorFactory) {
o.stability[config.TracesDataType] = sl
o.CreateTracesProcessorFunc = createTracesProcessor
})
}

// WithMetricsProcessor overrides the default "error not supported" implementation for CreateMetricsProcessor.
// Deprecated: [v0.55.0] Use WithMetricsProcessorAndStabilityLevel instead.
func WithMetricsProcessor(createMetricsProcessor CreateMetricsProcessorFunc) ProcessorFactoryOption {
return processorFactoryOptionFunc(func(o *processorFactory) {
o.CreateMetricsProcessorFunc = createMetricsProcessor
})
}

// WithMetricsProcessorAndStabilityLevel overrides the default "error not supported" implementation for CreateMetricsProcessor and the default "undefined" stability level.
func WithMetricsProcessorAndStabilityLevel(createMetricsProcessor CreateMetricsProcessorFunc, sl StabilityLevel) ProcessorFactoryOption {
return processorFactoryOptionFunc(func(o *processorFactory) {
o.stability[config.MetricsDataType] = sl
o.CreateMetricsProcessorFunc = createMetricsProcessor
})
}

// WithLogsProcessor overrides the default "error not supported" implementation for CreateLogsProcessor.
// Deprecated: [v0.55.0] Use WithLogsProcessorAndStabilityLevel instead.
func WithLogsProcessor(createLogsProcessor CreateLogsProcessorFunc) ProcessorFactoryOption {
return processorFactoryOptionFunc(func(o *processorFactory) {
o.CreateLogsProcessorFunc = createLogsProcessor
})
}

// WithLogsProcessorAndStabilityLevel overrides the default "error not supported" implementation for CreateLogsProcessor and the default "undefined" stability level.
func WithLogsProcessorAndStabilityLevel(createLogsProcessor CreateLogsProcessorFunc, sl StabilityLevel) ProcessorFactoryOption {
return processorFactoryOptionFunc(func(o *processorFactory) {
o.stability[config.LogsDataType] = sl
o.CreateLogsProcessorFunc = createLogsProcessor
})
}

// NewProcessorFactory returns a ProcessorFactory.
func NewProcessorFactory(cfgType config.Type, createDefaultConfig ProcessorCreateDefaultConfigFunc, options ...ProcessorFactoryOption) ProcessorFactory {
f := &processorFactory{
baseFactory: baseFactory{cfgType: cfgType},
baseFactory: baseFactory{cfgType: cfgType, stability: make(map[config.DataType]StabilityLevel)},
ProcessorCreateDefaultConfigFunc: createDefaultConfig,
}
for _, opt := range options {
Expand Down
25 changes: 25 additions & 0 deletions component/processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,31 @@ func TestNewProcessorFactory_WithOptions(t *testing.T) {
assert.NoError(t, err)
}

func TestNewProcessorFactory_WithStabilityLevel(t *testing.T) {
const typeStr = "test"
defaultCfg := config.NewProcessorSettings(config.NewComponentID(typeStr))
factory := NewProcessorFactory(
typeStr,
func() config.Processor { return &defaultCfg },
WithTracesProcessorAndStabilityLevel(createTracesProcessor, StabilityLevelAlpha),
WithMetricsProcessorAndStabilityLevel(createMetricsProcessor, StabilityLevelBeta),
WithLogsProcessorAndStabilityLevel(createLogsProcessor, StabilityLevelUnmaintained))
assert.EqualValues(t, typeStr, factory.Type())
assert.EqualValues(t, &defaultCfg, factory.CreateDefaultConfig())

assert.EqualValues(t, StabilityLevelAlpha, factory.StabilityLevel(config.TracesDataType))
_, err := factory.CreateTracesProcessor(context.Background(), ProcessorCreateSettings{}, &defaultCfg, nil)
assert.NoError(t, err)

assert.EqualValues(t, StabilityLevelBeta, factory.StabilityLevel(config.MetricsDataType))
_, err = factory.CreateMetricsProcessor(context.Background(), ProcessorCreateSettings{}, &defaultCfg, nil)
assert.NoError(t, err)

assert.EqualValues(t, StabilityLevelUnmaintained, factory.StabilityLevel(config.LogsDataType))
_, err = factory.CreateLogsProcessor(context.Background(), ProcessorCreateSettings{}, &defaultCfg, nil)
assert.NoError(t, err)
}

func createTracesProcessor(context.Context, ProcessorCreateSettings, config.Processor, consumer.Traces) (TracesProcessor, error) {
return nil, nil
}
Expand Down
29 changes: 28 additions & 1 deletion component/receiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,30 +211,57 @@ type receiverFactory struct {
}

// WithTracesReceiver overrides the default "error not supported" implementation for CreateTracesReceiver.
// Deprecated: [v0.55.0] Use WithTracesReceiverAndStabilityLevel instead.
func WithTracesReceiver(createTracesReceiver CreateTracesReceiverFunc) ReceiverFactoryOption {
return receiverFactoryOptionFunc(func(o *receiverFactory) {
o.CreateTracesReceiverFunc = createTracesReceiver
})
}

// WithTracesReceiverAndStabilityLevel overrides the default "error not supported" implementation for CreateTracesReceiver and the default "undefined" stability level.
func WithTracesReceiverAndStabilityLevel(createTracesReceiver CreateTracesReceiverFunc, sl StabilityLevel) ReceiverFactoryOption {
return receiverFactoryOptionFunc(func(o *receiverFactory) {
o.stability[config.TracesDataType] = sl
o.CreateTracesReceiverFunc = createTracesReceiver
})
}

// WithMetricsReceiver overrides the default "error not supported" implementation for CreateMetricsReceiver.
// Deprecated: [v0.55.0] Use WithMetricsReceiverAndStabilityLevel instead.
func WithMetricsReceiver(createMetricsReceiver CreateMetricsReceiverFunc) ReceiverFactoryOption {
return receiverFactoryOptionFunc(func(o *receiverFactory) {
o.CreateMetricsReceiverFunc = createMetricsReceiver
})
}

// WithMetricsReceiverAndStabilityLevel overrides the default "error not supported" implementation for CreateMetricsReceiver and the default "undefined" stability level.
func WithMetricsReceiverAndStabilityLevel(createMetricsReceiver CreateMetricsReceiverFunc, sl StabilityLevel) ReceiverFactoryOption {
return receiverFactoryOptionFunc(func(o *receiverFactory) {
o.stability[config.MetricsDataType] = sl
o.CreateMetricsReceiverFunc = createMetricsReceiver
})
}

// WithLogsReceiver overrides the default "error not supported" implementation for CreateLogsReceiver.
// Deprecated: [v0.55.0] Use WithLogsReceiverAndStabilityLevel instead.
func WithLogsReceiver(createLogsReceiver CreateLogsReceiverFunc) ReceiverFactoryOption {
return receiverFactoryOptionFunc(func(o *receiverFactory) {
o.CreateLogsReceiverFunc = createLogsReceiver
})
}

// WithLogsReceiverAndStabilityLevel overrides the default "error not supported" implementation for CreateLogsReceiver and the default "undefined" stability level.
func WithLogsReceiverAndStabilityLevel(createLogsReceiver CreateLogsReceiverFunc, sl StabilityLevel) ReceiverFactoryOption {
return receiverFactoryOptionFunc(func(o *receiverFactory) {
o.stability[config.LogsDataType] = sl
o.CreateLogsReceiverFunc = createLogsReceiver
})
}

// NewReceiverFactory returns a ReceiverFactory.
func NewReceiverFactory(cfgType config.Type, createDefaultConfig ReceiverCreateDefaultConfigFunc, options ...ReceiverFactoryOption) ReceiverFactory {
f := &receiverFactory{
baseFactory: baseFactory{cfgType: cfgType},
baseFactory: baseFactory{cfgType: cfgType, stability: make(map[config.DataType]StabilityLevel)},
ReceiverCreateDefaultConfigFunc: createDefaultConfig,
}
for _, opt := range options {
Expand Down
Loading