Skip to content

Commit

Permalink
use a map instead of a single stability level
Browse files Browse the repository at this point in the history
  • Loading branch information
codeboten committed Jun 29, 2022
1 parent f26f1a2 commit dc73bfb
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 12 deletions.
14 changes: 10 additions & 4 deletions component/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ const (
type StabilityLevel int

const (
_ StabilityLevel = iota // skip 0, start types from 1.
StabilityLevelUndefined = iota // skip 0, start types from 1.
StabilityLevelUnmaintained
StabilityLevelDeprecated
StabilityLevelInDevelopment
Expand Down Expand Up @@ -146,12 +146,15 @@ 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.Type) StabilityLevel

unexportedFactoryFunc()
}

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

func (baseFactory) unexportedFactoryFunc() {}
Expand All @@ -160,6 +163,9 @@ func (bf baseFactory) Type() config.Type {
return bf.cfgType
}

func (bf baseFactory) StabilityLevel() StabilityLevel {
return bf.stability
func (bf baseFactory) StabilityLevel(cfgType config.Type) StabilityLevel {
if val, ok := bf.stability[cfgType]; ok {
return val
}
return StabilityLevelUndefined
}
7 changes: 6 additions & 1 deletion component/componenttest/nop_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,12 @@ func NewNopExporterFactory() component.ExporterFactory {
component.WithTracesExporter(createTracesExporter),
component.WithMetricsExporter(createMetricsExporter),
component.WithLogsExporter(createLogsExporter),
component.WithExporterStabilityLevel(component.StabilityLevelInDevelopment))
component.WithExporterStabilityLevel(map[config.Type]component.StabilityLevel{
config.LogsDataType: component.StabilityLevelInDevelopment,
config.TracesDataType: component.StabilityLevelInDevelopment,
config.MetricsDataType: component.StabilityLevelInDevelopment,
}),
)
}

func createTracesExporter(context.Context, component.ExporterCreateSettings, config.Exporter) (component.TracesExporter, error) {
Expand Down
2 changes: 1 addition & 1 deletion component/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ func WithLogsExporter(createLogsExporter CreateLogsExporterFunc) ExporterFactory
}

// WithExporterStabiityLevel overrides the default "unmaintained" stability level.
func WithExporterStabilityLevel(sl StabilityLevel) ExporterFactoryOption {
func WithExporterStabilityLevel(sl map[config.Type]StabilityLevel) ExporterFactoryOption {
return func(o *exporterFactory) {
o.stability = sl
}
Expand Down
7 changes: 5 additions & 2 deletions exporter/loggingexporter/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (
const (
// The value of "type" key in configuration.
typeStr = "logging"
stability = component.StabilityLevelInDevelopment
defaultSamplingInitial = 2
defaultSamplingThereafter = 500
)
Expand All @@ -40,7 +39,11 @@ func NewFactory() component.ExporterFactory {
component.WithTracesExporter(createTracesExporter),
component.WithMetricsExporter(createMetricsExporter),
component.WithLogsExporter(createLogsExporter),
component.WithExporterStabilityLevel(stability))
component.WithExporterStabilityLevel(map[config.Type]component.StabilityLevel{
config.LogsDataType: component.StabilityLevelInDevelopment,
config.TracesDataType: component.StabilityLevelInDevelopment,
config.MetricsDataType: component.StabilityLevelInDevelopment,
}))
}

func createDefaultConfig() config.Exporter {
Expand Down
6 changes: 5 additions & 1 deletion exporter/otlpexporter/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@ func NewFactory() component.ExporterFactory {
component.WithTracesExporter(createTracesExporter),
component.WithMetricsExporter(createMetricsExporter),
component.WithLogsExporter(createLogsExporter),
component.WithExporterStabilityLevel(stability))
component.WithExporterStabilityLevel(map[config.Type]component.StabilityLevel{
config.LogsDataType: component.StabilityLevelBeta,
config.TracesDataType: component.StabilityLevelStable,
config.MetricsDataType: component.StabilityLevelStable,
}))
}

