From 843d360ee08597da49d89b0d98e08b9db8848f58 Mon Sep 17 00:00:00 2001 From: ZverGuy Date: Thu, 5 Nov 2026 01:24:53 +0700 Subject: [PATCH] fix(observability-proxy): send Retry-After with the metrics concurrency 429 The metrics root has its own admission, so the hint added to the logs root did not reach it, and a console graph polling into the limit had no back-off hint. Assisted-by: LLM Signed-off-by: ZverGuy --- internal/observabilityproxy/server.go | 2 +- internal/observabilityproxy/server_metrics_test.go | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/internal/observabilityproxy/server.go b/internal/observabilityproxy/server.go index 50b6ac89e..eb540a271 100644 --- a/internal/observabilityproxy/server.go +++ b/internal/observabilityproxy/server.go @@ -282,7 +282,7 @@ func (s *Server) serve(w http.ResponseWriter, r *http.Request, route Route) *HTT func (s *Server) serveMetrics(w http.ResponseWriter, r *http.Request, route Route, user string) *HTTPError { release, ok := s.limits.acquire(user) if !ok { - return errorf(http.StatusTooManyRequests, "too many concurrent requests") + return tooManyConcurrent(w) } defer release() if herr := s.readForm(w, r); herr != nil { diff --git a/internal/observabilityproxy/server_metrics_test.go b/internal/observabilityproxy/server_metrics_test.go index a1c07d944..ea47cf782 100644 --- a/internal/observabilityproxy/server_metrics_test.go +++ b/internal/observabilityproxy/server_metrics_test.go @@ -179,12 +179,16 @@ func TestServerMetricsConcurrency(t *testing.T) { } } hold("good") - refused := make(chan int, 1) - go func() { refused <- h.status(http.MethodPost, metricsRoot+"api/v1/query?query=up", "good") }() + refused := make(chan *http.Response, 1) + go func() { + resp := h.do(http.MethodPost, metricsRoot+"api/v1/query?query=up", "good", nil, nil) + _ = resp.Body.Close() + refused <- resp + }() select { case got := <-refused: - if got != http.StatusTooManyRequests { - t.Fatalf("concurrent request answered %d, want 429", got) + if got.StatusCode != http.StatusTooManyRequests || got.Header.Get("Retry-After") == "" { + t.Fatalf("concurrent request answered %d with Retry-After %q, want 429 with a value", got.StatusCode, got.Header.Get("Retry-After")) } case <-time.After(2 * time.Second): t.Fatal("concurrent request of the same user reached the upstream")