Add instance key ID to the health check endpoint

Fixes #1429
This commit is contained in:
Joseph Schorr 2016-07-05 14:14:22 -04:00
parent 781f2eec72
commit 7fddc61b8f
2 changed files with 11 additions and 9 deletions

View file

@ -12,7 +12,7 @@ from flask.ext.login import current_user
import features import features
from app import (app, billing as stripe, build_logs, avatar, signer, log_archive, config_provider, from app import (app, billing as stripe, build_logs, avatar, signer, log_archive, config_provider,
get_app_url) get_app_url, instance_keys)
from auth import scopes from auth import scopes
from auth.auth import require_session_login, process_oauth, has_basic_auth, process_auth_or_cookie from auth.auth import require_session_login, process_oauth, has_basic_auth, process_auth_or_cookie
from auth.permissions import (AdministerOrganizationPermission, ReadRepositoryPermission, from auth.permissions import (AdministerOrganizationPermission, ReadRepositoryPermission,
@ -234,7 +234,7 @@ def privacy():
@web.route('/health/instance', methods=['GET']) @web.route('/health/instance', methods=['GET'])
@no_cache @no_cache
def instance_health(): def instance_health():
checker = get_healthchecker(app, config_provider) checker = get_healthchecker(app, config_provider, instance_keys)
(data, status_code) = checker.check_instance() (data, status_code) = checker.check_instance()
response = jsonify(dict(data=data, status_code=status_code)) response = jsonify(dict(data=data, status_code=status_code))
response.status_code = status_code response.status_code = status_code
@ -246,7 +246,7 @@ def instance_health():
@web.route('/health/endtoend', methods=['GET']) @web.route('/health/endtoend', methods=['GET'])
@no_cache @no_cache
def endtoend_health(): def endtoend_health():
checker = get_healthchecker(app, config_provider) checker = get_healthchecker(app, config_provider, instance_keys)
(data, status_code) = checker.check_endtoend() (data, status_code) = checker.check_endtoend()
response = jsonify(dict(data=data, status_code=status_code)) response = jsonify(dict(data=data, status_code=status_code))
response.status_code = status_code response.status_code = status_code

View file

@ -4,15 +4,16 @@ from health.services import check_all_services
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
def get_healthchecker(app, config_provider): def get_healthchecker(app, config_provider, instance_keys):
""" Returns a HealthCheck instance for the given app. """ """ Returns a HealthCheck instance for the given app. """
return HealthCheck.get_checker(app, config_provider) return HealthCheck.get_checker(app, config_provider, instance_keys)
class HealthCheck(object): class HealthCheck(object):
def __init__(self, app, config_provider, instance_skips=None): def __init__(self, app, config_provider, instance_keys, instance_skips=None):
self.app = app self.app = app
self.config_provider = config_provider self.config_provider = config_provider
self.instance_keys = instance_keys
self.instance_skips = instance_skips or [] self.instance_skips = instance_skips or []
def check_instance(self): def check_instance(self):
@ -55,20 +56,21 @@ class HealthCheck(object):
'services': service_statuses, 'services': service_statuses,
'notes': notes, 'notes': notes,
'is_testing': self.app.config['TESTING'], 'is_testing': self.app.config['TESTING'],
'config_provider': self.config_provider.provider_id 'config_provider': self.config_provider.provider_id,
'local_service_key_id': self.instance_keys.local_key_id,
} }
return (data, 200 if is_healthy else 503) return (data, 200 if is_healthy else 503)
@classmethod @classmethod
def get_checker(cls, app, config_provider): def get_checker(cls, app, config_provider, instance_keys):
name = app.config['HEALTH_CHECKER'][0] name = app.config['HEALTH_CHECKER'][0]
parameters = app.config['HEALTH_CHECKER'][1] or {} parameters = app.config['HEALTH_CHECKER'][1] or {}
for subc in cls.__subclasses__(): for subc in cls.__subclasses__():
if name in subc.check_names(): if name in subc.check_names():
return subc(app, config_provider, **parameters) return subc(app, config_provider, instance_keys, **parameters)
raise Exception('Unknown health check with name %s' % name) raise Exception('Unknown health check with name %s' % name)