Package: simple-health-checks
Simple health checks takes a modular plugin based approach to provide health checks that are right for you.Example response from health checks endpoint{"serviceName":"myProject","requestUrl":"localhost:8000/health/1/","datetime":"2021-11-19T11:53:26ZUTC","components":["Database","RabbitMQ"],"status":"OK","version":"1.5.0","simpleHealthChecksVersion":"1.0.0"}SetupEnvironment variablesThe following environment variables should be set up:SETTINGS_FILE_FOR_DYNACONF- Can be used to point to a config file to load the environment variables listed below,
check thedynaconf documentationHEALTH_CHECKS_RESOURCES- all resources available for health check,for env vars it should be set in the following format@json ["resource1", "resource2"]for ini files it can be set as=resource1,resource2without quotationsHEALTH_CHECKS_CRITICAL- same format required asHEALTH_CHECKS_RESOURCESresource file names (the same as you use inHEALTH_CHECKS) that are critical for the
application and will result in a DOWN status, they should also be present inHEALTH_CHECKSHEALTH_CHECKS_TIMEOUT- seconds until timeout, default 10HEALTH_CHECKS_CACHE_SECONDS- seconds to cache health check results, default 5HEALTH_CHECKS_SERVICE_NAME- name of the service you're adding this to (this should
match the filename of the resource if a health check exists for the service)HEALTH_CHECKS_SERVICE_VERSION- the current version of the service hosting this packageHEALTH_CHECKS_MAX_WORKERS- Number of workers to run processes in parallel, default 2If using thedjango_viewsplugin:HEALTH_CHECKS_TOKEN- token required to access health of dependenciesIf using therabbitmqplugin:HEALTH_CHECKS_RABBITMQ_BROKER_URL- the broker url used by rabbitmqInstalling for local developmentMove to thesrc/directory
Runpip install .To install plugins run:pip install plugins/<folder containing setup.py>from thesrc/directorySetting up a new resourceNotes: can_skip - does the resource you are adding support?skip=parameter - if not we should not send it (can_skip should be False) as
external dependencies can be sensitive to unknown query parametersPluginsPlugins can be created by following the directory structure shown in the existing plugins. They should mirror the structure ofsimple_health_checksYou can extend config by providing a file that addsdynaconfvalidators. This file should exist inadditional_configs/directory within your plugin, should containconfigin the filename and should define a list called validators containing your dynaconfValidator'sYou'll need both aVERSIONfile and aMANIFEST.infile containinginclude VERSION.Add the plugin's setup.py to thebuild_and_publish_pypistage in.gitlab-ci.ymland adding the version in to yourVERSIONfileAdd the plugin'spip installcommand to the.pystage using the path to your pluginssetup.pyEnsure that you add any modules that you wish to exist insimple_health_checksto yoursetup.pyunderpackages=an example is shown below for thedjango_viewspluginsetup(name="simple_health_checks_django_views",version="0.0.0",description="Django views plugin for simple-health-checks,"" adds endpoints for ping and health checks",packages=["simple_health_checks.views","simple_health_checks.serializers",],install_requires=["simple_health_checks","Django","djangorestframework",],)Notice this package adds two new modules,viewsandserializerstosimple_health_checks. If you wish to add a new file to an existing module, for example
adding a new resource toresourcesyou would addpackages=["simple_health_checks.resources"]You should avoid making any config required and instead use a default value, preferringis_configuredon the resource to define whether a resource has been
correctly configured. Another reason for this is that we initialiseHealthCheckwithinsimple_health_checks.health_checkswhich will be problematic for testing.