@@ -155,7 +155,7 @@ func (i *Incident) ProcessEvent(ctx context.Context, ev *event.Event, created bo
155
155
}
156
156
157
157
// Re-evaluate escalations based on the newly evaluated rules.
158
- escalations , err := i .evaluateEscalations (ev . Time )
158
+ escalations , err := i .evaluateEscalations (ev )
159
159
if err != nil {
160
160
return err
161
161
}
@@ -196,7 +196,7 @@ func (i *Incident) RetriggerEscalations(ev *event.Event) {
196
196
return
197
197
}
198
198
199
- escalations , err := i .evaluateEscalations (ev . Time )
199
+ escalations , err := i .evaluateEscalations (ev )
200
200
if err != nil {
201
201
i .logger .Errorw ("Reevaluating time-based escalations failed" , zap .Error (err ))
202
202
return
@@ -393,7 +393,7 @@ func (i *Incident) evaluateRules(ctx context.Context, tx *sqlx.Tx, eventID int64
393
393
394
394
// evaluateEscalations evaluates this incidents rule escalations to be triggered if they aren't already.
395
395
// Returns the newly evaluated escalations to be triggered or an error on database failure.
396
- func (i * Incident ) evaluateEscalations (eventTime time. Time ) ([]* rule.Escalation , error ) {
396
+ func (i * Incident ) evaluateEscalations (e * event. Event ) ([]* rule.Escalation , error ) {
397
397
if i .EscalationState == nil {
398
398
i .EscalationState = make (map [int64 ]* EscalationState )
399
399
}
@@ -406,7 +406,7 @@ func (i *Incident) evaluateEscalations(eventTime time.Time) ([]*rule.Escalation,
406
406
i .timer = nil
407
407
}
408
408
409
- filterContext := & rule.EscalationFilter {IncidentAge : eventTime .Sub (i .StartedAt ), IncidentSeverity : i .Severity }
409
+ filterContext := & rule.EscalationFilter {IncidentAge : e . Time .Sub (i .StartedAt ), IncidentSeverity : i .Severity }
410
410
411
411
var escalations []* rule.Escalation
412
412
retryAfter := rule .RetryNever
@@ -453,16 +453,17 @@ func (i *Incident) evaluateEscalations(eventTime time.Time) ([]*rule.Escalation,
453
453
// i.e. if an incident is 15m old and an escalation rule evaluates incident_age>=1h the retryAfter would
454
454
// contain 45m (1h - incident age (15m)). Therefore, we have to use the event time instead of the incident
455
455
// start time here.
456
- nextEvalAt := eventTime .Add (retryAfter )
456
+ nextEvalAt := e . Time .Add (retryAfter )
457
457
458
458
i .logger .Infow ("Scheduling escalation reevaluation" , zap .Duration ("after" , retryAfter ), zap .Time ("at" , nextEvalAt ))
459
459
i .timer = time .AfterFunc (retryAfter , func () {
460
460
i .logger .Info ("Reevaluating escalations" )
461
461
462
462
i .RetriggerEscalations (& event.Event {
463
- Type : event .TypeInternal ,
464
- Time : nextEvalAt ,
465
- Message : fmt .Sprintf ("Incident reached age %v" , nextEvalAt .Sub (i .StartedAt )),
463
+ Type : event .TypeInternal ,
464
+ Time : nextEvalAt ,
465
+ Severity : e .Severity ,
466
+ Message : fmt .Sprintf ("Incident reached age %v" , nextEvalAt .Sub (i .StartedAt )),
466
467
})
467
468
})
468
469
}
0 commit comments