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.

Preserve reviewed sparse history with current disk-temperature consumers

pulse-triage[bot]152aacaa6a59
diff --cc internal/monitoring/monitor_metrics.go
index 78fef51c5e,1949f205f8..b4290380dd
--- a/internal/monitoring/monitor_metrics.go
+++ b/internal/monitoring/monitor_metrics.go
@@@ -353,8 -354,23 +353,12 @@@ func (m *Monitor) GetPhysicalDiskTemper
}
}
- // A live temperature is not two historical observations. Leave empty
- // or single-point histories intact instead of inventing a flat line.
- // Sparklines require >= 2 points. If the store returned 0 or 1 points
- // but the disk has a live temperature reading, pad to 2 points so the
- // chart can render (flat line at current temperature). A retained
- // last-known temperature (standby, a silent host agent) is not a
- // reading taken now, so the stored samples stay as they are and a
- // disk with none has no series.
- if len(tempPoints) < 2 {
- if d.collectedTemperature > 0 {
- now := time.Now()
- tempPoints = []MetricPoint{
- {Timestamp: now.Add(-60 * time.Second), Value: float64(d.collectedTemperature)},
- {Timestamp: now, Value: float64(d.collectedTemperature)},
- }
- } else if len(tempPoints) == 0 {
- continue
- }
++ // Neither a current nor a retained temperature is two historical
++ // observations. Keep single-point histories intact, and omit disks
++ // without stored samples instead of inventing a flat line.
++ if len(tempPoints) == 0 {
++ continue
+ }
result[d.resourceID] = DiskChartEntry{
Name: d.name,
diff --cc internal/monitoring/monitor_metrics_slo_test.go
index ca24b2cacb,cbd20fb9d6..5a5065e945
--- a/internal/monitoring/monitor_metrics_slo_test.go
+++ b/internal/monitoring/monitor_metrics_slo_test.go
@@@ -671,6 -672,50 +672,50 @@@ func TestSLO_GetPhysicalDiskTemperature
assertLatencySLO(t, "GetPhysicalDiskTemperatureCharts(native-history fallback)", latencies, target)
}
-// The disk temperature charts pad a short series to now with the disk's
-// current reading. A retained last-known temperature (a disk in standby, a host
-// agent past its reporting lease) is not a reading taken now: the samples
-// stored while the disk was live stay as they are, and a disk with none gets no
-// series rather than a flat line at the retained value.
-func TestDiskTemperatureChartsPadOnlyWithCollectedReading(t *testing.T) {
++// A temperature, current or retained, cannot supply historical timestamps.
++// Keep only observed samples, including single-point histories, and omit disks
++// with none. This composes upstream retained-value protection with the reviewed
++// sparse-history contract rather than restoring synthetic two-point padding.
++func TestDiskTemperatureChartsRetainOnlyObservedSamples(t *testing.T) {
+ now := time.Now().UTC()
+ standby := &diskinventory.CollectionStatus{Temperature: diskinventory.Unavailable("smartctl", "disk is in standby")}
+ silent := &diskinventory.CollectionStatus{Temperature: diskinventory.Unavailable("smartctl", models.HostAgentStoppedReportingReason)}
+ collected := &diskinventory.CollectionStatus{Temperature: diskinventory.Available("smartctl")}
+ registry := unifiedresources.NewRegistry(nil)
+ registry.IngestSnapshot(models.StateSnapshot{PhysicalDisks: []models.PhysicalDisk{
+ {ID: "disk-standby", Node: "node-a", DevPath: "/dev/sda", Model: "WDC WD80EFAX", Serial: "STANDBY-NO-HISTORY", Temperature: 41, Collection: standby, LastChecked: now},
+ {ID: "disk-silent", Node: "node-a", DevPath: "/dev/sdb", Model: "WDC WD80EFAX", Serial: "SILENT-ONE-SAMPLE", Temperature: 43, Collection: silent, LastChecked: now},
+ {ID: "disk-live", Node: "node-a", DevPath: "/dev/sdc", Model: "WDC WD80EFAX", Serial: "LIVE-NO-HISTORY", Temperature: 38, Collection: collected, LastChecked: now},
+ }})
+ m := &Monitor{
+ metricsHistory: NewMetricsHistory(1024, 24*time.Hour),
+ state: models.NewState(),
+ resourceStore: unifiedresources.NewMonitorAdapter(registry),
+ }
+ sampledAt := now.Add(-20 * time.Minute)
+ m.metricsHistory.AddDiskMetric("SILENT-ONE-SAMPLE", "smart_temp", 44, sampledAt)
+
+ charts := m.GetPhysicalDiskTemperatureCharts(time.Hour)
+ if entry, ok := charts["STANDBY-NO-HISTORY"]; ok {
+ t.Fatalf("a standby disk with no stored samples got a series from its retained reading: %+v", entry.Temperature)
+ }
+ silentEntry, ok := charts["SILENT-ONE-SAMPLE"]
+ if !ok || len(silentEntry.Temperature) != 1 || silentEntry.Temperature[0].Value != 44 ||
+ !silentEntry.Temperature[0].Timestamp.Equal(sampledAt) {
+ t.Fatalf("silent agent disk series = %+v (found %v), want only its stored 44C sample at %s", silentEntry.Temperature, ok, sampledAt)
+ }
+ live, ok := charts["LIVE-NO-HISTORY"]
- if !ok || len(live.Temperature) != 2 {
- t.Fatalf("live disk series = %+v (found %v), want the padded 2-point sparkline", live.Temperature, ok)
- }
- for _, point := range live.Temperature {
- if point.Value != 38 {
- t.Fatalf("live disk padded with %.0f, want its collected 38C", point.Value)
- }
++ if ok {
++ t.Fatalf("a live disk with no stored samples got fabricated history: %+v", live.Temperature)
++ }
++ m.metricsHistory.AddDiskMetric("LIVE-NO-HISTORY", "smart_temp", 37, sampledAt)
++ live, ok = m.GetPhysicalDiskTemperatureCharts(time.Hour)["LIVE-NO-HISTORY"]
++ if !ok || len(live.Temperature) != 1 || live.Temperature[0].Value != 37 ||
++ !live.Temperature[0].Timestamp.Equal(sampledAt) {
++ t.Fatalf("live disk series = %+v (found %v), want only its observed 37C sample at %s", live.Temperature, ok, sampledAt)
+ }
+ }
+
func TestSLO_GetDiskMetricsForChart_WithNativeStoreFallback(t *testing.T) {
skipMonitoringSLOUnderRace(t)
suppressMonitoringTestLogs(t)