Skip to content

Commit df9bcfc

Browse files
fix(alerts): backport PVE disk mute policy to v6.4
Backport the #2112 PVE physical-disk alert alias and #2237 restored-policy reconciliation to the selected release line for a later checkpoint. Keep the persisted alert reference and occurrence ID stable, apply exact per-disk mute, and leave unrelated disks alerting. Adapt the proof to the line's existing monitor adapter API; update alerts, monitoring and unified-resource contracts and verification in this same commit. Frozen v6.4.5-rc.3 remains unchanged. Change-source: pulse-maintainer
1 parent a3a0e96 commit df9bcfc

10 files changed

Lines changed: 217 additions & 4 deletions

File tree

‎docs/release-control/v6/internal/subsystems/alerts.md‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,20 @@
1515

1616
## Purpose
1717

18+
### PVE physical-disk alert identity and mute — issue #2112
19+
20+
PVE disk-health and wearout alerts retain their persisted path-shaped resource
21+
reference, `instance:node:disk:<sanitised device path>`, and their existing alert
22+
ID strings. The reference is resolved through the unified-resource physical-disk
23+
alias before exact operator intent is evaluated. A mute on one identified disk
24+
must clear its active wearout occurrence and suppress new evaluations for that
25+
disk without silencing a different device path. Absent wearout readings do not
26+
prove recovery; the separate confirmed-recovery rule still applies.
27+
`TestProxmoxDiskCanonicalResourceIDTrimsIdentity` pins representative persisted
28+
path keys, and monitoring's `TestProxmoxPhysicalDiskMuteResolvesAndSuppressesWearoutAlert`
29+
pins targeted active/new-alert suppression. These are source checks, not proof of
30+
installed notification relief for the reporter.
31+
1832
### Automatic acknowledgement lifecycle
1933

2034
Cleanup-triggered acknowledgement uses the same canonical retention records and

‎docs/release-control/v6/internal/subsystems/monitoring.md‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,18 @@
1717

1818
## Purpose
1919

20+
### Restored disk alerts and persisted operator policy — issues #2237/#2112
21+
22+
Alerts can restore before the resource registry and persisted operator state
23+
are attached. Once monitoring installs the alert-intent resolver, it must
24+
reconcile already-active alerts against that state and publish the changed
25+
alert snapshot when suppression clears any occurrence. This closes the
26+
startup gap for a muted PVE disk's existing wearout alert without turning a
27+
mute into a recovery notification or suppressing other disks. The resolver
28+
uses this release line's `MonitorAdapter.ResolveCanonicalResourceID` bridge;
29+
`TestProxmoxPhysicalDiskMuteResolvesAndSuppressesWearoutAlert` covers the
30+
active-alert reconciliation, subsequent suppression and unaffected peer.
31+
2032
### Linked Pulse agent memory for Proxmox LXC — issue #2148 (21 September 2026)
2133

2234
Both LXC memory paths — the efficient `cluster/resources` builder

‎docs/release-control/v6/internal/subsystems/unified-resources.md‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,18 @@
1515

1616
## Purpose
1717

18+
### PVE physical-disk alert reference alias — issue #2112
19+
20+
A Proxmox physical-disk resource with a non-empty instance, node name and
21+
`PhysicalDisk.DevPath` indexes the legacy PVE disk-alert reference as a
22+
canonical alias. The alias uses the same path sanitisation as alert creation;
23+
it is not the source ID, canonical primary ID or metrics identity. Non-disk
24+
resources and incomplete PVE disk identities must not claim that reference.
25+
Normal registry ambiguity rules still govern resolution when more than one
26+
resource claims an alias. `TestProxmoxPhysicalDiskAlertAliasIsScopedToDisk`
27+
pins the admission boundary; monitoring's targeted-mute test covers the
28+
registry-to-alert bridge on distinct device paths.
29+
1830
### System-container linked agent memory read — issue #2148 (21 September 2026)
1931

2032
`ContainerView.LinkedAgentMemory` exposes the linked agent's own memory sample

‎internal/alerts/alerts_test.go‎

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -423,9 +423,21 @@ func TestBuildBackupPVETemplateSubjectKeyTrimsParts(t *testing.T) {
423423
}
424424

