refactor(backend): external logging metrics, required mode, health checks
- Add external_logging_init_failures counter - Add external_log_required flag, raise if init fails and required - Health endpoint: add external_logging status check - Blocklist service: enrich with metadata fields, update import logic - Health check task: add runtime_state dependency, fix return typing - Metrics: add Histogram for request latencies - Frontend: align BlocklistImportLogSection props - Docs: update deployment guide, remove stale tasks Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -182,6 +182,7 @@ async def _lifespan(app: FastAPI) -> AsyncGenerator[None, None]:
|
||||
global _external_log_handler # noqa: PLW0603
|
||||
|
||||
settings: Settings = app.state.settings
|
||||
runtime_state = app.state.runtime_state
|
||||
|
||||
http_session, scheduler, startup_db = await startup_shared_resources(app, settings)
|
||||
app.state.http_session = http_session
|
||||
@@ -210,10 +211,18 @@ async def _lifespan(app: FastAPI) -> AsyncGenerator[None, None]:
|
||||
if _external_log_handler:
|
||||
_external_log_handler.start_periodic_flush()
|
||||
except ValueError as exc:
|
||||
log.warning(
|
||||
from app.utils import metrics as _metrics_mod
|
||||
|
||||
_metrics_mod.external_logging_init_failures.inc()
|
||||
runtime_state.external_log_init_failed = True
|
||||
log.error(
|
||||
"external_logging_initialization_failed",
|
||||
error=str(exc),
|
||||
)
|
||||
if settings.external_log_required:
|
||||
msg = f"External logging is required but handler creation failed: {exc}"
|
||||
log.critical("external_logging_required_but_unavailable", error=str(exc))
|
||||
raise RuntimeError(msg) from exc
|
||||
|
||||
# Now configure logging with the handler in place
|
||||
_configure_logging(settings.log_level, settings)
|
||||
|
||||
Reference in New Issue
Block a user