Have the health check also ping the registry endpoint to make sure it is functional.

This commit is contained in:
Joseph Schorr 2015-01-14 23:39:58 -05:00
parent 90b724d3a0
commit a4de476a85
3 changed files with 24 additions and 7 deletions

View file

@ -156,11 +156,21 @@ def v1():
@web.route('/health', methods=['GET'])
@no_cache
def health():
client = app.config['HTTPCLIENT']
db_healthy = model.check_health()
buildlogs_healthy = build_logs.check_health()
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)
registry_healthy = client.get(registry_url, verify=False).status_code == 200
check = HealthCheck.get_check(app.config['HEALTH_CHECKER'][0], app.config['HEALTH_CHECKER'][1])
(data, is_healthy) = check.conduct_healthcheck(db_healthy, buildlogs_healthy)
(data, is_healthy) = check.conduct_healthcheck(db_healthy, buildlogs_healthy, registry_healthy)
response = jsonify(dict(data=data, is_healthy=is_healthy))
response.status_code = 200 if is_healthy else 503