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 LogMessage and move LogStabilityLevel #5633

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
add LogMessage and move LogStabilityLevel
This change will make the func available for extensions as well.
  • Loading branch information
Alex Boten committed Jul 7, 2022
commit 39ddea07d848e0865b26588f7dea9f0d1c41526c
18 changes: 18 additions & 0 deletions component/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,24 @@ func (sl StabilityLevel) String() string {
return "undefined"
}

func (sl StabilityLevel) LogMessage() string {
switch sl {
case StabilityLevelUnmaintained:
return "This component is unmaintained and actively looking for contributors. This component will become deprecated after 6 months of remaining unmaintained."
case StabilityLevelDeprecated:
return "This component has been deprecated and will be removed in future releases."
case StabilityLevelInDevelopment:
return "This component is in development and may change in the future."
case StabilityLevelAlpha:
return "This component is alpha and may change in the future."
case StabilityLevelBeta:
return "This component is beta and may change in the future."
case StabilityLevelStable:
return "This component is stable."
codeboten marked this conversation as resolved.
Show resolved Hide resolved
}
return "The stability level of this component is undefined"
}

// Factory is implemented by all component factories.
//
// This interface cannot be directly implemented. Implementations must
Expand Down
28 changes: 28 additions & 0 deletions service/internal/components/components.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// 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.opentelemetry.io/collector/component"
"go.uber.org/zap"
)

func LogStabilityLevel(logger *zap.Logger, sl component.StabilityLevel) {
codeboten marked this conversation as resolved.
Show resolved Hide resolved
if sl >= component.StabilityLevelAlpha {
logger.Debug(sl.LogMessage(), zap.String(ZapStabilityKey, sl.String()))
} else {
logger.Info(sl.LogMessage(), zap.String(ZapStabilityKey, sl.String()))
}
}
55 changes: 55 additions & 0 deletions service/internal/components/components_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// 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.opentelemetry.io/collector/component"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
"go.uber.org/zap/zaptest/observer"
)

func TestLogStabilityLevle(t *testing.T) {
codeboten marked this conversation as resolved.
Show resolved Hide resolved
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())
}
}
21 changes: 3 additions & 18 deletions service/internal/pipelines/pipelines.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
33 changes: 0 additions & 33 deletions service/internal/pipelines/pipelines_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down