mirror of
https://github.com/rcourtman/Pulse.git
synced 2026-05-22 19:36:46 +00:00
fix: Preserve ackState for old acknowledged alerts during restore
When LoadActiveAlerts skipped acknowledged alerts older than 1 hour, it was also not populating ackState. This meant that when the same alert (e.g., backup-age) was recreated on the next poll cycle, preserveAlertState couldn't find any acknowledgement record and the alert would retrigger notifications. Now ackState is populated even for skipped old acknowledged alerts, so if they reappear, the acknowledgement will be restored. Related to #1043
This commit is contained in:
parent
74ea90e4b3
commit
48fdff3efb
2 changed files with 26 additions and 3 deletions
|
|
@ -8726,9 +8726,20 @@ func (m *Manager) LoadActiveAlerts() error {
|
|||
continue
|
||||
}
|
||||
|
||||
// Skip acknowledged alerts older than 1 hour
|
||||
// Skip acknowledged alerts older than 1 hour from activeAlerts,
|
||||
// but still preserve the ackState so if the same alert reappears
|
||||
// (e.g., backup-age alerts) it won't retrigger notifications.
|
||||
if alert.Acknowledged && alert.AckTime != nil && now.Sub(*alert.AckTime) > time.Hour {
|
||||
log.Debug().Str("alertID", alert.ID).Msg("Skipping old acknowledged alert")
|
||||
log.Debug().Str("alertID", alert.ID).Msg("Skipping old acknowledged alert from activeAlerts but preserving ackState")
|
||||
ackTime := alert.StartTime
|
||||
if alert.AckTime != nil {
|
||||
ackTime = *alert.AckTime
|
||||
}
|
||||
m.ackState[alert.ID] = ackRecord{
|
||||
acknowledged: true,
|
||||
user: alert.AckUser,
|
||||
time: ackTime,
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -15343,10 +15343,22 @@ func TestLoadActiveAlerts(t *testing.T) {
|
|||
|
||||
m.mu.RLock()
|
||||
_, exists := m.activeAlerts["old-ack-alert"]
|
||||
ackRecord, ackExists := m.ackState["old-ack-alert"]
|
||||
m.mu.RUnlock()
|
||||
|
||||
if exists {
|
||||
t.Error("old acknowledged alert (>1h) should be skipped during load")
|
||||
t.Error("old acknowledged alert (>1h) should be skipped from activeAlerts")
|
||||
}
|
||||
|
||||
// But ackState should be preserved so the alert doesn't retrigger if it reappears
|
||||
if !ackExists {
|
||||
t.Error("ackState should be preserved for old acknowledged alerts to prevent retriggering")
|
||||
}
|
||||
if ackExists && !ackRecord.acknowledged {
|
||||
t.Error("ackState.acknowledged should be true")
|
||||
}
|
||||
if ackExists && ackRecord.user != "testuser" {
|
||||
t.Errorf("ackState.user should be 'testuser', got %q", ackRecord.user)
|
||||
}
|
||||
})
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue