Skip to content

[service] Allow running the Collector without any pipelines #12613

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

Merged
merged 7 commits into from
Mar 17, 2025
Merged
Show file tree
Hide file tree
Changes from 6 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/allow-no-pipelines.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: 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: []
5 changes: 3 additions & 2 deletions otelcol/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/service"
"go.opentelemetry.io/collector/service/pipelines"
)

var (
Expand Down Expand Up @@ -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
}

Expand Down
24 changes: 21 additions & 3 deletions otelcol/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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{
Expand Down
10 changes: 8 additions & 2 deletions service/pipelines/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
15 changes: 15 additions & 0 deletions service/pipelines/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
Loading