func createDefaultConfig() config.Exporter {
Expand Down
6 changes: 5 additions & 1 deletion exporter/otlphttpexporter/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@ func NewFactory() component.ExporterFactory {
component.WithTracesExporter(createTracesExporter),
component.WithMetricsExporter(createMetricsExporter),
component.WithLogsExporter(createLogsExporter),
component.WithExporterStabilityLevel(stability))
component.WithExporterStabilityLevel(map[config.Type]component.StabilityLevel{
config.LogsDataType: component.StabilityLevelBeta,
config.TracesDataType: component.StabilityLevelStable,
config.MetricsDataType: component.StabilityLevelStable,
}))
}

func createDefaultConfig() config.Exporter {
Expand Down
6 changes: 5 additions & 1 deletion internal/testcomponents/example_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@ var ExampleExporterFactory = component.NewExporterFactory(
component.WithTracesExporter(createTracesExporter),
component.WithMetricsExporter(createMetricsExporter),
component.WithLogsExporter(createLogsExporter),
component.WithExporterStabilityLevel(stability))
component.WithExporterStabilityLevel(map[config.Type]component.StabilityLevel{
config.LogsDataType: component.StabilityLevelInDevelopment,
config.TracesDataType: component.StabilityLevelInDevelopment,
config.MetricsDataType: component.StabilityLevelInDevelopment,
}))

func createExporterDefaultConfig() config.Exporter {
return &ExampleExporterConfig{
Expand Down
1 change: 1 addition & 0 deletions service/internal/components/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ const (
ZapKindPipeline = "pipeline"
ZapNameKey = "name"
ZapDataTypeKey = "data_type"
ZapStabilityKey = "stability"
)
20 changes: 19 additions & 1 deletion service/internal/pipelines/pipelines.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ type Pipelines struct {

// StartAll starts all pipelines.
//
// Start with exporters, processors (in revers configured order), then receivers.
// Start with exporters, processors (in reverse configured order), then receivers.
// This is important so that components that are earlier in the pipeline and reference components that are
// later in the pipeline do not start sending data to later components which are not yet started.
func (bps *Pipelines) StartAll(ctx context.Context, host component.Host) error {
Expand Down Expand Up @@ -304,6 +304,23 @@ func Build(ctx context.Context, settings component.TelemetrySettings, buildInfo
return exps, nil
}

func logStabilityMessage(logger *zap.Logger, sl component.StabilityLevel) {
switch sl {
case component.StabilityLevelDeprecated:
logger.Info("Component has been deprecated and will be removed in future releases.", zap.String(components.ZapStabilityKey, sl.String()))
case component.StabilityLevelUnmaintained:
logger.Info("Component is unmaintained and actively looking for contributors.", zap.String(components.ZapStabilityKey, sl.String()))
case component.StabilityLevelInDevelopment:
logger.Info("Component is under development.", zap.String(components.ZapStabilityKey, sl.String()))
case component.StabilityLevelAlpha:
case component.StabilityLevelBeta:
case component.StabilityLevelStable:
logger.Debug("Stability level", zap.String(components.ZapStabilityKey, sl.String()))
default:
logger.Info("Stability level of component undefined", zap.String(components.ZapStabilityKey, sl.String()))
}
}

func buildExporter(
ctx context.Context,
settings component.TelemetrySettings,
Expand All @@ -328,6 +345,7 @@ func buildExporter(
BuildInfo: buildInfo,
}
set.TelemetrySettings.Logger = exporterLogger(settings.Logger, id, pipelineID.Type())
logStabilityMessage(set.TelemetrySettings.Logger, factory.StabilityLevel(pipelineID.Type()))

exp, err := createExporter(ctx, set, cfg, id, pipelineID, factory)
if err != nil {
Expand Down

0 comments on commit dc73bfb

Please sign in to comment.