diff --git a/.chloggen/profiles-featuregate.yaml b/.chloggen/profiles-featuregate.yaml new file mode 100644 index 00000000000..4c7db2797c1 --- /dev/null +++ b/.chloggen/profiles-featuregate.yaml @@ -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] diff --git a/service/pipelines/config.go b/service/pipelines/config.go index 30db3e820db..76a444127a6 100644 --- a/service/pipelines/config.go +++ b/service/pipelines/config.go @@ -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" ) @@ -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. @@ -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()) } diff --git a/service/pipelines/config_test.go b/service/pipelines/config_test.go index 520085ee79c..74f129e725c 100644 --- a/service/pipelines/config_test.go +++ b/service/pipelines/config_test.go @@ -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 }{ { @@ -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 @@ -37,8 +40,8 @@ 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 }, @@ -46,8 +49,8 @@ func TestConfigValidate(t *testing.T) { }, { 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 }, @@ -55,15 +58,15 @@ func TestConfigValidate(t *testing.T) { }, { 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")}, @@ -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")},