Skip to content

Move the resampling buffer to its own class - #1501

Merged
llucax merged 4 commits into
frequenz-floss:v1.x.xfrom
llucax:resampler-buffer-class
Dec 1, 2026
Merged

llucax merged 4 commits into
frequenz-floss:v1.x.xfrom
llucax:resampler-buffer-class

Conversation

@llucax

@llucax llucax commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

This moves the resampling buffer and its bookkeeping out of the resampling helper into its own class, and improves the warning about timeseries without relevant samples.

  • The new _ResamplingBuffer holds the samples, keeps the source properties about them up to date, and logs the problems it finds. The helper now only decides which window to resample and how. Adding samples costs the same as before: the helper uses the buffer's add() method directly as its add_sample().
  • The warning about missing relevant samples is now one line, with the requested period and the buffer contents in it, as multi-line log messages are hard to process.
  • That warning was logged at every resampling while a timeseries had no relevant samples, so a device that stopped sending data filled the log with a warning per window. Now it's logged once per gap in the data, and an info message says when relevant samples are back and after how many windows.
  • SourceProperties has two new fields, total_windows_without_samples and current_windows_without_samples, with the number of windows without relevant samples in total and in the current gap. They tell how healthy a timeseries is without reading the logs.

@github-actions github-actions Bot added part:docs Affects the documentation part:tests Affects the unit, integration and performance (benchmarks) tests part:data-pipeline Affects the data pipeline labels Nov 27, 2026
@llucax
llucax force-pushed the resampler-buffer-class branch 4 times, most recently from 0008d44 to 844eaee Compare November 30, 2026 12:07
@llucax
llucax marked this pull request as ready for review November 30, 2026 12:11
@llucax
llucax requested a review from a team as a code owner November 30, 2026 12:11
@llucax
llucax requested review from florian-wagner-frequenz and removed request for a team November 30, 2026 12:11
@llucax llucax self-assigned this Nov 30, 2026
@llucax llucax added this to the v1.0.0-rc2217 milestone Nov 30, 2026
@llucax
llucax requested review from Marenz, cwasicki and shsms November 30, 2026 12:11
cwasicki
cwasicki previously approved these changes Nov 30, 2026
@github-project-automation github-project-automation Bot moved this from To do to Review approved in Python SDK Roadmap Nov 30, 2026
relevant_samples = list(itertools.islice(self._samples, min_index, max_index))
# Missing samples are logged once per gap in the data, not for each window.
props = self._source_properties
if not relevant_samples:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: if a device stops sending for good, there's now one warning and then nothing, and the gap's length is only logged if samples come back (or never, if the timeseries is removed first). The commit explains why not to log it only once, which makes sense. Did you consider repeating it with a backoff (e.g. after 10, 100, 1000 windows) with the current count?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I didn't consider it for this PR. In frequenz-floss/frequenz-client-base-python#301 we only log the recovery after 5 minutes without drops, to avoid logging over and over when a buffer is at the edge. We could do something similar here, but if this becomes a common pattern I'd rather have a shared solution, like the log rate limiting we discussed in #1132 (comment). A generic rate limiter can't add details like the number of windows, but it could simplify things quite a bit. I'd leave this as is for now, and bring up log rate limiting as a general topic in a meeting.

The resampling helper kept the buffer of samples together with its
bookkeeping: the removed samples, whether dropping samples or holding
too many was already logged, and the code finding the relevant
samples. That is only about keeping the buffer, and it made the
helper harder to follow, as it should only decide which window to
resample and how.

The new _ResamplingBuffer holds the samples, keeps the source
properties about them up to date, and logs the problems it finds.
The helper still decides when older samples can be removed, as that
depends on the input period being known.

The buffer takes the limits and the source properties instead of the
resampler configuration, so it doesn't depend on the configuration
classes, and its tests don't need to run with each of them. The
helper keeps the tests of the buffer limits, to check that it passes
the limits of the configuration to the buffer. The helper uses the
buffer's add() method as its own add_sample(), so adding samples
doesn't get an extra call.

This doesn't change any behavior, except that the buffer messages are
logged by the new module's logger.

Signed-off-by: Leandro Lucarella <luca-frequenz@llucax.com>
The warning about a timeseries without relevant samples was spread
over three lines, with the requested period and the samples in the
buffer on lines of their own. Log lines are usually processed one by
one, so the details ended up separated from the message, or lost.

Now everything is in one line, in a form that still reads naturally.

Signed-off-by: Leandro Lucarella <luca-frequenz@llucax.com>
The resampler logged a warning at every resampling while a timeseries
had no relevant samples, so a device that stopped sending data filled
the log with one warning per window, every second with the usual
resampling period.

Now the warning is logged only for the first window of each gap in
the data. When relevant samples are found again, an info message says
so, with the number of windows without them, so the length of each gap
is still visible. Logging the warning only once, like the buffer
warnings, would hide later gaps: those warnings are about the
configuration, which doesn't change, while gaps come and go.

Signed-off-by: Leandro Lucarella <luca-frequenz@llucax.com>
How often a timeseries has no relevant samples, and whether it has a
gap in its data right now, tells how healthy its source is, but users
could only find it out from the logs.

SourceProperties now has two new fields, updated when resampling:
total_windows_without_samples, the number of windows without relevant
samples since the start, which is never reset, and
current_windows_without_samples, the number of windows in the current
gap, which goes back to 0 when relevant samples are found again.

These are the windows resampled as None. Windows without samples of
their own but with relevant older samples are not counted, as they
still have a value. The windows before the first sample are counted
too, as otherwise a source that never sends anything would look
healthy.

The warning about missing relevant samples now uses the counter of the
current gap instead of its own.

Signed-off-by: Leandro Lucarella <luca-frequenz@llucax.com>
@llucax
llucax added this pull request to the merge queue Dec 1, 2026
Merged via the queue into frequenz-floss:v1.x.x with commit 424ada3 Dec 1, 2026
9 checks passed
@llucax
llucax deleted the resampler-buffer-class branch December 1, 2026 13:30
@github-project-automation github-project-automation Bot moved this from Review approved to Done in Python SDK Roadmap Dec 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

part:data-pipeline Affects the data pipeline part:docs Affects the documentation part:tests Affects the unit, integration and performance (benchmarks) tests

Projects

Development

Successfully merging this pull request may close these issues.

3 participants