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.
Go aialertsdashboarddockerdocker-monitoringgohomelabinfrastructure-monitoringkubernetesmonitoringmspproxmoxproxmox-backup-serverproxmox-mail-gatewayproxmox-veself-hostedtruenastypescriptvspherewebhooks
Retain ownership of submitted alert configuration
pulse-triage[bot]569be6a85419
diff --git a/docs/release-control/v6/internal/subsystems/alerts.md b/docs/release-control/v6/internal/subsystems/alerts.mdindex d3c44eb5f3..0720b0d94f 100644--- a/docs/release-control/v6/internal/subsystems/alerts.md+++ b/docs/release-control/v6/internal/subsystems/alerts.md@@ -4319,3 +4319,21 @@ pending intent, retaining the reviewed agent/node ownership semantics.through a configuration save and the next report without losing the occurrence;`TestConfigSaveJudgesFilesystemAlertsByTheirOwnThreshold` retains per-filesystemand per-type controls. This is source composition, not installed delivery proof.++### Applied configuration input ownership++`Manager.UpdateConfig` clones the supplied configuration before normalisation+and retention. Callers keep ownership of its JSON-shaped maps, slices and+threshold pointers, just as they own `GetConfig` snapshots. Subsequent edits+do not alter running policy until explicitly reapplied; normalisation cannot+rewrite an input concurrently encoded for persistence or a response. The+existing typed clone's non-JSON custom filter-value limitation is unchanged.+`ApplyConfigUpdate` already decodes an owned configuration under the manager+lock and keeps its atomic partial-update semantics.++`config_validation_test.go` requires unchanged caller inputs, normalised+live thresholds, isolated edits, ordinary guest CPU evaluation, explicit+resubmission and concurrent response encoding/update under the race detector.+Existing snapshot, persistence, partial-update and threshold tests remain+required. This is source ownership acceptance, not installed notification or+guest-agent recovery evidence.diff --git a/internal/alerts/config_runtime.go b/internal/alerts/config_runtime.goindex 84204d064f..d3376f0487 100644--- a/internal/alerts/config_runtime.go+++ b/internal/alerts/config_runtime.go@@ -11,11 +11,13 @@ import ("github.com/rs/zerolog/log")-// UpdateConfig updates the alert configuration.+// UpdateConfig applies an owned copy of the alert configuration. The caller+// retains its maps, slices and thresholds for encoding or further edits; only+// another explicit update may change the running alert policy.func (m *Manager) UpdateConfig(config AlertConfig) {m.mu.Lock()defer m.mu.Unlock()- m.updateConfigLocked(config)+ m.updateConfigLocked(config.Clone())}// ErrConfigSnapshot reports an update that was applied but could not be copieddiff --git a/internal/alerts/config_validation_test.go b/internal/alerts/config_validation_test.goindex 3b4f7e30b3..a41141c8bf 100644--- a/internal/alerts/config_validation_test.go+++ b/internal/alerts/config_validation_test.go@@ -1,6 +1,9 @@package alertsimport (+ "encoding/json"+ "reflect"+ "sync""testing""time"@@ -281,3 +284,115 @@ func TestApplyConfigUpdateKeepsConcurrentPartialUpdates(t *testing.T) {}}}++func inputOwnershipConfig(m *Manager) AlertConfig {+ cfg := m.GetConfig()+ cfg.Enabled = true+ cfg.ActivationState = ActivationActive+ cfg.GuestDefaults.CPU = &HysteresisThreshold{Trigger: 80, Clear: 75}+ cfg.TimeThresholds = map[string]int{"guest": 0}+ cfg.Overrides = map[string]ThresholdConfig{"ownership-guest": {CPU: &HysteresisThreshold{Trigger: 80, Clear: 75}}}+ cfg.MetricTimeThresholds = map[string]map[string]int{"guest": {"cpu": 0}}+ cfg.MetricEvaluationWindows = map[string]map[string]int{"guest": {"cpu": 0}}+ cfg.IgnoredGuestPrefixes = []string{"ignored-"}+ cfg.Schedule.QuietHours.Days = map[string]bool{"monday": true}+ cfg.Schedule.Escalation.Levels = []EscalationLevel{{After: 10, Notify: "all", DestinationIDs: []string{"webhook:original"}}}+ return cfg+}++func TestUpdateConfigDoesNotNormalizeCallerInput(t *testing.T) {+ m := NewManagerWithDataDir(t.TempDir())+ t.Cleanup(m.Stop)+ cfg := inputOwnershipConfig(m)+ // Invalid hysteresis and delays must still be normalised in the manager,+ // without rewriting the caller's pointers or maps.+ cfg.GuestDefaults.CPU.Clear = 90+ cfg.TimeThresholds["guest"] = -1+ before := cfg.Clone()+ m.UpdateConfig(cfg)+ if !reflect.DeepEqual(cfg, before) {+ t.Error("applying a config rewrote caller-owned configuration")+ }+ live := m.GetConfig()+ if live.GuestDefaults.CPU.Clear != 75 || live.Overrides["ownership-guest"].CPU.Clear != 75 || live.TimeThresholds["guest"] < 0 {+ t.Fatalf("owned config did not retain normalisation: guest=%+v override=%+v delay=%d", live.GuestDefaults.CPU, live.Overrides["ownership-guest"].CPU, live.TimeThresholds["guest"])+ }+}++func TestUpdateConfigCallerEditsDoNotChangeAppliedPolicy(t *testing.T) {+ cases := map[string]func(*AlertConfig){+ "threshold-pointer": func(c *AlertConfig) { c.GuestDefaults.CPU.Trigger = 0 },+ "override-map": func(c *AlertConfig) { c.Overrides["ownership-guest"] = ThresholdConfig{Disabled: true} },+ "override-pointer": func(c *AlertConfig) { c.Overrides["ownership-guest"].CPU.Trigger = 0 },+ "delay-map": func(c *AlertConfig) { c.TimeThresholds["guest"] = 3600 },+ "nested-delay-map": func(c *AlertConfig) { c.MetricTimeThresholds["guest"]["cpu"] = 3600 },+ "window-map": func(c *AlertConfig) { c.MetricEvaluationWindows["guest"]["cpu"] = 3600 },+ "prefix-slice": func(c *AlertConfig) { c.IgnoredGuestPrefixes[0] = "ownership-" },+ "schedule-map": func(c *AlertConfig) { c.Schedule.QuietHours.Days["monday"] = false },+ "destination-slice": func(c *AlertConfig) { c.Schedule.Escalation.Levels[0].DestinationIDs[0] = "webhook:changed" },+ }+ for name, edit := range cases {+ t.Run(name, func(t *testing.T) {+ m := NewManagerWithDataDir(t.TempDir())+ t.Cleanup(m.Stop)+ cfg := inputOwnershipConfig(m)+ m.UpdateConfig(cfg)+ applied := m.GetConfig()+ edit(&cfg)+ if got := m.GetConfig(); !reflect.DeepEqual(got, applied) {+ t.Error("editing the submitted config changed live policy without an update")+ }+ guest := models.VM{ID: "ownership-guest", Name: "ownership-guest", Status: "running", CPU: .95}+ m.CheckGuest(guest, "ownership")+ found := false+ for _, alert := range m.GetActiveAlerts() {+ if alert.ResourceID == guest.ID && alert.Type == "cpu" {+ found = true+ }+ }+ if !found {+ t.Error("submitted-config edit prevented the ordinary CPU alert")+ }+ // An intentional resubmission still applies the changed setting.+ m.UpdateConfig(cfg)+ expected := m.GetConfig()+ if reflect.DeepEqual(expected, applied) {+ t.Error("explicit resubmission did not apply the edit")+ }+ })+ }+}++func TestUpdateConfigInputCanBeEncodedDuringLaterUpdates(t *testing.T) {+ m := NewManagerWithDataDir(t.TempDir())+ t.Cleanup(m.Stop)+ cfg := inputOwnershipConfig(m)+ m.UpdateConfig(cfg)+ before := cfg.Clone()+ // A caller may retain an applied snapshot for a response or persistence.+ // Later policy reconciliation must not write its override map while it is+ // being encoded. Exercise this under -race, using actual manager updates.+ var wg sync.WaitGroup+ wg.Add(2)+ go func() {+ defer wg.Done()+ for i := 0; i < 100; i++ {+ if _, err := json.Marshal(cfg); err != nil {+ t.Error(err)+ }+ }+ }()+ go func() {+ defer wg.Done()+ for i := 0; i < 100; i++ {+ // An alias of an already applied config is legal sequential input. The+ // manager owns normalisation; neither call transfers caller ownership.+ m.UpdateConfig(cfg)+ m.CheckGuest(models.VM{ID: "ownership-guest", Status: "running", CPU: .2, LastSeen: time.Now()}, "ownership")+ }+ }()+ wg.Wait()+ if !reflect.DeepEqual(cfg, before) {+ t.Error("later updates modified retained input")+ }+}