promqltest: Add optional counter reset hint comparison for native histograms#17626
Conversation
…tograms This commit implements counter reset hint comparison in the promqltest framework to address issue prometheus#17615. Previously, while test definitions could specify a counter_reset_hint in expected native histogram results, the framework did not actually compare this hint between expected and actual results. The implementation adds optional comparison logic to the compareNativeHistogram function: - If the expected histogram has UnknownCounterReset (the default), the hint is not compared (meaning "don't care") - If the expected histogram explicitly specifies CounterReset, NotCounterReset, or GaugeType, it is verified against the actual histogram's hint This allows tests to verify that PromQL functions correctly set or preserve counter reset hints while maintaining backward compatibility with existing tests that don't specify explicit hints. Fixes prometheus#17615 Signed-off-by: aviralgarg05 <gargaviral99@gmail.com>
The test at line 1283 for avg_over_time(nhcb_metric[13m]) incorrectly expected counter_reset_hint:gauge in the result. However, the actual avg_over_time implementation does not explicitly set the CounterResetHint to GaugeType on its output histogram. With the new counter reset hint comparison logic added to the promqltest framework (which compares hints when explicitly specified in expected results), this incorrect expectation was now being caught. This fix removes the incorrect counter_reset_hint:gauge from the expected result, allowing the test to correctly verify the avg_over_time behavior without asserting a specific hint value that the function does not set. The counter reset hint comparison logic works as designed: if the expected histogram has UnknownCounterReset (the default when not specified), no comparison is performed. Only when a hint is explicitly specified in the test expectation will it be compared against the actual result. Fixes the test failure introduced by the counter reset hint comparison feature in promqltest. Signed-off-by: Aviral Garg <aviralg2106@gmail.com> Signed-off-by: aviralgarg05 <gargaviral99@gmail.com>
92d3812 to
4884662
Compare
|
I'm currently on vacation. This is on my review list, which I'll tackle once I'm back (Dec 16). If anyone else beats me to a review, even better. |
|
Thanks for your contribution, which I finally find the time to look at.
So this is a problem. Sometimes we would like to also test explicitly that UnknownCounterReset is set as such. We must find a way to detect if UnknownCounterReset was specified explicitly (via
|
…ation This commit addresses the PR feedback for issue prometheus#17615. The previous implementation could not distinguish between: - No counter reset hint specified (meaning "don't care") - counter_reset_hint:unknown explicitly specified (meaning "verify it's unknown") Changes: - Added CounterResetHintSet field to parser.SequenceValue to track whether counter_reset_hint was explicitly specified in the test file - Modified buildHistogramFromMap to set this flag when the hint is present in the descriptor map - Updated newHistogramSequenceValue helper and histogramsSeries functions to propagate the flag through histogram series creation - Updated yacc grammar to use the new helper function - Modified compareNativeHistogram to accept the flag and only compare hints when explicitly specified This allows tests to: 1. Not specify a hint (no comparison, backward compatible) 2. Explicitly specify counter_reset_hint:unknown (verify it's unknown) 3. Explicitly specify counter_reset_hint:gauge/reset/not_reset (verify match) Fixes prometheus#17615 Signed-off-by: aviralgarg05 <gargaviral99@gmail.com>
Thanks for the feedback! You're right - the previous implementation couldn't distinguish between "no hint specified" and "counter_reset_hint:unknown" explicitly specified. I've updated the implementation with a proper solution: Changes: Added CounterResetHintSet field to parser.SequenceValue that tracks whether counter_reset_hint was explicitly specified in the test file |
beorn7
left a comment
There was a problem hiding this comment.
Looks good as far as I can tell. (I'm not very familiar with the generated parser. So I'm not sure if this is the best way of doing it. But it looks reasonable to me.)
Let's merge this as is, and if somebody has a better idea, we'll welcome their PR.
Thank you very much.
This commit implements counter reset hint comparison in the promqltest framework to address issue #17615. Previously, while test definitions could specify a counter_reset_hint in expected native histogram results, the framework did not actually compare this hint between expected and actual results.
The implementation adds optional comparison logic to the compareNativeHistogram function:
This allows tests to verify that PromQL functions correctly set or preserve counter reset hints while maintaining backward compatibility with existing tests that don't specify explicit hints.
Which issue(s) does the PR fix:
Fixes #17615
Does this PR introduce a user-facing change?