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

[service] Add service::telemetry::metrics::views config key #12433

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
32 changes: 32 additions & 0 deletions .chloggen/service-telemetry-views.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# 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 config key to set metric views used for internal telemetry

# One or more tracking issues or pull requests related to the change
issues: [10769]

# (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: |
The `service::telemetry::metrics::views` config key can now be used to explicitly set the list of
metric views used for internal telemetry, mirroring `meter_provider::views` in the SDK config.
This can be used to disable specific internal metrics, among other uses.

This key will cause an error if used alongside other features which would normally implicitly create views, such as:
- not setting `service::telemetry::metrics::level` to `detailed`;
- enabling the `telemetry.disableHighCardinalityMetrics` feature flag.

# 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]
40 changes: 23 additions & 17 deletions service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,15 @@

sch := semconv.SchemaURL

views := configureViews(cfg.Telemetry.Metrics.Level)
var views []config.View
if cfg.Telemetry.Metrics.Views != nil {
if disableHighCardinalityMetricsFeatureGate.IsEnabled() {
return nil, errors.New("telemetry.disableHighCardinalityMetrics gate is incompatible with setting views explicitly")
}
views = cfg.Telemetry.Metrics.Views

Check warning on line 145 in service/service.go

View check run for this annotation

Codecov / codecov/patch

service/service.go#L142-L145

Added lines #L142 - L145 were not covered by tests
} else {
views = configureViews(cfg.Telemetry.Metrics.Level)
}

readers := cfg.Telemetry.Metrics.Readers
if cfg.Telemetry.Metrics.Level == configtelemetry.LevelNone {
Expand Down Expand Up @@ -404,9 +412,19 @@
func configureViews(level configtelemetry.Level) []config.View {
views := []config.View{}

if disableHighCardinalityMetricsFeatureGate.IsEnabled() {
views = append(views, []config.View{
{
if level < configtelemetry.LevelDetailed {
// Drop all otelhttp and otelgrpc metrics if the level is not detailed.
views = append(views,
dropViewOption(&config.ViewSelector{
MeterName: ptr("go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc"),
}),
dropViewOption(&config.ViewSelector{
MeterName: ptr("go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"),
}),
)
} else if disableHighCardinalityMetricsFeatureGate.IsEnabled() {
views = append(views,
config.View{

Check warning on line 427 in service/service.go

View check run for this annotation

Codecov / codecov/patch

service/service.go#L426-L427

Added lines #L426 - L427 were not covered by tests
Selector: &config.ViewSelector{
MeterName: ptr("go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc"),
},
Expand All @@ -420,7 +438,7 @@
},
},
},
{
config.View{

Check warning on line 441 in service/service.go

View check run for this annotation

Codecov / codecov/patch

service/service.go#L441

Added line #L441 was not covered by tests
Selector: &config.ViewSelector{
MeterName: ptr("go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"),
},
Expand All @@ -433,18 +451,6 @@
},
},
},
}...)
}

if level < configtelemetry.LevelDetailed {
// Drop all otelhttp and otelgrpc metrics if the level is not detailed.
views = append(views,
dropViewOption(&config.ViewSelector{
MeterName: ptr("go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc"),
}),
dropViewOption(&config.ViewSelector{
MeterName: ptr("go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"),
}),
)
}

Expand Down
4 changes: 4 additions & 0 deletions service/telemetry/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,5 +111,9 @@
return errors.New("collector telemetry metrics reader should exist when metric level is not none")
}

if c.Metrics.Views != nil && c.Metrics.Level != configtelemetry.LevelDetailed {
return errors.New("metric views can only be set when level is detailed")
}

Check warning on line 116 in service/telemetry/config.go

View check run for this annotation

Codecov / codecov/patch

service/telemetry/config.go#L115-L116

Added lines #L115 - L116 were not covered by tests

return nil
}
5 changes: 5 additions & 0 deletions service/telemetry/internal/migration/v0.3.0.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ type MetricsConfigV030 struct {
// Readers allow configuration of metric readers to emit metrics to
// any number of supported backends.
Readers []config.MetricReader `mapstructure:"readers"`

// Views allows advanced configuration of emitted metrics by setting
// the list of views passed to the SDK.
// This is incompatible with `level` values other than `detailed`.
Views []config.View `mapstructure:"views"`
}

func (c *MetricsConfigV030) Unmarshal(conf *confmap.Conf) error {
Expand Down
Loading