Handle missing groupby_key in _group_runs_by_key
The _group_runs_by_key() helper function is there to re-organize the data grouped by a metadata value. However, it was not fault tolerant if the metadata key used for grouping was missing from any of the list of runs. In the course of normal operation this should not occur, because the metadata should be the same for all jobs in the OpenStack subunit2sql db. But, due to a worker bug and/or a service restart we're encountering a run that's missing a few metadata values. To make this error non-fatal this commit augments the function to just ignore runs where the groupby_key is not in the metadata. Change-Id: I87087c8e3a985d883db78e008fd14f4fb9ac4e24
This commit is contained in:
parent
f7909853f6
commit
26f188a102
|
@ -264,13 +264,14 @@ def _group_runs_by_key(runs_by_time, groupby_key):
|
|||
This function assumes that your runs are already grouped by time.
|
||||
"""
|
||||
|
||||
keyfunc = lambda c: c['metadata'][groupby_key]
|
||||
keyfunc = lambda c: c['metadata'].get(groupby_key)
|
||||
grouped_runs_by = {}
|
||||
for timestamp, runs_by_time in runs_by_time.items():
|
||||
for timestamp, run_by_time in runs_by_time.items():
|
||||
if timestamp not in grouped_runs_by:
|
||||
grouped_runs_by[timestamp] = {}
|
||||
for key, val in itertools.groupby(runs_by_time, keyfunc):
|
||||
grouped_runs_by[timestamp][key] = list(val)
|
||||
for key, val in itertools.groupby(run_by_time, keyfunc):
|
||||
if val:
|
||||
grouped_runs_by[timestamp][key] = list(val)
|
||||
return grouped_runs_by
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue