Skip to content

Commit

Permalink
add stability level to component factory (open-telemetry#5580)
Browse files Browse the repository at this point in the history
* add stability level to component factory

* update docstring

* use a map instead of a single stability level

* apply review feedback

* add tests

* fix impi, add changelog

* add processors, receivers

* fix inconsistency

* set noop to stable

* update calls in deprecated func
  • Loading branch information
Alex Boten authored Jul 5, 2022
1 parent 16aa10d commit 9f0d97c
Show file tree
Hide file tree
Showing 23 changed files with 302 additions and 43 deletions.
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)

### 💡 Enhancements 💡

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.
// 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.StabilityLevelStable),
component.WithMetricsExporterAndStabilityLevel(createMetricsExporter, component.StabilityLevelStable),
component.WithLogsExporterAndStabilityLevel(createLogsExporter, component.StabilityLevelStable),
)
}

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.StabilityLevelStable),
component.WithMetricsProcessorAndStabilityLevel(createMetricsProcessor, component.StabilityLevelStable),
component.WithLogsProcessorAndStabilityLevel(createLogsProcessor, component.StabilityLevelStable),
)
}

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.StabilityLevelStable),
component.WithMetricsReceiverAndStabilityLevel(createMetricsReceiver, component.StabilityLevelStable),
component.WithLogsReceiverAndStabilityLevel(createLogsReceiver, component.StabilityLevelStable))
}

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

// WithTracesExporter overrides the default "error not supported" implementation for CreateTracesExporter.
// Deprecated: [v0.55.0] Use WithTracesExporterAndStabilityLevel instead.
func WithTracesExporter(createTracesExporter CreateTracesExporterFunc) ExporterFactoryOption {
return WithTracesExporterAndStabilityLevel(createTracesExporter, StabilityLevelUndefined)
}

// 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 WithMetricsExporterAndStabilityLevel(createMetricsExporter, StabilityLevelUndefined)
}

// 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 WithLogsExporterAndStabilityLevel(createLogsExporter, StabilityLevelUndefined)
}

// 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 {
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
23 changes: 22 additions & 1 deletion component/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,30 +179,51 @@ 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 WithTracesProcessorAndStabilityLevel(createTracesProcessor, StabilityLevelUndefined)
}

// 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 WithMetricsProcessorAndStabilityLevel(createMetricsProcessor, StabilityLevelUndefined)
}

// 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 WithLogsProcessorAndStabilityLevel(createLogsProcessor, StabilityLevelUndefined)
}

// 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
23 changes: 22 additions & 1 deletion component/receiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,30 +211,51 @@ 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 WithTracesReceiverAndStabilityLevel(createTracesReceiver, StabilityLevelUndefined)
}

// 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 WithMetricsReceiverAndStabilityLevel(createMetricsReceiver, StabilityLevelUndefined)
}

// 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 WithLogsReceiverAndStabilityLevel(createLogsReceiver, StabilityLevelUndefined)
}

// 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
25 changes: 25 additions & 0 deletions component/receiver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,31 @@ func TestNewReceiverFactory_WithOptions(t *testing.T) {
assert.NoError(t, err)
}

func TestNewReceiverFactory_WithStabilityLevels(t *testing.T) {
const typeStr = "test"
defaultCfg := config.NewReceiverSettings(config.NewComponentID(typeStr))
factory := NewReceiverFactory(
typeStr,
func() config.Receiver { return &defaultCfg },
WithTracesReceiverAndStabilityLevel(createTracesReceiver, StabilityLevelDeprecated),
WithMetricsReceiverAndStabilityLevel(createMetricsReceiver, StabilityLevelAlpha),
WithLogsReceiverAndStabilityLevel(createLogsReceiver, StabilityLevelStable))
assert.EqualValues(t, typeStr, factory.Type())
assert.EqualValues(t, &defaultCfg, factory.CreateDefaultConfig())

assert.EqualValues(t, StabilityLevelDeprecated, factory.StabilityLevel(config.TracesDataType))
_, err := factory.CreateTracesReceiver(context.Background(), ReceiverCreateSettings{}, &defaultCfg, nil)
assert.NoError(t, err)

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

assert.EqualValues(t, StabilityLevelStable, factory.StabilityLevel(config.LogsDataType))
_, err = factory.CreateLogsReceiver(context.Background(), ReceiverCreateSettings{}, &defaultCfg, nil)
assert.NoError(t, err)
}

func createTracesReceiver(context.Context, ReceiverCreateSettings, config.Receiver, consumer.Traces) (TracesReceiver, error) {
return nil, nil
}
Expand Down
Loading

0 comments on commit 9f0d97c

Please sign in to comment.