common.app.health_check module
Health check module. It runs a web service on localhost and the specified port. The health state of the application can be queried at the ‘health’ end point.
The implementation of health check response is based on ‘Health Check Response Format for HTTP APIs’ (https://datatracker.ietf.org/doc/html/draft-inadarei-api-health-check-06)
- class common.app.health_check.State(value)
Bases:
EnumPossible microservice states
- WARMUP = 'Warming up'
- WORK = 'Working'
- SHUTDOWN = 'Shutting down'
- NOINFO = 'No information'
- class common.app.health_check.Status(value)
Bases:
EnumPossible statuses the api can return
- PASS = 'pass'
- FAIL = 'fail'
- WARN = 'warn'
- class common.app.health_check.Response(service_name: str)
Bases:
objectParent class of different responses
- notes: List[str]
- __init__(service_name: str)
- property create_response
Composes the response to an http request
- class common.app.health_check.Pass(service_name: str)
Bases:
ResponseResponse of passed status. For “pass” status, HTTP response code in the 2xx-3xx range MUST be used.
- status_code = 200
- notes: List[str] = ['Service is running']
- class common.app.health_check.Fail(service_name: str)
Bases:
ResponseResponse of failed status. For “fail” status, HTTP response code in the 4xx-5xx range MUST be used.
- status_code = 503
- notes: List[str] = ['No information about the service']
- class common.app.health_check.Warn(service_name: str)
Bases:
ResponseResponse of warning status. In case of the “warn” status, endpoints MUST return HTTP status in the 2xx-3xx range, and additional information SHOULD be provided, utilizing optional fields of the response.
- status_code = 202
- notes: List[str] = ['Service is not healthy, it is warming up or shutting down']
- class common.app.health_check.HealthCheck(logger, service_name: str, host='127.0.0.1', port=8008)
Bases:
objectClass for running web service to access the ‘health’ endpoint
- __init__(logger, service_name: str, host='127.0.0.1', port=8008)
- async health(_msg)
Handler for the health check endpoint. The response is in JSON format.
- async run_server()
Run the web service on localhost and the specified port
- set_state_warm_up()
Set the service state to ‘Warming up’
- set_state_working()
Set the service state to ‘Working’
- set_state_shut_down()
Set the service state to ‘Shutting down’
- set_state_no_info()
Set the service state to ‘No information’