diff --git a/component/component.go b/component/component.go index c73e042a222..8990baa8921 100644 --- a/component/component.go +++ b/component/component.go @@ -138,6 +138,24 @@ func (sl StabilityLevel) String() string { return "undefined" } +func (sl StabilityLevel) LogMessage() string { + switch sl { + case StabilityLevelUnmaintained: + return "Unmaintained component. Actively looking for contributors. Component will become deprecated after 6 months of remaining unmaintained." + case StabilityLevelDeprecated: + return "Deprecated component. Will be removed in future releases." + case StabilityLevelInDevelopment: + return "In development component. May change in the future." + case StabilityLevelAlpha: + return "Alpha component. May change in the future." + case StabilityLevelBeta: + return "Beta component. May change in the future." + case StabilityLevelStable: + return "Stable component." + } + return "Stability level of component is undefined" +} + // Factory is implemented by all component factories. // // This interface cannot be directly implemented. Implementations must diff --git a/service/internal/components/components.go b/service/internal/components/components.go new file mode 100644 index 00000000000..410fffb37db --- /dev/null +++ b/service/internal/components/components.go @@ -0,0 +1,32 @@ +// Copyright The OpenTelemetry Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package components // import "go.opentelemetry.io/collector/service/internal/components" + +import ( + "go.uber.org/zap" + + "go.opentelemetry.io/collector/component" +) + +// LogStabilityLevel logs the stability level of a component. The log level is set to info for +// undefined, unmaintained, deprecated and in development. The log level is set to debug +// for alpha, beta and stable. +func LogStabilityLevel(logger *zap.Logger, sl component.StabilityLevel) { + if sl >= component.StabilityLevelAlpha { + logger.Debug(sl.LogMessage(), zap.String(ZapStabilityKey, sl.String())) + } else { + logger.Info(sl.LogMessage(), zap.String(ZapStabilityKey, sl.String())) + } +} diff --git a/service/internal/components/components_test.go b/service/internal/components/components_test.go new file mode 100644 index 00000000000..221092da805 --- /dev/null +++ b/service/internal/components/components_test.go @@ -0,0 +1,56 @@ +// Copyright The OpenTelemetry Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package components // import "go.opentelemetry.io/collector/service/internal/components" + +import ( + "testing" + + "github.com/stretchr/testify/require" + "go.uber.org/zap" + "go.uber.org/zap/zapcore" + "go.uber.org/zap/zaptest/observer" + + "go.opentelemetry.io/collector/component" +) + +func TestLogStabilityLevel(t *testing.T) { + tests := []struct { + level zapcore.Level + expectedLogs int + }{ + { + level: zapcore.DebugLevel, + expectedLogs: 7, + }, + { + level: zapcore.InfoLevel, + expectedLogs: 4, + }, + } + + for _, tt := range tests { + observed, logs := observer.New(tt.level) + logger := zap.New(observed) + // ensure log levels are set correctly for each stability level + LogStabilityLevel(logger, component.StabilityLevelUndefined) + LogStabilityLevel(logger, component.StabilityLevelUnmaintained) + LogStabilityLevel(logger, component.StabilityLevelDeprecated) + LogStabilityLevel(logger, component.StabilityLevelInDevelopment) + LogStabilityLevel(logger, component.StabilityLevelAlpha) + LogStabilityLevel(logger, component.StabilityLevelBeta) + LogStabilityLevel(logger, component.StabilityLevelStable) + require.Equal(t, tt.expectedLogs, logs.Len()) + } +} diff --git a/service/internal/pipelines/pipelines.go b/service/internal/pipelines/pipelines.go index dc32b584abe..098b511ce54 100644 --- a/service/internal/pipelines/pipelines.go +++ b/service/internal/pipelines/pipelines.go @@ -331,21 +331,6 @@ func Build(ctx context.Context, set Settings) (*Pipelines, error) { 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. This component will become deprecated after 6 months of remaining unmaintained", zap.String(components.ZapStabilityKey, sl.String())) - case component.StabilityLevelInDevelopment: - logger.Info("Component is under development.", zap.String(components.ZapStabilityKey, sl.String())) - case component.StabilityLevelAlpha, component.StabilityLevelBeta, component.StabilityLevelStable: - logger.Debug("Stability level", zap.String(components.ZapStabilityKey, sl.String())) - default: - logger.Debug("Stability level of component undefined", zap.String(components.ZapStabilityKey, sl.String())) - } -} - func buildExporter( ctx context.Context, settings component.TelemetrySettings, @@ -370,7 +355,7 @@ func buildExporter( BuildInfo: buildInfo, } set.TelemetrySettings.Logger = exporterLogger(settings.Logger, id, pipelineID.Type()) - logStabilityMessage(set.TelemetrySettings.Logger, factory.StabilityLevel(pipelineID.Type())) + components.LogStabilityLevel(set.TelemetrySettings.Logger, factory.StabilityLevel(pipelineID.Type())) exp, err := createExporter(ctx, set, cfg, id, pipelineID, factory) if err != nil { @@ -452,7 +437,7 @@ func buildProcessor(ctx context.Context, BuildInfo: buildInfo, } set.TelemetrySettings.Logger = processorLogger(settings.Logger, id, pipelineID) - logStabilityMessage(set.TelemetrySettings.Logger, factory.StabilityLevel(pipelineID.Type())) + components.LogStabilityLevel(set.TelemetrySettings.Logger, factory.StabilityLevel(pipelineID.Type())) proc, err := createProcessor(ctx, set, procCfg, id, pipelineID, next, factory) if err != nil { @@ -506,7 +491,7 @@ func buildReceiver(ctx context.Context, BuildInfo: buildInfo, } set.TelemetrySettings.Logger = receiverLogger(settings.Logger, id, pipelineID.Type()) - logStabilityMessage(set.TelemetrySettings.Logger, factory.StabilityLevel(pipelineID.Type())) + components.LogStabilityLevel(set.TelemetrySettings.Logger, factory.StabilityLevel(pipelineID.Type())) recv, err := createReceiver(ctx, set, cfg, id, pipelineID, nexts, factory) if err != nil { diff --git a/service/internal/pipelines/pipelines_test.go b/service/internal/pipelines/pipelines_test.go index 12c7195e5ad..38d8b5cc68f 100644 --- a/service/internal/pipelines/pipelines_test.go +++ b/service/internal/pipelines/pipelines_test.go @@ -22,9 +22,6 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "go.uber.org/zap" - "go.uber.org/zap/zapcore" - "go.uber.org/zap/zaptest/observer" "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/component/componenttest" @@ -348,36 +345,6 @@ func TestFailToStartAndShutdown(t *testing.T) { } } -func TestLogStabilityLevle(t *testing.T) { - tests := []struct { - level zapcore.Level - expectedLogs int - }{ - { - level: zapcore.DebugLevel, - expectedLogs: 7, - }, - { - level: zapcore.InfoLevel, - expectedLogs: 3, - }, - } - - for _, tt := range tests { - observed, logs := observer.New(tt.level) - logger := zap.New(observed) - // ensure log levels are set correctly for each stability level - logStabilityMessage(logger, component.StabilityLevelUndefined) - logStabilityMessage(logger, component.StabilityLevelUnmaintained) - logStabilityMessage(logger, component.StabilityLevelDeprecated) - logStabilityMessage(logger, component.StabilityLevelInDevelopment) - logStabilityMessage(logger, component.StabilityLevelAlpha) - logStabilityMessage(logger, component.StabilityLevelBeta) - logStabilityMessage(logger, component.StabilityLevelStable) - require.Equal(t, tt.expectedLogs, logs.Len()) - } -} - func newBadReceiverFactory() component.ReceiverFactory { return component.NewReceiverFactory("bf", func() config.Receiver { return &struct {