M26: harden clean observability acceptance
This commit is contained in:
@@ -10,7 +10,7 @@ from sqlalchemy import func, select
|
||||
from app.core.config import get_settings
|
||||
from app.core.db import SessionLocal
|
||||
from app.core.observability import OUTBOX_EVENTS
|
||||
from app.models.outbox import DEMO_SCENARIO_ERROR_CODE, OutboxEvent
|
||||
from app.models.outbox import DELIVERY_STATUSES, DEMO_SCENARIO_ERROR_CODE, OutboxEvent
|
||||
|
||||
router = APIRouter(tags=["observability"])
|
||||
settings = get_settings()
|
||||
@@ -26,8 +26,14 @@ def _refresh_database_metrics() -> None:
|
||||
).group_by(OutboxEvent.delivery_status, "demo")
|
||||
).all()
|
||||
OUTBOX_EVENTS.clear()
|
||||
# Keep every time series present even when a state currently contains no rows.
|
||||
# Stable zero-valued series make dashboards and alerts deterministic after resets,
|
||||
# restores and fresh installations instead of turning "zero" into "no data".
|
||||
for scenario in ("synthetic", "operational"):
|
||||
for status in DELIVERY_STATUSES:
|
||||
OUTBOX_EVENTS.labels(scenario, status).set(0)
|
||||
for status, is_demo, count in rows:
|
||||
OUTBOX_EVENTS.labels(str(status), "synthetic" if is_demo else "operational").set(count)
|
||||
OUTBOX_EVENTS.labels("synthetic" if is_demo else "operational", str(status)).set(count)
|
||||
|
||||
|
||||
@router.get("/metrics", include_in_schema=False)
|
||||
|
||||
@@ -30,7 +30,7 @@ HTTP_IN_PROGRESS = Gauge(
|
||||
OUTBOX_EVENTS = Gauge(
|
||||
"mobilityops_outbox_events",
|
||||
"Persisted outbox events by state and scenario type.",
|
||||
("status", "scenario"),
|
||||
("scenario", "status"),
|
||||
)
|
||||
DATABASE_READY = Gauge(
|
||||
"mobilityops_database_ready",
|
||||
|
||||
+4
-4
@@ -148,11 +148,11 @@ def readiness() -> JSONResponse:
|
||||
db.execute(text("SELECT 1"))
|
||||
except Exception: # noqa: BLE001 -- readiness must convert infrastructure errors to 503
|
||||
DATABASE_READY.set(0)
|
||||
return JSONResponse(
|
||||
status_code=503,
|
||||
content={"status": "not_ready", "service": "mobilityops-api", "database": "down"},
|
||||
)
|
||||
DATABASE_READY.set(1)
|
||||
return JSONResponse(
|
||||
status_code=503,
|
||||
content={"status": "not_ready", "service": "mobilityops-api", "database": "down"},
|
||||
)
|
||||
return JSONResponse(content={"status": "ready", "service": "mobilityops-api", "database": "up"})
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user