Skip to content

Commit cba1b7e

Browse files
committed
Be more consistent when removing outdated samples
When removing outdated samples, samples falling just right at the resapmling time are used in 2 different periods. Even if this is not technically wrong, it is unexpected, as it would be more natural that a moving window doesn't intersect with previous moving windows (if using one period, or after moving the window max_data_age_in_periods_s). Signed-off-by: Leandro Lucarella <[email protected]>
1 parent 73e13d7 commit cba1b7e

File tree

2 files changed

+2
-3
lines changed

2 files changed

+2
-3
lines changed

src/frequenz/sdk/timeseries/_resampler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def _remove_outdated_samples(self, threshold: datetime) -> None:
9494
"""
9595
while self._buffer:
9696
sample: Sample = self._buffer[0]
97-
if sample.timestamp >= threshold:
97+
if sample.timestamp > threshold:
9898
return
9999

100100
self._buffer.popleft()

tests/timeseries/test_resampling.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ def test_component_metric_resampler_remove_outdated_samples() -> None:
5151

5252
resampler._remove_outdated_samples(threshold=timestamp)
5353
assert list(resampler._buffer) == [
54-
sample1,
5554
sample2,
5655
] # pylint: disable=protected-access
5756

@@ -144,7 +143,7 @@ def test_component_metric_group_resampler() -> None:
144143
value22 = 999.0
145144

146145
sample11 = Sample(now - timedelta(seconds=0.7), value=value11)
147-
sample12 = Sample(now - timedelta(seconds=0.5), value=value12)
146+
sample12 = Sample(now - timedelta(seconds=0.49), value=value12)
148147
sample21 = Sample(now - timedelta(seconds=5.05), value=value21)
149148
sample22 = Sample(now - timedelta(seconds=0.99), value=value22)
150149

0 commit comments

Comments
 (0)