This commit is contained in:
Joseph Schorr 2017-07-11 13:48:55 +03:00
parent 4853634c2f
commit 7b1dfbb256
4 changed files with 14 additions and 8 deletions

View file

@ -4,6 +4,7 @@ from health.services import check_all_services
logger = logging.getLogger(__name__)
def get_healthchecker(app, config_provider, instance_keys):
""" Returns a HealthCheck instance for the given app. """
return HealthCheck.get_checker(app, config_provider, instance_keys)
@ -62,7 +63,6 @@ class HealthCheck(object):
return (data, 200 if is_healthy else 503)
@classmethod
def get_checker(cls, app, config_provider, instance_keys):
name = app.config['HEALTH_CHECKER'][0]
@ -77,8 +77,8 @@ class HealthCheck(object):
class LocalHealthCheck(HealthCheck):
def __init__(self, app, config_provider, instance_keys):
super(LocalHealthCheck, self).__init__(app, config_provider, instance_keys,
['redis', 'storage'])
super(LocalHealthCheck, self).__init__(app, config_provider, instance_keys, [
'redis', 'storage'])
@classmethod
def check_names(cls):
@ -88,8 +88,8 @@ class LocalHealthCheck(HealthCheck):
class RDSAwareHealthCheck(HealthCheck):
def __init__(self, app, config_provider, instance_keys, access_key, secret_key,
db_instance='quay', region='us-east-1'):
super(RDSAwareHealthCheck, self).__init__(app, config_provider, instance_keys,
['redis', 'storage'])
super(RDSAwareHealthCheck, self).__init__(app, config_provider, instance_keys, [
'redis', 'storage'])
self.access_key = access_key
self.secret_key = secret_key
@ -121,7 +121,6 @@ class RDSAwareHealthCheck(HealthCheck):
return self.calculate_overall_health(service_statuses, skip=skip, notes=notes)
def _get_rds_status(self):
""" Returns the status of the RDS instance as reported by AWS. """
try:
@ -130,7 +129,8 @@ class RDSAwareHealthCheck(HealthCheck):
response = region.describe_db_instances()['DescribeDBInstancesResponse']
result = response['DescribeDBInstancesResult']
instances = [i for i in result['DBInstances'] if i['DBInstanceIdentifier'] == self.db_instance]
instances = [
i for i in result['DBInstances'] if i['DBInstanceIdentifier'] == self.db_instance]
if not instances:
return 'error'

View file

@ -1,11 +1,13 @@
from abc import ABCMeta, abstractmethod
from six import add_metaclass
@add_metaclass(ABCMeta)
class HealthCheckDataInterface(object):
"""
Interface that represents all data store interactions required by health checks.
"""
@abstractmethod
def check_health(self, app_config):
""" Returns True if the connection to the database is healthy and False otherwise. """

View file

@ -1,8 +1,10 @@
from data.model import health
from health.models_interface import HealthCheckDataInterface
class PreOCIModel(HealthCheckDataInterface):
def check_health(self, app_config):
return health.check_health(app_config)
pre_oci_model = PreOCIModel()

View file

@ -2,7 +2,6 @@ import logging
from app import build_logs, storage
from health.models_pre_oci import pre_oci_model as model
logger = logging.getLogger(__name__)
@ -27,14 +26,17 @@ def _check_registry_gunicorn(app):
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()
def _check_storage(app):
""" Returns the status of storage, as accessed from this instance. """
try: