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): recover storage incidents on confirmed empty capacity

pulse-triage[bot]49b998a2517b
diff --git a/docs/release-control/v6/internal/subsystems/alerts.md b/docs/release-control/v6/internal/subsystems/alerts.md
index c0bcfbe9f6..54113774e1 100644
--- a/docs/release-control/v6/internal/subsystems/alerts.md
+++ b/docs/release-control/v6/internal/subsystems/alerts.md
@@ -619,6 +619,25 @@ inspectability, or convert missing/stale evidence into health.
## Current State
+### Confirmed empty storage is recovery evidence
+
+Static storage capacity evaluation must admit a zero usage observation when
+`Total > 0`, `Used == 0`, and `Free == Total` together confirm an empty store.
+Offline or unavailable storage remains ineligible. Zero usage without those
+consistent byte counters is unknown capacity, not evidence of recovery.
+The observation passes through the existing canonical capacity lifecycle,
+including recovery confirmation and any predictive-capacity evidence; this
+rule does not directly clear an incident or bypass notification eligibility.
+
+`TestStorageEmptyCapacityRecovery` in `internal/alerts/alerts_test.go` pins
+confirmed empty recovery and retention under absent/inconsistent counters and
+offline/unavailable status. `internal/monitoring/monitor_storage_webhook_test.go`
+pins production callback/queue delivery of the correlated zero-value recovery,
+current observation time, matching history and duplicate avoidance, with no
+recovery on missing capacity. This is synthetic local receiver proof, not
+installed PBS API, off-host delivery or release qualification.
+
+
### Alert-quality telemetry folds only canonical durable lifecycle truth
`internal/alerts/telemetry_quality.go` folds active alerts and the canonical
diff --git a/internal/alerts/alerts_test.go b/internal/alerts/alerts_test.go
index 780a68c3d8..1718ece0c0 100644
--- a/internal/alerts/alerts_test.go
+++ b/internal/alerts/alerts_test.go
@@ -20991,3 +20991,53 @@ func TestCheckStorageForecastUsesCanonicalUsageAlertIdentity(t *testing.T) {
t.Fatalf("capacity origin = %v, want forecast", got)
}
}
+
+// Empty capacity requires consistent byte evidence, not a default zero usage.
+func TestStorageEmptyCapacityRecovery(t *testing.T) {
+ for _, tc := range []struct {
+ name string
+ total, used, free int64
+ status string
+ recover bool
+ }{
+ {"confirmed empty", 1000, 0, 1000, "online", true},
+ {"missing capacity", 0, 0, 0, "online", false},
+ {"missing free", 1000, 0, 0, "online", false},
+ {"inconsistent used", 1000, 100, 1000, "online", false},
+ {"offline", 1000, 0, 1000, "offline", false},
+ {"unavailable", 1000, 0, 1000, "unavailable", false},
+ } {
+ t.Run(tc.name, func(t *testing.T) {
+ m := NewManagerWithDataDir(t.TempDir())
+ defer m.Stop()
+ m.UpdateConfig(AlertConfig{Enabled: true, ActivationState: ActivationActive,
+ TimeThresholds: map[string]int{"storage": 0}, StorageDefault: HysteresisThreshold{Trigger: 80, Clear: 70}})
+ s := models.Storage{ID: "pbs-test-backups", Name: "backups", Type: "pbs", Status: "online", Total: 1000, Used: 850, Free: 150, Usage: 85}
+ for range 5 {
+ m.CheckStorage(s)
+ }
+ id := canonicalMetricStateID(s.ID, "usage")
+ original := testRequireActiveAlert(t, m, id)
+ s.Usage, s.Total, s.Used, s.Free, s.Status = 0, tc.total, tc.used, tc.free, tc.status
+ for range 5 {
+ m.CheckStorage(s)
+ }
+ if !tc.recover {
+ if !testHasActiveAlert(t, m, id) {
+ t.Fatal("unknown or offline capacity cleared usage incident")
+ }
+ if m.GetResolvedAlert(id) != nil {
+ t.Fatal("fabricated recovery history")
+ }
+ return
+ }
+ if testHasActiveAlert(t, m, id) {
+ t.Fatal("confirmed empty storage retained usage incident")
+ }
+ resolved := m.GetResolvedAlert(id)
+ if resolved == nil || resolved.Value != 0 || !resolved.StartTime.Equal(original.StartTime) {
+ t.Fatalf("wrong clearing observation or incident: %+v", resolved)
+ }
+ })
+ }
+}
diff --git a/internal/alerts/storage.go b/internal/alerts/storage.go
index 20e4e70bad..281d4f8858 100644
--- a/internal/alerts/storage.go
+++ b/internal/alerts/storage.go
@@ -101,8 +101,11 @@ func (m *Manager) CheckStorageWithCapacityTrend(storage models.Storage, trend Ca
Float64("clear", thresholds.Usage.Clear).
Msg("Checking storage thresholds")
- // Check usage if storage is online - checkMetric will skip if threshold is nil or <= 0
- if storage.Status != "offline" && storage.Status != "unavailable" && storage.Usage > 0 {
+ // Zero usage is a clearing observation only when the byte counters also
+ // confirm an empty store. A default zero from missing capacity telemetry
+ // must not resolve an existing incident.
+ confirmedEmpty := storage.Usage == 0 && storage.Total > 0 && storage.Used == 0 && storage.Free == storage.Total
+ if storage.Status != "offline" && storage.Status != "unavailable" && (storage.Usage > 0 || confirmedEmpty) {
m.evaluateStorageCapacity(storage, thresholds, trend)
}
diff --git a/internal/monitoring/monitor_storage_webhook_test.go b/internal/monitoring/monitor_storage_webhook_test.go
new file mode 100644
index 0000000000..c3d9257adb
--- /dev/null
+++ b/internal/monitoring/monitor_storage_webhook_test.go
@@ -0,0 +1,134 @@
+package monitoring
+
+import (
+ "encoding/json"
+ "net/http"
+ "net/http/httptest"
+ "strings"
+ "testing"
+ "time"
+
+ "github.com/rcourtman/pulse-go-rewrite/internal/alerts"
+ "github.com/rcourtman/pulse-go-rewrite/internal/models"
+ "github.com/rcourtman/pulse-go-rewrite/internal/notifications"
+)
+
+// Synthetic storage observations and a local receiver exercise the production
+// callback/queue path. This does not qualify an installed PBS poller or image.
+func TestStorageEmptyRecoveryWebhook(t *testing.T) {
+ type payload struct {
+ Event string `json:"event"`
+ Alerts []alerts.Alert `json:"alerts"`
+ }
+ received := make(chan payload, 16)
+ receiver := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ var p payload
+ if r.Method != http.MethodPost || json.NewDecoder(r.Body).Decode(&p) != nil {
+ t.Error("invalid webhook request")
+ http.Error(w, "invalid request", http.StatusBadRequest)
+ return
+ }
+ select {
+ case received <- p:
+ default:
+ t.Error("unexpected webhook flood")
+ }
+ w.WriteHeader(http.StatusOK)
+ }))
+ defer receiver.Close()
+ nm := notifications.NewNotificationManagerWithDataDir("", t.TempDir())
+ defer nm.Stop()
+ nm.SetGroupingWindow(0)
+ nm.SetNotifyOnResolve(true)
+ if err := nm.UpdateAllowedPrivateCIDRs("127.0.0.1/32"); err != nil {
+ t.Fatal(err)
+ }
+ nm.AddWebhook(notifications.WebhookConfig{ID: "local-receiver", Name: "local-receiver", URL: receiver.URL, Enabled: true})
+
+ manager := alerts.NewManagerWithDataDir(t.TempDir())
+ defer manager.Stop()
+ manager.UpdateConfig(alerts.AlertConfig{Enabled: true, ActivationState: alerts.ActivationActive,
+ TimeThresholds: map[string]int{"storage": 0}, StorageDefault: alerts.HysteresisThreshold{Trigger: 80, Clear: 70}})
+ monitor := newPBSHealthAuthorityMonitor(nil)
+ monitor.alertManager, monitor.notificationMgr = manager, nm
+ monitor.wireExternalAlertCallbacks(nil)
+ receive := func() payload {
+ t.Helper()
+ select {
+ case p := <-received:
+ return p
+ case <-time.After(5 * time.Second):
+ t.Fatal("webhook not received")
+ return payload{}
+ }
+ }
+ waitSent := func(want int) {
+ t.Helper()
+ deadline := time.Now().Add(5 * time.Second)
+ for time.Now().Before(deadline) {
+ entries, err := nm.GetDeliveryLog(time.Time{}, 20)
+ if err != nil {
+ t.Fatal(err)
+ }
+ sent := 0
+ for _, e := range entries {
+ if e.Success {
+ sent++
+ }
+ }
+ if sent == want {
+ return
+ }
+ time.Sleep(10 * time.Millisecond)
+ }
+ t.Fatalf("did not record %d successful deliveries", want)
+ }
+ storage := models.Storage{ID: "pbs-test-backups", Name: "backups", Type: "pbs", Status: "online", Total: 1000, Used: 850, Free: 150, Usage: 85}
+ for range 5 {
+ manager.CheckStorage(storage)
+ }
+ firing := receive()
+ if len(firing.Alerts) != 1 || firing.Alerts[0].Type != "usage" || firing.Event == "resolved" {
+ t.Fatalf("unexpected firing: %+v", firing)
+ }
+ incident := firing.Alerts[0]
+ waitSent(1)
+ // Missing free capacity must not masquerade as a measured empty store.
+ storage.Usage, storage.Used, storage.Free = 0, 0, 0
+ for range 5 {
+ manager.CheckStorage(storage)
+ }
+ if len(manager.GetActiveAlerts()) != 1 || manager.GetResolvedAlert(incident.ID) != nil {
+ t.Fatal("missing capacity fabricated recovery")
+ }
+ select {
+ case p := <-received:
+ t.Fatalf("missing capacity sent webhook: %+v", p)
+ case <-time.After(150 * time.Millisecond):
+ }
+ storage.Free = 1000
+ for range 5 {
+ manager.CheckStorage(storage)
+ }
+ recovery := receive()
+ if recovery.Event != "resolved" || len(recovery.Alerts) != 1 {
+ t.Fatalf("unexpected recovery: %+v", recovery)
+ }
+ resolved := recovery.Alerts[0]
+ if resolved.ID != incident.ID || !resolved.StartTime.Equal(incident.StartTime) || resolved.Value != 0 || !resolved.LastSeen.After(incident.LastSeen) || !strings.Contains(resolved.Message, "0.0%") || !strings.HasPrefix(resolved.Message, "Resolved: ") {
+ t.Fatalf("incorrect clearing payload: %+v", resolved)
+ }
+ waitSent(2)
+ history := manager.GetResolvedAlert(incident.ID)
+ if history == nil || history.Value != 0 || history.Message != resolved.Message {
+ t.Fatalf("incorrect history: %+v", history)
+ }
+ for range 5 {
+ manager.CheckStorage(storage)
+ }
+ select {
+ case p := <-received:
+ t.Fatalf("duplicate webhook: %+v", p)
+ case <-time.After(150 * time.Millisecond):
+ }
+}