vmalert: fix vmalert_remotewrite_send_duration_seconds_total metric value (#4801)

The deferred call's arguments are evaluated immediately, but the function call is not executed until the surrounding function returns.

Signed-off-by: Abirdcfly <fp544037857@gmail.com>
This commit is contained in:
Abirdcfly 2023-08-10 10:51:44 +08:00 committed by Aliaksandr Valialkin
parent 1786a703fd
commit 70780306b3
No known key found for this signature in database
GPG key ID: A72BEC6CD3D0DED1

View file

@ -216,7 +216,9 @@ func (c *Client) flush(ctx context.Context, wr *prompbmarshal.WriteRequest) {
retryInterval = maxRetryInterval
}
timeStart := time.Now()
defer sendDuration.Add(time.Since(timeStart).Seconds())
defer func() {
sendDuration.Add(time.Since(timeStart).Seconds())
}()
L:
for attempts := 0; ; attempts++ {
err := c.send(ctx, b)