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

Add support to ignore request in metrics #15653

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
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"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can test this in this PR but has to be moved to the related repo: https://github.com/knative/networking

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

)

// 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