diff --git a/.chloggen/allow-no-pipelines.yaml b/.chloggen/allow-no-pipelines.yaml new file mode 100644 index 00000000000..5f47198d66d --- /dev/null +++ b/.chloggen/allow-no-pipelines.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: Add `service.AllowNoPipelines` feature gate to allow starting the Collector without pipelines. + +# One or more tracking issues or pull requests related to the change +issues: [12613] + +# (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: This can be used to start with only extensions. + +# 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: [] diff --git a/otelcol/config.go b/otelcol/config.go index 2bfd863e2f2..fa2a624f2e9 100644 --- a/otelcol/config.go +++ b/otelcol/config.go @@ -9,6 +9,7 @@ import ( "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/service" + "go.opentelemetry.io/collector/service/pipelines" ) var ( @@ -50,13 +51,13 @@ func (cfg *Config) Validate() error { // Currently, there is no default receiver enabled. // The configuration must specify at least one receiver to be valid. - if len(cfg.Receivers) == 0 { + if !pipelines.AllowNoPipelines.IsEnabled() && len(cfg.Receivers) == 0 { return errMissingReceivers } // Currently, there is no default exporter enabled. // The configuration must specify at least one exporter to be valid. - if len(cfg.Exporters) == 0 { + if !pipelines.AllowNoPipelines.IsEnabled() && len(cfg.Exporters) == 0 { return errMissingExporters } diff --git a/otelcol/config_test.go b/otelcol/config_test.go index 19970060926..654125750a8 100644 --- a/otelcol/config_test.go +++ b/otelcol/config_test.go @@ -8,13 +8,14 @@ import ( "fmt" "testing" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" config "go.opentelemetry.io/contrib/otelconf/v0.3.0" "go.uber.org/zap/zapcore" "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/config/configtelemetry" "go.opentelemetry.io/collector/confmap/xconfmap" + "go.opentelemetry.io/collector/featuregate" "go.opentelemetry.io/collector/pipeline" "go.opentelemetry.io/collector/service" "go.opentelemetry.io/collector/service/pipelines" @@ -244,14 +245,31 @@ func TestConfigValidate(t *testing.T) { cfg := tt.cfgFn() err := xconfmap.Validate(cfg) if tt.expected != nil { - assert.EqualError(t, err, tt.expected.Error()) + require.EqualError(t, err, tt.expected.Error()) } else { - assert.NoError(t, err) + require.NoError(t, err) } }) } } +func TestNoPipelinesFeatureGate(t *testing.T) { + cfg := generateConfig() + cfg.Receivers = nil + cfg.Exporters = nil + cfg.Service.Pipelines = pipelines.Config{} + + require.Error(t, xconfmap.Validate(cfg)) + + gate := pipelines.AllowNoPipelines + require.NoError(t, featuregate.GlobalRegistry().Set(gate.ID(), true)) + defer func() { + require.NoError(t, featuregate.GlobalRegistry().Set(gate.ID(), false)) + }() + + require.NoError(t, xconfmap.Validate(cfg)) +} + func generateConfig() *Config { return &Config{ Receivers: map[component.ID]component.Config{ diff --git a/service/pipelines/config.go b/service/pipelines/config.go index 18e2621a86c..2109b09b70c 100644 --- a/service/pipelines/config.go +++ b/service/pipelines/config.go @@ -25,14 +25,20 @@ var ( featuregate.WithRegisterFromVersion("v0.112.0"), featuregate.WithRegisterDescription("Controls whether profiles support can be enabled"), ) + AllowNoPipelines = featuregate.GlobalRegistry().MustRegister( + "service.AllowNoPipelines", + featuregate.StageAlpha, + featuregate.WithRegisterFromVersion("v0.122.0"), + featuregate.WithRegisterDescription("Allow starting the Collector without starting any pipelines."), + ) ) // Config defines the configurable settings for service telemetry. type Config map[pipeline.ID]*PipelineConfig func (cfg Config) Validate() error { - // Must have at least one pipeline. - if len(cfg) == 0 { + // Must have at least one pipeline unless explicitly disabled. + if !AllowNoPipelines.IsEnabled() && len(cfg) == 0 { return errMissingServicePipelines } diff --git a/service/pipelines/config_test.go b/service/pipelines/config_test.go index c24f8c744c9..49813335161 100644 --- a/service/pipelines/config_test.go +++ b/service/pipelines/config_test.go @@ -120,6 +120,21 @@ func TestConfigValidate(t *testing.T) { } } +func TestNoPipelinesFeatureGate(t *testing.T) { + cfg := Config{} + + require.Error(t, xconfmap.Validate(cfg)) + + gate := AllowNoPipelines + err := featuregate.GlobalRegistry().Set(gate.ID(), true) + require.NoError(t, err) + defer func() { + require.NoError(t, featuregate.GlobalRegistry().Set(gate.ID(), false)) + }() + + require.NoError(t, xconfmap.Validate(cfg)) +} + func generateConfig(t *testing.T) Config { t.Helper()