425425
func TestProxmoxDiskCanonicalResourceIDTrimsIdentity(t *testing.T) {
426-
got := proxmoxDiskCanonicalResourceID(" inst ", " node ", "/dev/sda")
427-
if got != "inst:node:disk:dev-sda" {
428-
t.Fatalf("proxmoxDiskCanonicalResourceID() = %q, want %q", got, "inst:node:disk:dev-sda")
426+
cases := []struct {
427+
path string
428+
want string
429+
}{
430+
{path: "/dev/sda", want: "inst:node:disk:dev-sda"},
431+
{path: "/dev/nvme0n1", want: "inst:node:disk:dev-nvme0n1"},
432+
{path: "/dev/disk/by-id/SSD X", want: "inst:node:disk:dev-disk-by-id-ssd-x"},
433+
}
434+
for _, tc := range cases {
435+
t.Run(tc.path, func(t *testing.T) {
436+
got := proxmoxDiskCanonicalResourceID(" inst ", " node ", tc.path)
437+
if got != tc.want {
438+
t.Fatalf("proxmoxDiskCanonicalResourceID() = %q, want %q", got, tc.want)
439+
}
440+
})
429441
}
430442
}
431443

‎internal/alerts/disk_health.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
)
1414

1515
func proxmoxDiskCanonicalResourceID(instance, node, devPath string) string {
16-
return fmt.Sprintf("%s:%s:disk:%s", strings.TrimSpace(instance), strings.TrimSpace(node), sanitizeAlertKey(devPath))
16+
return unifiedresources.ProxmoxPhysicalDiskAlertResourceID(instance, node, devPath)
1717
}
1818

1919
func proxmoxDiskAlertMetadata(disk proxmox.Disk) map[string]interface{} {

‎internal/monitoring/monitor_alert_intent.go‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,11 @@ func (m *Monitor) installOperatorIntentResolver(store ResourceStoreInterface) {
9595
}
9696
return context, found || context.MaintenanceEndAt != nil
9797
})
98+
// Alerts restore before the resource store is attached during startup.
99+
// Reconcile that restored set as soon as persisted policy is available.
100+
if m.alertManager.ReconcileOperatorIntentState() > 0 && m.state != nil {
101+
m.SyncAlertState()
102+
}
98103
}
99104

100105
func (m *Monitor) resolveBackupIntentContext(_ string, instance, node string, vmid int, now time.Time) (alerts.BackupIntentContext, bool) {

‎internal/monitoring/monitor_alert_intent_test.go‎

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,60 @@ func TestInstallOperatorIntentResolverProjectsCanonicalResourcePolicy(t *testing
3939
}
4040
}
4141

