Label request metrics with standard HTTP methods only (closes #274) #277

Merged
clawbot merged 2 commits from issue-274-metrics-method-label into next 2026-10-15 21:47:11 +02:00
Collaborator

The metrics middleware labelled each request with its method as sent. Go's HTTP server accepts any method name that is a valid token, and the middleware measures every request before routing, so each made-up method a client sent added series to the registry that were never removed. The method label is now the request's method only for GET, HEAD, POST, PUT, PATCH, DELETE, OPTIONS, CONNECT and TRACE, and other for any other method. README.md says so where it describes the metrics, next to unmatched for the handler label from #260.

go-http-metrics has no setting for the method label: it reads the method from the request it is handed. So the middleware hands the library a shallow copy of the request whose method is the label, and serves the next handler the original request, through the response writer the library wraps to see the status and size. Handlers and the other middleware still see the method the client sent; the new test checks that too.

The in-flight gauge carries no method label, so only the duration and size histograms change.

The failing test is its own commit ahead of the fix, as the repo's CLAUDE.md asks. No existing test changed.

  • Judgement call: the shared value is other, lowercase like unmatched.

Model: opus-5-5

The metrics middleware labelled each request with its method as sent. Go's HTTP server accepts any method name that is a valid token, and the middleware measures every request before routing, so each made-up method a client sent added series to the registry that were never removed. The `method` label is now the request's method only for `GET`, `HEAD`, `POST`, `PUT`, `PATCH`, `DELETE`, `OPTIONS`, `CONNECT` and `TRACE`, and `other` for any other method. `README.md` says so where it describes the metrics, next to `unmatched` for the `handler` label from https://git.eeqj.de/sneak/pixa/pulls/260. go-http-metrics has no setting for the method label: it reads the method from the request it is handed. So the middleware hands the library a shallow copy of the request whose method is the label, and serves the next handler the original request, through the response writer the library wraps to see the status and size. Handlers and the other middleware still see the method the client sent; the new test checks that too. The in-flight gauge carries no method label, so only the duration and size histograms change. The failing test is its own commit ahead of the fix, as the repo's `CLAUDE.md` asks. No existing test changed. - Judgement call: the shared value is `other`, lowercase like `unmatched`. Model: opus-5-5
clawbot added 2 commits 2026-10-15 21:19:34 +02:00
The test sends two requests with made-up methods through the metrics
middleware and expects /metrics to count both under the method label
"other", and the handler to see each method as sent. It fails until the
middleware stops using every method name as its own label value.

Model: opus-5-5
The method label was each request's method as sent, and Go's HTTP
server accepts any method name, so made-up methods added series to the
registry that were never removed. It is now the method only for GET,
HEAD, POST, PUT, PATCH, DELETE, OPTIONS, CONNECT and TRACE, and "other"
for any other. go-http-metrics reads the method from the request it is
handed, so the middleware hands it a copy carrying the label and serves
the next handler the original request.

Model: opus-5-5
clawbot added the needs-review label 2026-10-15 21:19:36 +02:00
clawbot self-assigned this 2026-10-15 21:19:37 +02:00
Author
Collaborator

Review passed.

Model: opus-5-5

Review passed. Model: opus-5-5
clawbot merged commit 16f9d1dfd1 into next 2026-10-15 21:47:11 +02:00
clawbot deleted branch issue-274-metrics-method-label 2026-10-15 21:47:11 +02:00
Sign in to join this conversation.
No Reviewers
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: sneak/pixa#277