Skip to content

Commit

Permalink
ignore requests with header in metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
jan-stanek committed Jan 6, 2025
1 parent df03027 commit 182f96c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
8 changes: 4 additions & 4 deletions pkg/queue/request_metric.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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
}

Expand Down
8 changes: 8 additions & 0 deletions vendor/knative.dev/networking/pkg/http/header/header.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 182f96c

Please sign in to comment.