42+
func TestProxmoxPhysicalDiskMuteResolvesAndSuppressesWearoutAlert(t *testing.T) {
43+
store := unifiedresources.NewMemoryStore()
44+
registry := unifiedresources.NewRegistry(store)
45+
instance, node := "pve", "rocket"
46+
makeDisk := func(path string) models.PhysicalDisk {
47+
return models.PhysicalDisk{
48+
ID: unifiedresources.ProxmoxPhysicalDiskSourceID(instance, node, path, "", ""),
49+
Instance: instance, Node: node, DevPath: path,
50+
Model: "KINGSTON SA400", Type: "ssd", Health: "PASSED", Wearout: 0,
51+
LastChecked: time.Now().UTC(),
52+
}
53+
}
54+
registry.IngestSnapshot(models.StateSnapshot{
55+
PhysicalDisks: []models.PhysicalDisk{makeDisk("/dev/sda"), makeDisk("/dev/sdb")},
56+
})
57+
resolver := unifiedresources.NewMonitorAdapter(registry)
58+
diskID := unifiedresources.ProxmoxPhysicalDiskAlertResourceID(instance, node, "/dev/sda")
59+
canonicalID, found := resolver.ResolveCanonicalResourceID(diskID)
60+
if !found {
61+
t.Fatalf("PVE wearout alert resource %q did not resolve to a physical disk", diskID)
62+
}
63+
otherID := unifiedresources.ProxmoxPhysicalDiskAlertResourceID(instance, node, "/dev/sdb")
64+
if other, ok := resolver.ResolveCanonicalResourceID(otherID); !ok || other == canonicalID {
65+
t.Fatalf("other PVE disk identity = %q, %v; want a different disk", other, ok)
66+
}
67+
68+
manager := alerts.NewManagerWithDataDir(t.TempDir())
69+
t.Cleanup(manager.Stop)
70+
worn := proxmox.Disk{DevPath: "/dev/sda", Model: "KINGSTON SA400", Type: "ssd", Health: "PASSED", Wearout: 0}
71+
manager.CheckDiskHealth(instance, node, worn)
72+
if got := len(manager.GetActiveAlerts()); got != 1 {
73+
t.Fatalf("unmuted worn disk raised %d alerts, want one", got)
74+
}
75+
if err := store.SetResourceOperatorState(unifiedresources.ResourceOperatorState{
76+
CanonicalID: canonicalID, MonitoringMode: unifiedresources.MonitoringModeMuted,
77+
}); err != nil {
78+
t.Fatal(err)
79+
}
80+
monitor := &Monitor{alertManager: manager}
81+
monitor.installOperatorIntentResolver(resolver)
82+
if got := len(manager.GetActiveAlerts()); got != 0 {
83+
t.Fatalf("mute left %d existing PVE wearout alerts active", got)
84+
}
85+
manager.CheckDiskHealth(instance, node, worn)
86+
if got := len(manager.GetActiveAlerts()); got != 0 {
87+
t.Fatalf("muted PVE disk raised %d new wearout alerts", got)
88+
}
89+
worn.DevPath = "/dev/sdb"
90+
manager.CheckDiskHealth(instance, node, worn)
91+
if got := len(manager.GetActiveAlerts()); got != 1 {
92+
t.Fatalf("other PVE disk raised %d alerts, want one", got)
93+
}
94+
}
95+
4296
func TestInstallOperatorIntentResolverInheritsScopedMaintenanceFromParent(t *testing.T) {
4397
store := unifiedresources.NewMemoryStore()
4498
registry := unifiedresources.NewRegistry(store)

‎internal/unifiedresources/canonical_identity.go‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,16 @@ func canonicalAliases(resource Resource, primaryID, platformID, hostname string)
117117
strings.TrimSpace(resource.Proxmox.NodeName),
118118
)
119119
values = append(values, resource.Proxmox.NodeAliases...)
120+
// PVE disk alerts predate the unified resource registry and retain a
121+
// path-shaped resource reference. Resolve it to this exact physical
122+
// disk so a UI mute reaches both new and restored occurrences (#2112).
123+
if CanonicalResourceType(resource.Type) == ResourceTypePhysicalDisk && resource.PhysicalDisk != nil &&
124+
strings.TrimSpace(resource.Proxmox.Instance) != "" && strings.TrimSpace(resource.Proxmox.NodeName) != "" &&
125+
strings.TrimSpace(resource.PhysicalDisk.DevPath) != "" {
126+
values = append(values, ProxmoxPhysicalDiskAlertResourceID(
127+
resource.Proxmox.Instance, resource.Proxmox.NodeName, resource.PhysicalDisk.DevPath,
128+
))
129+
}
120130
}
121131

122132
return uniqueTrimmed(values...)

‎internal/unifiedresources/canonical_identity_test.go‎

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,64 @@ import (
88
"github.com/rcourtman/pulse-go-rewrite/internal/models"
99
)
1010

