Skip to content

promqltest: Add optional counter reset hint comparison for native histograms#17626

Merged
beorn7 merged 3 commits intoprometheus:mainfrom
aviralgarg05:fix-promqltest-counter-reset-hint-comparison
Jan 22, 2026
Merged

promqltest: Add optional counter reset hint comparison for native histograms#17626
beorn7 merged 3 commits intoprometheus:mainfrom
aviralgarg05:fix-promqltest-counter-reset-hint-comparison

Conversation

@aviralgarg05
Copy link
Contributor

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:

  • 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.

Which issue(s) does the PR fix:

Fixes #17615

Does this PR introduce a user-facing change?

NONE

…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>
@aviralgarg05 aviralgarg05 force-pushed the fix-promqltest-counter-reset-hint-comparison branch from 92d3812 to 4884662 Compare November 30, 2025 12:37
@beorn7 beorn7 requested review from beorn7 and removed request for roidelapluie December 2, 2025 11:25
@beorn7
Copy link
Member

beorn7 commented Dec 6, 2025

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.

@beorn7
Copy link
Member

beorn7 commented Dec 17, 2025

Thanks for your contribution, which I finally find the time to look at.

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

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 counter_reset_hint:unknown in the test file) or if no counter reset hint was specified at all. This probably needs some surgery in the parser code for the tests. As I said in the issue, it's not as easy as just adding the comparison:

This is probably not as easy as adding this comparison. Ideally, we could implement a semantics where not specifying the counter reset hint means "I don't care about the counter reset", while an explicitly specified counter reset hint means "please check this".

…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>
@aviralgarg05
Copy link
Contributor Author

Thanks for your contribution, which I finally find the time to look at.

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

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 counter_reset_hint:unknown in the test file) or if no counter reset hint was specified at all. This probably needs some surgery in the parser code for the tests. As I said in the issue, it's not as easy as just adding the comparison:

This is probably not as easy as adding this comparison. Ideally, we could implement a semantics where not specifying the counter reset hint means "I don't care about the counter reset", while an explicitly specified counter reset hint means "please check this".

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
Modified buildHistogramFromMap to set this flag when the hint is present in the descriptor map
Updated the yacc grammar to use a new helper function newHistogramSequenceValue that preserves this flag
Modified compareNativeHistogram to accept the flag and only compare hints when explicitly specified

Copy link
Member

@beorn7 beorn7 left a comment

Choose a reason for hiding this comment

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

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.

@beorn7 beorn7 merged commit 82fec75 into prometheus:main Jan 22, 2026
28 checks passed
charleskorn added a commit to grafana/mimir that referenced this pull request Jan 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

promqltest: Allow testing of native histogram counter reset hint

2 participants