This repository has been archived on 2020-03-24. You can view files and clone it, but cannot push or open issues or pull requests.
quay/health/services.py

73 lines
2.3 KiB
Python
Raw Normal View History

import logging
2017-05-11 03:55:19 +00:00
from app import build_logs, storage, authentication
2017-07-11 10:48:25 +00:00
from health.models_pre_oci import pre_oci_model as model
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]
scheme = app.config['PREFERRED_URL_SCHEME']
if app.config.get('EXTERNAL_TLS_TERMINATION', False):
scheme = 'http'
registry_url = '%s://localhost%s/v1/_internal_ping' % (scheme, port)
try:
status_code = client.get(registry_url, verify=False, timeout=2).status_code
return (status_code == 200, 'Got non-200 response for registry: %s' % status_code)
except Exception as ex:
logger.exception('Exception when checking registry health: %s', registry_url)
return (False, 'Exception when checking registry health: %s' % registry_url)
2017-07-11 10:48:55 +00:00
def _check_database(app):
""" Returns the status of the database, as accessed from this instance. """
2017-07-11 10:48:25 +00:00
return model.check_health(app.config)
2017-07-11 10:48:55 +00:00
def _check_redis(app):
""" Returns the status of Redis, as accessed from this instance. """
return build_logs.check_health()
2017-07-11 10:48:55 +00:00
def _check_storage(app):
""" Returns the status of storage, as accessed from this instance. """
try:
storage.validate(storage.preferred_locations, app.config['HTTPCLIENT'])
return (True, None)
except Exception as ex:
logger.exception('Storage check failed with exception %s', ex)
return (False, 'Storage check failed with exception %s' % ex.message)
2017-05-11 03:55:19 +00:00
def _check_auth(app):
""" Returns the status of the auth engine, as accessed from this instance. """
return authentication.ping()
2017-05-11 03:55:19 +00:00
_SERVICES = {
'registry_gunicorn': _check_registry_gunicorn,
'database': _check_database,
'redis': _check_redis,
'storage': _check_storage,
2017-05-11 03:55:19 +00:00
'auth': _check_auth,
}
def check_all_services(app, skip):
""" Returns a dictionary containing the status of all the services defined. """
status = {}
for name in _SERVICES:
if name in skip:
continue
status[name] = _SERVICES[name](app)
return status