Fix last metrics for task are updated for events reported without variants

This commit is contained in:
allegroai 2024-03-18 15:44:28 +02:00
parent 6112910768
commit 85f5b8b6f6
2 changed files with 29 additions and 31 deletions

View File

@ -438,10 +438,8 @@ class EventBLL(object):
last_events contains [hashed_metric_name -> hashed_variant_name -> event]. Keys are hashed to avoid mongodb
key conflicts due to invalid characters and/or long field names.
"""
metric = event.get("metric")
variant = event.get("variant")
if not (metric and variant):
return
metric = event.get("metric") or ""
variant = event.get("variant") or ""
metric_hash = dbutils.hash_field_name(metric)
variant_hash = dbutils.hash_field_name(variant)
@ -486,9 +484,9 @@ class EventBLL(object):
recent than the currently stored event for its metric/event_type combination.
last_events contains [metric_name -> event_type -> event]
"""
metric = event.get("metric")
metric = event.get("metric") or ""
event_type = event.get("type")
if not (metric and event_type):
if not event_type:
return
timestamp = last_events[metric][event_type].get("timestamp", None)

View File

@ -193,7 +193,7 @@ class TestTaskEvents(TestService):
def test_last_scalar_metrics(self):
metric = "Metric1"
variant = "Variant1"
for variant in ("Variant1", None):
iter_count = 100
task = self._temp_task()
events = [