@@ -269,18 +269,25 @@ func (i *Incident) evaluateRules(eventID int64, causedBy types.Int) (types.Int,
269
269
i .Rules [r .ID ] = struct {}{}
270
270
i .logger .Infof ("Rule %q matches" , r .Name )
271
271
272
+ err := i .AddRuleMatched (r )
273
+ if err != nil {
274
+ i .logger .Errorw ("Failed to upsert incident rule" , zap .String ("rule" , r .Name ), zap .Error (err ))
275
+
276
+ return types.Int {}, errors .New ("failed to insert incident rule" )
277
+ }
278
+
272
279
history := & HistoryRow {
273
280
Time : types .UnixMilli (time .Now ()),
274
281
EventID : utils .ToDBInt (eventID ),
275
282
RuleID : utils .ToDBInt (r .ID ),
276
283
Type : RuleMatched ,
277
284
CausedByIncidentHistoryID : causedBy ,
278
285
}
279
- insertedID , err := i .AddRuleMatchedHistory ( r , history )
286
+ insertedID , err := i .AddHistory ( history , true )
280
287
if err != nil {
281
- i .logger .Errorw ("Failed to add incident rule matched history" , zap .String ("rule" , r .Name ), zap .Error (err ))
288
+ i .logger .Errorw ("Failed to insert rule matched incident history" , zap .String ("rule" , r .Name ), zap .Error (err ))
282
289
283
- return types.Int {}, errors .New ("failed to add incident rule matched history" )
290
+ return types.Int {}, errors .New ("failed to insert rule matched incident history" )
284
291
}
285
292
286
293
if insertedID .Valid && ! causedBy .Valid {
@@ -365,6 +372,16 @@ func (i *Incident) notifyContacts(ev *event.Event, causedBy types.Int) error {
365
372
r := i .runtimeConfig .Rules [escalation .RuleID ]
366
373
i .logger .Infof ("Rule %q reached escalation %q" , r .Name , escalation .DisplayName ())
367
374
375
+ err := i .AddEscalationTriggered (state )
376
+ if err != nil {
377
+ i .logger .Errorw (
378
+ "Failed to upsert escalation state" , zap .String ("rule" , r .Name ),
379
+ zap .String ("escalation" , escalation .DisplayName ()), zap .Error (err ),
380
+ )
381
+
382
+ return errors .New ("failed to upsert escalation state" )
383
+ }
384
+
368
385
history := & HistoryRow {
369
386
Time : state .TriggeredAt ,
370
387
EventID : utils .ToDBInt (ev .ID ),
@@ -373,27 +390,19 @@ func (i *Incident) notifyContacts(ev *event.Event, causedBy types.Int) error {
373
390
Type : EscalationTriggered ,
374
391
CausedByIncidentHistoryID : causedBy ,
375
392
}
376
-
377
- causedByHistoryId , err := i .AddEscalationTriggered (state , history )
393
+ causedBy , err = i .AddHistory (history , true )
378
394
if err != nil {
379
395
i .logger .Errorw (
380
- "Failed to add escalation triggered history" , zap .String ("rule" , r .Name ),
396
+ "Failed to insert escalation triggered incident history" , zap .String ("rule" , r .Name ),
381
397
zap .String ("escalation" , escalation .DisplayName ()), zap .Error (err ),
382
398
)
383
399
384
- return errors .New ("failed to add escalation triggered history" )
400
+ return errors .New ("failed to insert escalation triggered incident history" )
385
401
}
386
402
387
- causedBy = causedByHistoryId
388
-
389
403
err = i .AddRecipient (escalation , ev .ID )
390
404
if err != nil {
391
- i .logger .Errorw (
392
- "Failed to add incident recipients" , zap .String ("rule" , r .Name ), zap .String ("escalation" , escalation .DisplayName ()),
393
- zap .String ("recipients" , escalation .DisplayName ()), zap .Error (err ),
394
- )
395
-
396
- return errors .New ("failed to add incident recipients" )
405
+ return err
397
406
}
398
407
}
399
408
0 commit comments