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): resolve canonically keyed metric alerts instead of leaving them stale

rcourtman20ea1ea4d3a9
diff --git a/internal/alerts/metric_resolve_regression_test.go b/internal/alerts/metric_resolve_regression_test.go
new file mode 100644
index 0000000000..6fb12dd1a9
--- /dev/null
+++ b/internal/alerts/metric_resolve_regression_test.go
@@ -0,0 +1,46 @@
+package alerts
+
+import (
+ "testing"
+)
+
+// Regression: checkMetric stores canonical-identity alerts under the
+// canonical state key, but its hysteresis resolution removed by the legacy
+// "<resourceID>-<metric>" ID, which is not registered as an alias. The
+// removal silently no-oped: a resolved notification went out while the
+// alert stayed active and re-resolved on every subsequent poll. Guest
+// per-disk usage alerts were the remaining production caller of this path.
+func TestCheckMetricResolveRemovesCanonicallyKeyedAlert(t *testing.T) {
+ manager := NewManagerWithDataDir(t.TempDir(), WithoutPersistedAlertRestore())
+ t.Cleanup(manager.Stop)
+
+ manager.mu.Lock()
+ manager.config.Enabled = true
+ manager.config.TimeThresholds = map[string]int{}
+ manager.mu.Unlock()
+
+ threshold := &HysteresisThreshold{Trigger: 80, Clear: 75}
+ resourceID := "guest-123/disk:root"
+
+ manager.checkMetric(resourceID, "test-vm", "node1", "qemu/123", "VM", "disk", 85, threshold, nil)
+
+ manager.mu.Lock()
+ activeAfterFire := len(manager.activeAlerts)
+ manager.mu.Unlock()
+ if activeAfterFire != 1 {
+ t.Fatalf("active alerts after fire = %d, want 1", activeAfterFire)
+ }
+
+ manager.checkMetric(resourceID, "test-vm", "node1", "qemu/123", "VM", "disk", 70, threshold, nil)
+
+ manager.mu.Lock()
+ activeAfterResolve := len(manager.activeAlerts)
+ manager.mu.Unlock()
+ if activeAfterResolve != 0 {
+ t.Fatalf("active alerts after resolve = %d, want 0 (stale alert left behind)", activeAfterResolve)
+ }
+
+ if resolved := manager.GetResolvedAlert(buildCanonicalStateID(resourceID, "metric-threshold:disk")); resolved == nil {
+ t.Fatal("expected a recently-resolved entry for the cleared alert")
+ }
+}
diff --git a/internal/alerts/metric_runtime.go b/internal/alerts/metric_runtime.go
index 507dc54e31..5b369242d1 100644
--- a/internal/alerts/metric_runtime.go
+++ b/internal/alerts/metric_runtime.go
@@ -525,8 +525,12 @@ func (m *Manager) checkMetric(resourceID, resourceName, node, instance, resource
// Threshold cleared with hysteresis - auto resolve
resolvedAlert := m.newResolvedAlert(existingAlert, time.Now(), nil)
- // Remove from active alerts
- m.removeActiveAlertNoLock(alertID)
+ // Remove from active alerts by the key it is actually stored
+ // under. Canonical-identity alerts are keyed by canonical
+ // state, and the legacy alertID is not registered as an
+ // alias, so removing by alertID silently no-ops and leaves a
+ // stale active alert that re-resolves on every poll.
+ m.removeActiveAlertNoLock(activeAlertStorageKey(existingAlert, alertID))
m.saveActiveAlertsAsync("metric resolution")