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
This commit is contained in:
@@ -226,7 +226,8 @@ func TestMetricsRecordsServedRequest(t *testing.T) {
|
|||||||
// TestMetricsLabelsRequestsByRoute checks that the metrics middleware labels
|
// TestMetricsLabelsRequestsByRoute checks that the metrics middleware labels
|
||||||
// each request with the pattern of the route that answers it, never with its
|
// 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
|
// 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
|
// 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 a registry of its own here, as another test in this package
|
||||||
// registers with Prometheus' default registry, which can be done only once.
|
// 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, "/v1/image/b.example.com/two.jpg/1x1.png"},
|
||||||
{http.MethodGet, "/no-such-route"},
|
{http.MethodGet, "/no-such-route"},
|
||||||
{http.MethodGet, "/v1/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"},
|
{http.MethodPost, "/v1/image/a.example.com/one.jpg/1x1.png"},
|
||||||
} {
|
} {
|
||||||
router.ServeHTTP(httptest.NewRecorder(), httptest.NewRequestWithContext(
|
router.ServeHTTP(httptest.NewRecorder(), httptest.NewRequestWithContext(
|
||||||
@@ -263,7 +266,7 @@ func TestMetricsLabelsRequestsByRoute(t *testing.T) {
|
|||||||
got := requestCountsByHandler(t, registry)
|
got := requestCountsByHandler(t, registry)
|
||||||
t.Logf("requests counted by handler label: %v", got)
|
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) {
|
if !maps.Equal(got, want) {
|
||||||
t.Errorf("requests counted by handler label = %v, want %v", got, want)
|
t.Errorf("requests counted by handler label = %v, want %v", got, want)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user