-
Notifications
You must be signed in to change notification settings - Fork 9.9k
Description
Context: I was looking into cleaning up the iterator code, as I'm trying to add a separate SeekBefore() method, that would return the value at time t as defined by Prometheus without always parsing and iterating over a whole chunk covering the previous 5 minutes (when the looked up value is toward the beginning of a chunk).
However, I ran into some issues regarding how chunked series and iterators should actually work. There are a couple of gray areas that are only partially covered by comments or test code, making it impossible to figure out what is the expected correct behavior:
blockQuerierand the resultingchunkedSeriesandchunkSeriesIteratorall havemintandmaxtfields, which (along with(*chunkSeriesIterator).Seek()implementation details) suggest that iterators should only return samples with timestampsmint <= t <= maxt. However, there are bugs (such as the one I'm attempting to fix with Seek() shouldn't return true when past maxt. Also add some tests to s… prometheus-junkyard/tsdb#327) and even confusing/confused unit tests -- which appear to create an iterator withmint = 5,maxt = 8and expect(*chunkSeriesIterator).Seek()to return a value with timestamp3.Are
mintandmaxtsupposed to be "hard" limits on the respective iterators or only on which chunks are selected?- I gather (from the implementation again) that
SeriesIterator.Seek()is only supposed to seek forward (which doesn't work as expected, as it will also seek backward within the same chunk). Is this assumption correct? - Is
Seek()supposed to always advance the iterator or should a secondSeek()call with the same timestamp as the immediately preceding one leave the iterator positioned where it was before? - Is it actually a good idea for a
Seek()with a timestampt < mintto ever succeed? If so a poorly defined series e.g.[now - 10m, now]will "successfully" produce a value of the series atnow - 1yequal to the first value afternow - 10m.
I'm glad to do the work (including properly documenting the code) regardless of what the answers are, I'd just like to get some "authoritative" input. Thanks.