From 888cf029ca4a26e23d9830b100815003dd7c7e19 Mon Sep 17 00:00:00 2001 From: Simon Guilbault Date: Wed, 17 Jul 2024 16:43:11 +0000 Subject: [PATCH] Jobstats: Handle missing exe from metrics --- jobstats/views.py | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/jobstats/views.py b/jobstats/views.py index 2ae80cb..c930b53 100644 --- a/jobstats/views.py +++ b/jobstats/views.py @@ -488,13 +488,15 @@ def job(request, username, job_id): stats_exe = prom.query_prometheus_multiple(query_exe, job.time_start_dt(), job.time_end_dt()) context['applications'] = [] for exe in stats_exe: - name = exe['metric']['exe'] - value = statistics.mean(exe['y']) - if settings.DEMO: - if not name.startswith('/cvmfs'): - # skip non-cvmfs applications in demo mode - name = '[redacted]' - context['applications'].append({'name': name, 'value': value}) + # sometimes the exe is not present, skip those + if 'exe' in exe['metric']: + name = exe['metric']['exe'] + value = statistics.mean(exe['y']) + if settings.DEMO: + if not name.startswith('/cvmfs'): + # skip non-cvmfs applications in demo mode + name = '[redacted]' + context['applications'].append({'name': name, 'value': value}) except ValueError: pass @@ -836,14 +838,16 @@ def graph_thread(request, username, job_id): for line in stats_exe: x = list(map(lambda x: x.strftime('%Y-%m-%d %H:%M:%S'), line['x'])) y = line['y'] - name = os.path.basename(line['metric']['exe']) - data.append({ - 'x': x, - 'y': y, - 'type': 'scatter', - 'name': name, - 'hovertemplate': '%{y:.1f}', - }) + # sometimes the exe is not present, skip those + if 'exe' in line['metric']: + name = os.path.basename(line['metric']['exe']) + data.append({ + 'x': x, + 'y': y, + 'type': 'scatter', + 'name': name, + 'hovertemplate': '%{y:.1f}', + }) layout = { 'yaxis': {