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): preserve backup posture for offline guests (#1693)

rcourtmanc33ed56f1f61
diff --git a/docs/release-control/v6/internal/subsystems/alerts.md b/docs/release-control/v6/internal/subsystems/alerts.md
index bcfbcc82f9..1f0976f498 100644
--- a/docs/release-control/v6/internal/subsystems/alerts.md
+++ b/docs/release-control/v6/internal/subsystems/alerts.md
@@ -29,6 +29,10 @@ their updated thresholds and may apply explicit resource-disable policies, but
it must not treat provider-owned incidents as missing thresholds. Unrelated
configuration saves preserve those incidents and their acknowledgement state
until their provider evaluator supplies recovery evidence.
+When a VM or container stops, guest evaluation resolves only metric-threshold
+alerts whose observations are no longer meaningful. Backup-age and snapshot
+posture remain owned by their posture evaluator and may stay active while the
+guest is powered off; stopped state is not backup-recovery evidence.
Docker and Podman container CPU thresholds evaluate host-capacity-normalized
CPU percent, not Docker's runtime-native per-core percent. Alert metadata may
carry the raw per-core value and reporting host CPU count for evidence, but the
diff --git a/internal/alerts/alerts_test.go b/internal/alerts/alerts_test.go
index b9bb56737b..68675f2067 100644
--- a/internal/alerts/alerts_test.go
+++ b/internal/alerts/alerts_test.go
@@ -15069,6 +15069,52 @@ func TestCheckGuest(t *testing.T) {
}
})
+ t.Run("non-running guest preserves posture alerts", func(t *testing.T) {
+ m := newTestManager(t)
+
+ backupStateID := buildCanonicalStateID("vm100", "vm100-backup-age")
+ snapshotStateID := buildCanonicalStateID("vm100", "vm100/snapshot:snap1")
+ m.mu.Lock()
+ m.activeAlerts[backupStateID] = &Alert{
+ ID: backupStateID,
+ ResourceID: "vm100",
+ Type: "backup-age",
+ CanonicalKind: string(alertspecs.AlertSpecKindPostureThreshold),
+ CanonicalSpecID: "vm100-backup-age",
+ CanonicalState: backupStateID,
+ }
+ m.activeAlerts[snapshotStateID] = &Alert{
+ ID: snapshotStateID,
+ ResourceID: "vm100",
+ Type: "snapshot-age",
+ CanonicalKind: string(alertspecs.AlertSpecKindPostureThreshold),
+ CanonicalSpecID: "vm100/snapshot:snap1",
+ CanonicalState: snapshotStateID,
+ }
+ m.mu.Unlock()
+
+ vm := models.VM{
+ ID: "vm100",
+ Name: "TestVM",
+ Node: "node1",
+ Status: "stopped",
+ }
+
+ m.CheckGuest(vm, "pve1")
+
+ m.mu.RLock()
+ _, backupExists := testLookupActiveAlert(t, m, backupStateID)
+ _, snapshotExists := testLookupActiveAlert(t, m, snapshotStateID)
+ m.mu.RUnlock()
+
+ if !backupExists {
+ t.Error("expected backup-age alert to remain active for a non-running guest")
+ }
+ if !snapshotExists {
+ t.Error("expected snapshot-age alert to remain active for a non-running guest")
+ }
+ })
+
t.Run("running guest clears powered-off alert", func(t *testing.T) {
// t.Parallel()
m := newTestManager(t)
diff --git a/internal/alerts/config_runtime.go b/internal/alerts/config_runtime.go
index 90839be404..b7dd8bce8e 100644
--- a/internal/alerts/config_runtime.go
+++ b/internal/alerts/config_runtime.go
@@ -326,15 +326,6 @@ func alertResourceTypeKeysContain(keys []string, target string) bool {
return false
}
-func isConfigReevaluatedMetricType(metricType string) bool {
- switch metricType {
- case "cpu", "memory", "disk", "diskRead", "diskWrite", "networkIn", "networkOut", "temperature", "usage":
- return true
- default:
- return false
- }
-}
-
// reevaluateActiveAlertsLocked re-evaluates all active alerts against the current configuration.
// This should only be called with m.mu already locked.
func (m *Manager) reevaluateActiveAlertsLocked() {
@@ -545,7 +536,7 @@ func (m *Manager) reevaluateActiveAlertsLocked() {
// observations. An unrelated config save must leave their lifecycle and
// acknowledgement state intact; only their evaluator (or an explicit
// resource-disable policy handled above) can resolve them.
- if !isConfigReevaluatedMetricType(metricType) {
+ if !isMetricThresholdAlertType(metricType) {
continue
}
diff --git a/internal/alerts/host.go b/internal/alerts/host.go
index 63f1612b0f..d09fc4868c 100644
--- a/internal/alerts/host.go
+++ b/internal/alerts/host.go
@@ -1043,7 +1043,7 @@ func (m *Manager) clearGuestMetricAlerts(guestID string, metrics ...string) int
cleared := 0
for storageKey, alert := range m.activeAlerts {
- if alert == nil || alert.Type == "powered-off" {
+ if alert == nil || !isMetricThresholdAlertType(alert.Type) {
continue
}
if alert.ResourceID != guestID && !strings.HasPrefix(alert.ResourceID, perDiskPrefix) &&
diff --git a/internal/alerts/metric_runtime.go b/internal/alerts/metric_runtime.go
index 1b9c5d172a..507dc54e31 100644
--- a/internal/alerts/metric_runtime.go
+++ b/internal/alerts/metric_runtime.go
@@ -9,6 +9,15 @@ import (
"github.com/rs/zerolog/log"
)
+func isMetricThresholdAlertType(metricType string) bool {
+ switch metricType {
+ case "cpu", "memory", "disk", "diskRead", "diskWrite", "networkIn", "networkOut", "temperature", "usage":
+ return true
+ default:
+ return false
+ }
+}
+
// getThresholdForMetric returns the threshold for a specific metric type from a ThresholdConfig.
func getThresholdForMetric(config ThresholdConfig, metricType string) *HysteresisThreshold {
switch metricType {