promqltest: Add optional counter reset hint comparison for native histograms

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.

Fixes #17615

Signed-off-by: aviralgarg05 <gargaviral99@gmail.com>
This commit is contained in:
aviralgarg05 2025-11-29 17:15:59 +05:30
parent b0649e08c4
commit e894d7a271

View File

@ -1163,6 +1163,14 @@ func compareNativeHistogram(exp, cur *histogram.FloatHistogram) bool {
return false
}
// Compare CounterResetHint only if explicitly specified in expected histogram.
// UnknownCounterReset (the default) means "don't care about the hint".
if exp.CounterResetHint != histogram.UnknownCounterReset {
if exp.CounterResetHint != cur.CounterResetHint {
return false
}
}
return true
}