Label a request with an empty path by the / route in metrics
check / check (push) Waiting to run

When both r.URL.Path and r.URL.RawPath are empty, as for the request
line GET http://pixa.example HTTP/1.1, chi routes the request as /, but
routePattern asked Find about the empty path and labelled it unmatched.
It now uses / then, as chi does. After the rebase onto next, the TODO.md
entry is back at the top of Completed Steps.

Model: opus-5-5
This commit is contained in:
2026-10-15 12:32:27 +00:00
parent 874e9217c1
commit 5ec908df6c
2 changed files with 14 additions and 10 deletions
+5 -1
View File
@@ -239,7 +239,7 @@ func (s *Middleware) Metrics() func(http.Handler) http.Handler {
// "unmatched" when it matches none or is not served by a chi router. The
// metrics library takes the label before the request is routed, so the
// router is asked which route matches, with the path it routes on:
// r.URL.RawPath when set, else r.URL.Path.
// r.URL.RawPath when set, else r.URL.Path, else /.
func routePattern(r *http.Request) string {
pattern := ""
@@ -250,6 +250,10 @@ func routePattern(r *http.Request) string {
path = r.URL.Path
}
if path == "" {
path = "/"
}
pattern = rctx.Routes.Find(chi.NewRouteContext(), r.Method, path)
// For the path a subrouter is mounted at, such as /v1 or /v1/, Find