Skip to content

Commit

Permalink
Hide profiles behind a feature gate (open-telemetry#11477)
Browse files Browse the repository at this point in the history
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue.
Ex. Adding a feature - Explain what this achieves.-->
#### Description

This hides profiles support behind a feature gate, so folks have to
enable them explicitly to be able to use them.
  • Loading branch information
dmathieu authored Oct 17, 2024
1 parent 4dbbb90 commit 3456b43
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 13 deletions.
25 changes: 25 additions & 0 deletions .chloggen/profiles-featuregate.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Use this changelog template to create an entry for release notes.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: enhancement

# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver)
component: service

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Hide profiles support behind a feature gate while it remains alpha.

# One or more tracking issues or pull requests related to the change
issues: [11477]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:

# Optional: The change log or logs in which this entry should be included.
# e.g. '[user]' or '[user, api]'
# Include 'user' if the change is relevant to end users.
# Include 'api' if there is a change to a library API.
# Default: '[user]'
change_logs: [user]
19 changes: 18 additions & 1 deletion service/pipelines/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"fmt"

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/featuregate"
"go.opentelemetry.io/collector/pipeline"
"go.opentelemetry.io/collector/pipeline/pipelineprofiles"
)
Expand All @@ -16,6 +17,14 @@ var (
errMissingServicePipelines = errors.New("service must have at least one pipeline")
errMissingServicePipelineReceivers = errors.New("must have at least one receiver")
errMissingServicePipelineExporters = errors.New("must have at least one exporter")

serviceProfileSupportGateID = "service.profilesSupport"
serviceProfileSupportGate = featuregate.GlobalRegistry().MustRegister(
serviceProfileSupportGateID,
featuregate.StageAlpha,
featuregate.WithRegisterFromVersion("v0.112.0"),
featuregate.WithRegisterDescription("Controls whether profiles support can be enabled"),
)
)

// Config defines the configurable settings for service telemetry.
Expand All @@ -31,8 +40,16 @@ func (cfg Config) Validate() error {
// only configured components.
for pipelineID, p := range cfg {
switch pipelineID.Signal() {
case pipeline.SignalTraces, pipeline.SignalMetrics, pipeline.SignalLogs, pipelineprofiles.SignalProfiles:
case pipeline.SignalTraces, pipeline.SignalMetrics, pipeline.SignalLogs:
// Continue
case pipelineprofiles.SignalProfiles:
if !serviceProfileSupportGate.IsEnabled() {
return fmt.Errorf(
"pipeline %q: profiling signal support is at alpha level, gated under the %q feature gate",
pipelineID.String(),
serviceProfileSupportGateID,
)
}
default:
return fmt.Errorf("pipeline %q: unknown signal %q", pipelineID.String(), pipelineID.Signal())
}
Expand Down
60 changes: 48 additions & 12 deletions service/pipelines/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,18 @@ import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/featuregate"
"go.opentelemetry.io/collector/pipeline"
"go.opentelemetry.io/collector/pipeline/pipelineprofiles"
)

func TestConfigValidate(t *testing.T) {
var testCases = []struct {
name string // test case name (also file name containing config yaml)
cfgFn func() Config
cfgFn func(*testing.T) Config
expected error
}{
{
Expand All @@ -27,8 +30,8 @@ func TestConfigValidate(t *testing.T) {
},
{
name: "duplicate-processor-reference",
cfgFn: func() Config {
cfg := generateConfig()
cfgFn: func(*testing.T) Config {
cfg := generateConfig(t)
pipe := cfg[pipeline.NewID(pipeline.SignalTraces)]
pipe.Processors = append(pipe.Processors, pipe.Processors...)
return cfg
Expand All @@ -37,33 +40,33 @@ func TestConfigValidate(t *testing.T) {
},
{
name: "missing-pipeline-receivers",
cfgFn: func() Config {
cfg := generateConfig()
cfgFn: func(*testing.T) Config {
cfg := generateConfig(t)
cfg[pipeline.NewID(pipeline.SignalTraces)].Receivers = nil
return cfg
},
expected: fmt.Errorf(`pipeline "traces": %w`, errMissingServicePipelineReceivers),
},
{
name: "missing-pipeline-exporters",
cfgFn: func() Config {
cfg := generateConfig()
cfgFn: func(*testing.T) Config {
cfg := generateConfig(t)
cfg[pipeline.NewID(pipeline.SignalTraces)].Exporters = nil
return cfg
},
expected: fmt.Errorf(`pipeline "traces": %w`, errMissingServicePipelineExporters),
},
{
name: "missing-pipelines",
cfgFn: func() Config {
cfgFn: func(*testing.T) Config {
return nil
},
expected: errMissingServicePipelines,
},
{
name: "invalid-service-pipeline-type",
cfgFn: func() Config {
cfg := generateConfig()
cfgFn: func(*testing.T) Config {
cfg := generateConfig(t)
cfg[pipeline.MustNewID("wrongtype")] = &PipelineConfig{
Receivers: []component.ID{component.MustNewID("nop")},
Processors: []component.ID{component.MustNewID("nop")},
Expand All @@ -73,17 +76,50 @@ func TestConfigValidate(t *testing.T) {
},
expected: errors.New(`pipeline "wrongtype": unknown signal "wrongtype"`),
},
{
name: "disabled-featuregate-profiles",
cfgFn: func(*testing.T) Config {
cfg := generateConfig(t)
cfg[pipeline.NewID(pipelineprofiles.SignalProfiles)] = &PipelineConfig{
Receivers: []component.ID{component.MustNewID("nop")},
Processors: []component.ID{component.MustNewID("nop")},
Exporters: []component.ID{component.MustNewID("nop")},
}
return cfg
},
expected: errors.New(`pipeline "profiles": profiling signal support is at alpha level, gated under the "service.profilesSupport" feature gate`),
},
{
name: "enabled-featuregate-profiles",
cfgFn: func(t *testing.T) Config {
require.NoError(t, featuregate.GlobalRegistry().Set(serviceProfileSupportGateID, true))

cfg := generateConfig(t)
cfg[pipeline.NewID(pipelineprofiles.SignalProfiles)] = &PipelineConfig{
Receivers: []component.ID{component.MustNewID("nop")},
Processors: []component.ID{component.MustNewID("nop")},
Exporters: []component.ID{component.MustNewID("nop")},
}
return cfg
},
expected: nil,
},
}

for _, tt := range testCases {
t.Run(tt.name, func(t *testing.T) {
cfg := tt.cfgFn()
cfg := tt.cfgFn(t)
assert.Equal(t, tt.expected, cfg.Validate())

// Clean up the profiles support gate, which may have been enabled in `cfgFn`.
require.NoError(t, featuregate.GlobalRegistry().Set(serviceProfileSupportGateID, false))
})
}
}

func generateConfig() Config {
func generateConfig(t *testing.T) Config {
t.Helper()

return map[pipeline.ID]*PipelineConfig{
pipeline.NewID(pipeline.SignalTraces): {
Receivers: []component.ID{component.MustNewID("nop")},
Expand Down

0 comments on commit 3456b43

Please sign in to comment.