diff --git a/health/healthcheck.py b/health/healthcheck.py index 4208a0a62..cfb427a31 100644 --- a/health/healthcheck.py +++ b/health/healthcheck.py @@ -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' diff --git a/health/models_interface.py b/health/models_interface.py index 1d82ce934..ff49a4dde 100644 --- a/health/models_interface.py +++ b/health/models_interface.py @@ -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. """ diff --git a/health/models_pre_oci.py b/health/models_pre_oci.py index 54178a19b..9f50b55eb 100644 --- a/health/models_pre_oci.py +++ b/health/models_pre_oci.py @@ -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() diff --git a/health/services.py b/health/services.py index 1946db5c5..49ba07199 100644 --- a/health/services.py +++ b/health/services.py @@ -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: