New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Histogram reuse bug in query evaluation #14072
Comments
Hey @fpetkovski @krajorama, I've seen you working on optimisations around histograms in PromQL engine recently. Perhaps you could take a look at this bug? I've tried to come up with a fix, however, promql engine code is very complex and this bug requires deep knowledge about reusing histograms in the iterators to fix it properly. |
I will take a look! |
@faustuzas I took at look at the bug and I don't think that the iterator stub used in tests is implemented correctly. I've made a suggestion for the correct implementation: https://github.com/faustuzas/prometheus/pull/1/files#r1597967140. I am curious how you discovered the bug. Did you see it inside Prometheus or are you using the engine or some other Prometheus package in a different project? |
Hey, @fpetkovski, thank you for taking a look. Yes, this bug was discovered outside the Prometheus. Your suggested change to the stub iterator makes sense, the semantics of the engine have changed a little with the addition of histogram re-use and the reduction of allocations. I will close the issue, thanks for the help again! |
What did you do?
I have noticed a bug in histogram memory reuse when
(chunkenc.Iterator).AtFloatHistogram
returns multiple histograms with the same address and does not use the newly added destination histogram functionality.Exemplary way to reproduce the bug:
histograms
slice now looks like this:[X, X (.....)]
,()
denotes part of the slice wherelen <= i < cap
.histograms
slice which is pointing to X gets pivoted to the unused back of the slice in:prometheus/promql/engine.go
Lines 2134 to 2138 in 312e3fd
histograms
slice is[X, Y (X, .....)]
.prometheus/promql/engine.go
Lines 2169 to 2175 in 312e3fd
Demo unit test reproducing the bug: faustuzas#1
Debug logs from the test above printing the inputs to the rate function inside the PromQL engine:
The problem is absent when line
prometheus/promql/engine.go
Line 2218 in 312e3fd
However, this defeats the whole purpose of having a destination histogram in the iterator.
What did you expect to see?
No response
What did you see instead? Under which circumstances?
System information
No response
Prometheus version
main
branchPrometheus configuration file
No response
Alertmanager version
No response
Alertmanager configuration file
No response
Logs
No response
The text was updated successfully, but these errors were encountered: