Skip to content

Commit

Permalink
Add duration to the notify success message (prometheus#3559)
Browse files Browse the repository at this point in the history
This commit updates Alertmanager to add a duration to the notify
success message. It complements the existing histogram to offer
fine-grained information about notification attempts. This can be
useful when debuggin duplicate notifications, for example, when
the duration exceeds peer_timeout.

Signed-off-by: George Robinson <george.robinson@grafana.com>
  • Loading branch information
grobinson-grafana authored and alexweav committed Oct 27, 2023
1 parent 2bf5cb9 commit 507f6bf
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions notify/notify.go
Original file line number Diff line number Diff line change
Expand Up @@ -813,12 +813,11 @@ func (r RetryStage) exec(ctx context.Context, l log.Logger, alerts ...*types.Ale
case <-tick.C:
now := time.Now()
retry, err := r.integration.Notify(ctx, sent...)

duration := time.Since(now)
r.metrics.notificationLatencySeconds.WithLabelValues(r.labelValues...).Observe(duration.Seconds())
dur := time.Since(now)
r.metrics.notificationLatencySeconds.WithLabelValues(r.labelValues...).Observe(dur.Seconds())
r.metrics.numNotificationRequestsTotal.WithLabelValues(r.labelValues...).Inc()

r.integration.Report(now, model.Duration(duration), err)
r.integration.Report(now, model.Duration(dur), err)
if err != nil {
r.metrics.numNotificationRequestsFailedTotal.WithLabelValues(r.labelValues...).Inc()
if !retry {
Expand All @@ -838,7 +837,7 @@ func (r RetryStage) exec(ctx context.Context, l log.Logger, alerts ...*types.Ale
lvl = level.Debug(log.With(l, "alerts", fmt.Sprintf("%v", alerts)))
}

lvl.Log("msg", "Notify success", "attempts", i)
lvl.Log("msg", "Notify success", "attempts", i, "duration", dur)
return ctx, alerts, nil
}
case <-ctx.Done():
Expand Down

0 comments on commit 507f6bf

Please sign in to comment.