From 3b11036e4381da229f11bde83bb7ebc89e559500 Mon Sep 17 00:00:00 2001 From: Alan Protasio Date: Thu, 9 May 2024 05:41:02 -0700 Subject: [PATCH] Fix race condition on ingester client metric (#5939) Signed-off-by: alanprot --- pkg/ingester/client/client.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/pkg/ingester/client/client.go b/pkg/ingester/client/client.go index c62b9c59f4..20d98aa64c 100644 --- a/pkg/ingester/client/client.go +++ b/pkg/ingester/client/client.go @@ -73,10 +73,9 @@ func (c *closableHealthAndIngesterClient) Push(ctx context.Context, in *cortexpb func (c *closableHealthAndIngesterClient) handlePushRequest(mainFunc func() (*cortexpb.WriteResponse, error)) (*cortexpb.WriteResponse, error) { currentInflight := c.inflightRequests.Inc() - c.inflightPushRequests.WithLabelValues(c.addr).Inc() + c.inflightPushRequests.WithLabelValues(c.addr).Set(float64(currentInflight)) defer func() { - c.inflightPushRequests.WithLabelValues(c.addr).Dec() - c.inflightRequests.Dec() + c.inflightPushRequests.WithLabelValues(c.addr).Set(float64(c.inflightRequests.Dec())) }() if c.maxInflightPushRequests > 0 && currentInflight > c.maxInflightPushRequests { return nil, errTooManyInflightPushRequests