django-health-check: Django sending Internal Server Error mails for health check endpoint
After upgrading our Django app (Django 2.0.9 -> 2.1.3, Python 3.6 -> 3.7, django-health-check 3.5.1 -> 3.8.0) we’re sometimes getting Internal Server Error mails from Django triggered by the health check endpoint. Unfortunately these mails do not contain a stack trace or any other information that is helpful in determining what’s going on, which is why I’m opening this issue.
We’re running our app on Kubernetes, and it is configured to periodically call the health check endpoint to verify that the app is still alive. There are django-health-check checks configured for db (PostgreSQL) and cache (memcached).
The first part of the error mail is as follows:
Internal Server Error: /healthz
Report at /healthz
Internal Server Error: /healthz
Request Method: GET
Request URL: http://10.244.2.193:8000/healthz
Django Version: 2.1.3
Python Executable: /usr/local/bin/python
Python Version: 3.7.1
Python Path: ['/srv', '/usr/local/bin', '/usr/local/lib/python37.zip', '/usr/local/lib/python3.7', '/usr/local/lib/python3.7/lib-dynload', '/usr/local/lib/python3.7/site-packages']
Server time: vr, 9 Nov 2018 19:14:47 +0100
Installed Applications:
(...
'health_check',
'health_check.db',
'health_check.cache',
...)
Do you happen to have any idea what could be causing these internal server errors?
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 18
Cheers! Enabling the
health-checklogging did the trick. Apparently the Internal Server Errors were caused by a failing cache health check:I’m not quite sure why this happens (memcached is running alongside Django, so it cannot be a network problem), but at least there’s some context.
Hi @GitRon sure, it’d be my pleasure.
By the
health-check-logger, I mean the name of the logger. In Django you can configure the handlers for each logger or other behavior via theLOGGINGsetting.In this particular case you want to add:
See also Django’s documentation on logging for more information: https://docs.djangoproject.com/en/stable/topics/logging/