Probes log locally only while the hub is unreachable; the hub confirms silences with that log

Probe: no access log, nothing written while reports get through. When the hub
can't be reached, failed reports go to data/outage.jsonl and unsent results to
data/backlog.jsonl (survives restarts). The first report that gets through
uploads both and they are deleted.

Hub: a probe that misses reports gets a "Not reporting" incident. When it
reports again, the runs from its outage log become confirmed "Hub unreachable"
incidents; the rest of the silence (probe off or restarting) is dropped.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
neil 2026-11-04 20:50:30 -08:00
parent 462525b1e2
commit be727949c1
13 changed files with 449 additions and 32 deletions

View file

@ -5,7 +5,7 @@ from collections import defaultdict
from fastapi import APIRouter, HTTPException, Query
from app.hub import settings
from app.hub import outages, settings
from app.hub.db import db
from app.hub.probes import is_online
@ -136,7 +136,8 @@ def _uptime(buckets) -> float | None:
@router.get("/health/incidents")
def incidents(range: str = "24h", probe: int | None = None, until: float | None = None, limit: int = Query(200, ge=1, le=1000)) -> dict:
"""Runs of failed or slow measurements, merged per probe → target when they are close together."""
"""Runs of failed or slow measurements, merged per probe → target when they are close together,
plus stretches when a probe didn't report (see outages.py)."""
since, until, _, _ = _range(range, until)
s = settings.get()
gap = s.probe_interval * 2.5 + 5
@ -147,6 +148,7 @@ def incidents(range: str = "24h", probe: int | None = None, until: float | None
rows = con.execute(f"""SELECT * FROM (SELECT ts, probe_id, target, label, kind, method, ok, latency, loss, error, {sev} sev
FROM measurements WHERE {where}) WHERE sev > 0 ORDER BY probe_id, target, ts""",
{**params, "since": since, "until": until, "probe": probe}).fetchall()
silent = outages.incidents(con, probes, since, until, probe)
found, cur = [], None
for r in rows:
if r["probe_id"] not in probes:
@ -177,6 +179,7 @@ def incidents(range: str = "24h", probe: int | None = None, until: float | None
i["ongoing"] = now - i["end"] < gap
i["duration"] = i["end"] - i["start"] + s.probe_interval
out.append(i)
out += silent
out.sort(key=lambda i: -i["start"])
return {"since": since, "until": until, "incidents": out[:limit], "total": len(out),
"thresholds": {"lan_ms": s.slow_lan_ms, "wan_ms": s.slow_wan_ms, "dns_ms": s.slow_dns_ms, "loss": 0.3}}
@ -212,4 +215,6 @@ def series(probe: int, range: str = "24h", until: float | None = None) -> dict:
def prune(con, retention_days: float) -> int:
return con.execute("DELETE FROM measurements WHERE ts < ?", (time.time() - retention_days * 86400,)).rowcount
n = con.execute("DELETE FROM measurements WHERE ts < ?", (time.time() - retention_days * 86400,)).rowcount
outages.prune(con, retention_days)
return n