vmalert: fix vmalert_remotewrite_send_duration_seconds_total metric value

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-09 16:53:01 +08:00
parent 1d4a0796f4
commit 4c815ed59b
No known key found for this signature in database
GPG Key ID: A4EA876831B0458B

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)