From d79a5f6bfe58ddbb001f6f947430fb5aa3dcf39d Mon Sep 17 00:00:00 2001 From: Dennis Zhuang Date: Thu, 22 Oct 2026 02:38:52 +0800 Subject: [PATCH] test(promql): keep Go float format tests with go_format and pin histogram_quantiles constants Signed-off-by: Dennis Zhuang --- src/promql/src/aggregate/tests.rs | 22 ----------------- .../float_cases.txt} | 0 src/promql/src/go_format/tests.rs | 24 ++++++++++++++++++- src/promql/src/histogram_eval.rs | 3 +++ src/promql/src/histogram_eval/tests.rs | 2 +- 5 files changed, 27 insertions(+), 24 deletions(-) rename src/promql/src/{aggregate/format_float_cases.txt => go_format/float_cases.txt} (100%) diff --git a/src/promql/src/aggregate/tests.rs b/src/promql/src/aggregate/tests.rs index 9d71cb0ca48..eec4e8de068 100644 --- a/src/promql/src/aggregate/tests.rs +++ b/src/promql/src/aggregate/tests.rs @@ -898,28 +898,6 @@ fn an_aggregation_of_sparse_inputs_is_compared_in_full_against_the_reference() { assert_eq!(piece_ranges(&counts), vec![(2, 1), (6, 1)]); } -/// `count_values` writes value labels the way Go's `strconv.FormatFloat(v, 'f', -1, 64)` does, -/// including the round-half-even choice of the last shortest digit; see the header of -/// `format_float_cases.txt` (promql-compat `cmd/narthex-golden-formatfloat`). -#[test] -fn value_labels_format_like_go() { - let mut checked = 0; - for line in include_str!("format_float_cases.txt").lines() { - let (bits, expected) = line.split_once(' ').unwrap(); - let value = f64::from_bits(u64::from_str_radix(bits, 16).unwrap()); - assert_eq!(crate::go_format::format_float_f(value), expected, "{bits}"); - checked += 1; - } - assert!(checked > 2_400, "{checked}"); - for (value, expected) in [ - (f64::NAN, "NaN"), - (f64::INFINITY, "+Inf"), - (f64::NEG_INFINITY, "-Inf"), - ] { - assert_eq!(crate::go_format::format_float_f(value), expected); - } -} - /// A point where the `q` scalar has no value has no `quantile` result, as a missing scalar point /// yields no output in the other scalar operators. #[test] diff --git a/src/promql/src/aggregate/format_float_cases.txt b/src/promql/src/go_format/float_cases.txt similarity index 100% rename from src/promql/src/aggregate/format_float_cases.txt rename to src/promql/src/go_format/float_cases.txt diff --git a/src/promql/src/go_format/tests.rs b/src/promql/src/go_format/tests.rs index ef7a02591a4..a8ab2d7a14e 100644 --- a/src/promql/src/go_format/tests.rs +++ b/src/promql/src/go_format/tests.rs @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -use crate::go_format::format_open_metrics_float; +use crate::go_format::{format_float_f, format_open_metrics_float}; /// Prometheus `labels.FormatOpenMetricsFloat`; `open_metrics_cases.txt` comes from promql-compat /// `narthex-golden-formatfloat -openmetrics` as ` `. @@ -27,3 +27,25 @@ fn open_metrics_floats_format_like_prometheus() { } assert!(checked > 300, "{checked}"); } + +/// Go's `strconv.FormatFloat(v, 'f', -1, 64)`, the form `count_values` writes value labels in, +/// including the round-half-even choice of the last shortest digit and the round-trip check at +/// powers of two; `float_cases.txt` comes from promql-compat `narthex-golden-formatfloat`. +#[test] +fn floats_format_like_go() { + let mut checked = 0; + for line in include_str!("float_cases.txt").lines() { + let (bits, expected) = line.split_once(' ').unwrap(); + let value = f64::from_bits(u64::from_str_radix(bits, 16).unwrap()); + assert_eq!(format_float_f(value), expected, "{bits}"); + checked += 1; + } + assert!(checked > 2_400, "{checked}"); + for (value, expected) in [ + (f64::NAN, "NaN"), + (f64::INFINITY, "+Inf"), + (f64::NEG_INFINITY, "-Inf"), + ] { + assert_eq!(format_float_f(value), expected); + } +} diff --git a/src/promql/src/histogram_eval.rs b/src/promql/src/histogram_eval.rs index 4aa577fc54a..4a53635c52a 100644 --- a/src/promql/src/histogram_eval.rs +++ b/src/promql/src/histogram_eval.rs @@ -62,6 +62,9 @@ pub enum HistogramFunction { /// writes it. Results that then share a label set merge as [`merge_same_labelset`] does, so a /// repeated `q`, or a `label` that overwrites the label telling two histograms apart, fails at a /// point both hold. +/// +/// Each `q` is a constant. Prometheus evaluates the quantile arguments at every step, so a +/// quantile that varies over time is not this kernel's to evaluate. pub fn histogram_quantiles( label: &str, quantiles: &[f64], diff --git a/src/promql/src/histogram_eval/tests.rs b/src/promql/src/histogram_eval/tests.rs index 052dd80e0d6..41db4cd3ba5 100644 --- a/src/promql/src/histogram_eval/tests.rs +++ b/src/promql/src/histogram_eval/tests.rs @@ -151,7 +151,7 @@ fn histogram_quantiles_match_prometheus() { let actual = histogram_quantiles(&case.spec[1], &quantiles, &schema, &input); failed += usize::from(assert_outcome(case, actual, &case.outcome)); } - assert!(failed > 5, "{failed} failed"); + assert_eq!(failed, 13, "{failed} failed"); } #[test]