Merge pull request #2764 from coreos-inc/joseph.schorr/QUAY-623/health-data-interface

Convert health check to use a data interface
This commit is contained in:
josephschorr 2017-07-12 11:36:27 +03:00 committed by GitHub
commit 457f685952
4 changed files with 35 additions and 10 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

@ -0,0 +1,14 @@
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. """
pass

10
health/models_pre_oci.py Normal file
View file

@ -0,0 +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

@ -1,7 +1,6 @@
import logging
from data.model import health
from app import build_logs, storage
from health.models_pre_oci import pre_oci_model as model
logger = logging.getLogger(__name__)
@ -30,12 +29,14 @@ def _check_registry_gunicorn(app):
def _check_database(app):
""" Returns the status of the database, as accessed from this instance. """
return health.check_health(app.config)
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: