Skip to content

Commit

Permalink
Fix time_measurement for empty events after deleter deleted the event (
Browse files Browse the repository at this point in the history
…#437)

* fix time_measurement for empty events after deleter
  • Loading branch information
dtrai2 authored Aug 28, 2023
1 parent 11f1442 commit ed54b25
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
### Improvements
### Bugfix

* Fix writing time measurements into the event after the deleter has deleted the event. The bug only
happened when the `metrics.measure_time.append_to_event` configuration was set to `true`.

## v6.8.0
### Features

Expand Down
2 changes: 2 additions & 0 deletions logprep/util/time_measurement.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ def inner(*args, **kwargs): # nosemgrep
return func(*args, **kwargs)

def add_processing_times_to_event(event, processing_time, caller, name): # nosemgrep
if caller.name == "deleter" and not event:
return
if not event.get("processing_times"):
event["processing_times"] = {}
if name is None:
Expand Down
11 changes: 11 additions & 0 deletions tests/unit/util/test_time_measurement.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
class TestTimeMeasurement:
def setup_method(self):
self.event = {"test_key": "test_val"}
self.name = "TestTimeMeasurement"

@TimeMeasurement.measure_time("test")
def dummy_method(self, event): # pylint: disable=unused-argument
Expand All @@ -34,6 +35,16 @@ def test_time_measurement_decorator_appends_processing_times_to_event(self):
assert timestamp is not None
assert isinstance(timestamp, float)

def test_time_measurement_decorator_does_not_append_processing_time_to_event_after_deleter_deletes_event(
self,
):
TimeMeasurement.TIME_MEASUREMENT_ENABLED = True
TimeMeasurement.APPEND_TO_EVENT = True
self.name = "deleter" # setting the caller name to deleter, simulates a call of the deleter
event = {}
self.dummy_method(event)
assert not event

def test_deactivated_decorator_does_not_do_a_thing(self):
TimeMeasurement.TIME_MEASUREMENT_ENABLED = False
TimeMeasurement.APPEND_TO_EVENT = False
Expand Down

0 comments on commit ed54b25

Please sign in to comment.