Skip to content

Commit

Permalink
#69 - Fix an issue with the callback iteration timestamp drifting
Browse files Browse the repository at this point in the history
The callback iteration slowly drifts a few milliseconds per call
This is due to inaccuracies of time.sleep and some overhead on the `_run_callback` method

This fix the issue by using sched.enterabs instead of sched.enter.
This time to enter is always calculated based on the start timestamp of the callback

There will still be some milliseconds variation from execution to execution, but it will never drift.
  • Loading branch information
dlopes7 committed Jun 22, 2024
1 parent f3c605c commit 1d9cbb6
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions dynatrace_extension/sdk/callback.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def __init__(
self.ok_count = 0 # counter per interval = 1 min by default
self.timeouts_count = 0 # counter per interval = 1 min by default
self.exception_count = 0 # counter per interval = 1 min by default
self.iterations = 0 # how many times we ran the callback iterator for this callback
self.iterations = 0 # how many times we ran the callback iterator for this callback

def get_current_time_with_cluster_diff(self):
return datetime.now() + timedelta(milliseconds=self.cluster_time_diff)
Expand Down Expand Up @@ -140,5 +140,6 @@ def get_next_execution_timestamp(self) -> float:
This is done using execution total, the interval and the start timestamp
:return: datetime
"""
return (self.start_timestamp + timedelta(seconds=self.interval.total_seconds() * (self.iterations or 1))).timestamp()

return (
self.start_timestamp + timedelta(seconds=self.interval.total_seconds() * (self.iterations or 1))
).timestamp()

0 comments on commit 1d9cbb6

Please sign in to comment.