mirror of
https://github.com/rcourtman/Pulse.git
synced 2026-12-03 10:33:40 +01:00
Normalization may keep a disk temperature it did not collect (a disk in standby, a host agent past its reporting lease) as long as its collection state says so. Two consumers still presented that value as current. The metrics-history handler answered an empty disk range with the disk's temperature as a "live" point at now, regardless of its state. Since the history writers stopped recording retained temperatures, a short-range chart for a silent agent's disk or a sleeping disk showed the retained value as a fresh reading. Mock mode also seeded synthetic series from it and padded sparse stored series out to now. All of these now require a temperature collected now (diskinventory.TemperatureCollected, the shared form of the rule the history writers apply). Unraid array-inventory rows carry no per-field provenance, so a temperature taken from one looked collected after the agent went silent. The adapter now derives its state from the host lease that ExpireHostTelemetry already records, and from the disk's spin state: unavailable once the host is offline or the disk is spun down. A SMART row that borrows the inventory reading takes that state, including available. The native row records only the withdrawing states, because the registry merge picks temperature and state separately and an available claim from it would mask the SMART row's own state. A withdrawn inventory temperature no longer counts as heat in disk risk.
90 lines
3.6 KiB
Go
90 lines
3.6 KiB
Go
package diskinventory
|
|
|
|
import "testing"
|
|
|
|
func TestMergeStatusPrefersAvailableEvidencePerField(t *testing.T) {
|
|
existing := &CollectionStatus{
|
|
Serial: Available("smartctl"),
|
|
Temperature: Unavailable("smartctl", "deadline exceeded"),
|
|
}
|
|
incoming := &CollectionStatus{
|
|
Serial: Unsupported("provider", "not exposed"),
|
|
Temperature: Available("provider"),
|
|
IO: Missing("kernel", "counter absent"),
|
|
}
|
|
|
|
got := MergeStatus(existing, incoming)
|
|
if got.Serial.State != FieldAvailable || got.Serial.Source != "smartctl" {
|
|
t.Fatalf("available serial evidence was downgraded: %+v", got.Serial)
|
|
}
|
|
if got.Temperature.State != FieldAvailable || got.Temperature.Source != "provider" {
|
|
t.Fatalf("available temperature evidence did not win: %+v", got.Temperature)
|
|
}
|
|
if got.IO.State != FieldMissing {
|
|
t.Fatalf("missing I/O state was not retained: %+v", got.IO)
|
|
}
|
|
}
|
|
|
|
func TestMergeReportedStatusLetsTheSourceWithdrawItsOwnAvailability(t *testing.T) {
|
|
existing := &CollectionStatus{
|
|
Serial: Available("smartctl"),
|
|
Temperature: Available("smartctl"),
|
|
IO: Available("kernel_diskstats"),
|
|
Pool: Available("proxmox_zfs"),
|
|
}
|
|
reported := &CollectionStatus{
|
|
Serial: Available("smartctl"),
|
|
Temperature: Unavailable("smartctl", "host agent stopped reporting"),
|
|
IO: Unavailable("kernel_diskstats", "host agent stopped reporting"),
|
|
Pool: Unavailable("zpool", "command failed"),
|
|
}
|
|
|
|
got := MergeReportedStatus(existing, reported)
|
|
if got.Temperature != reported.Temperature || got.IO != reported.IO {
|
|
t.Fatalf("the source's later word on its own fields was ignored: %+v", got)
|
|
}
|
|
if got.Serial != Available("smartctl") {
|
|
t.Fatalf("still-available field changed: %+v", got.Serial)
|
|
}
|
|
if got.Pool != Available("proxmox_zfs") {
|
|
t.Fatalf("another source's available evidence was withdrawn: %+v", got.Pool)
|
|
}
|
|
|
|
// A copy that is already weaker never overrides a current report, and the
|
|
// rule is plain MergeStatus when either side is absent.
|
|
if got := MergeReportedStatus(reported, existing); got.Temperature != Available("smartctl") {
|
|
t.Fatalf("current report lost to a weaker copy: %+v", got.Temperature)
|
|
}
|
|
if got := MergeReportedStatus(nil, reported); got.Temperature != reported.Temperature {
|
|
t.Fatalf("nil existing: %+v", got)
|
|
}
|
|
if got := MergeReportedStatus(existing, nil); got.Temperature != existing.Temperature {
|
|
t.Fatalf("nil report: %+v", got)
|
|
}
|
|
if existing.Temperature != Available("smartctl") {
|
|
t.Fatal("MergeReportedStatus mutated its input")
|
|
}
|
|
}
|
|
|
|
func TestTemperatureCollectedOnlyForAReadingTakenByThisObservation(t *testing.T) {
|
|
for _, tc := range []struct {
|
|
name string
|
|
temperature int
|
|
status *CollectionStatus
|
|
want bool
|
|
}{
|
|
{"no reading", 0, &CollectionStatus{Temperature: Available("smartctl")}, false},
|
|
{"collected", 41, &CollectionStatus{Temperature: Available("smartctl")}, true},
|
|
{"predates collection state", 41, nil, true},
|
|
{"no temperature state", 41, &CollectionStatus{Serial: Available("smartctl")}, true},
|
|
{"retained in standby", 41, &CollectionStatus{Temperature: Unavailable("smartctl", "disk is in standby")}, false},
|
|
{"retained past the agent lease", 41, &CollectionStatus{Temperature: Unavailable("unraid", "host agent stopped reporting")}, false},
|
|
{"unsupported", 41, &CollectionStatus{Temperature: Unsupported("proxmox_disks", "not exposed")}, false},
|
|
{"missing", 41, &CollectionStatus{Temperature: Missing("smartctl", "attribute absent")}, false},
|
|
} {
|
|
if got := TemperatureCollected(tc.temperature, tc.status); got != tc.want {
|
|
t.Errorf("%s: TemperatureCollected = %v, want %v", tc.name, got, tc.want)
|
|
}
|
|
}
|
|
}
|