Label request metrics by route, not by path (closes #254)
check / check (push) Waiting to run

The metrics middleware gave the handler label each request's path, so
every new path added series that were never removed, and /metrics
listed encrypted URL tokens. The label is now the pattern of the chi
route the request matches, or "unmatched" for one that matches none.
The metrics library takes the label before calling the handler, so the
middleware asks the router with chi's Find which route matches.

The existing TestMetricsRecordsServedRequest now fails: it serves a
request outside any router and expects handler="/test", the path.
Changing it needs the owner's approval.

Model: opus-5-5
This commit is contained in:
2026-10-15 01:45:21 +00:00
parent 5ec16ef619
commit f438c10c0c
3 changed files with 47 additions and 3 deletions
+4 -1
View File
@@ -621,7 +621,10 @@ See `configs/config.example.yml` for all options with defaults.
- **Metrics**: Prometheus, at `/metrics`: generic HTTP request metrics
(duration, response size, requests in flight) and the Go runtime and process
metrics; requests are measured and `/metrics` is served only when
`metrics.username` and `metrics.password` are set
`metrics.username` and `metrics.password` are set. A request's `handler` label
is the pattern of the route it matches, such as `/v1/image/*`, never its path.
Requests that match no route share the label `unmatched`: those the router
answers 404 or 405, and CORS preflights
- **Logging**: stdlib slog
## Entrypoints