Skip to content

Commit 91e1768

Browse files
authored
Fix linter deprecation warnings (#3335)
* change regexp to ignore all uses of SimpleClientset * drop use of deprecated otelhttp.WithMetricAttributesFn
1 parent 5d1c12d commit 91e1768

2 files changed

Lines changed: 15 additions & 11 deletions

File tree

.golangci.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ linters:
193193
text: corev1.Endpoint.* is deprecated
194194
- linters:
195195
- staticcheck
196-
text: fakek8s.NewSimpleClientset is deprecated
196+
text: .*NewSimpleClientset is deprecated
197197
- linters:
198198
- gosec
199199
- noctx

webhook/webhook.go

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ import (
3737
"knative.dev/pkg/observability/semconv"
3838

3939
"go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"
40-
"go.opentelemetry.io/otel/attribute"
4140
"go.opentelemetry.io/otel/metric"
4241
"go.opentelemetry.io/otel/propagation"
4342
"go.opentelemetry.io/otel/trace"
@@ -313,19 +312,11 @@ func (wh *Webhook) Run(stop <-chan struct{}) error {
313312
}
314313

315314
otelHandler := otelhttp.NewHandler(
316-
drainer,
315+
&routeLabeler{next: drainer},
317316
wh.Options.ServiceName, // Note this service is k8s service name
318317
otelhttp.WithMeterProvider(wh.Options.MeterProvider),
319318
otelhttp.WithTracerProvider(wh.Options.TracerProvider),
320319
otelhttp.WithPropagators(wh.Options.TextMapPropagator),
321-
otelhttp.WithMetricAttributesFn(func(r *http.Request) []attribute.KeyValue {
322-
if r.URL.Path == "" {
323-
return nil
324-
}
325-
return []attribute.KeyValue{
326-
semconv.HTTPRoute(r.URL.Path),
327-
}
328-
}),
329320
otelhttp.WithFilter(func(r *http.Request) bool {
330321
// Don't trace kubelet probes
331322
return !network.IsKubeletProbe(r)
@@ -406,3 +397,16 @@ func (wh *Webhook) ServeHTTP(w http.ResponseWriter, r *http.Request) {
406397

407398
wh.mux.ServeHTTP(w, r)
408399
}
400+
401+
type routeLabeler struct {
402+
next http.Handler
403+
}
404+
405+
func (rl *routeLabeler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
406+
if r.URL.Path != "" {
407+
labeler, _ := otelhttp.LabelerFromContext(r.Context())
408+
labeler.Add(semconv.HTTPRoute(r.URL.Path))
409+
}
410+
411+
rl.next.ServeHTTP(w, r)
412+
}

0 commit comments

Comments
 (0)