Update observability docs and task utilities
- Add Observability.md documentation - Standardize task logging with correlation_id support - Add log_sanitizer utility for PII masking - Update Tasks.md tracking - Update geo_cache tasks and other task modules with correlation_id Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -13,11 +13,15 @@ keys). If the health probe subsequently detects an online→offline transition
|
||||
within 60 seconds of that activation, a
|
||||
:class:`~app.models.config.PendingRecovery` record is written to
|
||||
``app.state.pending_recovery`` so the UI can offer a one-click rollback.
|
||||
|
||||
Correlation IDs are propagated through the task using :mod:`app.utils.correlation`
|
||||
so that task logs can be correlated across runs.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import datetime
|
||||
import uuid
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
import structlog
|
||||
@@ -25,6 +29,7 @@ import structlog
|
||||
from app.models.server import ServerStatus
|
||||
from app.services import health_service
|
||||
from app.tasks.timeout_utils import run_with_timeout
|
||||
from app.utils.correlation import reset_correlation_id, set_correlation_id
|
||||
from app.utils.runtime_state import (
|
||||
RuntimeState,
|
||||
get_effective_settings,
|
||||
@@ -47,13 +52,30 @@ HEALTH_CHECK_INTERVAL: int = 30
|
||||
HEALTH_PROBE_TIMEOUT_SECONDS: int = 10
|
||||
|
||||
|
||||
async def _run_probe_with_resources(settings: Settings, runtime_state: RuntimeState) -> None:
|
||||
async def _run_probe_with_resources(
|
||||
settings: Settings,
|
||||
runtime_state: RuntimeState,
|
||||
correlation_id: str | None = None,
|
||||
) -> None:
|
||||
"""Probe fail2ban and cache the result on the runtime state.
|
||||
|
||||
Args:
|
||||
settings: The resolved application settings used for the probe.
|
||||
runtime_state: The mutable runtime state manager.
|
||||
correlation_id: Optional correlation ID for log correlation.
|
||||
"""
|
||||
if correlation_id is None:
|
||||
correlation_id = str(uuid.uuid4())
|
||||
|
||||
token = set_correlation_id(correlation_id)
|
||||
try:
|
||||
await _do_probe_with_resources(settings, runtime_state)
|
||||
finally:
|
||||
reset_correlation_id(token)
|
||||
|
||||
|
||||
async def _do_probe_with_resources(settings: Settings, runtime_state: RuntimeState) -> None:
|
||||
"""Inner probe logic that runs with correlation context set."""
|
||||
|
||||
async def _do_probe() -> None:
|
||||
socket_path: str = settings.fail2ban_socket
|
||||
|
||||
Reference in New Issue
Block a user