Skip to main content

sanic-healthchecks

Code style: black PyPI version PyPI pyversions PyPI - Downloads

sanic-healthchecks makes it easy for you to start a healthcheck server on a different thread than your actual Sanic application.

Installation

pip3 install sanic-healthchecks

Healthcheck Example

from sanic import Sanic
from sanic.response import json

from sanic_healthchecks import start_healthcheck_server, healthcheck_response

APP = Sanic()


async def healthcheck_handler(_):
    data = {"status": "ok"}
    return healthcheck_response(data)


@APP.route("/")
async def root(_):
    return json({"example_of": "a very simple healthcheck"})


if __name__ == "__main__":
    start_healthcheck_server(healthcheck_handler)
    APP.run(host="0.0.0.0", port=8000)

Your Sanic application will now respond on to healthchecks on a different port:

⇒  curl http://localhost:8000 -i
HTTP/1.1 200 OK
Connection: keep-alive
Keep-Alive: 5
Content-Length: 17
Content-Type: application/json

{"hello":"world"}

⇒  curl http://localhost:8082 -i
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
Content-Length: 16
Date: Sun, 03 Mar 2019 20:55:52 GMT
Server: Python/3.7 aiohttp/3.5.4

{"status": "ok"}

Changelog

Release Changelogs.

License

Apache 2.0

But why?

Why would you want to run your healthchecks on a different thread, as opposed to creating another endpoint on your actual Sanic server?

Great question, internet stranger, and I have a few answers.

By running your healthchecks separately, we maintain a strong separation of concerns. Since Sanic runs on a single thread, then any time you need to respond to healthchecks, you're actually taking compute time away from the event loop that is powering the actual requests that your application is there to serve. Likewise, the state of your actual application is not going to affect the healthchecks. There's a few camps of thought on this subject.

Some people say that if your web service isn't capable of responding to your healthcheck probe, then the service shouldn't be considered healthy. I can totally understand and respect this perspective, and if this is how you feel, then there's no need to use sanic-healthchecks.

On the other hand, if you're like me, you've convinced yourself that the point of healthchecks isn't purely to determine if the service can respond, but also to determine if your service has everything that it needs from downstream dependencies. If your requests are taking so long that the readiness or liveness probes are timing out, that could mean that your service is unhealthy, but it also could be a symptom of services that have long running requests.

Since we can run the healthchecks on a different web server entirely, we have the ability to check that all of the downstream dependencies, like databases and other services, are available. This helps narrow the problems with why a service might be in a degraded state.

I would even make an argument that an increase in response latency could be a metric that you use for automatically scaling your service. Treating it as a way to kill instances makes it much fuzzier in terms of how to interpret the increase in latency.

Another great reason to run your healthchecks on a different server is so that you can assign a different port to this new server. This is valuable because your healthchecks might actually have debug information in them that should not be exposed to the same groups of people who are able to consume the main service. By putting healthchecks on a different port, you can make sure to map your load balancer to not include this healthcheck port.

Metadata

Release files for sanic-healthchecks 1.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for sanic-healthchecks 1.0.1
File Size Uploaded Provenance
sanic-healthchecks-1.0.1.tar.gz 8.2 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for sanic-healthchecks 1.0.1
File Interpreter ABI Platform
sanic_healthchecks-1.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 16.7 kB

Release files / sanic-healthchecks-1.0.1.tar.gz

Download URL sanic-healthchecks-1.0.1.tar.gz
Size 8.2 kB
Tags Source
SHA-256 checksum
How to use checksums
40c2fc586bf50977138a0ab27aa1458ceee0acc0ef5f05ed79d72d61ebb048cf
BLAKE2b-256 checksum
How to use checksums
a170481f16f43210a70e27ef32ea3414dee107fff6cc2d9bf8f2ffeead6b34bb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/0.12.16 CPython/3.7.3 Linux/4.15.0-1032-gcp

Release files / sanic_healthchecks-1.0.1-py3-none-any.whl

Download URL sanic_healthchecks-1.0.1-py3-none-any.whl
Size 8.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
09c181506d3e11377090e538b4251272b4f672df3575cd29873137b0db75665a
BLAKE2b-256 checksum
How to use checksums
550cb9b82755d2cfc9aa5f711b3423cf4e1342045d17443f14920cd8d67cd780
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/0.12.16 CPython/3.7.3 Linux/4.15.0-1032-gcp

Security for sanic-healthchecks 1.0.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page