Skip to content

[metrics]: Allow request metadata as Prometheus labels - #149

Open
pseudomuto wants to merge 1 commit into
metrics-configfrom
metrics-metadata-tags
Open

[metrics]: Allow request metadata as Prometheus labels#149
pseudomuto wants to merge 1 commit into
metrics-configfrom
metrics-metadata-tags

Conversation

@pseudomuto

Copy link
Copy Markdown
Collaborator

Proxy metrics could only be sliced by dimensions the proxy itself knows: the method, the upstream, the outcome. An operator running a single proxy for several tenants or clusters has no way to attribute traffic to them because the identifiers that identify them travel in request metadata that the collectors never see.

Add a metrics.tags list, written as "

:", that carries an inbound metadata value onto the metrics emitted while serving a request. The gateway's own request metrics, the routing decision, and the vault operations all gain the configured labels.

Things that aren't request-based are left as is. crypto.Observer, for example, has no request context and runs some logic in a goroutine with no request available, so nothing is added there.

Having 2 different headers mapping to the same label is a startup (validation) error, since Prometheus would panic at runtime with two values set for the same one. There's also validation for the header and label names to keep them in line with gRPC/Prometheus requirements and ensure issues are caught at startup rather than at runtime. gRPC binary metadata (ending in -bin) is not allowed.

Finally, gRPC metadata is a map[string][]string where each value is the ordered set of values set for the key. If multiple values exist, the last value is used as the label.

Proxy metrics could only be sliced by dimensions the proxy itself knows: the
method, the upstream, the outcome. An operator running one proxy for several
tenants or clusters has no way to attribute traffic to them, because the thing
that identifies them travels in request metadata the collectors never see.

Add a metrics.tags list, written as "<header>:<label>", that carries an inbound
metadata value onto the metrics emitted while serving a request. The gateway's
own request metrics, the routing decision, and the vault operations all gain
the configured labels.

Things that aren't request based are is left as is. `crypto.Observer`,
for example, which has no request context, and has some logic in a
go routine with no request available at all.

Having 2 different headers mapping to the same label is a startup
(validation) error, since Prometheus would panic at runtime with two
values set for the same one. There's also some validation for the header
and label names to keep them inline with gRPC/Prometheus requirements
and ensure they're caught at startup and not at runtime. gRPC binary
metadata (ending in `-bin`) are not allowed.

Finally, gRPC metadata is a `map[string][]string` where each value is
the ordered set of values set for the key. In the case that multiple
values exist, the last value is used as the label.
@pseudomuto
pseudomuto requested a review from a team as a code owner September 3, 2026 14:36
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.16312% with 4 lines in your changes missing coverage. Please review.

📢 Thoughts on this report? Let us know!

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants