flask-healthz


Nameflask-healthz JSON
Version 1.0.1 PyPI version JSON
download
home_pagehttps://github.com/fedora-infra/flask-healthz
SummaryA simple module to allow you to easily add health endpoints to your Flask application
upload_time2023-10-30 15:26:00
maintainer
docs_urlNone
authorFedora Infrastructure
requires_python>=3.8.0,<4.0.0
licenseBSD-3-Clause
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Flask-Healthz

Define endpoints in your Flask application that Kubernetes can use as
[liveness and readiness probes](https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes/).


## Setting it up

### Blueprint

Register the blueprint on your Flask application:

```python
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`.

```python
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:

```python
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:

```python
HEALTHZ = {
    "live": lambda: None,
}
```

Check that the endpoints actually work:

```
$ curl http://localhost/yourapp/healthz/live
{"status": 200, "title": "OK"}
$ curl http://localhost/yourapp/healthz/ready
{"status": 200, "title": "OK"}
```

Now your can configure Kubernetes or OpenShift to check for those endpoints.

### Extension

You can also use the provided Flask extension to register the `healthz` blueprint:

```python
from flask import Flask
from flask_healthz import Healthz

app = Flask(__name__)
Healthz(app)
```

The rest of the configuration is identical.

The extension has an additional option, `no_log`, that can disable logging of the HTTP requests
handled by your healthz endpoints, to avoid cluttering your web log files with automated requests.
At the moment, only the [gunicorn](https://gunicorn.org/) web server is supported.

```python
Healthz(app, no_log=True)
```

## Examples

Here's an example of how you could use flask-healthz in OpenShift's `deploymentconfig`:

```yaml
kind: DeploymentConfig
spec:
  [...]
  template:
    [...]
    spec:
      containers:
      - name: yourapp
        [...]
        livenessProbe:
          httpGet:
            path: /healthz/live
            port: 8080
          initialDelaySeconds: 5
          timeoutSeconds: 1
        readinessProbe:
          httpGet:
            path: /healthz/ready
            port: 8080
          initialDelaySeconds: 5
          timeoutSeconds: 1
```

Some projects that have setup flask-healthz:

- Noggin: https://github.com/fedora-infra/noggin/pull/287
- FASJSON: https://github.com/fedora-infra/fasjson/pull/81


## License

Copyright 2020-2021 Red Hat

Flask-Healthz is licensed under the same license as Flask itself: BSD 3-clause.


[![codecov](https://codecov.io/gh/fedora-infra/flask-healthz/branch/dev/graph/badge.svg?token=lwlZLiSImq)](https://codecov.io/gh/fedora-infra/flask-healthz)


            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/fedora-infra/flask-healthz",
    "name": "flask-healthz",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8.0,<4.0.0",
    "maintainer_email": "",
    "keywords": "",
    "author": "Fedora Infrastructure",
    "author_email": "admin@fedoraproject.org",
    "download_url": "https://files.pythonhosted.org/packages/6e/a3/4566a5059d8ac22a8be35b34f22b0e6c02997a6e7c85cddcbf4f49f303a9/flask_healthz-1.0.1.tar.gz",
    "platform": null,
    "description": "# Flask-Healthz\n\nDefine endpoints in your Flask application that Kubernetes can use as\n[liveness and readiness probes](https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes/).\n\n\n## Setting it up\n\n### Blueprint\n\nRegister the blueprint on your Flask application:\n\n```python\nfrom flask import Flask\nfrom flask_healthz import healthz\n\napp = Flask(__name__)\napp.register_blueprint(healthz, url_prefix=\"/healthz\")\n```\n\nDefine the functions you want to use to check health. To signal an error, raise `flask_healthz.HealthError`.\n\n```python\nfrom flask_healthz import HealthError\n\ndef liveness():\n    pass\n\ndef readiness():\n    try:\n        connect_database()\n    except Exception:\n        raise HealthError(\"Can't connect to the database\")\n```\n\nNow point to those functions in the Flask configuration:\n\n```python\nHEALTHZ = {\n    \"live\": \"yourapp.checks.liveness\",\n    \"ready\": \"yourapp.checks.readiness\",\n}\n```\n\nIt is possible to directly set callables in the configuration, so you could write something like:\n\n```python\nHEALTHZ = {\n    \"live\": lambda: None,\n}\n```\n\nCheck that the endpoints actually work:\n\n```\n$ curl http://localhost/yourapp/healthz/live\n{\"status\": 200, \"title\": \"OK\"}\n$ curl http://localhost/yourapp/healthz/ready\n{\"status\": 200, \"title\": \"OK\"}\n```\n\nNow your can configure Kubernetes or OpenShift to check for those endpoints.\n\n### Extension\n\nYou can also use the provided Flask extension to register the `healthz` blueprint:\n\n```python\nfrom flask import Flask\nfrom flask_healthz import Healthz\n\napp = Flask(__name__)\nHealthz(app)\n```\n\nThe rest of the configuration is identical.\n\nThe extension has an additional option, `no_log`, that can disable logging of the HTTP requests\nhandled by your healthz endpoints, to avoid cluttering your web log files with automated requests.\nAt the moment, only the [gunicorn](https://gunicorn.org/) web server is supported.\n\n```python\nHealthz(app, no_log=True)\n```\n\n## Examples\n\nHere's an example of how you could use flask-healthz in OpenShift's `deploymentconfig`:\n\n```yaml\nkind: DeploymentConfig\nspec:\n  [...]\n  template:\n    [...]\n    spec:\n      containers:\n      - name: yourapp\n        [...]\n        livenessProbe:\n          httpGet:\n            path: /healthz/live\n            port: 8080\n          initialDelaySeconds: 5\n          timeoutSeconds: 1\n        readinessProbe:\n          httpGet:\n            path: /healthz/ready\n            port: 8080\n          initialDelaySeconds: 5\n          timeoutSeconds: 1\n```\n\nSome projects that have setup flask-healthz:\n\n- Noggin: https://github.com/fedora-infra/noggin/pull/287\n- FASJSON: https://github.com/fedora-infra/fasjson/pull/81\n\n\n## License\n\nCopyright 2020-2021 Red Hat\n\nFlask-Healthz is licensed under the same license as Flask itself: BSD 3-clause.\n\n\n[![codecov](https://codecov.io/gh/fedora-infra/flask-healthz/branch/dev/graph/badge.svg?token=lwlZLiSImq)](https://codecov.io/gh/fedora-infra/flask-healthz)\n\n",
    "bugtrack_url": null,
    "license": "BSD-3-Clause",
    "summary": "A simple module to allow you to easily add health endpoints to your Flask application",
    "version": "1.0.1",
    "project_urls": {
        "Homepage": "https://github.com/fedora-infra/flask-healthz",
        "Repository": "https://github.com/fedora-infra/flask-healthz"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "fd4290a825d7f90332b298c670fa78adfad4c401a3dcab41873b8f3e096ad958",
                "md5": "c87b45e29a4b59a01feda4a9a90caa1c",
                "sha256": "208e1f35d12d70bca623ac2dd9de17813c397f9f0a0c09aa746b4a543c75615d"
            },
            "downloads": -1,
            "filename": "flask_healthz-1.0.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "c87b45e29a4b59a01feda4a9a90caa1c",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8.0,<4.0.0",
            "size": 7411,
            "upload_time": "2023-10-30T15:25:59",
            "upload_time_iso_8601": "2023-10-30T15:25:59.400978Z",
            "url": "https://files.pythonhosted.org/packages/fd/42/90a825d7f90332b298c670fa78adfad4c401a3dcab41873b8f3e096ad958/flask_healthz-1.0.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "6ea34566a5059d8ac22a8be35b34f22b0e6c02997a6e7c85cddcbf4f49f303a9",
                "md5": "beab3f58f1ca17767cff0615c622b5fd",
                "sha256": "3b25bfd8606950a77632925cfbbf19cac20650be51fc0efbe78c387e559e2541"
            },
            "downloads": -1,
            "filename": "flask_healthz-1.0.1.tar.gz",
            "has_sig": false,
            "md5_digest": "beab3f58f1ca17767cff0615c622b5fd",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8.0,<4.0.0",
            "size": 5341,
            "upload_time": "2023-10-30T15:26:00",
            "upload_time_iso_8601": "2023-10-30T15:26:00.505287Z",
            "url": "https://files.pythonhosted.org/packages/6e/a3/4566a5059d8ac22a8be35b34f22b0e6c02997a6e7c85cddcbf4f49f303a9/flask_healthz-1.0.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-10-30 15:26:00",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "fedora-infra",
    "github_project": "flask-healthz",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "tox": true,
    "lcname": "flask-healthz"
}
        
Elapsed time: 0.38754s