@@ -46,11 +46,12 @@ type AlertDiscovery struct {
46
46
47
47
// Alert has info for an alert.
48
48
type Alert struct {
49
- Labels labels.Labels `json:"labels"`
50
- Annotations labels.Labels `json:"annotations"`
51
- State string `json:"state"`
52
- ActiveAt * time.Time `json:"activeAt"`
53
- Value string `json:"value"`
49
+ Labels labels.Labels `json:"labels"`
50
+ Annotations labels.Labels `json:"annotations"`
51
+ State string `json:"state"`
52
+ ActiveAt * time.Time `json:"activeAt"`
53
+ KeepFiringSince * time.Time `json:"keepFiringSince,omitempty"`
54
+ Value string `json:"value"`
54
55
}
55
56
56
57
// RuleDiscovery has info for all rules
@@ -80,6 +81,7 @@ type alertingRule struct {
80
81
Name string `json:"name"`
81
82
Query string `json:"query"`
82
83
Duration float64 `json:"duration"`
84
+ KeepFiringFor float64 `json:"keepFiringFor"`
83
85
Labels labels.Labels `json:"labels"`
84
86
Annotations labels.Labels `json:"annotations"`
85
87
Alerts []* Alert `json:"alerts"`
@@ -211,13 +213,17 @@ func (a *API) PrometheusRules(w http.ResponseWriter, req *http.Request) {
211
213
if g .ActiveRules [i ].Rule .Alert != "" {
212
214
alerts := make ([]* Alert , 0 , len (rl .Alerts ))
213
215
for _ , a := range rl .Alerts {
214
- alerts = append ( alerts , & Alert {
216
+ alert := & Alert {
215
217
Labels : cortexpb .FromLabelAdaptersToLabels (a .Labels ),
216
218
Annotations : cortexpb .FromLabelAdaptersToLabels (a .Annotations ),
217
219
State : a .GetState (),
218
220
ActiveAt : & a .ActiveAt ,
219
221
Value : strconv .FormatFloat (a .Value , 'e' , - 1 , 64 ),
220
- })
222
+ }
223
+ if ! a .KeepFiringSince .IsZero () {
224
+ alert .KeepFiringSince = & a .KeepFiringSince
225
+ }
226
+ alerts = append (alerts , alert )
221
227
}
222
228
grp .Rules [i ] = alertingRule {
223
229
State : rl .GetState (),
@@ -232,6 +238,7 @@ func (a *API) PrometheusRules(w http.ResponseWriter, req *http.Request) {
232
238
LastEvaluation : rl .GetEvaluationTimestamp (),
233
239
EvaluationTime : rl .GetEvaluationDuration ().Seconds (),
234
240
Type : v1 .RuleTypeAlerting ,
241
+ KeepFiringFor : rl .Rule .KeepFiringFor .Seconds (),
235
242
}
236
243
} else {
237
244
grp .Rules [i ] = recordingRule {
@@ -296,13 +303,17 @@ func (a *API) PrometheusAlerts(w http.ResponseWriter, req *http.Request) {
296
303
for _ , rl := range g .ActiveRules {
297
304
if rl .Rule .Alert != "" {
298
305
for _ , a := range rl .Alerts {
299
- alerts = append ( alerts , & Alert {
306
+ alert := & Alert {
300
307
Labels : cortexpb .FromLabelAdaptersToLabels (a .Labels ),
301
308
Annotations : cortexpb .FromLabelAdaptersToLabels (a .Annotations ),
302
309
State : a .GetState (),
303
310
ActiveAt : & a .ActiveAt ,
304
311
Value : strconv .FormatFloat (a .Value , 'e' , - 1 , 64 ),
305
- })
312
+ }
313
+ if ! a .KeepFiringSince .IsZero () {
314
+ alert .KeepFiringSince = & a .KeepFiringSince
315
+ }
316
+ alerts = append (alerts , alert )
306
317
}
307
318
}
308
319
}
0 commit comments