Reuse HTTP probe responses within diagnostic reports

This commit is contained in:
juvenal.diaz 2026-11-04 14:24:04 -06:00
parent d721c4cea9
commit 9f193c0a1b
4 changed files with 37 additions and 12 deletions

View File

@ -6,7 +6,9 @@ Compact `status` and `doctor-homelab` run independent read-only probes in
parallel (four at a time by default, capped at eight). Set
`LAB_REPORT_PARALLELISM=1` to serialize them or `LAB_REPORT_TIMING=true` to
print probe elapsed time. Identical selected HTTP/container probes reuse results
only within that report. Healing performs its own live identity checks.
only within that report. HTTP checks for the same URL also share one response
while retaining each check's accepted status codes. Healing performs its own
live identity checks.
Compact reports also share one nodes, pods, Deployments, and StatefulSets list
per resource type as needed; snapshots are point-in-time, may differ across
resource types, and are discarded when the report ends. API readiness, logs,

View File

@ -6,7 +6,9 @@ Compact `status` and `doctor-homelab` run independent read-only probes in
parallel (four at a time by default, capped at eight). Set
`LAB_REPORT_PARALLELISM=1` to serialize them or `LAB_REPORT_TIMING=true` to
print probe elapsed time. Identical selected HTTP/container probes reuse results
only within that report. Healing performs its own live identity checks.
only within that report. HTTP checks for the same URL also share one response
while retaining each check's accepted status codes. Healing performs its own
live identity checks.
Compact reports also share one nodes, pods, Deployments, and StatefulSets list
per resource type as needed; snapshots are point-in-time, may differ across
resource types, and are discarded when the report ends. API readiness, logs,

View File

@ -1389,16 +1389,20 @@ status_http() {
fi
}
status_http_ok() {
status_http_response() {
local url="$1"
local status
if ! command -v curl >/dev/null 2>&1; then
echo "curl not installed" >&2
return 1
fi
curl -k -sS -o /dev/null --connect-timeout 5 --max-time 10 -w '%{http_code}' "${url}"
}
status="$(curl -k -sS -o /dev/null --connect-timeout 5 --max-time 10 -w '%{http_code}' "${url}")" || {
status_http_ok() {
local url="$1"
local status
status="$(report_ui_cached_probe status_http_response "${url}")" || {
echo "unreachable ${url}" >&2
return 1
}
@ -1417,12 +1421,7 @@ status_http_reachable() {
local url="$1"
local status
if ! command -v curl >/dev/null 2>&1; then
echo "curl not installed" >&2
return 1
fi
status="$(curl -k -sS -o /dev/null --connect-timeout 5 --max-time 10 -w '%{http_code}' "${url}")" || {
status="$(report_ui_cached_probe status_http_response "${url}")" || {
echo "unreachable ${url}" >&2
return 1
}

View File

@ -11,6 +11,28 @@ ROOT = Path(__file__).resolve().parents[2]
class ParallelReportTests(unittest.TestCase):
def test_http_response_shared_without_changing_health_semantics(self):
with tempfile.TemporaryDirectory() as directory:
env = dict(os.environ, PROBE_COUNTER=str(Path(directory) / "calls"), LAB_REPORT_PARALLELISM="2")
program = r'''
set -euo pipefail
source scripts/report-ui
source lib/jeannie/commands.sh
curl() { printf 'call\n' >>"$PROBE_COUNTER"; printf 404; }
report_ui_begin
REPORT_UI_PARALLEL=true
report_ui_check fail A strict fix '' '' status_http_ok http://example.invalid/
report_ui_check fail A reachable fix '' '' status_http_reachable http://example.invalid/
report_ui_finish
cat "$REPORT_UI_ROWS_FILE"
report_ui_cleanup
'''
result = subprocess.run(["bash", "-c", program], cwd=ROOT, env=env,
text=True, capture_output=True, check=True)
lines = result.stdout.splitlines()
self.assertEqual([line.split("\t")[0] for line in lines], ["fail", "ok"])
self.assertEqual(Path(env["PROBE_COUNTER"]).read_text().splitlines(), ["call"])
def test_order_cache_and_failure_are_preserved(self):
with tempfile.TemporaryDirectory() as directory:
env = dict(os.environ, PROBE_COUNTER=str(Path(directory) / "calls"), LAB_REPORT_PARALLELISM="2")