mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2026-11-29 06:17:25 +00:00
ci(deploy): sample host memory, pressure and top RSS into the rescue diagnostics
Deploy jobs killed by the deploy cap left no record of host memory or CPU pressure, so a slow job could not be told apart from a starved one. Every deploy matrix job now starts a background sampler that appends mem, load, PSI and the ten largest processes by RSS (pid, rss, comm only; never argv or env) to host-metrics.log in the rescue-diagnostics folder every 60 s, which the existing always() upload ships. report_failures now downloads each failed artifact into its own folder, because gh refuses to overwrite and the second artifact of a role was lost, and it reports 'no rescue snapshot' only when no artifact holds capture content below <distro>/<app>. Accepted MEDUSA false positive: B603 on the list-argv gh subprocess call in cli/meta/ci/report_failures.py. 🎯 Fix: 90 % 💥 Break: 3 % 💸 Cost: – ⏱️ Time: – 🛡️ Security: 100 % 🏆 Score: 87 🚦 Gate: ✅ 90/5, cost and time <= 100, security 100 % Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
be3458fa2d
commit
8458f8043a
5 files changed
+364
-3
No files matched your search
@@ -1,19 +1,116 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import subprocess
|
||||
import tempfile
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
from unittest.mock import patch
|
||||
|
||||
from cli.meta.ci.report_failures import (
|
||||
_NO_SNAPSHOT,
|
||||
Failure,
|
||||
_download_excerpt,
|
||||
artifact_name,
|
||||
decisive_excerpt,
|
||||
failed_roles,
|
||||
has_snapshot,
|
||||
issue_body,
|
||||
list_jobs,
|
||||
)
|
||||
|
||||
ROLE = "web-app-nextcloud"
|
||||
SWARM_0 = Failure("swarm", "0", "clearnet", "debian", "ext4", "amd64")
|
||||
SWARM_7 = Failure("swarm", "7", "clearnet", "debian", "ext4", "amd64")
|
||||
|
||||
|
||||
def _fake_gh(contents: dict[str, dict[str, str]]):
|
||||
"""Args:
|
||||
contents: artifact name -> {relative path: text} it extracts.
|
||||
|
||||
Returns a ``_gh`` stand-in that extracts like ``gh run download``: it
|
||||
refuses to overwrite a file and fails the call, and an unknown artifact
|
||||
fails too.
|
||||
"""
|
||||
|
||||
def gh(args: list[str]) -> str:
|
||||
name = args[args.index("-n") + 1]
|
||||
target = Path(args[args.index("-D") + 1])
|
||||
if name not in contents:
|
||||
raise subprocess.CalledProcessError(1, ["gh", *args])
|
||||
for rel, text in contents[name].items():
|
||||
path = target / rel
|
||||
path.parent.mkdir(parents=True, exist_ok=True)
|
||||
try:
|
||||
with path.open("x", encoding="utf-8") as handle:
|
||||
handle.write(text)
|
||||
except FileExistsError as exc:
|
||||
raise subprocess.CalledProcessError(1, ["gh", *args]) from exc
|
||||
return ""
|
||||
|
||||
return gh
|
||||
|
||||
|
||||
def _artifact(variant: str, error: str) -> dict[str, str]:
|
||||
return {
|
||||
"host-metrics.log": f"metrics of #{variant}\n",
|
||||
f"debian/{ROLE}/error-context.md": error,
|
||||
}
|
||||
|
||||
|
||||
class TestDownloadExcerpt(unittest.TestCase):
|
||||
def _download(self, contents: dict[str, dict[str, str]], dest: Path) -> str:
|
||||
with patch("cli.meta.ci.report_failures._gh", _fake_gh(contents)):
|
||||
return _download_excerpt("o/r", "1", ROLE, [SWARM_0, SWARM_7], dest)
|
||||
|
||||
def test_two_artifacts_of_one_role_are_both_extracted(self) -> None:
|
||||
names = [artifact_name(ROLE, SWARM_0), artifact_name(ROLE, SWARM_7)]
|
||||
with tempfile.TemporaryDirectory() as td:
|
||||
dest = Path(td) / "rescue"
|
||||
excerpt = self._download(
|
||||
{
|
||||
names[0]: _artifact("0", "502 from #0\n"),
|
||||
names[1]: _artifact("7", "502 from #7\n"),
|
||||
},
|
||||
dest,
|
||||
)
|
||||
expected = [
|
||||
f"{name}/{rel}"
|
||||
for name, variant in zip(names, ("0", "7"), strict=True)
|
||||
for rel in _artifact(variant, "")
|
||||
]
|
||||
present = [rel for rel in expected if (dest / rel).is_file()]
|
||||
folders = sorted(path.name for path in dest.iterdir())
|
||||
self.assertEqual(present, expected)
|
||||
self.assertEqual(folders, sorted(names))
|
||||
self.assertIn("502 from #0", excerpt)
|
||||
|
||||
def test_host_metrics_alone_is_no_snapshot(self) -> None:
|
||||
with tempfile.TemporaryDirectory() as td:
|
||||
dest = Path(td) / "rescue"
|
||||
excerpt = self._download(
|
||||
{artifact_name(ROLE, SWARM_0): {"host-metrics.log": "metrics\n"}},
|
||||
dest,
|
||||
)
|
||||
self.assertFalse(has_snapshot(dest))
|
||||
self.assertEqual(excerpt, _NO_SNAPSHOT)
|
||||
|
||||
def test_no_artifact_at_all_is_no_snapshot(self) -> None:
|
||||
with tempfile.TemporaryDirectory() as td:
|
||||
self.assertEqual(self._download({}, Path(td) / "rescue"), _NO_SNAPSHOT)
|
||||
|
||||
def test_a_snapshot_without_a_decisive_file_says_so(self) -> None:
|
||||
with tempfile.TemporaryDirectory() as td:
|
||||
excerpt = self._download(
|
||||
{
|
||||
artifact_name(ROLE, SWARM_0): {
|
||||
"host-metrics.log": "metrics\n",
|
||||
f"debian/{ROLE}/free.txt": "Swap: 16G 6.8G\n",
|
||||
}
|
||||
},
|
||||
Path(td) / "rescue",
|
||||
)
|
||||
self.assertIn("No decisive", excerpt)
|
||||
|
||||
|
||||
class TestReportFailures(unittest.TestCase):
|
||||
def test_failed_roles_parses_mode_role_variant(self) -> None:
|
||||
|
||||
Reference in new issue
Block a user