Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 0 additions & 21 deletions internal/incident/incident.go
Original file line number Diff line number Diff line change
Expand Up @@ -759,27 +759,6 @@ func (i *Incident) getRecipientsChannel(t time.Time) rule.ContactChannels {
return contactChs
}

// restoreRecipients reloads the current incident recipients from the database.
// Returns error on database failure.
func (i *Incident) restoreRecipients(ctx context.Context) error {
contact := &ContactRow{}
var contacts []*ContactRow
err := i.db.SelectContext(ctx, &contacts, i.db.Rebind(i.db.BuildSelectStmt(contact, contact)+` WHERE "incident_id" = ?`), i.Id)
if err != nil {
i.logger.Errorw("Failed to restore incident recipients from the database", zap.Error(err))
return err
}

recipients := make(map[recipient.Key]*RecipientState)
for _, contact := range contacts {
recipients[contact.Key] = &RecipientState{Role: contact.Role}
}

i.Recipients = recipients

return nil
}

// isRecipientNotifiable checks whether the given recipient should be notified about the current incident.
// If the specified recipient has not yet been notified of this incident, it always returns false.
// Otherwise, the recipient role is forwarded to IsNotifiable and may or may not return true.
Expand Down
15 changes: 1 addition & 14 deletions internal/incident/incidents.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,7 @@ func LoadOpenIncidents(ctx context.Context, db *database.DB, logger *logging.Log
}

func GetCurrent(
ctx context.Context, db *database.DB, obj *object.Object, logger *logging.Logger, runtimeConfig *config.RuntimeConfig,
create bool,
db *database.DB, obj *object.Object, logger *logging.Logger, runtimeConfig *config.RuntimeConfig, create bool,
) (*Incident, error) {
currentIncidentsMu.Lock()
defer currentIncidentsMu.Unlock()
Expand All @@ -164,17 +163,6 @@ func GetCurrent(
currentIncidents[obj] = currentIncident
}

if currentIncident != nil {
currentIncident.Lock()
defer currentIncident.Unlock()

if !currentIncident.StartedAt.Time().IsZero() {
if err := currentIncident.restoreRecipients(ctx); err != nil {
return nil, err
}
}
}

return currentIncident, nil
}

Expand Down Expand Up @@ -240,7 +228,6 @@ func ProcessEvent(

createIncident := ev.Severity != baseEv.SeverityNone && ev.Severity != baseEv.SeverityOK
currentIncident, err := GetCurrent(
ctx,
db,
obj,
logs.GetChildLogger("incident"),
Expand Down
Loading