parent
781f2eec72
commit
7fddc61b8f
2 changed files with 11 additions and 9 deletions
|
@ -12,7 +12,7 @@ from flask.ext.login import current_user
|
|||
import features
|
||||
|
||||
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.auth import require_session_login, process_oauth, has_basic_auth, process_auth_or_cookie
|
||||
from auth.permissions import (AdministerOrganizationPermission, ReadRepositoryPermission,
|
||||
|
@ -234,7 +234,7 @@ def privacy():
|
|||
@web.route('/health/instance', methods=['GET'])
|
||||
@no_cache
|
||||
def instance_health():
|
||||
checker = get_healthchecker(app, config_provider)
|
||||
checker = get_healthchecker(app, config_provider, instance_keys)
|
||||
(data, status_code) = checker.check_instance()
|
||||
response = jsonify(dict(data=data, status_code=status_code))
|
||||
response.status_code = status_code
|
||||
|
@ -246,7 +246,7 @@ def instance_health():
|
|||
@web.route('/health/endtoend', methods=['GET'])
|
||||
@no_cache
|
||||
def endtoend_health():
|
||||
checker = get_healthchecker(app, config_provider)
|
||||
checker = get_healthchecker(app, config_provider, instance_keys)
|
||||
(data, status_code) = checker.check_endtoend()
|
||||
response = jsonify(dict(data=data, status_code=status_code))
|
||||
response.status_code = status_code
|
||||
|
|
|
@ -4,15 +4,16 @@ from health.services import check_all_services
|
|||
|
||||
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. """
|
||||
return HealthCheck.get_checker(app, config_provider)
|
||||
return HealthCheck.get_checker(app, config_provider, instance_keys)
|
||||
|
||||
|
||||
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.config_provider = config_provider
|
||||
self.instance_keys = instance_keys
|
||||
self.instance_skips = instance_skips or []
|
||||
|
||||
def check_instance(self):
|
||||
|
@ -55,20 +56,21 @@ class HealthCheck(object):
|
|||
'services': service_statuses,
|
||||
'notes': notes,
|
||||
'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)
|
||||
|
||||
|
||||
@classmethod
|
||||
def get_checker(cls, app, config_provider):
|
||||
def get_checker(cls, app, config_provider, instance_keys):
|
||||
name = app.config['HEALTH_CHECKER'][0]
|
||||
parameters = app.config['HEALTH_CHECKER'][1] or {}
|
||||
|
||||
for subc in cls.__subclasses__():
|
||||
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)
|
||||
|
||||
|
|
Reference in a new issue