Skip to content

Commit

Permalink
changed cache check from critical to not critical (fix #341) (#402)
Browse files Browse the repository at this point in the history
* changed cache check from critical to not critical (fix #341)
* add _check_not_critical function
  • Loading branch information
chicco785 committed Nov 30, 2020
1 parent e4e8312 commit 07a9408
Showing 1 changed file with 22 additions and 16 deletions.
38 changes: 22 additions & 16 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 geocache (critical)
health = check_cache()
if health['status'] != 'pass':
res.setdefault('details', {})['redis'] = health
if health['status'] == 'fail' or res['status'] == 'pass':
res['status'] = health['status']
# Check cache (not critical)
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 07a9408

Please sign in to comment.