Skip to content

Commit

Permalink
add _check_not_critical function
Browse files Browse the repository at this point in the history
  • Loading branch information
chicco785 committed Nov 21, 2020
1 parent 30e760c commit 98e4925
Showing 1 changed file with 21 additions and 15 deletions.
36 changes: 21 additions & 15 deletions src/reporter/health.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,21 @@ def _get_http_code(res):
return code


def _check_not_critical(health, res, service):
if health['status'] != 'pass':
res.setdefault('details', {})[service] = health
if res['status'] == 'pass':
res['status'] = 'warn'
return res


def _check_critical(health, res, service):
if health['status'] != 'pass':
res['status'] = health['status']
res.setdefault('details', {})[service] = health
return res


def get_health(with_geocoder=False):
"""
Return status of QuantumLeap service, taking into account status of the
Expand All @@ -56,32 +71,23 @@ def get_health(with_geocoder=False):
This endpoint should be memoized (with timeout of course).
"""
res = {}
res = {
'status': 'pass'
}

# Check crateDB (critical)
try:
health = check_crate()
res['status'] = health['status']
if health['status'] != 'pass':
res.setdefault('details', {})['crateDB'] = health
res = _check_critical(check_crate(), res, 'crateDB')
except Exception:
res['status'] = 'fail'
res.setdefault('details', {})['crateDB'] = 'cannot reach crate'

# Check cache (not critical)
health = check_cache()
if health['status'] != 'pass':
res.setdefault('details', {})['redis'] = health
if res['status'] == 'pass':
res['status'] = 'warn'
res = _check_not_critical(check_cache(), res, 'redis')

# Check geocoder (not critical)
if with_geocoder:
health = check_geocoder()
if health['status'] != 'pass':
res.setdefault('details', {})['osm'] = health
if res['status'] == 'pass':
res['status'] = 'warn'
res = _check_not_critical(check_geocoder(), res, 'osm')

# Determine HTTP code
code = _get_http_code(res)
Expand Down

0 comments on commit 98e4925

Please sign in to comment.