Skip to content

armgit / Pulse

Public Imported from GitHub
0

Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.

fix(alerts): prevent duplicate history entries for flapping alerts

rcourtman40ad4178ba69
diff --git a/internal/alerts/canonical_lifecycle.go b/internal/alerts/canonical_lifecycle.go
index 3afc524318..6c834e34ba 100644
--- a/internal/alerts/canonical_lifecycle.go
+++ b/internal/alerts/canonical_lifecycle.go
@@ -401,6 +401,27 @@ func (m *Manager) evaluateCanonicalLifecycleAlert(params canonicalLifecycleAlert
return result, true
}
+ if resolved, ok := m.getResolvedAlertNoLock(storageKey); ok && resolved != nil && resolved.Alert != nil {
+ if resolved.ResolvedTime.After(time.Now().Add(-5 * time.Minute)) {
+ if !resolved.Alert.StartTime.IsZero() {
+ alert.StartTime = resolved.Alert.StartTime
+ }
+ m.removeResolvedAlertUnlocked(storageKey)
+ if params.AddToHistory {
+ m.historyManager.UpdateAlertLastSeenForAlert(alert, alert.LastSeen)
+ }
+ log.Debug().
+ Str("alertID", storageKey).
+ Time("resolvedAt", resolved.ResolvedTime).
+ Msg("Alert re-fired within cooldown, reactivated without new history entry")
+ if params.RateLimit && !m.checkRateLimit(trackingKey) {
+ return result, true
+ }
+ m.dispatchAlert(alert, params.DispatchAsync)
+ return result, true
+ }
+ }
+
if params.AddToHistory {
m.historyManager.AddAlert(*alert)
}
diff --git a/internal/alerts/connection_test.go b/internal/alerts/connection_test.go
index 7103aeb23f..565dfc6fe4 100644
--- a/internal/alerts/connection_test.go
+++ b/internal/alerts/connection_test.go
@@ -284,3 +284,43 @@ func TestClearConnectionDegradedAlert(t *testing.T) {
}
})
}
+
+func TestConnectionAlertReFireCooldown(t *testing.T) {
+ t.Run("re-fire within cooldown does not create duplicate history entry", func(t *testing.T) {
+ m := newTestManager(t)
+ snap := platformConnectionSnapshot("conn-cooldown", "Delly PVE", ConnectionStateUnreachable)
+ snap.StateReason = "context deadline exceeded"
+ alertID := canonicalDiscreteStateStateID(snap.ID, connectionDegradedStateKey)
+
+ m.CheckConnection(snap)
+ m.CheckConnection(snap)
+ m.CheckConnection(snap)
+ originalAlert := testRequireActiveAlert(t, m, alertID)
+ originalStart := originalAlert.StartTime
+
+ historyAfterFire := len(m.historyManager.GetAllHistory(1000))
+
+ snap.State = ConnectionStateActive
+ m.CheckConnection(snap)
+ m.CheckConnection(snap)
+ m.CheckConnection(snap)
+ if testHasActiveAlert(t, m, alertID) {
+ t.Fatal("expected alert to clear after recovery")
+ }
+
+ snap.State = ConnectionStateUnreachable
+ m.CheckConnection(snap)
+ m.CheckConnection(snap)
+ m.CheckConnection(snap)
+ reactivated := testRequireActiveAlert(t, m, alertID)
+
+ historyAfterReFire := len(m.historyManager.GetAllHistory(1000))
+ if historyAfterReFire != historyAfterFire {
+ t.Errorf("expected %d history entries after re-fire (same as after initial fire), got %d", historyAfterFire, historyAfterReFire)
+ }
+
+ if !reactivated.StartTime.Equal(originalStart) {
+ t.Errorf("expected reactivated alert to preserve original StartTime %v, got %v", originalStart, reactivated.StartTime)
+ }
+ })
+}