Put readiness behind a port and log the drain window through Logger

The /health/ready route imported the PostgreSQL adapter and kept the
drain flag in the HTTP layer, which gunicorn_conf imported to raise it.
Readiness is now a port of the shared application layer; its adapter in
shared/infrastructure checks the per-process drain flag and pings
PostgreSQL, and PlatformProvider assembles it. The route only knows the
port, and gunicorn_conf raises the flag through the infrastructure
module. Another critical dependency now changes the adapter and the
provider, not the HTTP layer.

The drain window was logged by a uvicorn logger with a printf string;
it is now the service.draining event of a StructlogLogger with the same
fields as the application, and failover-evidence looks for it.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01V1d3RLHNBBMA6UqBLLJv27
This commit is contained in:
Artyom
2026-10-30 05:40:16 +03:00
co-authored by Claude Opus 5.5
parent aa1485bd86
commit d99a48a5db
10 changed files with 47 additions and 23 deletions
+4 -4
View File
@@ -1,5 +1,4 @@
import asyncio
import logging
import os
import sys
from typing import Any
@@ -10,12 +9,13 @@ from uvicorn.server import Server
from uvicorn_worker import UvicornWorker
from messenger.main import LOG_FIELDS
from messenger.shared.entrypoints.health import DRAINING
from messenger.shared.infrastructure.logging import configure
from messenger.shared.infrastructure.logging import StructlogLogger, configure
from messenger.shared.infrastructure.readiness import DRAINING
LOG_LEVEL = os.environ.get("LOG_LEVEL", "INFO")
SHUTDOWN_SECONDS = int(os.environ.get("SHUTDOWN_TIMEOUT_SECONDS", "6"))
DRAIN_SECONDS = float(os.environ.get("DRAIN_SECONDS", "2"))
LOGGER = StructlogLogger(level=LOG_LEVEL, allowed_fields=LOG_FIELDS)
class StructlogGunicornLogger(GunicornBaseLogger):
@@ -31,7 +31,7 @@ class DrainingServer(Server):
await super().main_loop()
if not self.force_exit:
DRAINING.set()
logging.getLogger("uvicorn.error").info("Draining for %.1f s", DRAIN_SECONDS)
LOGGER.info("service.draining", limit=DRAIN_SECONDS)
await asyncio.sleep(DRAIN_SECONDS)