mirror of
https://github.com/cozystack/cozystack.git
synced 2026-11-21 12:13:55 +09:00
fix(observability-proxy): answer 429 to the metrics concurrency limit
The logs root answers 429 when a user has too many requests in flight, so clients back off instead of treating the refusal as a bad query. The metrics root kept its own 422 for the same limit; it now matches. The rate limit is shared and already answers 429 with Retry-After, which the metrics test now expects too. Assisted-by: LLM Signed-off-by: ZverGuy <maximbel2003@gmail.com>
This commit is contained in:
1 parent
6d6f05a1c7
commit
19030c7a1a
2 files changed
+8
-5
No files matched your search
@@ -291,7 +291,7 @@ func (s *Server) serveMetrics(w http.ResponseWriter, r *http.Request, route Rout
|
||||
}
|
||||
release, ok := s.limits.acquire(user)
|
||||
if !ok {
|
||||
return errorf(http.StatusUnprocessableEntity, "too many concurrent requests")
|
||||
return errorf(http.StatusTooManyRequests, "too many concurrent requests")
|
||||
}
|
||||
defer release()
|
||||
|
||||
|
||||
@@ -151,8 +151,11 @@ func TestServerMetricsStatusCodes(t *testing.T) {
|
||||
|
||||
h4 := newHarness(t, Config{Limiter: LimiterConfig{RatePerUser: 0.001, RateBurst: 1}}, promUpstream)
|
||||
h4.status(http.MethodGet, metricsRoot+"api/v1/query?query=up", "good")
|
||||
if got := h4.status(http.MethodGet, metricsRoot+"api/v1/query?query=up", "good"); got != http.StatusUnprocessableEntity {
|
||||
t.Errorf("rate-limited request answered %d, want 422", got)
|
||||
limited := h4.do(http.MethodGet, metricsRoot+"api/v1/query?query=up", "good", nil, nil)
|
||||
_ = limited.Body.Close()
|
||||
if limited.StatusCode != http.StatusTooManyRequests || limited.Header.Get("Retry-After") != "1000" {
|
||||
t.Errorf("rate-limited request answered %d with Retry-After %q, want 429 with 1000",
|
||||
limited.StatusCode, limited.Header.Get("Retry-After"))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -180,8 +183,8 @@ func TestServerMetricsConcurrency(t *testing.T) {
|
||||
go func() { refused <- h.status(http.MethodPost, metricsRoot+"api/v1/query?query=up", "good") }()
|
||||
select {
|
||||
case got := <-refused:
|
||||
if got != http.StatusUnprocessableEntity {
|
||||
t.Fatalf("concurrent request answered %d, want 422", got)
|
||||
if got != http.StatusTooManyRequests {
|
||||
t.Fatalf("concurrent request answered %d, want 429", got)
|
||||
}
|
||||
case <-time.After(2 * time.Second):
|
||||
t.Fatal("concurrent request of the same user reached the upstream")
|
||||
|
||||
Reference in new issue
Block a user