From b20b455a76ca78dadc1bada84e1784825a3fe218 Mon Sep 17 00:00:00 2001 From: George Robinson Date: Wed, 14 Feb 2024 15:13:03 +0000 Subject: [PATCH] Alertmanager: Update Alertmanager to commit d352d16 This commit updates Alertmanager from f69a508 to d352d16. It has the following changes: - https://github.com/prometheus/alertmanager/pull/3565 - https://github.com/prometheus/alertmanager/pull/3718 - https://github.com/prometheus/alertmanager/pull/3707 - https://github.com/prometheus/alertmanager/pull/3719 - https://github.com/prometheus/alertmanager/pull/3592 - https://github.com/prometheus/alertmanager/pull/3572 - https://github.com/prometheus/alertmanager/pull/3722 --- go.mod | 2 +- go.sum | 4 +- .../featurecontrol/featurecontrol.go | 2 +- .../alertmanager/matchers/compat/parse.go | 4 +- .../prometheus/alertmanager/notify/notify.go | 58 ++++++++++++++----- vendor/modules.txt | 2 +- 6 files changed, 50 insertions(+), 22 deletions(-) diff --git a/go.mod b/go.mod index 33b1111bebc..afd86955f41 100644 --- a/go.mod +++ b/go.mod @@ -31,7 +31,7 @@ require ( github.com/opentracing-contrib/go-stdlib v1.0.0 github.com/opentracing/opentracing-go v1.2.1-0.20220228012449-10b1cf09e00b github.com/pkg/errors v0.9.1 - github.com/prometheus/alertmanager v0.26.1-0.20240208095903-f69a5086657b + github.com/prometheus/alertmanager v0.26.1-0.20240214111828-d352d16e277a github.com/prometheus/client_golang v1.18.0 github.com/prometheus/client_model v0.5.0 github.com/prometheus/common v0.46.0 diff --git a/go.sum b/go.sum index 8e964c72225..74a309ba6e8 100644 --- a/go.sum +++ b/go.sum @@ -769,8 +769,8 @@ github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRI github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI= github.com/posener/complete v1.2.3/go.mod h1:WZIdtGGp+qx0sLrYKtIRAruyNpv6hFCicSgv7Sy7s/s= -github.com/prometheus/alertmanager v0.26.1-0.20240208095903-f69a5086657b h1:qdLfwUabfhvvvOhnObLgRfXo5wq2V3pZSdLhUMgN4QE= -github.com/prometheus/alertmanager v0.26.1-0.20240208095903-f69a5086657b/go.mod h1:8Ia/R3urPmbzJ8OsdvmZvIprDwvwmYCmUbwBL+jlPOE= +github.com/prometheus/alertmanager v0.26.1-0.20240214111828-d352d16e277a h1:VyOIk5Rn/xrjaVr8tMB/30Anvo271JtzgCCDkEnczaU= +github.com/prometheus/alertmanager v0.26.1-0.20240214111828-d352d16e277a/go.mod h1:8Ia/R3urPmbzJ8OsdvmZvIprDwvwmYCmUbwBL+jlPOE= github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo= github.com/prometheus/client_golang v1.4.0/go.mod h1:e9GMxYsXl05ICDXkRhurwBS4Q3OK1iX/F2sw+iXX5zU= diff --git a/vendor/github.com/prometheus/alertmanager/featurecontrol/featurecontrol.go b/vendor/github.com/prometheus/alertmanager/featurecontrol/featurecontrol.go index a8a5585267f..9ff7a2d8fd2 100644 --- a/vendor/github.com/prometheus/alertmanager/featurecontrol/featurecontrol.go +++ b/vendor/github.com/prometheus/alertmanager/featurecontrol/featurecontrol.go @@ -97,7 +97,7 @@ func NewFlags(logger log.Logger, features string) (Flagger, error) { level.Warn(logger).Log("msg", "Classic mode enabled") case FeatureUTF8StrictMode: opts = append(opts, enableUTF8StrictMode()) - level.Warn(logger).Log("msg", "UTF-8 mode enabled") + level.Warn(logger).Log("msg", "UTF-8 strict mode enabled") default: return nil, fmt.Errorf("Unknown option '%s' for --enable-feature", feature) } diff --git a/vendor/github.com/prometheus/alertmanager/matchers/compat/parse.go b/vendor/github.com/prometheus/alertmanager/matchers/compat/parse.go index 7aa4e2d95b5..0c0dfffb1fd 100644 --- a/vendor/github.com/prometheus/alertmanager/matchers/compat/parse.go +++ b/vendor/github.com/prometheus/alertmanager/matchers/compat/parse.go @@ -133,7 +133,7 @@ func FallbackMatcherParser(l log.Logger) ParseMatcher { // The input is valid in the pkg/labels parser, but not the matchers/parse // parser. This means the input is not forwards compatible. suggestion := cMatcher.String() - level.Warn(l).Log("msg", "Alertmanager is moving to a new parser for labels and matchers, and this input is incompatible. Alertmanager has instead parsed the input using the old matchers parser as a fallback. To make this input compatible with the new parser please make sure all regular expressions and values are double-quoted. If you are still seeing this message please open an issue.", "input", input, "origin", origin, "err", nErr, "suggestion", suggestion) + level.Warn(l).Log("msg", "Alertmanager is moving to a new parser for labels and matchers, and this input is incompatible. Alertmanager has instead parsed the input using the classic matchers parser as a fallback. To make this input compatible with the UTF-8 matchers parser please make sure all regular expressions and values are double-quoted. If you are still seeing this message please open an issue.", "input", input, "origin", origin, "err", nErr, "suggestion", suggestion) return cMatcher, nil } // If the input is valid in both parsers, but produces different results, @@ -173,7 +173,7 @@ func FallbackMatchersParser(l log.Logger) ParseMatchers { suggestion := sb.String() // The input is valid in the pkg/labels parser, but not the // new matchers/parse parser. - level.Warn(l).Log("msg", "Alertmanager is moving to a new parser for labels and matchers, and this input is incompatible. Alertmanager has instead parsed the input using the old matchers parser as a fallback. To make this input compatible with the new parser please make sure all regular expressions and values are double-quoted. If you are still seeing this message please open an issue.", "input", input, "origin", origin, "err", nErr, "suggestion", suggestion) + level.Warn(l).Log("msg", "Alertmanager is moving to a new parser for labels and matchers, and this input is incompatible. Alertmanager has instead parsed the input using the classic matchers parser as a fallback. To make this input compatible with the UTF-8 matchers parser please make sure all regular expressions and values are double-quoted. If you are still seeing this message please open an issue.", "input", input, "origin", origin, "err", nErr, "suggestion", suggestion) return cMatchers, nil } // If the input is valid in both parsers, but produces different results, diff --git a/vendor/github.com/prometheus/alertmanager/notify/notify.go b/vendor/github.com/prometheus/alertmanager/notify/notify.go index 0a2b0d032b3..30861a30270 100644 --- a/vendor/github.com/prometheus/alertmanager/notify/notify.go +++ b/vendor/github.com/prometheus/alertmanager/notify/notify.go @@ -251,6 +251,7 @@ type Metrics struct { numTotalFailedNotifications *prometheus.CounterVec numNotificationRequestsTotal *prometheus.CounterVec numNotificationRequestsFailedTotal *prometheus.CounterVec + numNotificationSuppressedTotal *prometheus.CounterVec notificationLatencySeconds *prometheus.HistogramVec ff featurecontrol.Flagger @@ -284,6 +285,11 @@ func NewMetrics(r prometheus.Registerer, ff featurecontrol.Flagger) *Metrics { Name: "notification_requests_failed_total", Help: "The total number of failed notification requests.", }, labels), + numNotificationSuppressedTotal: prometheus.NewCounterVec(prometheus.CounterOpts{ + Namespace: "alertmanager", + Name: "notifications_suppressed_total", + Help: "The total number of notifications suppressed for being outside of active time intervals or within muted time intervals.", + }, []string{"reason"}), notificationLatencySeconds: prometheus.NewHistogramVec(prometheus.HistogramOpts{ Namespace: "alertmanager", Name: "notification_latency_seconds", @@ -296,7 +302,7 @@ func NewMetrics(r prometheus.Registerer, ff featurecontrol.Flagger) *Metrics { r.MustRegister( m.numNotifications, m.numTotalFailedNotifications, m.numNotificationRequestsTotal, m.numNotificationRequestsFailedTotal, - m.notificationLatencySeconds, + m.numNotificationSuppressedTotal, m.notificationLatencySeconds, ) return m @@ -381,10 +387,10 @@ func (pb *PipelineBuilder) New( rs := make(RoutingStage, len(receivers)) ms := NewGossipSettleStage(peer) - is := NewMuteStage(inhibitor) - tas := NewTimeActiveStage(intervener) - tms := NewTimeMuteStage(intervener) - ss := NewMuteStage(silencer) + is := NewMuteStage(inhibitor, pb.metrics) + tas := NewTimeActiveStage(intervener, pb.metrics) + tms := NewTimeMuteStage(intervener, pb.metrics) + ss := NewMuteStage(silencer, pb.metrics) for name := range receivers { st := createReceiverStage(name, receivers[name], wait, notificationLog, pb.metrics) @@ -507,14 +513,22 @@ func (n *GossipSettleStage) Exec(ctx context.Context, _ log.Logger, alerts ...*t return ctx, alerts, nil } +const ( + suppressedReasonSilence = "silence" + suppressedReasonInhibition = "inhibition" + suppressedReasonMuteTimeInterval = "mute_time_interval" + suppressedReasonActiveTimeInterval = "active_time_interval" +) + // MuteStage filters alerts through a Muter. type MuteStage struct { - muter types.Muter + muter types.Muter + metrics *Metrics } // NewMuteStage return a new MuteStage. -func NewMuteStage(m types.Muter) *MuteStage { - return &MuteStage{muter: m} +func NewMuteStage(m types.Muter, metrics *Metrics) *MuteStage { + return &MuteStage{muter: m, metrics: metrics} } // Exec implements the Stage interface. @@ -535,7 +549,18 @@ func (n *MuteStage) Exec(ctx context.Context, logger log.Logger, alerts ...*type } if len(muted) > 0 { level.Debug(logger).Log("msg", "Notifications will not be sent for muted alerts", "alerts", fmt.Sprintf("%v", muted)) + + var reason string + switch n.muter.(type) { + case *silence.Silencer: + reason = suppressedReasonSilence + case *inhibit.Inhibitor: + reason = suppressedReasonInhibition + default: + } + n.metrics.numNotificationSuppressedTotal.WithLabelValues(reason).Add(float64(len(muted))) } + return ctx, filtered, nil } @@ -894,13 +919,14 @@ func (n SetNotifiesStage) Exec(ctx context.Context, l log.Logger, alerts ...*typ } type timeStage struct { - muter types.TimeMuter + muter types.TimeMuter + metrics *Metrics } type TimeMuteStage timeStage -func NewTimeMuteStage(m types.TimeMuter) *TimeMuteStage { - return &TimeMuteStage{m} +func NewTimeMuteStage(m types.TimeMuter, metrics *Metrics) *TimeMuteStage { + return &TimeMuteStage{m, metrics} } // Exec implements the stage interface for TimeMuteStage. @@ -927,7 +953,8 @@ func (tms TimeMuteStage) Exec(ctx context.Context, l log.Logger, alerts ...*type // If the current time is inside a mute time, all alerts are removed from the pipeline. if muted { - level.Debug(l).Log("msg", "Notifications not sent, route is within mute time") + tms.metrics.numNotificationSuppressedTotal.WithLabelValues(suppressedReasonMuteTimeInterval).Add(float64(len(alerts))) + level.Debug(l).Log("msg", "Notifications not sent, route is within mute time", "alerts", len(alerts)) return ctx, nil, nil } return ctx, alerts, nil @@ -935,8 +962,8 @@ func (tms TimeMuteStage) Exec(ctx context.Context, l log.Logger, alerts ...*type type TimeActiveStage timeStage -func NewTimeActiveStage(m types.TimeMuter) *TimeActiveStage { - return &TimeActiveStage{m} +func NewTimeActiveStage(m types.TimeMuter, metrics *Metrics) *TimeActiveStage { + return &TimeActiveStage{m, metrics} } // Exec implements the stage interface for TimeActiveStage. @@ -964,7 +991,8 @@ func (tas TimeActiveStage) Exec(ctx context.Context, l log.Logger, alerts ...*ty // If the current time is not inside an active time, all alerts are removed from the pipeline if !muted { - level.Debug(l).Log("msg", "Notifications not sent, route is not within active time") + tas.metrics.numNotificationSuppressedTotal.WithLabelValues(suppressedReasonActiveTimeInterval).Add(float64(len(alerts))) + level.Debug(l).Log("msg", "Notifications not sent, route is not within active time", "alerts", len(alerts)) return ctx, nil, nil } diff --git a/vendor/modules.txt b/vendor/modules.txt index ec525189046..563b75b140c 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -823,7 +823,7 @@ github.com/pkg/errors # github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 ## explicit github.com/pmezard/go-difflib/difflib -# github.com/prometheus/alertmanager v0.26.1-0.20240208095903-f69a5086657b +# github.com/prometheus/alertmanager v0.26.1-0.20240214111828-d352d16e277a ## explicit; go 1.21 github.com/prometheus/alertmanager/api github.com/prometheus/alertmanager/api/metrics