Review fixes: demo fans, record averages and restarts, combined alerts, quiet sensors
- demo.py: FakeBoard grows rpms(). The top fans' stall check (b2da221) called
it, so under --demo every poll raised AttributeError and the case fans sat
in CONTROL ERROR at 100%.
- control.py: TopFanCurve.update hands the headers back to the BIOS on any
failure, a bug included, instead of letting it escape into the case fans'
loop (unexpected errors are logged with a traceback once). The worker's
catch-all now fails the top fans safe as well as the case fans, as the
device-error path already did. The snapshot gives None for a channel whose
tach has never turned, and the UI says "no tach reading" (and "Channel",
not "Port") rather than showing SYS_FAN1's unwired tach as a dead fan.
- record.py: an hour's average is over the samples that carried the metric,
not all of them: a GPU that dropped out for half an hour no longer halves
its recorded power. Lines carry the count as a fourth number; the reader
weights by it, and treats three-number lines as before.
- record.py: the hour in progress is checkpointed to records-current.json
every minute and on close and resumed at start, so a hard stop (schtasks
/End, the documented restart) loses at most a minute instead of the hour;
a checkpoint from an earlier hour is written out at start. A failing write
no longer stops recording for the run: it is logged at most once an hour
and finished hours wait in memory (up to 48) until the disk works.
- app.py: alerts that start together share one balloon (Windows shows one at
a time, so each notify() replaced the last), shortened to fit 255
characters; a problem that clears and comes back balloons again only after
10 minutes.
- telemetry/service.py: health also counts a source that returns no
temperature three reads running. GpuSensors and CpuSensors don't raise
when their device is lost, so a lost GPU driver used to show as healthy.
- hid.py: buffers of IRPs the driver never finished cancelling are kept for
the life of the process; freeing them with their channel could still let a
late completion write into reused memory.
- Tests: 13 new (160 pass). README updated to match.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
8cc1e9223f
commit
b983528183
12 files changed
+394
-73
No files matched your search
+74
-13
@@ -3,6 +3,7 @@ import os
|
||||
import tempfile
|
||||
import time
|
||||
import unittest
|
||||
from unittest.mock import patch
|
||||
|
||||
from kurgan.telemetry.readings import PowerReadings, Readings
|
||||
from kurgan.telemetry.record import Recorder, load
|
||||
@@ -19,43 +20,92 @@ def sample(t, cpu_temp=50.0, gpu_temp=None, vram=None, cpu_w=30.0, gpu_w=80.0, o
|
||||
def written(directory):
|
||||
rows = []
|
||||
for name in sorted(os.listdir(directory)):
|
||||
if not name.endswith(".jsonl"):
|
||||
continue # records-current.json is the checkpoint of the hour in progress
|
||||
with open(os.path.join(directory, name), encoding="utf-8") as f:
|
||||
rows += [json.loads(line) for line in f if line.strip()]
|
||||
return rows
|
||||
|
||||
|
||||
def at(t):
|
||||
"""Pretend the wall clock reads t (the recorder decides at startup whether its checkpoint is this hour)."""
|
||||
return patch("kurgan.telemetry.record.time.time", return_value=t)
|
||||
|
||||
|
||||
class RecorderTest(unittest.TestCase):
|
||||
def test_an_hour_is_written_when_it_ends(self):
|
||||
with tempfile.TemporaryDirectory() as d:
|
||||
rec = Recorder(d)
|
||||
rec.on_sample(sample(HOUR + 1))
|
||||
rec.on_sample(sample(HOUR + 3599, cpu_temp=70.0))
|
||||
rec.on_sample(sample(HOUR + 3600, cpu_temp=40.0)) # the new hour flushes the old one
|
||||
rec.close() # ... and closing writes the hour still in progress
|
||||
rec.on_sample(sample(HOUR + 3600, cpu_temp=40.0)) # the new hour writes the old one
|
||||
rec.close() # ... and closing checkpoints the hour still in progress
|
||||
month = time.strftime("%Y-%m", time.gmtime(HOUR))
|
||||
self.assertEqual(os.listdir(d), [f"records-{month}.jsonl"])
|
||||
self.assertEqual(sorted(os.listdir(d)), [f"records-{month}.jsonl", "records-current.json"])
|
||||
rows = written(d)
|
||||
self.assertEqual(len(rows), 2)
|
||||
first, second = rows
|
||||
self.assertEqual(len(rows), 1)
|
||||
first = rows[0]
|
||||
self.assertEqual((first["hour"], first["n"]), (HOUR, 2))
|
||||
self.assertEqual(first["cpu_temp"], [50.0, 60.0, 70.0]) # min, avg, max
|
||||
self.assertEqual(first["total_w"], [130.0, 130.0, 130.0]) # 30 + 80 + 20 W every sample
|
||||
self.assertEqual(first["cpu_temp"], [50.0, 60.0, 70.0, 2]) # min, avg, max, samples
|
||||
self.assertEqual(first["total_w"], [130.0, 130.0, 130.0, 2]) # 30 + 80 + 20 W every sample
|
||||
self.assertIsNone(first["gpu_temp"]) # a metric no sample carried stays null ...
|
||||
self.assertIsNone(first["vram_used"])
|
||||
self.assertEqual((second["hour"], second["n"], second["cpu_temp"]), (HOUR + 3600, 1, [40.0, 40.0, 40.0]))
|
||||
|
||||
def test_a_failing_disk_stops_recording_quietly(self):
|
||||
def test_an_average_counts_only_the_samples_that_had_the_metric(self):
|
||||
with tempfile.TemporaryDirectory() as d:
|
||||
rec = Recorder(d)
|
||||
rec.on_sample(sample(HOUR + 1, gpu_w=80.0))
|
||||
rec.on_sample(sample(HOUR + 2, gpu_w=None)) # the GPU's power reading dropped out
|
||||
rec.on_sample(sample(HOUR + 3, gpu_w=100.0))
|
||||
rec.on_sample(sample(HOUR + 3600))
|
||||
row = written(d)[0]
|
||||
self.assertEqual(row["n"], 3)
|
||||
self.assertEqual(row["gpu_w"], [80.0, 90.0, 100.0, 2]) # not 60: the gap isn't a zero
|
||||
|
||||
def test_a_hard_stop_loses_at_most_a_minute(self):
|
||||
with tempfile.TemporaryDirectory() as d:
|
||||
with at(HOUR + 1):
|
||||
first = Recorder(d)
|
||||
first.on_sample(sample(HOUR + 1, cpu_temp=40.0))
|
||||
first.on_sample(sample(HOUR + 61, cpu_temp=60.0)) # checkpointed; then killed, no close()
|
||||
with at(HOUR + 300):
|
||||
second = Recorder(d) # the same hour: carries on with it
|
||||
second.on_sample(sample(HOUR + 301, cpu_temp=80.0))
|
||||
second.on_sample(sample(HOUR + 3600))
|
||||
rows = written(d)
|
||||
self.assertEqual(len(rows), 1)
|
||||
self.assertEqual((rows[0]["n"], rows[0]["cpu_temp"]), (3, [40.0, 60.0, 80.0, 3]))
|
||||
|
||||
def test_a_checkpoint_from_an_earlier_hour_is_written_at_start(self):
|
||||
with tempfile.TemporaryDirectory() as d:
|
||||
with at(HOUR + 1):
|
||||
first = Recorder(d)
|
||||
first.on_sample(sample(HOUR + 1))
|
||||
first.close()
|
||||
self.assertEqual(written(d), [])
|
||||
with at(HOUR + 7200):
|
||||
Recorder(d)
|
||||
rows = written(d)
|
||||
self.assertNotIn("records-current.json", os.listdir(d))
|
||||
with at(HOUR + 7300):
|
||||
Recorder(d) # nothing left to write a second time
|
||||
self.assertEqual(written(d), rows)
|
||||
self.assertEqual([(r["hour"], r["n"]) for r in rows], [(HOUR, 1)])
|
||||
|
||||
def test_a_failing_disk_is_logged_once_and_catches_up_when_it_recovers(self):
|
||||
with tempfile.TemporaryDirectory() as d:
|
||||
blocked = os.path.join(d, "blocked")
|
||||
open(blocked, "w").close()
|
||||
rec = Recorder(blocked) # the "directory" is a file: every write fails
|
||||
with self.assertLogs("kurgan.telemetry.record", level="WARNING") as logs:
|
||||
rec.on_sample(sample(HOUR))
|
||||
rec.on_sample(sample(HOUR + 3600)) # the hour boundary is where the write fails
|
||||
rec.on_sample(sample(HOUR + 7200)) # already stopped: nothing happens, nothing raised
|
||||
rec.close()
|
||||
self.assertTrue(rec._stopped)
|
||||
rec.on_sample(sample(HOUR + 3600)) # the hour can't be written: it waits
|
||||
rec.on_sample(sample(HOUR + 7200))
|
||||
self.assertEqual(len(logs.output), 1)
|
||||
os.remove(blocked)
|
||||
os.makedirs(blocked) # the disk is back
|
||||
rec.on_sample(sample(HOUR + 10800))
|
||||
self.assertEqual([r["hour"] for r in written(blocked)], [HOUR, HOUR + 3600, HOUR + 7200])
|
||||
|
||||
def test_pruning_removes_months_older_than_the_retention(self):
|
||||
with tempfile.TemporaryDirectory() as d:
|
||||
@@ -87,6 +137,17 @@ class LoadTest(unittest.TestCase):
|
||||
self.assertEqual(row["cpu_temp"], [30.0, 42.5, 80.0]) # min, sample-weighted avg, max
|
||||
self.assertIsNone(row.get("total_w"))
|
||||
|
||||
def test_load_weights_averages_by_the_samples_that_had_the_metric(self):
|
||||
h = int(time.time() // 3600) * 3600
|
||||
with tempfile.TemporaryDirectory() as d:
|
||||
path = os.path.join(d, f"records-{time.strftime('%Y-%m', time.gmtime(h))}.jsonl")
|
||||
with open(path, "w", encoding="utf-8") as f:
|
||||
f.write(json.dumps({"hour": h, "n": 3000, "gpu_w": [50.0, 100.0, 150.0, 3000]}) + "\n")
|
||||
f.write(json.dumps({"hour": h, "n": 600, "gpu_w": [10.0, 40.0, 70.0, 100]}) + "\n") # the GPU dropped out
|
||||
row = load(d, days=1)["rows"][0]
|
||||
self.assertEqual(row["n"], 3600)
|
||||
self.assertEqual([round(v, 2) for v in row["gpu_w"]], [10.0, 98.06, 150.0]) # (100*3000 + 40*100) / 3100
|
||||
|
||||
def test_load_without_a_directory_is_empty(self):
|
||||
data = load(os.path.join(tempfile.gettempdir(), "kurgan-no-such-records-dir"), 7)
|
||||
self.assertEqual(data["rows"], [])
|
||||
|
||||
Reference in new issue
Block a user