Skip to content

feat: suppress uvicorn access logs for /health and /ready probes#5881

Open
jonpspri wants to merge 3 commits into
IBM:mainfrom
jonpspri:feat/health-check-log-suppression
Open

feat: suppress uvicorn access logs for /health and /ready probes#5881
jonpspri wants to merge 3 commits into
IBM:mainfrom
jonpspri:feat/health-check-log-suppression

Conversation

@jonpspri

Copy link
Copy Markdown
Collaborator

Summary

Install a logging.Filter on the uvicorn.access logger from LoggingService.initialize() that suppresses access-log records for GET /health and GET /ready. Kubernetes and other orchestrators poll these endpoints on short intervals, generating high-volume, low-value log noise that drowns out useful request logs. All other endpoints (and non-uvicorn.access loggers) are logged normally, and the filter never raises: any failure while formatting the message falls through to "allow".

Matching the behavior on the contributing branch, the suppression is always-on (no config flag); happy to add an opt-out setting if maintainers prefer.

Closes #5880

Origin / framing

This change was discovered during the decomposition of PR #5417 into reviewable units. It was not part of the originally reviewed plan scope — it is offered here as a standalone, self-contained PR so that maintainers (or the original author) can decline it without any impact on the rest of the decomposition.

Overlap note

Sibling PR #5870 (log config file watcher) touches mcpgateway/services/logging_service.py in the same LoggingService.initialize() region (log-level resolution) but not the same lines as this change. Whichever merges second should expect a trivial rebase; no semantic conflicts.

Changes

  • mcpgateway/services/logging_service.py (+81): _UvicornHealthCheckFilter + LoggingService._install_uvicorn_health_check_filter(), installed during initialize() alongside the existing ClosedResourceError and httpx-sanitize filters.
  • tests/unit/mcpgateway/services/test_logging_service.py (+98): TestUvicornHealthCheckFilter — suppresses /health and /ready, passes /api/tools, ignores non-uvicorn.access loggers, and survives malformed records and exceptions.
  • docs/docs/manage/logging.md (+3): note documenting the suppression behavior.

Test plan

  • pytest tests/unit/mcpgateway/services/test_logging_service.py — 36 passed (7 new)
  • Failing-first verified: the 7 new tests fail against unmodified main
  • Doctests for the new method pass (pytest --doctest-modules mcpgateway/services/logging_service.py)
  • ruff check / ruff format / interrogate / pre-commit hooks clean (2 pre-existing ruff findings in the test file on main are untouched)

Install a logging filter on the uvicorn.access logger from
LoggingService.initialize() that drops access-log records for GET
/health and GET /ready. Kubernetes and other orchestrators poll these
endpoints on short intervals, generating high-volume, low-value log
noise. All other endpoints and loggers are unaffected, and the filter
never raises: any failure while formatting the message falls through
to allow.

Closes IBM#5880

Signed-off-by: Jonathan Springer <jps@s390x.com>
@jonpspri
jonpspri force-pushed the feat/health-check-log-suppression branch from 773894f to d28d51d Compare July 25, 2026 12:37
jonpspri added 2 commits July 25, 2026 16:44
Signed-off-by: Jonathan Springer <jps@s390x.com>
… compliance

The diff-cover tool reported 88% coverage (below 93% threshold) on the
health-check log suppression changes, specifically the except Exception
block. This adds a test that patches getMessage() to raise an exception
to ensure the filter handles it gracefully.

Signed-off-by: Jonathan Springer <jps@s390x.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE]: Suppress uvicorn access logs for /health and /ready probes

1 participant