Skip to content

Improve logging for failed health checks #747

Description

@danielmursa-dev

While testing my application on Kubernetes, I configured the /_healthz/ endpoint as the startupProbe.

The probe kept failing, but nothing was logged to indicate which health check was responsible.
The only way I could identify the issue was by manually running the checks from the shell:

>>> from health_check.checks import *; import asyncio; res = asyncio.run(DNS().get_result()); print(res)
HealthCheckResult(..., error=ServiceUnavailable("DNS resolution failed..."), ...)
  • get_result() already captures the exception and returns it in a HealthCheckResult, but the error is never logged

Would it be possible to log failed health checks (e.g. at warning or error level)?

This would make debugging much easier and allow us to immediately see which checks fails.

Maybe, add a logger here:

has_errors = any(result.error for result in self.results)
something similar to
async def _run_checks_directly(self, path):

Thanks
Daniel

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions