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.

test(alerts): distinguish divergent backup overrides on config load

pulse-triage[bot]412135214812
diff --git a/docs/release-control/v6/internal/subsystems/alerts.md b/docs/release-control/v6/internal/subsystems/alerts.md
index 0fd8d6ae12..3c7a2add58 100644
--- a/docs/release-control/v6/internal/subsystems/alerts.md
+++ b/docs/release-control/v6/internal/subsystems/alerts.md
@@ -1561,8 +1561,15 @@ whose threshold tuple exactly matches the current globals into sparse
enabled-only form. Those full copies were artifacts of the legacy per-guest
toggle, and the equality condition makes the rewrite behavior-preserving at
the moment it runs while letting the guest track later global edits (#1126).
-Overrides whose thresholds differ from the current globals are deliberate
-per-guest values and must never be rewritten.
+Overrides whose thresholds differ from the current globals must be preserved:
+persisted values alone cannot distinguish deliberate per-guest settings from a
+legacy copy made before the globals changed. A global-settings screenshot does
+not establish the effective guest threshold.
+`TestBackupDivergentDefaultsOnLoad` in `internal/alerts/alerts_test.go` verifies
+JSON-decoded configuration with 33/34-day globals: absent and enabled-only
+overrides inherit the globals, while a retained 7/14-day override still fires
+a seven-day warning. This is configuration-path evidence, not a reproduction
+of a reporter installation or a migration that guesses operator intent.
`TestGuestBackupOverrideInheritsGlobalThresholds`,
`TestFrozenBackupOverrideMigratesToSparse`,
`TestDeliberateBackupOverridePreserved`, and
diff --git a/internal/alerts/alerts_test.go b/internal/alerts/alerts_test.go
index 0b60ff4bf0..41d66feaa4 100644
--- a/internal/alerts/alerts_test.go
+++ b/internal/alerts/alerts_test.go
@@ -21228,3 +21228,55 @@ func TestActiveMirrorFailedWriteRetries(t *testing.T) {
t.Fatalf("temporary files: %v, %v", temps, err)
}
}
+
+// #1126: a globals screenshot alone cannot establish effective guest thresholds.
+// A legacy copy already divergent on load is indistinguishable from an explicit
+// override. Do not erase intentional settings to guess at their provenance.
+func TestBackupDivergentDefaultsOnLoad(t *testing.T) {
+ for _, tc := range []struct {
+ name string
+ override *BackupAlertConfig
+ wantAlert bool
+ }{
+ {name: "no override"},
+ {name: "sparse toggle", override: &BackupAlertConfig{Enabled: true}},
+ {name: "preexisting seven day values", override: &BackupAlertConfig{
+ Enabled: true, WarningDays: 7, CriticalDays: 14, FreshHours: 24, StaleHours: 72,
+ }, wantAlert: true},
+ } {
+ t.Run(tc.name, func(t *testing.T) {
+ m := newTestManager(t)
+ m.ClearActiveAlerts()
+ cfg := m.GetConfig()
+ cfg.Enabled = true
+ cfg.BackupDefaults = BackupAlertConfig{
+ Enabled: true, WarningDays: 33, CriticalDays: 34, FreshHours: 745, StaleHours: 746,
+ }
+ cfg.CustomRules = nil
+ cfg.Overrides = map[string]ThresholdConfig{}
+ if tc.override != nil {
+ cfg.Overrides["inst:node:100"] = ThresholdConfig{Backup: tc.override}
+ }
+ data, err := json.Marshal(cfg)
+ if err != nil {
+ t.Fatal(err)
+ }
+ var loaded AlertConfig
+ if err := json.Unmarshal(data, &loaded); err != nil {
+ t.Fatal(err)
+ }
+ m.UpdateConfig(loaded)
+ rollups, byKey, byVMID, key := backupTestFixtures(time.Now(), 8)
+ m.CheckBackups(rollups, byKey, byVMID)
+ m.mu.RLock()
+ alert, exists := testLookupActiveAlert(t, m, "backup-age-"+sanitizeAlertKey(key))
+ m.mu.RUnlock()
+ if exists != tc.wantAlert {
+ t.Fatalf("alert present = %v, want %v", exists, tc.wantAlert)
+ }
+ if exists && (alert.Level != AlertLevelWarning || alert.Threshold != 7) {
+ t.Fatalf("expected seven-day warning, got level=%s threshold=%v", alert.Level, alert.Threshold)
+ }
+ })
+ }
+}
diff --git a/internal/alerts/config/normalize.go b/internal/alerts/config/normalize.go
index 6916831cd3..e73a527a48 100644
--- a/internal/alerts/config/normalize.go
+++ b/internal/alerts/config/normalize.go
@@ -219,7 +219,8 @@ func NormalizeSnapshotDefaults(config *AlertConfig) {
// guests (#1126). Zero-valued fields inherit the global default at evaluation
// time, so the rewrite is behavior-preserving at the moment it runs and lets
// the override track future global changes. Overrides whose thresholds differ
-// from the current globals are deliberate per-guest values and are left alone.
+// from the current globals are left alone: persisted values cannot distinguish
+// an intentional override from a legacy copy made before the globals changed.
func NormalizeRecoveryOverrides(config *AlertConfig) {
for id, override := range config.Overrides {
changed := false