-
Notifications
You must be signed in to change notification settings - Fork 630
[WIP] Add configurable metric attributes deny list to config-observability #9090
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
base: main
Are you sure you want to change the base?
Changes from 3 commits
085719f
2b4ff1c
4b6d081
ca71a7a
99cabfb
c288ebb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,6 +21,7 @@ import ( | |
|
|
||
| "go.opentelemetry.io/contrib/instrumentation/runtime" | ||
| "go.opentelemetry.io/otel" | ||
| "go.opentelemetry.io/otel/attribute" | ||
| "go.opentelemetry.io/otel/sdk/metric" | ||
| sdkresource "go.opentelemetry.io/otel/sdk/resource" | ||
| "go.opentelemetry.io/otel/sdk/trace" | ||
|
|
@@ -60,10 +61,15 @@ func SetupObservabilityOrDie( | |
|
|
||
| otelResource := resource.Default(component) | ||
|
|
||
| meterOpts := []metric.Option{metric.WithResource(otelResource)} | ||
| if len(cfg.MetricAttributesDenyList) > 0 { | ||
| meterOpts = append(meterOpts, metric.WithView(metricAttributesDenyFilter(cfg.MetricAttributesDenyList))) | ||
| } | ||
|
|
||
| meterProvider, err := metrics.NewMeterProvider( | ||
| ctx, | ||
| cfg.Metrics, | ||
| metric.WithResource(otelResource), | ||
| meterOpts..., | ||
| ) | ||
| if err != nil { | ||
| logger.Fatalw("failed to set up meter provider", zap.Error(err)) | ||
|
|
@@ -155,3 +161,16 @@ func GetObservabilityConfig(ctx context.Context) (*observability.Config, error) | |
|
|
||
| return configmap.Parse(cm) | ||
| } | ||
|
|
||
| func metricAttributesDenyFilter(denyList []string) metric.View { | ||
| keys := make([]attribute.Key, len(denyList)) | ||
| for i, k := range denyList { | ||
| keys[i] = attribute.Key(k) | ||
| } | ||
| return metric.NewView( | ||
| metric.Instrument{Name: "kn.eventing.*"}, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this mean the filter would only filter the
(from prometheus:)
which might be problematic.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes this filter applies only to kn_eventing metrics (I thought, that the "problematic" ones are from there only).
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. well, looking at mt-broker-filter and mt-broker-ingress, the most problematic ones are in the
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ah ok. then lets use |
||
| metric.Stream{ | ||
| AttributeFilter: attribute.NewDenyKeysFilter(keys...), | ||
| }, | ||
| ) | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| /* | ||
| Copyright 2026 The Knative Authors | ||
|
|
||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| */ | ||
|
|
||
| package otel | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/assert" | ||
| "go.opentelemetry.io/otel/attribute" | ||
| "go.opentelemetry.io/otel/sdk/metric" | ||
| ) | ||
|
|
||
| func TestMetricAttributesDenyFilter(t *testing.T) { | ||
| view := metricAttributesDenyFilter([]string{"cloudevents.type", "messaging.destination.name"}) | ||
|
|
||
| stream, ok := view(metric.Instrument{Name: "kn.eventing.dispatch.duration"}) | ||
| assert.True(t, ok, "view should match kn.eventing.* instruments") | ||
| assert.NotNil(t, stream.AttributeFilter) | ||
|
|
||
| denied := []attribute.KeyValue{ | ||
| attribute.String("cloudevents.type", "com.example.event"), | ||
| attribute.String("messaging.destination.name", "my-destination"), | ||
| } | ||
| for _, kv := range denied { | ||
| assert.False(t, stream.AttributeFilter(kv), "attribute %s should be denied", kv.Key) | ||
| } | ||
|
|
||
| allowed := []attribute.KeyValue{ | ||
| attribute.String("messaging.system", "knative"), | ||
| attribute.Int("http.response.status_code", 200), | ||
| } | ||
| for _, kv := range allowed { | ||
| assert.True(t, stream.AttributeFilter(kv), "attribute %s should be allowed", kv.Key) | ||
| } | ||
| } | ||
|
|
||
| func TestMetricAttributesDenyFilterDoesNotMatchOtherInstruments(t *testing.T) { | ||
| view := metricAttributesDenyFilter([]string{"cloudevents.type"}) | ||
|
|
||
| _, ok := view(metric.Instrument{Name: "http.server.request.duration"}) | ||
| assert.False(t, ok, "view should not match non kn.eventing.* instruments") | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
comment should be updated (not specific to kn.eventing.* anymore)