Merge pull request 'fix(health): ignore future article timestamps; flag unset vessel/FIRMS keys' (#59) from wt/t_ceb74e64 into master
Some checks failed
build-and-deploy / build-push-deploy (push) Failing after 5s

Reviewed-on: #59
This commit is contained in:
sirius 2026-11-17 19:56:20 +00:00
commit 3f11e647f0
3 changed files with 192 additions and 4 deletions

View file

@ -272,7 +272,14 @@ async def _pipeline_checks(session) -> dict:
await _age("SELECT max(ingested_at) FROM events", "events", 20 * 60)
await _age("SELECT max(ingested_at) FROM fires", "fires", 30 * 60)
await _age("SELECT max(timestamp) FROM articles", "articles", 2 * 3600)
# Same closed-at-now window as GET /api/news. A future max() made age_s
# negative and hid a fresh list. NULL timestamps are not fresh.
await _age(
"SELECT max(timestamp) FROM articles "
"WHERE timestamp IS NOT NULL AND timestamp <= now()",
"articles",
2 * 3600,
)
await _age("SELECT max(batch_timestamp) FROM article_summaries", "summaries", 2 * 3600)
return checks
@ -298,7 +305,7 @@ async def _stats_counts() -> dict:
aircraft_last_known, vessel_last_known, train_count, nws_alert_count,
)
counts: dict[str, int | str] = {
counts: dict = {
"aircraft": len(aircraft_last_known),
"vessels": len(vessel_last_known),
"trains": train_count,
@ -330,9 +337,41 @@ async def _stats_counts() -> dict:
logger.warning("stats_db_failed", error=str(exc))
counts["timestamp"] = datetime.now(timezone.utc).isoformat().replace("+00:00", "Z")
# Public booleans only. Never include the stored value, a prefix, or last-4.
counts["feeds"] = await _feed_flags()
return counts
async def _key_configured(*names: str) -> bool:
"""True when any named key has a non-empty value in the api_keys store.
Uses keystore.get_api_key — not env, not a second store. The value is
discarded after the emptiness check.
"""
from keystore import get_api_key
for name in names:
value = await get_api_key(name)
if isinstance(value, str) and value.strip():
return True
return False
async def _feed_flags() -> dict:
"""HUD layer flags. Fail closed (configured false) if the store is down."""
try:
vessels = await _key_configured("AISSTREAM_API_KEY", "VESSELAPI_API_KEY")
fires = await _key_configured("FIRMS_MAP_KEY")
except Exception as exc: # noqa: BLE001
logger.warning("stats_feed_flags_failed", error=str(exc))
vessels = False
fires = False
return {
"vessels": {"configured": vessels},
"fires": {"configured": fires},
}
@app.get("/api/stats")
async def api_stats():
"""Cheap HUD counters (counts only — no GeoJSON). Cached ~20 s."""