@@ -119,6 +119,7 @@ const (
119
119
keyNow
120
120
keyMuteTimeIntervals
121
121
keyActiveTimeIntervals
122
+ keyRouteID
122
123
)
123
124
124
125
// WithReceiverName populates a context with a receiver name.
@@ -165,6 +166,10 @@ func WithActiveTimeIntervals(ctx context.Context, at []string) context.Context {
165
166
return context .WithValue (ctx , keyActiveTimeIntervals , at )
166
167
}
167
168
169
+ func WithRouteID (ctx context.Context , routeID string ) context.Context {
170
+ return context .WithValue (ctx , keyRouteID , routeID )
171
+ }
172
+
168
173
// RepeatInterval extracts a repeat interval from the context. Iff none exists, the
169
174
// second argument is false.
170
175
func RepeatInterval (ctx context.Context ) (time.Duration , bool ) {
@@ -228,6 +233,13 @@ func ActiveTimeIntervalNames(ctx context.Context) ([]string, bool) {
228
233
return v , ok
229
234
}
230
235
236
+ // RouteID extracts a RouteID from the context. Iff none exists, the
237
+ // // second argument is false.
238
+ func RouteID (ctx context.Context ) (string , bool ) {
239
+ v , ok := ctx .Value (keyRouteID ).(string )
240
+ return v , ok
241
+ }
242
+
231
243
// A Stage processes alerts under the constraints of the given context.
232
244
type Stage interface {
233
245
Exec (ctx context.Context , l log.Logger , alerts ... * types.Alert ) (context.Context , []* types.Alert , error )
@@ -937,6 +949,11 @@ func NewTimeMuteStage(muter types.TimeMuter, marker types.GroupMarker, metrics *
937
949
// Exec implements the stage interface for TimeMuteStage.
938
950
// TimeMuteStage is responsible for muting alerts whose route is not in an active time.
939
951
func (tms TimeMuteStage ) Exec (ctx context.Context , l log.Logger , alerts ... * types.Alert ) (context.Context , []* types.Alert , error ) {
952
+ routeID , ok := RouteID (ctx )
953
+ if ! ok {
954
+ return ctx , nil , errors .New ("route ID missing" )
955
+ }
956
+
940
957
gkey , ok := GroupKey (ctx )
941
958
if ! ok {
942
959
return ctx , nil , errors .New ("group key missing" )
@@ -961,7 +978,7 @@ func (tms TimeMuteStage) Exec(ctx context.Context, l log.Logger, alerts ...*type
961
978
return ctx , alerts , err
962
979
}
963
980
// If muted is false then mutedBy is nil and the muted marker is removed.
964
- tms .marker .SetMuted (gkey , mutedBy )
981
+ tms .marker .SetMuted (routeID , gkey , mutedBy )
965
982
966
983
// If the current time is inside a mute time, all alerts are removed from the pipeline.
967
984
if muted {
@@ -982,6 +999,11 @@ func NewTimeActiveStage(muter types.TimeMuter, marker types.GroupMarker, metrics
982
999
// Exec implements the stage interface for TimeActiveStage.
983
1000
// TimeActiveStage is responsible for muting alerts whose route is not in an active time.
984
1001
func (tas TimeActiveStage ) Exec (ctx context.Context , l log.Logger , alerts ... * types.Alert ) (context.Context , []* types.Alert , error ) {
1002
+ routeID , ok := RouteID (ctx )
1003
+ if ! ok {
1004
+ return ctx , nil , errors .New ("route ID missing" )
1005
+ }
1006
+
985
1007
gkey , ok := GroupKey (ctx )
986
1008
if ! ok {
987
1009
return ctx , nil , errors .New ("group key missing" )
@@ -1014,7 +1036,7 @@ func (tas TimeActiveStage) Exec(ctx context.Context, l log.Logger, alerts ...*ty
1014
1036
// to be active.
1015
1037
mutedBy = activeTimeIntervalNames
1016
1038
}
1017
- tas .marker .SetMuted (gkey , mutedBy )
1039
+ tas .marker .SetMuted (routeID , gkey , mutedBy )
1018
1040
1019
1041
// If the current time is not inside an active time, all alerts are removed from the pipeline
1020
1042
if ! active {
0 commit comments