fix(runtime): watchdog canonical liveness
This commit is contained in:
@@ -157,7 +157,7 @@ class MissionCoreSelfWatchdog:
|
|||||||
journal: MissionCoreWatchdogJournal | None = None,
|
journal: MissionCoreWatchdogJournal | None = None,
|
||||||
) -> None:
|
) -> None:
|
||||||
self.policy = policy or MissionCoreWatchdogPolicy()
|
self.policy = policy or MissionCoreWatchdogPolicy()
|
||||||
self.probe = probe or _mission_core_health_probe(
|
self.probe = probe or _mission_core_liveness_probe(
|
||||||
self.policy.probe_timeout_seconds
|
self.policy.probe_timeout_seconds
|
||||||
)
|
)
|
||||||
self.request_shutdown = request_shutdown or _process_group_signal(signal.SIGTERM)
|
self.request_shutdown = request_shutdown or _process_group_signal(signal.SIGTERM)
|
||||||
@@ -232,7 +232,7 @@ def watchdog_enabled(environ: Mapping[str, str] = os.environ) -> bool:
|
|||||||
return environ.get(WATCHDOG_ENV) == WATCHDOG_ENABLED_VALUE
|
return environ.get(WATCHDOG_ENV) == WATCHDOG_ENABLED_VALUE
|
||||||
|
|
||||||
|
|
||||||
def _mission_core_health_probe(timeout_seconds: float) -> Probe:
|
def _mission_core_liveness_probe(timeout_seconds: float) -> Probe:
|
||||||
def probe() -> bool:
|
def probe() -> bool:
|
||||||
connection = http.client.HTTPConnection(
|
connection = http.client.HTTPConnection(
|
||||||
"127.0.0.1",
|
"127.0.0.1",
|
||||||
@@ -240,7 +240,7 @@ def _mission_core_health_probe(timeout_seconds: float) -> Probe:
|
|||||||
timeout=timeout_seconds,
|
timeout=timeout_seconds,
|
||||||
)
|
)
|
||||||
try:
|
try:
|
||||||
connection.request("GET", "/api/health", headers={"Connection": "close"})
|
connection.request("GET", "/api/liveness", headers={"Connection": "close"})
|
||||||
response = connection.getresponse()
|
response = connection.getresponse()
|
||||||
payload = response.read(64 * 1024 + 1)
|
payload = response.read(64 * 1024 + 1)
|
||||||
except (OSError, TimeoutError, http.client.HTTPException):
|
except (OSError, TimeoutError, http.client.HTTPException):
|
||||||
@@ -256,7 +256,7 @@ def _mission_core_health_probe(timeout_seconds: float) -> Probe:
|
|||||||
return bool(
|
return bool(
|
||||||
isinstance(document, dict)
|
isinstance(document, dict)
|
||||||
and document.get("ok") is True
|
and document.get("ok") is True
|
||||||
and document.get("status") == "ok"
|
and document.get("status") == "alive"
|
||||||
and document.get("service") == MISSION_CORE_SERVICE_ID
|
and document.get("service") == MISSION_CORE_SERVICE_ID
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -528,6 +528,17 @@ async def request_validation_error_handler(
|
|||||||
return JSONResponse(status_code=422, content={"detail": INVALID_REQUEST_DETAIL})
|
return JSONResponse(status_code=422, content={"detail": INVALID_REQUEST_DETAIL})
|
||||||
|
|
||||||
|
|
||||||
|
@app.get("/api/liveness")
|
||||||
|
async def liveness() -> dict[str, object]:
|
||||||
|
"""Prove only that the canonical event loop is responsive."""
|
||||||
|
|
||||||
|
return {
|
||||||
|
"ok": True,
|
||||||
|
"status": "alive",
|
||||||
|
"service": "mission-core-control-plane",
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@app.get("/api/health")
|
@app.get("/api/health")
|
||||||
def health() -> dict[str, Any]:
|
def health() -> dict[str, Any]:
|
||||||
return build_runtime_readiness(
|
return build_runtime_readiness(
|
||||||
|
|||||||
Reference in New Issue
Block a user