This package implements a few helpers and tools for Mozilla's Dockerflow pattern.
Please install the package using your favorite package installer:
pip install dockerflow
This package implements various tools to implement the Dockerflow requirements:
- Provide views for health monitoring:
/__version__- Serves aversion.jsonfile/__heartbeat__- Run Django checks as configured in theDOCKERFLOW_CHECKSsetting/__lbheartbeat__- Retuns a HTTP 200 response
To install python-dockerflow's Django support please follow these steps:
Add
dockerflow.djangoto yourINSTALLED_APPSsettingAdd the URL patterns to your project's URL patterns:
urlpatterns = [ url(r'^', include('dockerflow.django.urls', namespace='dockerflow')), # ... ]Define a
BASE_DIRsetting that is the root path of your Django project. This will be used to locate theversion.jsonfile that is generated by CircleCI or another process during deployment.
DOCKERFLOW_VERSION_CALLBACK - The dotted import path for the callable that
returns the content to return under /__version__. Defaults to
dockerflow.version.get_version which will be passed the BASE_DIR
setting by default.
DOCKERFLOW_CHECKS - A list of dotted import paths to register during
Django setup, to be used in the rendering of the /__heartbeat__ view.
Defaults to:
[
'dockerflow.django.checks.check_database_connected',
'dockerflow.django.checks.check_migrations_applied',
]
During the rendering of the /__heartbeat__ view two signals are being sent
to hook into the result of the checks:
dockerflow.django.signals.heartbeat_passed- Sent when the heartbeat checks passed successfully.dockerflow.django.signals.heartbeat_failed- Sent when the heartbeat checks raised either a warning or worse (error, critical).
Both signals receive an additional level parameter that indicates the
maximum check level that failed during the rendering.
E.g. to hook into those signals to send data to statsd, do this:
from django.dispatch import receiver
from dockerflow.django.signals import heartbeat_passed, heartbeat_failed
from statsd.defaults.django import statsd
@receiver(heartbeat_passed)
def heartbeat_passed_handler(sender, level, **kwargs):
statsd.incr('heartbeat.pass')
@receiver(heartbeat_failed)
def heartbeat_failed_handler(sender, level, **kwargs):
statsd.incr('heartbeat.fail')
- Port mozilla-cloud-services-logger to
dockerflow.logginganddockerflow.django.middlewaremozilla-cloud-services-logger - Document how to log to stdout and stderr
- Document how to use Whitenoise to serve static content
- Ship
Dockerfilefiles for Python 2 and 3 - Document how to use
python-decoupleordjango-configurationsto read environment variables for configuration values
- Added initial implementation for Django health checks based on Normandy and ATMO code. Many thanks to Mike Cooper for inspiration and majority of implementation.