Skip to content

Commit

Permalink
Fix fourfront_performance_metrics to work with new stats headers
Browse files Browse the repository at this point in the history
  • Loading branch information
carlvitzthum committed Jun 4, 2018
1 parent 1611c0e commit bfea247
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions chalicelib/system_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,22 +218,29 @@ def fourfront_performance_metrics(connection, **kwargs):
'files-fastq/4DNFIX75FSJM/?datastore=database'
]
for check_url in check_urls:
performance[check_url] = {}
try:
# set timeout really high
ff_resp = ff_utils.authorized_request(connection.ff_server + check_url, ff_env=connection.ff_env, timeout=1000)
except:
ff_resp = None
except Exception as e:
performance[check_url]['error'] = str(e)
if ff_resp and hasattr(ff_resp, 'headers') and 'X-stats' in ff_resp.headers:
x_stats = ff_resp.headers['X-stats']
if not isinstance(x_stats, basestring):
performance[check_url] = {}
performance[check_url]['error'] = 'Stats response is not a string.'
continue
# X-stats in form: 'db_count=148&db_time=1215810&es_count=4& ... '
split_stats = x_stats.strip().split('&')
parse_stats = [stat.split('=') for stat in split_stats]
performance[check_url] = {stat[0]: int(stat[1]) for stat in parse_stats if len(stat) == 2}
else:
performance[check_url] = {}
# stats can be strings or integers
for stat in parse_stats:
if not len(stat) == 2:
continue
try:
performance[check_url][stat[0]] = int(stat[1])
except ValueError:
performance[check_url][stat[0]] = stat[1]
performance[check_url]['error'] = ''
check.status = 'PASS'
full_output['performance'] = performance
check.full_output = full_output
Expand Down Expand Up @@ -354,8 +361,8 @@ def secondary_queue_deduplication(connection, **kwargs):
check.description = 'Items on %s secondary queue were deduplicated. Started with approximately %s items; replaced %s items and removed %s duplicates. Covered %s unique uuids. Took %s seconds.' % (connection.ff_env, starting_count, replaced, deduplicated, len(seen_uuids), elapsed)

return check


@check_function()
def clean_up_travis_queues(connection, **kwargs):
"""
Expand Down Expand Up @@ -383,6 +390,6 @@ def clean_up_travis_queues(connection, **kwargs):
print('... %s' % queue.url)
queue.delete()
num_deleted += 1
check.description = 'Cleaned up all indexing queues from Travis that are 3 days old or older. %s queues deleted.' % num_deleted

check.description = 'Cleaned up all indexing queues from Travis that are 3 days old or older. %s queues deleted.' % num_deleted
return check

0 comments on commit bfea247

Please sign in to comment.