chore(api): silence health-check and job-status polling in the access log

Docker health probes (5 s) and the dashboard's 2 s status poll filled uvicorn's access log with thousands of identical lines, burying the real job output. Drop /health* and /api/status/* at the access logger only; requests are still served.
This commit is contained in:
pedro-bento 2026-10-05 21:17:09 +01:00
parent 0fdd07bec2
commit 92c68f9fcf
2 changed files with 54 additions and 0 deletions

View file

@ -1,3 +1,4 @@
import logging
import os import os
from clipwright.pipeline import llm_backend, profiles from clipwright.pipeline import llm_backend, profiles
import re import re
@ -1470,6 +1471,25 @@ async def lifespan(app: FastAPI):
yield yield
# Cleanup (optional: cancel worker) # Cleanup (optional: cancel worker)
# Health probes (Docker, every 5 s) and the dashboard's 2 s job-status poll would
# otherwise fill uvicorn's access log with thousands of identical lines and bury
# the real job output. Drop those from the access logger only: the requests are
# still served normally, just not echoed to the console.
_QUIET_ACCESS_PREFIXES = ("/health", "/api/status/")
class _QuietAccessPaths(logging.Filter):
"""Suppress access-log lines for health checks and job-status polling."""
def filter(self, record: logging.LogRecord) -> bool:
args = record.args
path = args[2] if isinstance(args, tuple) and len(args) >= 3 else ""
return not str(path).startswith(_QUIET_ACCESS_PREFIXES)
logging.getLogger("uvicorn.access").addFilter(_QuietAccessPaths())
app = FastAPI(lifespan=lifespan) app = FastAPI(lifespan=lifespan)
# Free public tools behind the /tools SEO pages: YouTube transcript (existing # Free public tools behind the /tools SEO pages: YouTube transcript (existing

View file

@ -0,0 +1,34 @@
"""The access-log filter that hides health checks and job-status polling."""
import logging
from clipwright.api.app import _QuietAccessPaths
def _record(path):
return logging.LogRecord(
"uvicorn.access", logging.INFO, __file__, 1, "msg",
("1.2.3.4", "GET", path, "HTTP/1.1", 200), None,
)
def test_drops_health_and_status_lines():
f = _QuietAccessPaths()
assert f.filter(_record("/health")) is False
assert f.filter(_record("/health/ready")) is False
assert f.filter(_record("/api/status/4c533b81-ef05-4b51-80a3-137046577888")) is False
def test_keeps_real_requests():
f = _QuietAccessPaths()
assert f.filter(_record("/api/config")) is True
assert f.filter(_record("/api/uploads/abc")) is True
assert f.filter(_record("/videos/job/clip.mp4")) is True
def test_survives_unexpected_record_args():
# uvicorn access records always carry the args tuple, but a filter must never
# raise on a differently-shaped record.
f = _QuietAccessPaths()
rec = logging.LogRecord("uvicorn.access", logging.INFO, __file__, 1, "msg", None, None)
assert f.filter(rec) is True