11+
func TestProxmoxPhysicalDiskAlertAliasIsScopedToDisk(t *testing.T) {
12+
alertRef := ProxmoxPhysicalDiskAlertResourceID("pve", "rocket", "/dev/sda")
13+
cases := []struct {
14+
name string
15+
resource Resource
16+
want bool
17+
}{
18+
{
19+
name: "matching physical disk",
20+
resource: Resource{ID: "source-disk", Type: ResourceTypePhysicalDisk,
21+
Proxmox: &ProxmoxData{Instance: "pve", NodeName: "rocket"},
22+
PhysicalDisk: &PhysicalDiskMeta{DevPath: "/dev/sda"}},
23+
want: true,
24+
},
25+
{
26+
name: "different disk path",
27+
resource: Resource{ID: "other-disk", Type: ResourceTypePhysicalDisk,
28+
Proxmox: &ProxmoxData{Instance: "pve", NodeName: "rocket"},
29+
PhysicalDisk: &PhysicalDiskMeta{DevPath: "/dev/sdb"}},
30+
},
31+
{
32+
name: "missing instance",
33+
resource: Resource{ID: "no-instance", Type: ResourceTypePhysicalDisk,
34+
Proxmox: &ProxmoxData{NodeName: "rocket"},
35+
PhysicalDisk: &PhysicalDiskMeta{DevPath: "/dev/sda"}},
36+
},
37+
{
38+
name: "missing device path",
39+
resource: Resource{ID: "no-path", Type: ResourceTypePhysicalDisk,
40+
Proxmox: &ProxmoxData{Instance: "pve", NodeName: "rocket"},
41+
PhysicalDisk: &PhysicalDiskMeta{}},
42+
},
43+
{
44+
name: "non-disk resource",
45+
resource: Resource{ID: "vm", Type: ResourceTypeVM,
46+
Proxmox: &ProxmoxData{Instance: "pve", NodeName: "rocket"},
47+
PhysicalDisk: &PhysicalDiskMeta{DevPath: "/dev/sda"}},
48+
},
49+
}
50+
for _, tc := range cases {
51+
t.Run(tc.name, func(t *testing.T) {
52+
RefreshCanonicalIdentity(&tc.resource)
53+
if tc.resource.Canonical == nil {
54+
t.Fatal("canonical identity missing")
55+
}
56+
found := false
57+
for _, alias := range tc.resource.Canonical.Aliases {
58+
if alias == alertRef {
59+
found = true
60+
}
61+
}
62+
if found != tc.want {
63+
t.Fatalf("alert alias %q present = %t, want %t; aliases = %v", alertRef, found, tc.want, tc.resource.Canonical.Aliases)
64+
}
65+
})
66+
}
67+
}
68+
1169
func TestRefreshCanonicalIdentityPrefersTargetsAndCanonicalHostData(t *testing.T) {
1270
resource := Resource{
1371
ID: "agent-1",

‎internal/unifiedresources/physical_disk_ids.go‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,42 @@ func ProxmoxPhysicalDiskSourceID(instance, node, device, controller, target stri
6464
return legacy
6565
}
6666

67+
// ProxmoxPhysicalDiskAlertResourceID is the persisted resource reference used
68+
// by PVE disk-health and wearout alerts. Keep this distinct from the disk's
69+
// source ID: existing alert occurrences use this shape, while the registry
70+
// needs it as an alias to apply per-disk operator intent.
71+
func ProxmoxPhysicalDiskAlertResourceID(instance, node, device string) string {
72+
return fmt.Sprintf("%s:%s:disk:%s", strings.TrimSpace(instance), strings.TrimSpace(node), physicalDiskAlertKey(device))
73+
}
74+
75+
func physicalDiskAlertKey(device string) string {
76+
trimmed := strings.TrimSpace(device)
77+
if trimmed == "/" {
78+
return "root"
79+
}
80+
trimmed = strings.Trim(trimmed, "/\\ ")
81+
if trimmed == "" {
82+
trimmed = "root"
83+
}
84+
var builder strings.Builder
85+
previousDash := false
86+
for _, r := range strings.ToLower(trimmed) {
87+
switch {
88+
case r >= 'a' && r <= 'z', r >= '0' && r <= '9', r == '.':
89+
builder.WriteRune(r)
90+
previousDash = false
91+
case !previousDash:
92+
builder.WriteByte('-')
93+
previousDash = true
94+
}
95+
}
96+
key := strings.Trim(builder.String(), "-.")
97+
if key == "" {
98+
return "disk"
99+
}
100+
return key
101+
}
102+
67103
func PhysicalDiskMetricID(disk models.PhysicalDisk) string {
68104
if diskinventory.IsUsableHardwareID(disk.Serial) || diskinventory.IsUsableHardwareID(disk.WWN) {
69105
return PreferredPhysicalDiskMetricID(disk.Serial, disk.WWN, "")

0 commit comments

Comments
 (0)