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:
parent
462525b1e2
commit
be727949c1
13 changed files with 449 additions and 32 deletions
|
|
@ -8,7 +8,7 @@ import time
|
|||
from fastapi import APIRouter, Header, HTTPException, Request
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
from app.hub import devices, settings
|
||||
from app.hub import devices, outages, settings
|
||||
from app.hub.db import db
|
||||
|
||||
router = APIRouter()
|
||||
|
|
@ -44,6 +44,14 @@ class Neighbor(BaseModel):
|
|||
mac: str = Field(max_length=32)
|
||||
|
||||
|
||||
class OutageRun(BaseModel):
|
||||
"""A run of reports the probe couldn't get through (from its local outage log)."""
|
||||
start: float
|
||||
end: float
|
||||
failures: int = Field(ge=1)
|
||||
error: str | None = Field(default=None, max_length=300)
|
||||
|
||||
|
||||
class Report(BaseModel):
|
||||
version: str | None = Field(default=None, max_length=40)
|
||||
hostname: str | None = Field(default=None, max_length=255)
|
||||
|
|
@ -52,6 +60,7 @@ class Report(BaseModel):
|
|||
icmp: bool | None = None
|
||||
measurements: list[Measurement] = Field(default_factory=list, max_length=MAX_BATCH)
|
||||
neighbors: list[Neighbor] = Field(default_factory=list, max_length=4096)
|
||||
outages: list[OutageRun] = Field(default_factory=list, max_length=1000)
|
||||
|
||||
|
||||
def is_online(row, now: float | None = None) -> bool:
|
||||
|
|
@ -132,6 +141,7 @@ def delete_probe(probe_id: int, keep_history: bool = False) -> None:
|
|||
with db() as con:
|
||||
_get(con, probe_id)
|
||||
con.execute("DELETE FROM probes WHERE id = ?", (probe_id,))
|
||||
con.execute("DELETE FROM probe_outages WHERE probe_id = ?", (probe_id,))
|
||||
if not keep_history:
|
||||
con.execute("DELETE FROM measurements WHERE probe_id = ?", (probe_id,))
|
||||
|
||||
|
|
@ -171,6 +181,7 @@ def report(body: Report, request: Request, authorization: str = Header(default="
|
|||
row = con.execute("SELECT * FROM probes WHERE token = ?", (token,)).fetchone() if token else None
|
||||
if not row:
|
||||
raise HTTPException(401, "Unknown probe token. Add the probe on the hub and use its install command.")
|
||||
outages.resolve(con, row["id"], row["last_seen"], [o.model_dump() for o in body.outages], now)
|
||||
address = row["address"]
|
||||
if not row["address_locked"]:
|
||||
address = (body.advertise_addr or "").strip() or _client_ip(request) or address
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue