Skip to content

Commit

Permalink
hide profiles behind a feature gate
Browse files Browse the repository at this point in the history
  • Loading branch information
dmathieu committed Oct 17, 2024
1 parent 4dbbb90 commit a68ac5f
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 13 deletions.
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 a68ac5f

Please sign in to comment.