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

Fix panic when telemetry metrics are disabled #5642

Merged
merged 7 commits into from
Jul 8, 2022
Merged
Show file tree
Hide file tree
Changes from 4 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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

### 🧰 Bug fixes 🧰

- Fix Collector panic when disabling telemetry metrics (#5642)

## v0.55.0 Beta

### 🛑 Breaking changes 🛑
Expand Down
23 changes: 23 additions & 0 deletions service/collector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,29 @@ func TestCollectorStartWithOpenTelemetryMetrics(t *testing.T) {
}
}

func TestCollectorWithNoMetrics(t *testing.T) {
factories, err := componenttest.NopFactories()
require.NoError(t, err)

cfgProvider, err := NewConfigProvider(newDefaultConfigProviderSettings([]string{filepath.Join("testdata", "otelcol-nometrics.yaml")}))
require.NoError(t, err)

set := CollectorSettings{
BuildInfo: component.NewDefaultBuildInfo(),
Factories: factories,
ConfigProvider: cfgProvider,
telemetry: newColTelemetry(featuregate.NewRegistry()),
}
col, err := New(set)
require.NoError(t, err)

wg := startCollector(context.Background(), t, col)

col.Shutdown()
wg.Wait()
assert.Equal(t, Closed, col.GetState())
}

func TestCollectorShutdownBeforeRun(t *testing.T) {
factories, err := componenttest.NopFactories()
require.NoError(t, err)
Expand Down
9 changes: 6 additions & 3 deletions service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"go.uber.org/zap"

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/config/configtelemetry"
"go.opentelemetry.io/collector/service/internal"
"go.opentelemetry.io/collector/service/internal/extensions"
"go.opentelemetry.io/collector/service/internal/pipelines"
Expand Down Expand Up @@ -97,9 +98,11 @@ func newService(set *settings) (*service, error) {
return nil, fmt.Errorf("cannot build pipelines: %w", err)
}

// The process telemetry initialization requires the ballast size, which is available after the extensions are initialized.
if err = telemetry.RegisterProcessMetrics(srv.telemetryInitializer.ocRegistry, getBallastSize(srv.host)); err != nil {
return nil, fmt.Errorf("failed to register process metrics: %w", err)
if set.Config.Telemetry.Metrics.Level != configtelemetry.LevelNone && set.Config.Telemetry.Metrics.Address != "" {
mx-psi marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would expect an empty address to return a validation error, instead of silently disabling telemetry. Do you think this is worth an issue?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 I can open an issue for that, I would also expect an empty address to make it fail. (I didn't mention this in the PR but this check comes from

if cfg.Metrics.Level == configtelemetry.LevelNone || cfg.Metrics.Address == "" {
)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Yeah I eventually tracked down the same check :D

// The process telemetry initialization requires the ballast size, which is available after the extensions are initialized.
if err = telemetry.RegisterProcessMetrics(srv.telemetryInitializer.ocRegistry, getBallastSize(srv.host)); err != nil {
return nil, fmt.Errorf("failed to register process metrics: %w", err)
}
}

return srv, nil
Expand Down
14 changes: 14 additions & 0 deletions service/testdata/otelcol-nometrics.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
receivers:
nop:

exporters:
nop:

service:
telemetry:
metrics:
level: none
pipelines:
metrics:
receivers: [nop]
exporters: [nop]