Skip to content

Commit 80b3cb0

Browse files
authored
Notify: Several improvements around the suppressed_total metric and logs for muting. (#3723)
1 parent b7d4c4a commit 80b3cb0

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

notify/notify.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ func NewMetrics(r prometheus.Registerer, ff featurecontrol.Flagger) *Metrics {
288288
numNotificationSuppressedTotal: prometheus.NewCounterVec(prometheus.CounterOpts{
289289
Namespace: "alertmanager",
290290
Name: "notifications_suppressed_total",
291-
Help: "The total number of notifications suppressed for being outside of active time intervals or within muted time intervals.",
291+
Help: "The total number of notifications suppressed for being silenced, inhibited, outside of active time intervals or within muted time intervals.",
292292
}, []string{"reason"}),
293293
notificationLatencySeconds: prometheus.NewHistogramVec(prometheus.HistogramOpts{
294294
Namespace: "alertmanager",
@@ -514,10 +514,10 @@ func (n *GossipSettleStage) Exec(ctx context.Context, _ log.Logger, alerts ...*t
514514
}
515515

516516
const (
517-
suppressedReasonSilence = "silence"
518-
suppressedReasonInhibition = "inhibition"
519-
suppressedReasonMuteTimeInterval = "mute_time_interval"
520-
suppressedReasonActiveTimeInterval = "active_time_interval"
517+
SuppressedReasonSilence = "silence"
518+
SuppressedReasonInhibition = "inhibition"
519+
SuppressedReasonMuteTimeInterval = "mute_time_interval"
520+
SuppressedReasonActiveTimeInterval = "active_time_interval"
521521
)
522522

523523
// MuteStage filters alerts through a Muter.
@@ -548,17 +548,17 @@ func (n *MuteStage) Exec(ctx context.Context, logger log.Logger, alerts ...*type
548548
// TODO(fabxc): increment muted alerts counter if muted.
549549
}
550550
if len(muted) > 0 {
551-
level.Debug(logger).Log("msg", "Notifications will not be sent for muted alerts", "alerts", fmt.Sprintf("%v", muted))
552551

553552
var reason string
554553
switch n.muter.(type) {
555554
case *silence.Silencer:
556-
reason = suppressedReasonSilence
555+
reason = SuppressedReasonSilence
557556
case *inhibit.Inhibitor:
558-
reason = suppressedReasonInhibition
557+
reason = SuppressedReasonInhibition
559558
default:
560559
}
561560
n.metrics.numNotificationSuppressedTotal.WithLabelValues(reason).Add(float64(len(muted)))
561+
level.Debug(logger).Log("msg", "Notifications will not be sent for muted alerts", "alerts", fmt.Sprintf("%v", muted), "reason", reason)
562562
}
563563

564564
return ctx, filtered, nil
@@ -953,7 +953,7 @@ func (tms TimeMuteStage) Exec(ctx context.Context, l log.Logger, alerts ...*type
953953

954954
// If the current time is inside a mute time, all alerts are removed from the pipeline.
955955
if muted {
956-
tms.metrics.numNotificationSuppressedTotal.WithLabelValues(suppressedReasonMuteTimeInterval).Add(float64(len(alerts)))
956+
tms.metrics.numNotificationSuppressedTotal.WithLabelValues(SuppressedReasonMuteTimeInterval).Add(float64(len(alerts)))
957957
level.Debug(l).Log("msg", "Notifications not sent, route is within mute time", "alerts", len(alerts))
958958
return ctx, nil, nil
959959
}
@@ -991,7 +991,7 @@ func (tas TimeActiveStage) Exec(ctx context.Context, l log.Logger, alerts ...*ty
991991

992992
// If the current time is not inside an active time, all alerts are removed from the pipeline
993993
if !muted {
994-
tas.metrics.numNotificationSuppressedTotal.WithLabelValues(suppressedReasonActiveTimeInterval).Add(float64(len(alerts)))
994+
tas.metrics.numNotificationSuppressedTotal.WithLabelValues(SuppressedReasonActiveTimeInterval).Add(float64(len(alerts)))
995995
level.Debug(l).Log("msg", "Notifications not sent, route is not within active time", "alerts", len(alerts))
996996
return ctx, nil, nil
997997
}

0 commit comments

Comments
 (0)