Skip to content

Commit

Permalink
Restore incident rules gracefully
Browse files Browse the repository at this point in the history
  • Loading branch information
yhabteab committed Apr 12, 2024
1 parent 1eb8a4c commit f46b60e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
11 changes: 0 additions & 11 deletions internal/incident/incident.go
Original file line number Diff line number Diff line change
Expand Up @@ -635,17 +635,6 @@ func (i *Incident) processAcknowledgementEvent(ctx context.Context, tx *sqlx.Tx,
return nil
}

// RestoreEscalationStateRules restores this incident's rules based on the given escalation states.
func (i *Incident) RestoreEscalationStateRules() {
i.runtimeConfig.RLock()
defer i.runtimeConfig.RUnlock()

for _, state := range i.EscalationState {
escalation := i.runtimeConfig.GetRuleEscalation(state.RuleEscalationID)
i.Rules[escalation.RuleID] = struct{}{}
}
}

// getRecipientsChannel returns all the configured channels of the current incident and escalation recipients.
func (i *Incident) getRecipientsChannel(t time.Time) contactChannels {
contactChs := make(contactChannels)
Expand Down
10 changes: 9 additions & 1 deletion internal/incident/incidents.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,15 @@ func LoadOpenIncidents(ctx context.Context, db *icingadb.DB, logger *logging.Log
for _, i := range incidentsByObjId {
if i.ID() == state.IncidentID {
i.EscalationState[state.RuleEscalationID] = state

// Restore the incident rule matching the current escalation state if any.
i.runtimeConfig.RLock()
escalation := i.runtimeConfig.GetRuleEscalation(state.RuleEscalationID)
if escalation != nil {
i.Rules[escalation.RuleID] = struct{}{}
}
i.runtimeConfig.RUnlock()

break
}
}
Expand Down Expand Up @@ -205,7 +214,6 @@ func LoadOpenIncidents(ctx context.Context, db *icingadb.DB, logger *logging.Log
for _, i := range incidentsByObjId {
i.logger = logger.With(zap.String("object", i.Object.DisplayName()), zap.String("incident", i.String()))

i.RestoreEscalationStateRules()
i.RetriggerEscalations(&event.Event{
Time: time.Now(),
Type: event.TypeInternal,
Expand Down

0 comments on commit f46b60e

Please sign in to comment.