landregistry-healthchecks


Namelandregistry-healthchecks JSON
Version 0.9.9 PyPI version JSON
download
home_pageNone
SummaryStandardised health endpoints for HMLR Flask applications
upload_time2024-10-31 13:54:25
maintainerNone
docs_urlNone
authorIan Harvey
requires_python>=3.9
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Health Checks for HMLR Flask Applications

## Consistent health endpoints

### Features
* Easy provision of standard /health endpoint
* Nearly easy provision of standard /health/cascade endpoint
* Helpers for web app and PostgreSQL dependencies


This package depends on:
* Flask
* Requests


#### Flask applications
Import `HealthChecks` and initialise it as a Flask extension:


Just enough to get /health working:
```python
from landregistry.healthchecks import HealthChecks
from <somewhere> import app

health = HealthChecks()
health.init_app(app)
```

Adding dependencies for the cascading health check:
```python
DEPENDENCIES = {
    "Postgres": SQLALCHEMY_DATABASE_URI,
    "some-app": 'http://some-app:8080'
}
health.add_dependencies(DEPENDENCIES)
```

#### Caution

This currently doesn't do anything clever with avoiding endpoint collisions. It'll just fail.


#### HealthChecks methods

On initialisation, the extension registers `/health` and `/health/cascade/<x>` endpoints without
futher intervention.

The behaviour of the endpoints is documented in `api/openapi.yml`.

**add_web_dependency(name, uri)**

Add a single web-app dependency. The URI should be the base URI for the service (this extension
will add `/health/cascade/<num>` as required).

**add_dependencies(dict)**

Create a set of standard dependency checks. Supply a dictionary of name/uri pairs. Compatible
with the DEPENDENCIES configuration item from the skeleton application. Will accept a pair with
a name of `postgres` and a value containing a SQLAlchemy connection URI.

**add_dependency(name, callback)**

Create a custom dependency check.

Adds a dependency named `name`. Callback is a function pointer. The supplied function should
return a dictionary (any contents will be added to the healthcheck response body) on success
or raise an exception to indicate failure.

Custom dependency results will appear in the 'db' field of the healthcheck response.

#### Custom dependency example

Somewhere, define your new health check helper method. It must return a dict on success (empty
is OK) and throw an exception on failure.

```python
def one_is_more_than_zero_healthcheck():
    if 1 <= 0:
        raise Exception('The numbers have gone wrong')
    return {}
```

Use this method as a callback in `add_dependency`:
```python
health = HealthChecks(app)

health.add_dependency('one_and_zero', one_is_more_than_zero_healthcheck)
```

Now your application will check that 1 is greater than 0 as part of its cascading healthcheck.


#### Configuration Options

Configure the package behaviour but setting application configuration values (e.g. in `config.py`).

The `/health` and `/health/cacasde/<x>` routes have the following options:

