From abe1b088c078656df01034310a4d529fdae3c879 Mon Sep 17 00:00:00 2001 From: Ethan Hunter Date: Fri, 29 May 2026 14:35:37 -0400 Subject: [PATCH 1/3] remove SetNotifiesStage into its own file Signed-off-by: Ethan Hunter --- notify/notify.go | 55 ---------------------------------- notify/set_notifies.go | 67 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+), 55 deletions(-) create mode 100644 notify/set_notifies.go diff --git a/notify/notify.go b/notify/notify.go index 0a2e35d6d1..3477fc212a 100644 --- a/notify/notify.go +++ b/notify/notify.go @@ -1039,58 +1039,3 @@ func (r RetryStage) exec(ctx context.Context, l *slog.Logger, alerts ...*alert.A } } } - -// SetNotifiesStage sets the notification information about passed alerts. The -// passed alerts should have already been sent to the receivers. -type SetNotifiesStage struct { - nflog NotificationLog - recv *nflogpb.Receiver -} - -// NewSetNotifiesStage returns a new instance of a SetNotifiesStage. -func NewSetNotifiesStage(l NotificationLog, recv *nflogpb.Receiver) *SetNotifiesStage { - return &SetNotifiesStage{ - nflog: l, - recv: recv, - } -} - -// Exec implements the Stage interface. -func (n SetNotifiesStage) Exec(ctx context.Context, l *slog.Logger, alerts ...*alert.Alert) (context.Context, []*alert.Alert, error) { - gkey, ok := GroupKey(ctx) - if !ok { - return ctx, nil, errors.New("group key missing") - } - - ctx, span := tracer.Start(ctx, "notify.SetNotifiesStage.Exec", - trace.WithAttributes(attribute.String("alerting.group.key", gkey)), - trace.WithAttributes(attribute.Int("alerting.alerts.count", len(alerts))), - trace.WithSpanKind(trace.SpanKindInternal), - ) - defer span.End() - - firing, ok := FiringAlerts(ctx) - if !ok { - return ctx, nil, errors.New("firing alerts missing") - } - - resolved, ok := ResolvedAlerts(ctx) - if !ok { - return ctx, nil, errors.New("resolved alerts missing") - } - - repeat, ok := RepeatInterval(ctx) - if !ok { - return ctx, nil, errors.New("repeat interval missing") - } - expiry := 2 * repeat - - span.SetAttributes( - attribute.Int("alerting.alerts.firing.count", len(firing)), - attribute.Int("alerting.alerts.resolved.count", len(resolved)), - ) - - // Extract receiver data from context if present (it's ok for it to be nil). - store, _ := NflogStore(ctx) - return ctx, alerts, n.nflog.Log(n.recv, gkey, firing, resolved, store, expiry) -} diff --git a/notify/set_notifies.go b/notify/set_notifies.go new file mode 100644 index 0000000000..addf359fd7 --- /dev/null +++ b/notify/set_notifies.go @@ -0,0 +1,67 @@ +package notify + +import ( + "context" + "errors" + "log/slog" + + "github.com/prometheus/alertmanager/alert" + "github.com/prometheus/alertmanager/nflog/nflogpb" + "go.opentelemetry.io/otel/attribute" + "go.opentelemetry.io/otel/trace" +) + +// SetNotifiesStage sets the notification information about passed alerts. The +// passed alerts should have already been sent to the receivers. +type SetNotifiesStage struct { + nflog NotificationLog + recv *nflogpb.Receiver +} + +// NewSetNotifiesStage returns a new instance of a SetNotifiesStage. +func NewSetNotifiesStage(l NotificationLog, recv *nflogpb.Receiver) *SetNotifiesStage { + return &SetNotifiesStage{ + nflog: l, + recv: recv, + } +} + +// Exec implements the Stage interface. +func (n SetNotifiesStage) Exec(ctx context.Context, l *slog.Logger, alerts ...*alert.Alert) (context.Context, []*alert.Alert, error) { + gkey, ok := GroupKey(ctx) + if !ok { + return ctx, nil, errors.New("group key missing") + } + + ctx, span := tracer.Start(ctx, "notify.SetNotifiesStage.Exec", + trace.WithAttributes(attribute.String("alerting.group.key", gkey)), + trace.WithAttributes(attribute.Int("alerting.alerts.count", len(alerts))), + trace.WithSpanKind(trace.SpanKindInternal), + ) + defer span.End() + + firing, ok := FiringAlerts(ctx) + if !ok { + return ctx, nil, errors.New("firing alerts missing") + } + + resolved, ok := ResolvedAlerts(ctx) + if !ok { + return ctx, nil, errors.New("resolved alerts missing") + } + + repeat, ok := RepeatInterval(ctx) + if !ok { + return ctx, nil, errors.New("repeat interval missing") + } + expiry := 2 * repeat + + span.SetAttributes( + attribute.Int("alerting.alerts.firing.count", len(firing)), + attribute.Int("alerting.alerts.resolved.count", len(resolved)), + ) + + // Extract receiver data from context if present (it's ok for it to be nil). + store, _ := NflogStore(ctx) + return ctx, alerts, n.nflog.Log(n.recv, gkey, firing, resolved, store, expiry) +} From 2761dacf33793eec0464b9a018c256f2c8b6b596 Mon Sep 17 00:00:00 2001 From: Ethan Hunter Date: Fri, 29 May 2026 16:03:39 -0400 Subject: [PATCH 2/3] fix license header Signed-off-by: Ethan Hunter --- notify/set_notifies.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/notify/set_notifies.go b/notify/set_notifies.go index addf359fd7..09d599bd16 100644 --- a/notify/set_notifies.go +++ b/notify/set_notifies.go @@ -1,3 +1,15 @@ +// Copyright The Prometheus Authors +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. package notify import ( From 8c0bbea58c10bca561c385d02d7b41bca88a667b Mon Sep 17 00:00:00 2001 From: Ethan Hunter Date: Sat, 30 May 2026 09:58:55 -0600 Subject: [PATCH 3/3] fix golangci-lint Signed-off-by: Ethan Hunter --- notify/set_notifies.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/notify/set_notifies.go b/notify/set_notifies.go index 09d599bd16..57d501dee7 100644 --- a/notify/set_notifies.go +++ b/notify/set_notifies.go @@ -17,10 +17,11 @@ import ( "errors" "log/slog" - "github.com/prometheus/alertmanager/alert" - "github.com/prometheus/alertmanager/nflog/nflogpb" "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/trace" + + "github.com/prometheus/alertmanager/alert" + "github.com/prometheus/alertmanager/nflog/nflogpb" ) // SetNotifiesStage sets the notification information about passed alerts. The