Skip to content

Commit

Permalink
vmalert: fix vmalert_remotewrite_send_duration_seconds_total metric…
Browse files Browse the repository at this point in the history
… 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>
  • Loading branch information
Abirdcfly authored and f41gh7 committed Aug 10, 2023
1 parent 623e2fa commit 3008495
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion app/vmalert/remotewrite/remotewrite.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 3008495

Please sign in to comment.