diff --git a/pkg/queue/request_metric.go b/pkg/queue/request_metric.go index 6f43a01bc3e8..82b75673c2cb 100644 --- a/pkg/queue/request_metric.go +++ b/pkg/queue/request_metric.go @@ -109,8 +109,8 @@ func (h *requestMetricsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request startTime := time.Now() defer func() { - // Filter probe requests for revision metrics. - if netheader.IsProbe(r) { + // Filter probe requests and requests marked by ignore metrics header for revision metrics. + if netheader.IsProbe(r) || netheader.IsMetricsIgnored(r) { return } @@ -177,8 +177,8 @@ func (h *appRequestMetricsHandler) ServeHTTP(w http.ResponseWriter, r *http.Requ pkgmetrics.Record(h.statsCtx, queueDepthM.M(int64(h.breaker.InFlight()))) } defer func() { - // Filter probe requests for revision metrics. - if netheader.IsProbe(r) { + // Filter probe requests and requests marked by ignore metrics header for revision metrics. + if netheader.IsProbe(r) || netheader.IsMetricsIgnored(r) { return } diff --git a/vendor/knative.dev/networking/pkg/http/header/header.go b/vendor/knative.dev/networking/pkg/http/header/header.go index 143f8bedb24c..6ee9e107a27e 100644 --- a/vendor/knative.dev/networking/pkg/http/header/header.go +++ b/vendor/knative.dev/networking/pkg/http/header/header.go @@ -78,6 +78,9 @@ const ( // load balancers to not load balance the respective request but to // send it to the request's target directly. PassthroughLoadbalancingKey = "K-Passthrough-Lb" + + // IgnoreMetricsKey is used to mark requests that should not be counted in metrics. + IgnoreMetricsKey = "K-Ignore-Metrics" ) // User Agent Key & Values @@ -135,6 +138,11 @@ func IsKubeletProbe(r *http.Request) bool { r.Header.Get(KubeletProbeKey) != "" } +// IsMetricsIgnored returns true if the request is marked to be ignored by metrics. +func IsMetricsIgnored(r *http.Request) bool { + return r.Header.Get(IgnoreMetricsKey) != "" +} + // RewriteHostIn removes the `Host` header from the inbound (server) request // and replaces it with our custom header. // This is done to avoid Istio Host based routing, see #3870.