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

Hide profiles behind a feature gate #11477

Merged
merged 2 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
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
Loading