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.

Record the wearout evidence boundary in contracts and proofs

rcourtmand82d3bd6273b
diff --git a/docs/release-control/v6/internal/subsystems/agent-lifecycle.md b/docs/release-control/v6/internal/subsystems/agent-lifecycle.md
index 81d0fb3806..17445fea06 100644
--- a/docs/release-control/v6/internal/subsystems/agent-lifecycle.md
+++ b/docs/release-control/v6/internal/subsystems/agent-lifecycle.md
@@ -47,6 +47,13 @@ decoded JSON byte ceilings, derives the 80% early-warning boundaries, and
generates the operator-facing limit description consumed by server ingress
and every supported `pulse-agent` release target built from this source.
+
+Physical-disk evidence collected by a host agent must survive projection back
+into monitoring's models. Absent evidence has to carry its declared sentinel
+rather than a zero value that reads as a real measurement: an absent
+physical-disk view projects `Wearout` as `unifiedresources.WearoutUnreported`,
+never `0`, which would announce a spent disk the agent never reported.
+
## Canonical Files
1. `internal/api/agent_install_command_shared.go`
diff --git a/docs/release-control/v6/internal/subsystems/alerts.md b/docs/release-control/v6/internal/subsystems/alerts.md
index e908f52336..8170bc5161 100644
--- a/docs/release-control/v6/internal/subsystems/alerts.md
+++ b/docs/release-control/v6/internal/subsystems/alerts.md
@@ -51,6 +51,16 @@ start, clear, or match a custom metric filter. Alert units remain MiB/s at the
threshold boundary (`bytes/s / 1024 / 1024`); that display/threshold conversion
must not be applied to the upstream cumulative-counter divisor.
+
+Disk wearout is an evidence boundary, not a plain threshold. The field carries
+two distinct absent states and one real zero: `-1` is the canonical unreported
+sentinel, and `0` is genuine evidence only from a device that reports endurance
+at all. Rotational disks never do, so a `0` from one is absence. Alert
+evaluation must gate on `storagehealth.WearoutReported` rather than carrying its
+own inline boundary. A wearout arm keyed on `> 0` silently exempts the single
+worst reading a disk can publish, which let a spent SSD read critical on the
+Physical Disks surface while raising no alert at all.
+
## Canonical Files
1. `internal/alerts/specs/types.go`
diff --git a/docs/release-control/v6/internal/subsystems/frontend-primitives.md b/docs/release-control/v6/internal/subsystems/frontend-primitives.md
index 3fa656f3ba..3906805ecd 100644
--- a/docs/release-control/v6/internal/subsystems/frontend-primitives.md
+++ b/docs/release-control/v6/internal/subsystems/frontend-primitives.md
@@ -23,6 +23,14 @@
Own reusable frontend primitives and canonical page-shell patterns so feature
work extends shared components instead of creating new local variants.
+
+Presentation helpers that mirror a server-side classification must name the
+predicate they mirror and expose it as a single exported function rather than
+inlining the boundary at each call site. `isPhysicalDiskWearoutReported` mirrors
+`storagehealth.WearoutReported`, and both the health-status and life-column
+helpers gate on it, so a wearout reading cannot be classified one way in a
+status label and another way in the cell beside it.
+
## Canonical Files
1. `frontend-modern/src/components/shared/`
diff --git a/docs/release-control/v6/internal/subsystems/monitoring.md b/docs/release-control/v6/internal/subsystems/monitoring.md
index 8671f4b195..4f76172e64 100644
--- a/docs/release-control/v6/internal/subsystems/monitoring.md
+++ b/docs/release-control/v6/internal/subsystems/monitoring.md
@@ -226,6 +226,16 @@ Cluster display names are not global identity: config consolidation requires
overlapping endpoint authority, and different provider instances with the same
cluster/member names stay distinct in node and storage identity.
+
+Storage risk assessment owns the wearout evidence boundary for every consumer.
+`storagehealth.WearoutReported` is the single authority for whether a wearout
+reading is evidence: `-1` is unreported, a positive value is always evidence,
+and `0` is evidence only from a non-rotational device. Callers must not
+recompute that boundary inline. Read-state projection of physical disks must
+also preserve the unreported sentinel rather than collapsing an absent facet
+onto the struct zero value, because `0` is a real reading meaning no endurance
+remains.
+
## Canonical Files
1. `internal/monitoring/monitor.go`
diff --git a/docs/release-control/v6/internal/subsystems/storage-recovery.md b/docs/release-control/v6/internal/subsystems/storage-recovery.md
index bbba81d8d9..3fabcd12bd 100644
--- a/docs/release-control/v6/internal/subsystems/storage-recovery.md
+++ b/docs/release-control/v6/internal/subsystems/storage-recovery.md
@@ -50,6 +50,21 @@ Search includes both presentation and native diagnostics, duplicate display
values are allowed, and clearing an override deterministically restores the
current native node name.
+
+Physical-disk to node association is evidence-directional. A disk reported by a
+host agent carries no Proxmox scope, so its instance is empty and the matching
+node name is the only evidence available; that match must stand. A disk that
+does carry a Proxmox instance belongs only to a node in the same instance and
+must not attach to a node outside it, including a node with no instance at all.
+Requiring an instance on both sides drops every agent-reported disk off the
+Proxmox node it physically lives on, emptying the node filter, breaking per-node
+grouping, and stranding metric target resolution.
+
+The Physical Disks surface reads wearout through the same evidence boundary the
+server applies. `-1` is unreported and renders as a muted placeholder, a `0`
+from an endurance-reporting device is a spent disk and renders critical, and a
+`0` from a rotational or untyped disk is absence rather than a fault.
+
## Canonical Files
1. `internal/recovery/index.go`
diff --git a/docs/release-control/v6/internal/subsystems/unified-resources.md b/docs/release-control/v6/internal/subsystems/unified-resources.md
index 696d8b26f5..19ee51c8e7 100644
--- a/docs/release-control/v6/internal/subsystems/unified-resources.md
+++ b/docs/release-control/v6/internal/subsystems/unified-resources.md
@@ -104,6 +104,16 @@ NVMe percentage-used conversion is shared with storage risk: negative values
remain unknown, while values above 100 clamp to exhausted before remaining
life is derived.
+
+`WearoutUnreported` is the canonical absent-value sentinel for
+`PhysicalDiskMeta.Wearout` and is pinned to `-1`. Views and adapters must return
+it whenever a resource carries no physical-disk facet; returning the Go zero
+value publishes "no endurance remaining" for a disk that reported nothing, and
+downstream risk, presentation, and alert consumers cannot recover the
+distinction afterwards. The unified risk projection gates wearout on
+`storagehealth.WearoutReported` so its verdict and the server-side alert verdict
+about the same disk cannot diverge.
+
## Canonical Files
1. `internal/unifiedresources/types.go`
diff --git a/frontend-modern/src/features/storageBackups/__tests__/diskPresentation.test.ts b/frontend-modern/src/features/storageBackups/__tests__/diskPresentation.test.ts
index 95eb6c27af..55442305ba 100644
--- a/frontend-modern/src/features/storageBackups/__tests__/diskPresentation.test.ts
+++ b/frontend-modern/src/features/storageBackups/__tests__/diskPresentation.test.ts
@@ -13,6 +13,7 @@ import {
PHYSICAL_DISK_HEADER_DEVICE_CLASS,
PHYSICAL_DISK_HEADER_DISK_CLASS,
PHYSICAL_DISK_HEADER_LIFE_CLASS,
+ PHYSICAL_DISK_MUTED_PLACEHOLDER_CLASS,
PHYSICAL_DISK_NAME_TEXT_CLASS,
PHYSICAL_DISK_SOURCE_BADGE_CLASS,
PHYSICAL_DISK_TABLE_CLASS,
@@ -34,6 +35,7 @@ import {
getPhysicalDiskSourceBadgePresentation,
hasUnraidPhysicalDiskFaultSignal,
hasPhysicalDiskSmartWarning,
+ isPhysicalDiskWearoutReported,
isUnraidPhysicalDisk,
matchesPhysicalDiskSearch,
normalizePhysicalDiskFacetFilter,
@@ -443,3 +445,38 @@ describe('diskPresentation', () => {
).toEqual([]);
});
});
+
+describe('wearout evidence boundary', () => {
+ // Mirrors storagehealth.WearoutReported on the server. The Physical Disks
+ // view and the alert path have to agree about the same disk, so both gate on
+ // this predicate rather than each picking their own boundary.
+ it('treats -1 as unreported and a real 0 as evidence only from endurance-reporting devices', () => {
+ expect(isPhysicalDiskWearoutReported(makeDiskData({ wearout: -1, type: 'ssd' }))).toBe(false);
+ expect(isPhysicalDiskWearoutReported(makeDiskData({ wearout: 0, type: 'ssd' }))).toBe(true);
+ expect(isPhysicalDiskWearoutReported(makeDiskData({ wearout: 0, type: 'NVMe' }))).toBe(true);
+ expect(isPhysicalDiskWearoutReported(makeDiskData({ wearout: 0, type: 'hdd' }))).toBe(false);
+ expect(isPhysicalDiskWearoutReported(makeDiskData({ wearout: 0, type: '' }))).toBe(false);
+ expect(isPhysicalDiskWearoutReported(makeDiskData({ wearout: 42, type: 'hdd' }))).toBe(true);
+ });
+
+ it('flags a spent SSD but leaves a rotational zero alone', () => {
+ expect(
+ getPhysicalDiskHealthStatus(makeDiskData({ health: 'PASSED', wearout: 0, type: 'ssd' })).label,
+ ).toBe('Needs Attention');
+ expect(
+ getPhysicalDiskHealthStatus(makeDiskData({ health: 'PASSED', wearout: 0, type: 'hdd' })).label,
+ ).toBe('Healthy');
+ });
+
+ it('mutes the life column when there is no endurance evidence', () => {
+ expect(getPhysicalDiskLifeTextClass(makeDiskData({ wearout: -1, type: 'ssd' }))).toBe(
+ PHYSICAL_DISK_MUTED_PLACEHOLDER_CLASS,
+ );
+ expect(getPhysicalDiskLifeTextClass(makeDiskData({ wearout: 0, type: 'hdd' }))).toBe(
+ PHYSICAL_DISK_MUTED_PLACEHOLDER_CLASS,
+ );
+ expect(getPhysicalDiskLifeTextClass(makeDiskData({ wearout: 0, type: 'ssd' }))).toBe(
+ 'text-red-600 dark:text-red-400',
+ );
+ });
+});
diff --git a/internal/alerts/alerts_test.go b/internal/alerts/alerts_test.go
index a2ab356ed5..3497763578 100644
--- a/internal/alerts/alerts_test.go
+++ b/internal/alerts/alerts_test.go
@@ -19474,3 +19474,68 @@ func TestRecentlyResolvedCapsNewestEntries(t *testing.T) {
t.Fatal("newest recently resolved entry was pruned")
}
}
+
+// A disk reporting 0% endurance remaining is the worst reading the field can
+// carry, and it used to be the one reading that never alerted: the wearout arm
+// required Wearout > 0, so a spent SSD fell through as if it had reported
+// nothing while the Physical Disks view showed it critical. Alerting now gates
+// on the same storagehealth.WearoutReported predicate the risk projection uses.
+func TestCheckDiskHealthAlertsOnSpentSSD(t *testing.T) {
+ m := newTestManager(t)
+ m.ClearActiveAlerts()
+
+ disk := proxmox.Disk{
+ DevPath: "/dev/nvme0n1",
+ Model: "Generic NVMe 1TB",
+ Serial: "SPENT0000001",
+ Type: "nvme",
+ Health: "PASSED",
+ Wearout: 0,
+ Size: 1000204886016,
+ }
+
+ m.CheckDiskHealth("test-instance", "pve-node1", disk)
+
+ m.mu.RLock()
+ defer m.mu.RUnlock()
+ if !testHasActiveAlert(t, m, "disk-wearout-test-instance-pve-node1-/dev/nvme0n1") {
+ t.Fatal("an SSD reporting 0% life remaining must raise a wearout alert")
+ }
+}
+
+// -1 is the unreported sentinel and a rotational 0 means the device reports no
+// endurance at all. Neither is evidence, so neither may raise an alert.
+func TestCheckDiskHealthDoesNotAlertOnAbsentWearoutEvidence(t *testing.T) {
+ tests := []struct {
+ name string
+ diskType string
+ wearout int
+ }{
+ {"unreported sentinel on an nvme", "nvme", -1},
+ {"unreported sentinel on a rotational disk", "hdd", -1},
+ {"rotational disk reporting zero", "hdd", 0},
+ {"untyped disk reporting zero", "", 0},
+ }
+
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ m := newTestManager(t)
+ m.ClearActiveAlerts()
+
+ m.CheckDiskHealth("test-instance", "pve-node1", proxmox.Disk{
+ DevPath: "/dev/sda",
+ Model: "Generic Disk",
+ Serial: "ABSENT000001",
+ Type: tt.diskType,
+ Health: "PASSED",
+ Wearout: tt.wearout,
+ })
+
+ m.mu.RLock()
+ defer m.mu.RUnlock()
+ if testHasActiveAlert(t, m, "disk-wearout-test-instance-pve-node1-/dev/sda") {
+ t.Fatalf("absent wearout evidence (%s) must not raise a wearout alert", tt.name)
+ }
+ })
+ }
+}
diff --git a/internal/monitoring/monitor_host_agents_test.go b/internal/monitoring/monitor_host_agents_test.go
index 3962bab1b5..efa6b6329b 100644
--- a/internal/monitoring/monitor_host_agents_test.go
+++ b/internal/monitoring/monitor_host_agents_test.go
@@ -4206,3 +4206,14 @@ func TestRemoveHostAgentRetainsLastKnownPlatform(t *testing.T) {
t.Fatalf("removed record platform = %q, want OS-name fallback when Platform was never reported", got["removed-osname-host"])
}
}
+
+// Wearout 0 means no endurance remaining, so the absent case has to carry the
+// unreported sentinel rather than the struct zero value. The only production
+// call site filters nil views, but a zero-valued disk escaping this helper
+// would publish a spent disk that never existed.
+func TestPhysicalDiskFromReadStateView_AbsentViewReportsUnknownWearout(t *testing.T) {
+ disk := physicalDiskFromReadStateView(nil)
+ if disk.Wearout != unifiedresources.WearoutUnreported {
+ t.Fatalf("absent view wearout = %d, want %d", disk.Wearout, unifiedresources.WearoutUnreported)
+ }
+}
diff --git a/internal/storagehealth/risk.go b/internal/storagehealth/risk.go
index 49e6333dcd..eb0f026ecd 100644
--- a/internal/storagehealth/risk.go
+++ b/internal/storagehealth/risk.go
@@ -49,9 +49,9 @@ type Sample struct {
func AssessPhysicalDisk(disk models.PhysicalDisk) Assessment {
sample := Sample{
- Model: disk.Model,
- Health: disk.Health,
- Temperature: disk.Temperature,
+ Model: disk.Model,
+ Health: disk.Health,
+ Temperature: disk.Temperature,
Wearout: disk.Wearout,
WearoutKnown: WearoutReported(disk.Wearout, disk.Type),
}
diff --git a/internal/storagehealth/risk_test.go b/internal/storagehealth/risk_test.go
index 4f8ab6e731..c24217b1d8 100644
--- a/internal/storagehealth/risk_test.go
+++ b/internal/storagehealth/risk_test.go
@@ -436,3 +436,76 @@ func TestNormalizeHealth(t *testing.T) {
}
}
}
+
+// --- WearoutReported ---
+
+// Wearout has two distinct absent states and one real zero. -1 is the
+// canonical unreported sentinel, and 0 is genuine evidence only from a device
+// that reports endurance at all. Rotational disks never do, so a 0 from one is
+// absence rather than a spent disk. Every consumer gates on this single
+// predicate so the UI and the alert path cannot disagree about the same disk.
+func TestWearoutReported(t *testing.T) {
+ tests := []struct {
+ name string
+ wearout int
+ diskType string
+ expected bool
+ }{
+ {"unreported sentinel on an ssd", -1, "ssd", false},
+ {"unreported sentinel on an nvme", -1, "nvme", false},
+ {"unreported sentinel with no type", -1, "", false},
+ {"spent ssd reports zero", 0, "ssd", true},
+ {"spent nvme reports zero", 0, "nvme", true},
+ {"spent nvme reports zero regardless of case", 0, "NVMe", true},
+ {"rotational zero is absence, not a spent disk", 0, "hdd", false},
+ {"untyped zero is absence, not a spent disk", 0, "", false},
+ {"positive reading is evidence whatever the type", 5, "hdd", true},
+ {"full life is evidence", 100, "ssd", true},
+ }
+
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ if got := WearoutReported(tt.wearout, tt.diskType); got != tt.expected {
+ t.Errorf("WearoutReported(%d, %q) = %v, want %v", tt.wearout, tt.diskType, got, tt.expected)
+ }
+ })
+ }
+}
+
+// A spent SSD must reach the critical arm. Before the sentinel was unified,
+// WearoutKnown was computed inline and a 0 reading fell through as if the disk
+// had said nothing.
+func TestAssessPhysicalDisk_SpentSSDIsCritical(t *testing.T) {
+ assessment := AssessPhysicalDisk(models.PhysicalDisk{
+ Health: "PASSED",
+ Type: "ssd",
+ Wearout: 0,
+ })
+ if assessment.Level != RiskCritical {
+ t.Fatalf("spent SSD should assess critical, got %q", assessment.Level)
+ }
+}
+
+func TestAssessPhysicalDisk_UnreportedWearoutIsNotRisk(t *testing.T) {
+ for _, diskType := range []string{"ssd", "hdd", ""} {
+ assessment := AssessPhysicalDisk(models.PhysicalDisk{
+ Health: "PASSED",
+ Type: diskType,
+ Wearout: -1,
+ })
+ if assessment.Level == RiskCritical {
+ t.Errorf("unreported wearout on %q must not assess critical", diskType)
+ }
+ }
+}
+
+func TestAssessPhysicalDisk_RotationalZeroIsNotRisk(t *testing.T) {
+ assessment := AssessPhysicalDisk(models.PhysicalDisk{
+ Health: "PASSED",
+ Type: "hdd",
+ Wearout: 0,
+ })
+ if assessment.Level == RiskCritical {
+ t.Error("a rotational disk reporting 0 wearout reports no endurance at all and must not assess critical")
+ }
+}
diff --git a/internal/unifiedresources/canonical_ids_types_test.go b/internal/unifiedresources/canonical_ids_types_test.go
index f01e9625ac..d07f113772 100644
--- a/internal/unifiedresources/canonical_ids_types_test.go
+++ b/internal/unifiedresources/canonical_ids_types_test.go
@@ -501,3 +501,15 @@ func TestAgentMemoryMetaSerializesReclaimableCache(t *testing.T) {
t.Fatalf("cache should be omitted when unreported, got %s", empty)
}
}
+
+// WearoutUnreported is the one sentinel every layer agrees on. models.PhysicalDisk
+// and PhysicalDiskMeta both document wearout as "0-100, -1 unavailable", so the
+// constant must stay pinned to -1 rather than drifting onto a real percentage.
+func TestWearoutUnreportedSentinelIsNegativeOne(t *testing.T) {
+ if WearoutUnreported != -1 {
+ t.Fatalf("WearoutUnreported = %d, want -1", WearoutUnreported)
+ }
+ if WearoutUnreported >= 0 {
+ t.Fatal("the unreported sentinel must not fall inside the real 0-100 reporting range")
+ }
+}
diff --git a/internal/unifiedresources/physical_disk_risk.go b/internal/unifiedresources/physical_disk_risk.go
index 8ac5eb6587..2cb8007a46 100644
--- a/internal/unifiedresources/physical_disk_risk.go
+++ b/internal/unifiedresources/physical_disk_risk.go
@@ -80,9 +80,9 @@ func physicalDiskAssessmentFromMeta(meta *PhysicalDiskMeta) storagehealth.Assess
}
sample := storagehealth.Sample{
- Model: meta.Model,
- Health: meta.Health,
- Temperature: meta.Temperature,
+ Model: meta.Model,
+ Health: meta.Health,
+ Temperature: meta.Temperature,
Wearout: meta.Wearout,
WearoutKnown: storagehealth.WearoutReported(meta.Wearout, meta.DiskType),
}
diff --git a/internal/unifiedresources/registry_test.go b/internal/unifiedresources/registry_test.go
index 219602e930..2e2eacfdbb 100644
--- a/internal/unifiedresources/registry_test.go
+++ b/internal/unifiedresources/registry_test.go
@@ -5783,3 +5783,41 @@ func TestResourceRegistryClampsExhaustedSMARTWearout(t *testing.T) {
t.Fatalf("exhausted media risk = %+v, want critical", risk)
}
}
+
+// The unified-resource risk projection and the server-side alert path must
+// reach the same verdict about the same disk. Both now gate wearout on
+// storagehealth.WearoutReported instead of each carrying its own inline
+// boundary, which is how a spent SSD came to read critical in the UI while the
+// alert path stayed silent.
+func TestPhysicalDiskRiskProjectionUsesSharedWearoutPredicate(t *testing.T) {
+ tests := []struct {
+ name string
+ diskType string
+ wearout int
+ wantCritical bool
+ }{
+ {"spent ssd", "ssd", 0, true},
+ {"spent nvme", "nvme", 0, true},
+ {"rotational zero reports no endurance", "hdd", 0, false},
+ {"untyped zero reports no endurance", "", 0, false},
+ {"unreported sentinel", "ssd", -1, false},
+ {"healthy ssd", "ssd", 90, false},
+ }
+
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ meta := &PhysicalDiskMeta{Health: "PASSED", DiskType: tt.diskType, Wearout: tt.wearout}
+
+ assessment := physicalDiskAssessmentFromMeta(meta)
+ gotCritical := assessment.Level == storagehealth.RiskCritical
+ if gotCritical != tt.wantCritical {
+ t.Fatalf("risk level = %q, want critical=%v", assessment.Level, tt.wantCritical)
+ }
+
+ // The projection must agree with the predicate the alert path uses.
+ if storagehealth.WearoutReported(meta.Wearout, meta.DiskType) != (tt.wearout >= 0 && (tt.wearout > 0 || tt.diskType == "ssd" || tt.diskType == "nvme")) {
+ t.Fatal("projection and shared predicate disagree about whether this reading is evidence")
+ }
+ })
+ }
+}
diff --git a/internal/unifiedresources/views_test.go b/internal/unifiedresources/views_test.go
index d594e10a7c..302f591ed6 100644
--- a/internal/unifiedresources/views_test.go
+++ b/internal/unifiedresources/views_test.go
@@ -2133,3 +2133,33 @@ func TestViews_HostsIncludesVMwareInfrastructureResources(t *testing.T) {
t.Fatalf("MachineID() = %q, want uuid-host-1", got)
}
}
+
+// A view over a resource that carries no physical-disk facet has no endurance
+// evidence to publish. Returning the struct zero value here announced "0%
+// endurance remaining" for a disk that reported nothing, which the presentation
+// and alert layers then treated as a spent disk.
+func TestView_PhysicalDiskViewWearoutIsUnreportedWithoutFacet(t *testing.T) {
+ nilView := NewPhysicalDiskView(nil)
+ if got := nilView.Wearout(); got != WearoutUnreported {
+ t.Errorf("nil resource wearout = %d, want %d", got, WearoutUnreported)
+ }
+
+ facetlessView := NewPhysicalDiskView(&Resource{Type: ResourceTypePhysicalDisk})
+ if got := facetlessView.Wearout(); got != WearoutUnreported {
+ t.Errorf("resource without a physical-disk facet wearout = %d, want %d", got, WearoutUnreported)
+ }
+}
+
+// A real reading still passes through untouched, including a genuine 0 from a
+// device that does report endurance.
+func TestView_PhysicalDiskViewWearoutPassesThroughRealReadings(t *testing.T) {
+ for _, wearout := range []int{0, 1, 42, 100} {
+ v := NewPhysicalDiskView(&Resource{
+ Type: ResourceTypePhysicalDisk,
+ PhysicalDisk: &PhysicalDiskMeta{DiskType: "ssd", Wearout: wearout},
+ })
+ if got := v.Wearout(); got != wearout {
+ t.Errorf("wearout = %d, want %d", got, wearout)
+ }
+ }
+}