A simple module to allow you to easily add health endpoints to your Flask application
Project description
Flask-Healthz
Define endpoints in your Flask application that Kubernetes can use as liveness and readiness probes.
Setting it up
Register the blueprint on your Flask application:
from flask import Flask
from flask_healthz import healthz
app = Flask(__name__)
app.register_blueprint(healthz, url_prefix="/healthz")
Define the functions you want to use to check health. To signal an error, raise flask_healthz.HealthError
.
from flask_healthz import HealthError
def liveness():
pass
def readiness():
try:
connect_database()
except Exception:
raise HealthError("Can't connect to the database")
Now point to those functions in the Flask configuration:
HEALTHZ = {
"live": "yourapp.checks.liveness",
"ready": "yourapp.checks.readiness",
}
It is possible to directly set callables in the configuration, so you could write something like:
HEALTHZ = {
"live": lambda: None,
}
Check that the endpoints actually work:
$ curl http://localhost/yourapp/healthz/live
OK
$ curl http://localhost/yourapp/healthz/ready
OK
Now your can configure Kubernetes to check for those endpoints.
License
Copyright 2020 Red Hat
Flask-Healthz is licensed under the same license as Flask itself: BSD 3-clause.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for flask_healthz-0.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2115ed79be11c65f39b9cde173dd6fbec40f857f08e8390caf1d43fffe2b5306 |
|
MD5 | 44c036df3ce281926af4f3db183854ef |
|
BLAKE2b-256 | 0fe3b580546fe08ab3418db4e5e2ce27787f719d9b53a2b47460653012715174 |