Repository navigation
Move the resampling buffer to its own class - #1501
Conversation
0008d44 to
844eaee
Compare
| 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: |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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>
844eaee to
249584f
Compare
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.
_ResamplingBufferholds 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'sadd()method directly as itsadd_sample().SourcePropertieshas two new fields,total_windows_without_samplesandcurrent_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.