Skip to content

Commit

Permalink
Define a new API for components stability level to match extensions a…
Browse files Browse the repository at this point in the history
…s well (#5762)

Signed-off-by: Bogdan <bogdandrutu@gmail.com>
  • Loading branch information
bogdandrutu authored Aug 3, 2022
1 parent e07de93 commit 186077d
Show file tree
Hide file tree
Showing 16 changed files with 180 additions and 59 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,17 @@

### 🚩 Deprecations 🚩

- Deprecate the `component.Factory.StabilityLevel(config.DataType)` in favor of Stability per component (#5762):
- `component.ExporterFactory.TracesExporterStability`
- `component.ExporterFactory.MetricsExporterStability`
- `component.ExporterFactory.LogsExporterStability`
- `component.ProcessorFactory.TracesProcessorStability`
- `component.ProcessorFactory.MetricsProcessorStability`
- `component.ProcessorFactory.LogsProcessorStability`
- `component.ReceiverFactory.TracesReceiverStability`
- `component.ReceiverFactory.MetricsReceiverStability`
- `component.ReceiverFactory.LogsReceiverStability`

### 💡 Enhancements 💡

### 🧰 Bug fixes 🧰
Expand Down
6 changes: 5 additions & 1 deletion component/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ 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.
// Deprecated: [v0.58.0] replaced by the more specific versions in each Factory type.
StabilityLevel(config.DataType) StabilityLevel

unexportedFactoryFunc()
Expand All @@ -182,6 +182,10 @@ func (bf baseFactory) Type() config.Type {
}

func (bf baseFactory) StabilityLevel(dt config.DataType) StabilityLevel {
return bf.getStabilityLevel(dt)
}

func (bf baseFactory) getStabilityLevel(dt config.DataType) StabilityLevel {
if val, ok := bf.stability[dt]; ok {
return val
}
Expand Down
5 changes: 3 additions & 2 deletions component/componenttest/nop_extension.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type nopExtensionConfig struct {

// NewNopExtensionFactory returns a component.ExtensionFactory that constructs nop extensions.
func NewNopExtensionFactory() component.ExtensionFactory {
return component.NewExtensionFactory(
return component.NewExtensionFactoryWithStabilityLevel(
"nop",
func() config.Extension {
return &nopExtensionConfig{
Expand All @@ -44,7 +44,8 @@ func NewNopExtensionFactory() component.ExtensionFactory {
},
func(context.Context, component.ExtensionCreateSettings, config.Extension) (component.Extension, error) {
return nopExtensionInstance, nil
})
},
component.StabilityLevelStable)
}

var nopExtensionInstance = &nopExtension{}
Expand Down
27 changes: 24 additions & 3 deletions component/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,20 +68,29 @@ type ExporterFactory interface {
// tests of any implementation of the Factory interface.
CreateDefaultConfig() config.Exporter

// CreateTracesExporter creates a trace exporter based on this config.
// CreateTracesExporter creates a TracesExporter based on this config.
// If the exporter type does not support tracing or if the config is not valid,
// an error will be returned instead.
CreateTracesExporter(ctx context.Context, set ExporterCreateSettings, cfg config.Exporter) (TracesExporter, error)

// CreateMetricsExporter creates a metrics exporter based on this config.
// 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 config.Exporter) (MetricsExporter, error)

// CreateLogsExporter creates an exporter based on the config.
// 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 config.Exporter) (LogsExporter, error)

// LogsExporterStability gets the stability level of the LogsExporter.
LogsExporterStability() StabilityLevel
}

// ExporterFactoryOption apply changes to ExporterOptions.
Expand Down Expand Up @@ -148,6 +157,18 @@ type exporterFactory struct {
CreateLogsExporterFunc
}

func (e exporterFactory) TracesExporterStability() StabilityLevel {
return e.getStabilityLevel(config.TracesDataType)
}

func (e exporterFactory) MetricsExporterStability() StabilityLevel {
return e.getStabilityLevel(config.MetricsDataType)
}

func (e exporterFactory) LogsExporterStability() StabilityLevel {
return e.getStabilityLevel(config.LogsDataType)
}

// 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) {
Expand Down
6 changes: 3 additions & 3 deletions component/exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,15 @@ func TestNewExporterFactory_WithOptions(t *testing.T) {
assert.EqualValues(t, typeStr, factory.Type())
assert.EqualValues(t, &defaultCfg, factory.CreateDefaultConfig())

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

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

assert.Equal(t, StabilityLevelDeprecated, factory.StabilityLevel(config.LogsDataType))
assert.Equal(t, StabilityLevelDeprecated, factory.LogsExporterStability())
_, err = factory.CreateLogsExporter(context.Background(), ExporterCreateSettings{}, &defaultCfg)
assert.NoError(t, err)
}
Expand Down
19 changes: 19 additions & 0 deletions component/extension.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,21 +83,40 @@ type ExtensionFactory interface {

// CreateExtension creates an extension based on the given config.
CreateExtension(ctx context.Context, set ExtensionCreateSettings, cfg config.Extension) (Extension, error)

// ExtensionStability gets the stability level of the Extension.
ExtensionStability() StabilityLevel
}

type extensionFactory struct {
baseFactory
ExtensionCreateDefaultConfigFunc
CreateExtensionFunc
extensionStability StabilityLevel
}

func (ef *extensionFactory) ExtensionStability() StabilityLevel {
return ef.extensionStability
}

// Deprecated: [v0.58.0] use NewExtensionFactoryWithStabilityLevel.
func NewExtensionFactory(
cfgType config.Type,
createDefaultConfig ExtensionCreateDefaultConfigFunc,
createServiceExtension CreateExtensionFunc) ExtensionFactory {
return NewExtensionFactoryWithStabilityLevel(cfgType, createDefaultConfig, createServiceExtension, StabilityLevelUndefined)
}

// NewExtensionFactoryWithStabilityLevel returns a new ExtensionFactory based on this configuration.
func NewExtensionFactoryWithStabilityLevel(
cfgType config.Type,
createDefaultConfig ExtensionCreateDefaultConfigFunc,
createServiceExtension CreateExtensionFunc,
sl StabilityLevel) ExtensionFactory {
return &extensionFactory{
baseFactory: baseFactory{cfgType: cfgType},
ExtensionCreateDefaultConfigFunc: createDefaultConfig,
CreateExtensionFunc: createServiceExtension,
extensionStability: sl,
}
}
7 changes: 5 additions & 2 deletions component/extension_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,17 @@ func TestNewExtensionFactory(t *testing.T) {
defaultCfg := config.NewExtensionSettings(config.NewComponentID(typeStr))
nopExtensionInstance := new(nopExtension)

factory := NewExtensionFactory(
factory := NewExtensionFactoryWithStabilityLevel(
typeStr,
func() config.Extension { return &defaultCfg },
func(ctx context.Context, settings ExtensionCreateSettings, extension config.Extension) (Extension, error) {
return nopExtensionInstance, nil
})
},
StabilityLevelInDevelopment)
assert.EqualValues(t, typeStr, factory.Type())
assert.EqualValues(t, &defaultCfg, factory.CreateDefaultConfig())

assert.Equal(t, StabilityLevelInDevelopment, factory.ExtensionStability())
ext, err := factory.CreateExtension(context.Background(), ExtensionCreateSettings{}, &defaultCfg)
assert.NoError(t, err)
assert.Same(t, nopExtensionInstance, ext)
Expand Down
6 changes: 3 additions & 3 deletions component/factories_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ func TestMakeExtensionFactoryMap(t *testing.T) {
out map[config.Type]ExtensionFactory
}

p1 := NewExtensionFactory("p1", nil, nil)
p2 := NewExtensionFactory("p2", nil, nil)
p1 := NewExtensionFactoryWithStabilityLevel("p1", nil, nil, StabilityLevelAlpha)
p2 := NewExtensionFactoryWithStabilityLevel("p2", nil, nil, StabilityLevelAlpha)
testCases := []testCase{
{
name: "different names",
Expand All @@ -42,7 +42,7 @@ func TestMakeExtensionFactoryMap(t *testing.T) {
},
{
name: "same name",
in: []ExtensionFactory{p1, p2, NewExtensionFactory("p1", nil, nil)},
in: []ExtensionFactory{p1, p2, NewExtensionFactoryWithStabilityLevel("p1", nil, nil, StabilityLevelAlpha)},
},
}
for i := range testCases {
Expand Down
52 changes: 29 additions & 23 deletions component/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,35 +69,29 @@ type ProcessorFactory interface {
// tests of any implementation of the Factory interface.
CreateDefaultConfig() config.Processor

// CreateTracesProcessor creates a trace processor based on this config.
// CreateTracesProcessor creates a TracesProcessor based on this config.
// If the processor type does not support tracing or if the config is not valid,
// an error will be returned instead.
CreateTracesProcessor(
ctx context.Context,
set ProcessorCreateSettings,
cfg config.Processor,
nextConsumer consumer.Traces,
) (TracesProcessor, error)

// CreateMetricsProcessor creates a metrics processor based on this config.
CreateTracesProcessor(ctx context.Context, set ProcessorCreateSettings, cfg config.Processor, nextConsumer consumer.Traces) (TracesProcessor, error)

// TracesProcessorStability gets the stability level of the TracesProcessor.
TracesProcessorStability() StabilityLevel

// CreateMetricsProcessor creates a MetricsProcessor based on this config.
// If the processor type does not support metrics or if the config is not valid,
// an error will be returned instead.
CreateMetricsProcessor(
ctx context.Context,
set ProcessorCreateSettings,
cfg config.Processor,
nextConsumer consumer.Metrics,
) (MetricsProcessor, error)

// CreateLogsProcessor creates a processor based on the config.
CreateMetricsProcessor(ctx context.Context, set ProcessorCreateSettings, cfg config.Processor, nextConsumer consumer.Metrics) (MetricsProcessor, error)

// MetricsProcessorStability gets the stability level of the MetricsProcessor.
MetricsProcessorStability() StabilityLevel

// CreateLogsProcessor creates a LogsProcessor based on the config.
// If the processor type does not support logs or if the config is not valid,
// an error will be returned instead.
CreateLogsProcessor(
ctx context.Context,
set ProcessorCreateSettings,
cfg config.Processor,
nextConsumer consumer.Logs,
) (LogsProcessor, error)
CreateLogsProcessor(ctx context.Context, set ProcessorCreateSettings, cfg config.Processor, nextConsumer consumer.Logs) (LogsProcessor, error)

// LogsProcessorStability gets the stability level of the LogsProcessor.
LogsProcessorStability() StabilityLevel
}

// ProcessorCreateDefaultConfigFunc is the equivalent of ProcessorFactory.CreateDefaultConfig().
Expand Down Expand Up @@ -178,6 +172,18 @@ type processorFactory struct {
CreateLogsProcessorFunc
}

func (p processorFactory) TracesProcessorStability() StabilityLevel {
return p.getStabilityLevel(config.TracesDataType)
}

func (p processorFactory) MetricsProcessorStability() StabilityLevel {
return p.getStabilityLevel(config.MetricsDataType)
}

func (p processorFactory) LogsProcessorStability() StabilityLevel {
return p.getStabilityLevel(config.LogsDataType)
}

// WithTracesProcessor overrides the default "error not supported" implementation for CreateTracesProcessor and the default "undefined" stability level.
func WithTracesProcessor(createTracesProcessor CreateTracesProcessorFunc, sl StabilityLevel) ProcessorFactoryOption {
return processorFactoryOptionFunc(func(o *processorFactory) {
Expand Down
6 changes: 3 additions & 3 deletions component/processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,15 @@ func TestNewProcessorFactory_WithOptions(t *testing.T) {
assert.EqualValues(t, typeStr, factory.Type())
assert.EqualValues(t, &defaultCfg, factory.CreateDefaultConfig())

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

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

assert.Equal(t, StabilityLevelUnmaintained, factory.StabilityLevel(config.LogsDataType))
assert.Equal(t, StabilityLevelUnmaintained, factory.LogsProcessorStability())
_, err = factory.CreateLogsProcessor(context.Background(), ProcessorCreateSettings{}, &defaultCfg, nil)
assert.NoError(t, err)
}
Expand Down
36 changes: 27 additions & 9 deletions component/receiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,23 +114,29 @@ type ReceiverFactory interface {
// tests of any implementation of the Factory interface.
CreateDefaultConfig() config.Receiver

// CreateTracesReceiver creates a trace receiver based on this config.
// CreateTracesReceiver creates a TracesReceiver based on this config.
// If the receiver type does not support tracing or if the config is not valid
// an error will be returned instead.
CreateTracesReceiver(ctx context.Context, set ReceiverCreateSettings,
cfg config.Receiver, nextConsumer consumer.Traces) (TracesReceiver, error)
CreateTracesReceiver(ctx context.Context, set ReceiverCreateSettings, cfg config.Receiver, nextConsumer consumer.Traces) (TracesReceiver, error)

// CreateMetricsReceiver creates a metrics receiver based on this config.
// TracesReceiverStability gets the stability level of the TracesReceiver.
TracesReceiverStability() StabilityLevel

// CreateMetricsReceiver creates a MetricsReceiver based on this config.
// If the receiver type does not support metrics or if the config is not valid
// an error will be returned instead.
CreateMetricsReceiver(ctx context.Context, set ReceiverCreateSettings,
cfg config.Receiver, nextConsumer consumer.Metrics) (MetricsReceiver, error)
CreateMetricsReceiver(ctx context.Context, set ReceiverCreateSettings, cfg config.Receiver, nextConsumer consumer.Metrics) (MetricsReceiver, error)

// MetricsReceiverStability gets the stability level of the MetricsReceiver.
MetricsReceiverStability() StabilityLevel

// CreateLogsReceiver creates a log receiver based on this config.
// CreateLogsReceiver creates a LogsReceiver based on this config.
// If the receiver type does not support the data type or if the config is not valid
// an error will be returned instead.
CreateLogsReceiver(ctx context.Context, set ReceiverCreateSettings,
cfg config.Receiver, nextConsumer consumer.Logs) (LogsReceiver, error)
CreateLogsReceiver(ctx context.Context, set ReceiverCreateSettings, cfg config.Receiver, nextConsumer consumer.Logs) (LogsReceiver, error)

// LogsReceiverStability gets the stability level of the LogsReceiver.
LogsReceiverStability() StabilityLevel
}

// ReceiverFactoryOption apply changes to ReceiverOptions.
Expand Down Expand Up @@ -211,6 +217,18 @@ type receiverFactory struct {
CreateLogsReceiverFunc
}

func (r receiverFactory) TracesReceiverStability() StabilityLevel {
return r.getStabilityLevel(config.TracesDataType)
}

func (r receiverFactory) MetricsReceiverStability() StabilityLevel {
return r.getStabilityLevel(config.MetricsDataType)
}

func (r receiverFactory) LogsReceiverStability() StabilityLevel {
return r.getStabilityLevel(config.LogsDataType)
}

// WithTracesReceiver overrides the default "error not supported" implementation for CreateTracesReceiver and the default "undefined" stability level.
func WithTracesReceiver(createTracesReceiver CreateTracesReceiverFunc, sl StabilityLevel) ReceiverFactoryOption {
return receiverFactoryOptionFunc(func(o *receiverFactory) {
Expand Down
6 changes: 3 additions & 3 deletions component/receiver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,15 @@ func TestNewReceiverFactory_WithOptions(t *testing.T) {
assert.EqualValues(t, typeStr, factory.Type())
assert.EqualValues(t, &defaultCfg, factory.CreateDefaultConfig())

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

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

assert.Equal(t, StabilityLevelStable, factory.StabilityLevel(config.LogsDataType))
assert.Equal(t, StabilityLevelStable, factory.LogsReceiverStability())
_, err = factory.CreateLogsReceiver(context.Background(), ReceiverCreateSettings{}, &defaultCfg, nil)
assert.NoError(t, err)
}
Expand Down
2 changes: 1 addition & 1 deletion extension/ballastextension/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ var memHandler = iruntime.TotalMemory

// NewFactory creates a factory for FluentBit extension.
func NewFactory() component.ExtensionFactory {
return component.NewExtensionFactory(typeStr, createDefaultConfig, createExtension)
return component.NewExtensionFactoryWithStabilityLevel(typeStr, createDefaultConfig, createExtension, component.StabilityLevelBeta)
}

func createDefaultConfig() config.Extension {
Expand Down
2 changes: 1 addition & 1 deletion extension/zpagesextension/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const (

// NewFactory creates a factory for Z-Pages extension.
func NewFactory() component.ExtensionFactory {
return component.NewExtensionFactory(typeStr, createDefaultConfig, createExtension)
return component.NewExtensionFactoryWithStabilityLevel(typeStr, createDefaultConfig, createExtension, component.StabilityLevelBeta)
}

func createDefaultConfig() config.Extension {
Expand Down
Loading

0 comments on commit 186077d

Please sign in to comment.