@@ -27,6 +27,7 @@ import (
27
27
var gatheringFunctionBuilders = map [GatheringFunctionName ]GathererFunctionBuilderPtr {
28
28
GatherLogsOfNamespace : (* Gatherer ).BuildGatherLogsOfNamespace ,
29
29
GatherImageStreamsOfNamespace : (* Gatherer ).BuildGatherImageStreamsOfNamespace ,
30
+ GatherApiRequestCounts : (* Gatherer ).BuildGatherApiRequestCounts ,
30
31
}
31
32
32
33
// gatheringRules contains all the rules used to run conditional gatherings.
@@ -77,6 +78,21 @@ var defaultGatheringRules = []GatheringRule{
77
78
},
78
79
},
79
80
},
81
+ {
82
+ Conditions : []ConditionWithParams {
83
+ {
84
+ Type : AlertIsFiring ,
85
+ Params : AlertIsFiringConditionParams {
86
+ Name : "APIRemovedInNextReleaseInUse" ,
87
+ },
88
+ },
89
+ },
90
+ GatheringFunctions : GatheringFunctions {
91
+ GatherApiRequestCounts : GatherApiRequestCountsParams {
92
+ AlertName : "APIRemovedInNextReleaseInUse" ,
93
+ },
94
+ },
95
+ },
80
96
}
81
97
82
98
const canConditionalGathererFail = false
@@ -86,8 +102,9 @@ type Gatherer struct {
86
102
gatherProtoKubeConfig * rest.Config
87
103
metricsGatherKubeConfig * rest.Config
88
104
imageKubeConfig * rest.Config
89
- firingAlerts map [string ]bool // golang doesn't have sets :(
90
- gatheringRules []GatheringRule
105
+ // there can be multiple instances of the same alert
106
+ firingAlerts map [string ][]Alert // golang doesn't have sets :(
107
+ gatheringRules []GatheringRule
91
108
}
92
109
93
110
// New creates a new instance of conditional gatherer with the appropriate configs
@@ -138,7 +155,6 @@ func (g *Gatherer) GetGatheringFunctions(ctx context.Context) (map[string]gather
138
155
if err != nil {
139
156
return nil , err
140
157
}
141
-
142
158
if allConditionsAreSatisfied {
143
159
functions , errs := g .createGatheringClosures (conditionalGathering .GatheringFunctions )
144
160
if len (errs ) > 0 {
@@ -206,7 +222,7 @@ func (g *Gatherer) updateAlertsCache(ctx context.Context) error {
206
222
func (g * Gatherer ) updateAlertsCacheFromClient (ctx context.Context , metricsClient rest.Interface ) error {
207
223
const logPrefix = "conditional gatherer: "
208
224
209
- g .firingAlerts = make (map [string ]bool )
225
+ g .firingAlerts = make (map [string ][] Alert )
210
226
211
227
data , err := metricsClient .Get ().AbsPath ("federate" ).
212
228
Param ("match[]" , `ALERTS{alertstate="firing"}` ).
@@ -237,17 +253,31 @@ func (g *Gatherer) updateAlertsCacheFromClient(ctx context.Context, metricsClien
237
253
klog .Info (logPrefix + "metric is nil" )
238
254
continue
239
255
}
240
-
256
+ var alert Alert
241
257
for _ , label := range metric .GetLabel () {
242
258
if label == nil {
243
259
klog .Info (logPrefix + "label is nil" )
244
260
continue
245
261
}
246
-
247
- if label .GetName () == "alertname" {
248
- g .firingAlerts [label .GetValue ()] = true
262
+ switch label .GetName () {
263
+ case "alertname" :
264
+ alert .Name = label .GetValue ()
265
+ case "version" :
266
+ alert .Version = label .GetValue ()
267
+ case "resource" :
268
+ alert .Resource = label .GetValue ()
269
+ case "group" :
270
+ alert .Group = label .GetValue ()
249
271
}
250
272
}
273
+ alerts , ok := g .firingAlerts [alert .Name ]
274
+ if ok {
275
+ alerts = append (alerts , alert )
276
+ } else {
277
+ alerts = []Alert {alert }
278
+ }
279
+
280
+ g .firingAlerts [alert .Name ] = alerts
251
281
}
252
282
253
283
return nil
0 commit comments