Clean up the health checking code and move the endpoints to /health/instance and /health/endtoend.
This commit is contained in:
parent
92d32bc636
commit
b74b7de197
3 changed files with 146 additions and 88 deletions
46
health/services.py
Normal file
46
health/services.py
Normal file
|
@ -0,0 +1,46 @@
|
|||
import logging
|
||||
from data import model
|
||||
from app import build_logs
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
def _check_registry_gunicorn(app):
|
||||
""" Returns the status of the registry gunicorn workers. """
|
||||
# Compute the URL for checking the registry endpoint. We append a port if and only if the
|
||||
# hostname contains one.
|
||||
client = app.config['HTTPCLIENT']
|
||||
hostname_parts = app.config['SERVER_HOSTNAME'].split(':')
|
||||
port = ''
|
||||
if len(hostname_parts) == 2:
|
||||
port = ':' + hostname_parts[1]
|
||||
|
||||
registry_url = '%s://localhost%s/v1/_internal_ping' % (app.config['PREFERRED_URL_SCHEME'], port)
|
||||
try:
|
||||
return client.get(registry_url, verify=False, timeout=2).status_code == 200
|
||||
except Exception:
|
||||
logger.exception('Exception when checking registry health: %s', registry_url)
|
||||
return False
|
||||
|
||||
|
||||
def _check_database(app):
|
||||
""" Returns the status of the database, as accessed from this instance. """
|
||||
return model.check_health(app.config)
|
||||
|
||||
def _check_redis(app):
|
||||
""" Returns the status of Redis, as accessed from this instance. """
|
||||
return build_logs.check_health()
|
||||
|
||||
|
||||
_SERVICES = {
|
||||
'registry_gunicorn': _check_registry_gunicorn,
|
||||
'database': _check_database,
|
||||
'redis': _check_redis
|
||||
}
|
||||
|
||||
def check_all_services(app):
|
||||
""" Returns a dictionary containing the status of all the services defined. """
|
||||
status = {}
|
||||
for name in _SERVICES:
|
||||
status[name] = _SERVICES[name](app)
|
||||
|
||||
return status
|
Reference in a new issue