| Option                         | Default | Does what                                                                   |
| ------------------------------ | ------- | --------------------------------------------------------------------------- |
| HEALTH_INCLUDE_REQUEST_HEADERS | False   | If `True`, include request headers in healthcheck response `headers` field. |

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "landregistry-healthchecks",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": null,
    "keywords": null,
    "author": "Ian Harvey",
    "author_email": "ian.harvey@landregistry.gov.uk",
    "download_url": "https://files.pythonhosted.org/packages/e8/6a/034542ce7f6fc342808ffe77919eeba00a125526e8f04be82c06cfed6ed9/landregistry_healthchecks-0.9.9.tar.gz",
    "platform": null,
    "description": "# Health Checks for HMLR Flask Applications\n\n## Consistent health endpoints\n\n### Features\n* Easy provision of standard /health endpoint\n* Nearly easy provision of standard /health/cascade endpoint\n* Helpers for web app and PostgreSQL dependencies\n\n\nThis package depends on:\n* Flask\n* Requests\n\n\n#### Flask applications\nImport `HealthChecks` and initialise it as a Flask extension:\n\n\nJust enough to get /health working:\n```python\nfrom landregistry.healthchecks import HealthChecks\nfrom <somewhere> import app\n\nhealth = HealthChecks()\nhealth.init_app(app)\n```\n\nAdding dependencies for the cascading health check:\n```python\nDEPENDENCIES = {\n    \"Postgres\": SQLALCHEMY_DATABASE_URI,\n    \"some-app\": 'http://some-app:8080'\n}\nhealth.add_dependencies(DEPENDENCIES)\n```\n\n#### Caution\n\nThis currently doesn't do anything clever with avoiding endpoint collisions. It'll just fail.\n\n\n#### HealthChecks methods\n\nOn initialisation, the extension registers `/health` and `/health/cascade/<x>` endpoints without\nfuther intervention.\n\nThe behaviour of the endpoints is documented in `api/openapi.yml`.\n\n**add_web_dependency(name, uri)**\n\nAdd a single web-app dependency. The URI should be the base URI for the service (this extension\nwill add `/health/cascade/<num>` as required).\n\n**add_dependencies(dict)**\n\nCreate a set of standard dependency checks. Supply a dictionary of name/uri pairs. Compatible\nwith the DEPENDENCIES configuration item from the skeleton application. Will accept a pair with\na name of `postgres` and a value containing a SQLAlchemy connection URI.\n\n**add_dependency(name, callback)**\n\nCreate a custom dependency check.\n\nAdds a dependency named `name`. Callback is a function pointer. The supplied function should\nreturn a dictionary (any contents will be added to the healthcheck response body) on success\nor raise an exception to indicate failure.\n\nCustom dependency results will appear in the 'db' field of the healthcheck response.\n\n#### Custom dependency example\n\nSomewhere, define your new health check helper method. It must return a dict on success (empty\nis OK) and throw an exception on failure.\n\n```python\ndef one_is_more_than_zero_healthcheck():\n    if 1 <= 0:\n        raise Exception('The numbers have gone wrong')\n    return {}\n```\n\nUse this method as a callback in `add_dependency`:\n```python\nhealth = HealthChecks(app)\n\nhealth.add_dependency('one_and_zero', one_is_more_than_zero_healthcheck)\n```\n\nNow your application will check that 1 is greater than 0 as part of its cascading healthcheck.\n\n\n#### Configuration Options\n\nConfigure the package behaviour but setting application configuration values (e.g. in `config.py`).\n\nThe `/health` and `/health/cacasde/<x>` routes have the following options:\n\n| Option                         | Default | Does what                                                                   |\n| ------------------------------ | ------- | --------------------------------------------------------------------------- |\n| HEALTH_INCLUDE_REQUEST_HEADERS | False   | If `True`, include request headers in healthcheck response `headers` field. |\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Standardised health endpoints for HMLR Flask applications",
    "version": "0.9.9",
    "project_urls": null,
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "5450cf1f84a409360362f00007d122933009678ea1ef0bf29e20b226436194cc",
                "md5": "851985d9fb0d7104619f0274e3c7d55f",
                "sha256": "5b69bebc74d6e1ed38d171ae3eb0431910c9914d62f7990e85446ece4025982b"
            },
            "downloads": -1,
            "filename": "landregistry_healthchecks-0.9.9-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "851985d9fb0d7104619f0274e3c7d55f",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 7237,
            "upload_time": "2024-10-31T13:54:23",
            "upload_time_iso_8601": "2024-10-31T13:54:23.075807Z",
            "url": "https://files.pythonhosted.org/packages/54/50/cf1f84a409360362f00007d122933009678ea1ef0bf29e20b226436194cc/landregistry_healthchecks-0.9.9-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "e86a034542ce7f6fc342808ffe77919eeba00a125526e8f04be82c06cfed6ed9",
                "md5": "ea46591fc1ce80097a9860ff4c53f66e",
                "sha256": "8fb9e04359106eb8517a0be6e0675140a5c85c820448a91e066b0dfc0796fb2a"
            },
            "downloads": -1,
            "filename": "landregistry_healthchecks-0.9.9.tar.gz",
            "has_sig": false,
            "md5_digest": "ea46591fc1ce80097a9860ff4c53f66e",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 5750,
            "upload_time": "2024-10-31T13:54:25",
            "upload_time_iso_8601": "2024-10-31T13:54:25.010742Z",
            "url": "https://files.pythonhosted.org/packages/e8/6a/034542ce7f6fc342808ffe77919eeba00a125526e8f04be82c06cfed6ed9/landregistry_healthchecks-0.9.9.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-10-31 13:54:25",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "landregistry-healthchecks"
}
        
Elapsed time: 0.34937s