Skip to content

Commit e45cc3e

Browse files
committed
Set severity field of the dummy events
Otherwise, the notification subject is looking odd, since this field is used to build the notification messages: #2] internal {"host":"notify-test"} is
1 parent 95d048c commit e45cc3e

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

internal/incident/incident.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ func (i *Incident) ProcessEvent(ctx context.Context, ev *event.Event, created bo
155155
}
156156

157157
// Re-evaluate escalations based on the newly evaluated rules.
158-
escalations, err := i.evaluateEscalations(ev.Time)
158+
escalations, err := i.evaluateEscalations(ev)
159159
if err != nil {
160160
return err
161161
}
@@ -196,7 +196,7 @@ func (i *Incident) RetriggerEscalations(ev *event.Event) {
196196
return
197197
}
198198

199-
escalations, err := i.evaluateEscalations(ev.Time)
199+
escalations, err := i.evaluateEscalations(ev)
200200
if err != nil {
201201
i.logger.Errorw("Reevaluating time-based escalations failed", zap.Error(err))
202202
return
@@ -393,7 +393,7 @@ func (i *Incident) evaluateRules(ctx context.Context, tx *sqlx.Tx, eventID int64
393393

394394
// evaluateEscalations evaluates this incidents rule escalations to be triggered if they aren't already.
395395
// 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) {
397397
if i.EscalationState == nil {
398398
i.EscalationState = make(map[int64]*EscalationState)
399399
}
@@ -406,7 +406,7 @@ func (i *Incident) evaluateEscalations(eventTime time.Time) ([]*rule.Escalation,
406406
i.timer = nil
407407
}
408408

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}
410410

411411
var escalations []*rule.Escalation
412412
retryAfter := rule.RetryNever
@@ -453,16 +453,17 @@ func (i *Incident) evaluateEscalations(eventTime time.Time) ([]*rule.Escalation,
453453
// i.e. if an incident is 15m old and an escalation rule evaluates incident_age>=1h the retryAfter would
454454
// contain 45m (1h - incident age (15m)). Therefore, we have to use the event time instead of the incident
455455
// start time here.
456-
nextEvalAt := eventTime.Add(retryAfter)
456+
nextEvalAt := e.Time.Add(retryAfter)
457457

458458
i.logger.Infow("Scheduling escalation reevaluation", zap.Duration("after", retryAfter), zap.Time("at", nextEvalAt))
459459
i.timer = time.AfterFunc(retryAfter, func() {
460460
i.logger.Info("Reevaluating escalations")
461461

462462
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)),
466467
})
467468
})
468469
}

internal/incident/incidents.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,10 @@ func LoadOpenIncidents(ctx context.Context, db *icingadb.DB, logger *logging.Log
4646
}
4747

4848
incident.RetriggerEscalations(&event.Event{
49-
Time: time.Now(),
50-
Type: event.TypeInternal,
51-
Message: "Incident reevaluation at daemon startup",
49+
Time: time.Now(),
50+
Type: event.TypeInternal,
51+
Severity: incident.Severity,
52+
Message: "Incident reevaluation at daemon startup",
5253
})
5354
}
5455

0 commit comments

Comments
 (0)