Add RDSAwareHealthCheck
as alias for ProductionHealthCheck
This commit is contained in:
parent
685dd1a925
commit
45fe46d619
1 changed files with 13 additions and 10 deletions
|
@ -67,7 +67,7 @@ class HealthCheck(object):
|
||||||
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 subc.check_name() == name:
|
if name in subc.check_names():
|
||||||
return subc(app, config_provider, **parameters)
|
return subc(app, config_provider, **parameters)
|
||||||
|
|
||||||
raise Exception('Unknown health check with name %s' % name)
|
raise Exception('Unknown health check with name %s' % name)
|
||||||
|
@ -75,20 +75,22 @@ class HealthCheck(object):
|
||||||
|
|
||||||
class LocalHealthCheck(HealthCheck):
|
class LocalHealthCheck(HealthCheck):
|
||||||
@classmethod
|
@classmethod
|
||||||
def check_name(cls):
|
def check_names(cls):
|
||||||
return 'LocalHealthCheck'
|
return ['LocalHealthCheck']
|
||||||
|
|
||||||
|
|
||||||
class ProductionHealthCheck(HealthCheck):
|
class RDSAwareHealthCheck(HealthCheck):
|
||||||
def __init__(self, app, config_provider, access_key, secret_key, db_instance='quay'):
|
def __init__(self, app, config_provider, access_key, secret_key, db_instance='quay',
|
||||||
super(ProductionHealthCheck, self).__init__(app, config_provider, ['redis'])
|
region='us-east-1'):
|
||||||
|
super(RDSAwareHealthCheck, self).__init__(app, config_provider, ['redis'])
|
||||||
self.access_key = access_key
|
self.access_key = access_key
|
||||||
self.secret_key = secret_key
|
self.secret_key = secret_key
|
||||||
self.db_instance = db_instance
|
self.db_instance = db_instance
|
||||||
|
self.region = region
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def check_name(cls):
|
def check_names(cls):
|
||||||
return 'ProductionHealthCheck'
|
return ['RDSAwareHealthCheck', 'ProductionHealthCheck']
|
||||||
|
|
||||||
def get_instance_health(self, service_statuses):
|
def get_instance_health(self, service_statuses):
|
||||||
# Note: We skip the redis check because if redis is down, we don't want ELB taking the
|
# Note: We skip the redis check because if redis is down, we don't want ELB taking the
|
||||||
|
@ -115,8 +117,9 @@ class ProductionHealthCheck(HealthCheck):
|
||||||
def _get_rds_status(self):
|
def _get_rds_status(self):
|
||||||
""" Returns the status of the RDS instance as reported by AWS. """
|
""" Returns the status of the RDS instance as reported by AWS. """
|
||||||
try:
|
try:
|
||||||
region = boto.rds2.connect_to_region('us-east-1',
|
region = boto.rds2.connect_to_region(self.region, aws_access_key_id=self.access_key,
|
||||||
aws_access_key_id=self.access_key, aws_secret_access_key=self.secret_key)
|
aws_secret_access_key=self.secret_key)
|
||||||
|
|
||||||
response = region.describe_db_instances()['DescribeDBInstancesResponse']
|
response = region.describe_db_instances()['DescribeDBInstancesResponse']
|
||||||
result = response['DescribeDBInstancesResult']
|
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]
|
||||||
|
|
Reference in a new issue