mirror of
https://github.com/cozystack/cozystack.git
synced 2026-11-21 12:13:55 +09:00
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 <maximbel2003@gmail.com>
This commit is contained in:
1 parent
b4ddb93b6f
commit
843d360ee0
2 files changed
+9
-5
No files matched your search
@@ -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 {
|
||||
|
||||
@@ -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")
|
||||
|
||||
Reference in new issue
Block a user