From 95621636c787cc37ccd25fa94eced47b38c42630 Mon Sep 17 00:00:00 2001 From: sneak Date: Thu, 15 Oct 2026 10:14:26 +0000 Subject: [PATCH] Test that metrics label requests for /v1 and /v1/ unmatched No route answers /v1 or /v1/, the path the image subrouter is mounted at, and the router answers both with 404, yet the metrics middleware labels them "/v1" and "/v1/". The test now sends both and expects them counted under "unmatched". It fails. Model: opus-5-5 --- internal/middleware/middleware_internal_test.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/internal/middleware/middleware_internal_test.go b/internal/middleware/middleware_internal_test.go index 5801513..404d4eb 100644 --- a/internal/middleware/middleware_internal_test.go +++ b/internal/middleware/middleware_internal_test.go @@ -226,7 +226,8 @@ func TestMetricsRecordsServedRequest(t *testing.T) { // TestMetricsLabelsRequestsByRoute checks that the metrics middleware labels // each request with the pattern of the route that answers it, never with its // path: two paths one route answers share that route's pattern, and requests -// no route answers, a 404 or a 405, share "unmatched". With a label per path, +// no route answers, a 404 or a 405, share "unmatched", among them requests for +// the path the subrouter is mounted at, /v1 and /v1/. With a label per path, // any client could add series to the registry without limit. The middleware // registers with a registry of its own here, as another test in this package // registers with Prometheus' default registry, which can be done only once. @@ -254,6 +255,8 @@ func TestMetricsLabelsRequestsByRoute(t *testing.T) { {http.MethodGet, "/v1/image/b.example.com/two.jpg/1x1.png"}, {http.MethodGet, "/no-such-route"}, {http.MethodGet, "/v1/no-such-route"}, + {http.MethodGet, "/v1"}, + {http.MethodGet, "/v1/"}, {http.MethodPost, "/v1/image/a.example.com/one.jpg/1x1.png"}, } { router.ServeHTTP(httptest.NewRecorder(), httptest.NewRequestWithContext( @@ -263,7 +266,7 @@ func TestMetricsLabelsRequestsByRoute(t *testing.T) { got := requestCountsByHandler(t, registry) t.Logf("requests counted by handler label: %v", got) - want := map[string]uint64{"/v1/image/*": 2, "unmatched": 3} + want := map[string]uint64{"/v1/image/*": 2, "unmatched": 5} if !maps.Equal(got, want) { t.Errorf("requests counted by handler label = %v, want %v", got, want) }