mirror of
https://github.com/hasso5703/alzeo.git
synced 2026-12-05 12:24:28 +01:00
cockpit: a crash's kernel read is retried when it did not answer, and its window follows the crash
The journal read of crash_cause was guarded by answered() and the kernel one was not: a sudo journalctl that timed out was cached as no cause for the whole run. And the 15-minute window was anchored on the reading minute, so a cockpit that looked late, after its own restart or on a held lane, read the quarter-hour before its look and not the crash's. The unit's own state-change minute anchors it now, from the systemctl dict the cockpit already asks. 2 tests.
This commit is contained in:
1 parent
67fa296ff3
commit
bc03cc8812
2 files changed
+36
-9
No files matched your search
+12
-5
@@ -562,11 +562,14 @@ def _iso_epoch(line):
|
||||
return None
|
||||
|
||||
|
||||
def crash_cause(unit, invocation, now=None):
|
||||
def crash_cause(unit, invocation, now=None, ended=None):
|
||||
"""The known cause of the run `invocation` of `unit`, read once per run: its last 400 lines
|
||||
and the kernel's lines of the 15 minutes before (the same exact sudo argv collect_kernel
|
||||
uses). The matched line is shown with the API key masked, as the diagnostics bundle masks it."""
|
||||
and the kernel's lines of the 15 minutes around the minute it entered failed (the same exact
|
||||
sudo argv collect_kernel uses, the hour it can reach). `ended` is that minute: a cockpit
|
||||
that looks late still reads the minutes of the crash, not the minutes of the looking. The
|
||||
matched line is shown with the API key masked, as the diagnostics bundle masks it."""
|
||||
now = time.time() if now is None else now
|
||||
anchor = now if ended is None else ended
|
||||
seen = CRASH_CAUSE.get(unit)
|
||||
if seen and seen.get("invocation") == invocation:
|
||||
return seen
|
||||
@@ -580,8 +583,10 @@ def crash_cause(unit, invocation, now=None):
|
||||
return seen # a journal that did not answer is read again next tick
|
||||
lines = raw.splitlines()
|
||||
kern = run(["sudo", "-n", "/usr/bin/journalctl", "-k", "--since", "-1h", "--no-pager", "-o", "short-iso"], timeout=8)
|
||||
if not answered(kern):
|
||||
return seen # and so is a kernel log that did not answer
|
||||
kernel = [ln for ln in kern.splitlines()
|
||||
if (t := _iso_epoch(ln)) is not None and now - 900 <= t <= now + 60]
|
||||
if (t := _iso_epoch(ln)) is not None and anchor - 900 <= t <= anchor + 60]
|
||||
cause = mod.crash_cause(lines, kernel, data)
|
||||
key = api_key()
|
||||
if cause and cause.get("line") and key:
|
||||
@@ -1630,7 +1635,9 @@ def collect_lifecycle():
|
||||
elif st["state"] != "failed":
|
||||
CRASHED_SERVING.pop(unit, None)
|
||||
if st["state"] == "failed" and not is_image and not is_video:
|
||||
crash_cause(unit, d.get("InvocationID", ""))
|
||||
chg_us = int(d.get("StateChangeTimestampMonotonic") or 0)
|
||||
crash_cause(unit, d.get("InvocationID", ""),
|
||||
ended=time.time() - (monotonic_now() - chg_us / 1e6) if chg_us else None)
|
||||
crash = CRASH_CAUSE.get(unit)
|
||||
crash_age = time.time() - crash["at"] if crash else None
|
||||
# what the start guard said, when it is why the lane is not up (held, refused)
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
"""A text lane that stopped is told what is known about why (doctor.py's crash signatures).
|
||||
|
||||
Once per run: the run's own journal (its systemd invocation) and the kernel's lines of the 15
|
||||
minutes before, through the exact sudo argv collect_kernel uses. A journal that did not answer
|
||||
is read again; the API key never reaches the page; a doctor.py that does not load costs the
|
||||
cockpit nothing but the causes."""
|
||||
minutes around the minute it failed, through the exact sudo argv collect_kernel uses. A journal
|
||||
or a kernel log that did not answer is read again; the API key never reaches the page; a
|
||||
doctor.py that does not load costs the cockpit nothing but the causes."""
|
||||
import importlib.util
|
||||
import os
|
||||
import shutil
|
||||
@@ -59,6 +59,7 @@ class TheCrashCause(unittest.TestCase):
|
||||
f"{iso(self.now - 5)} gx10 kernel: NVRM: Xid (PCI:000f:01:00): 31, pid=4242, name=python3",
|
||||
"not a dated line"]
|
||||
self.journal_ok = True
|
||||
self.kernel_ok = True
|
||||
|
||||
def fake(argv, timeout=5.0, merge_err=False):
|
||||
self.calls.append(list(argv))
|
||||
@@ -66,7 +67,9 @@ class TheCrashCause(unittest.TestCase):
|
||||
r = self.cp.Ran("\n".join(self.journal) + "\n" if self.journal_ok else "")
|
||||
r.ok = self.journal_ok
|
||||
return r
|
||||
return self.cp.Ran("\n".join(self.kernel) + "\n")
|
||||
r = self.cp.Ran("\n".join(self.kernel) + "\n")
|
||||
r.ok = self.kernel_ok
|
||||
return r
|
||||
self.cp.run = fake
|
||||
|
||||
def test_a_known_cause_with_the_xid_of_the_same_minutes(self):
|
||||
@@ -107,6 +110,23 @@ class TheCrashCause(unittest.TestCase):
|
||||
self.assertEqual(self.cp.crash_cause("qwen38-flash.service", "inv-4", now=self.now)["cause"]["id"],
|
||||
"cublas-internal-error")
|
||||
|
||||
def test_a_kernel_log_that_did_not_answer_is_read_again(self):
|
||||
self.kernel_ok = False
|
||||
self.assertIsNone(self.cp.crash_cause("qwen38-flash.service", "inv-8", now=self.now))
|
||||
self.assertEqual(self.events, [], "no cause is claimed while the kernel log has not answered")
|
||||
self.kernel_ok = True
|
||||
rec = self.cp.crash_cause("qwen38-flash.service", "inv-8", now=self.now)
|
||||
self.assertEqual(rec["cause"]["id"], "cublas-internal-error")
|
||||
self.assertEqual(len(self.events), 1, "said once, when the kernel log answered")
|
||||
|
||||
def test_the_kernel_window_follows_the_crash_not_the_reading(self):
|
||||
self.kernel = [f"{iso(self.now - 1800)} gx10 kernel: NVRM: Xid (PCI:000f:01:00): 31, pid=4242, name=python3"]
|
||||
rec = self.cp.crash_cause("qwen38-sglang.service", "inv-9", now=self.now, ended=self.now - 1800)
|
||||
self.assertEqual(rec["cause"]["xids"], [31], "a late look finds the Xid of the crash minutes")
|
||||
self.cp.CRASH_CAUSE.clear()
|
||||
rec = self.cp.crash_cause("qwen38-sglang.service", "inv-10", now=self.now)
|
||||
self.assertEqual(rec["cause"]["xids"], [], "without a crash minute, the half-hour before the look is the rule")
|
||||
|
||||
def test_a_doctor_that_does_not_load_costs_only_the_causes(self):
|
||||
saved = list(self.cp._DOCTOR)
|
||||
self.cp._DOCTOR.clear()
|
||||
|
||||
Reference in new issue
Block a user