From 2c1f9558b26341c1842150dd235e0d01ef939b96 Mon Sep 17 00:00:00 2001 From: beorn7 Date: Wed, 27 Mar 2024 19:00:16 +0100 Subject: [PATCH 1/2] promql: Fix histogram comparison in test framework The definition of histograms in the test framework may create histograms in a non-compact form. Since histogram comparison relies on exact equality of the bucket layout, we have to compact the histograms created by the test framework language before comparing them to histograms returned from the PromQL engine. Signed-off-by: beorn7 --- promql/test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/promql/test.go b/promql/test.go index 296b3d3ca..a7b5b8b99 100644 --- a/promql/test.go +++ b/promql/test.go @@ -563,7 +563,7 @@ func (ev *evalCmd) compareResult(result parser.Value) error { return fmt.Errorf("expected histogram value at index %v for %s to have timestamp %v, but it had timestamp %v (result has %s)", i, ev.metrics[hash], expected.T, actual.T, formatSeriesResult(s)) } - if !actual.H.Equals(expected.H) { + if !actual.H.Equals(expected.H.Compact(0)) { return fmt.Errorf("expected histogram value at index %v (t=%v) for %s to be %v, but got %v (result has %s)", i, actual.T, ev.metrics[hash], expected.H, actual.H, formatSeriesResult(s)) } } @@ -595,7 +595,7 @@ func (ev *evalCmd) compareResult(result parser.Value) error { if expH != nil && v.H == nil { return fmt.Errorf("expected histogram %s for %s but got float value %v", HistogramTestExpression(expH), v.Metric, v.F) } - if expH != nil && !expH.Equals(v.H) { + if expH != nil && !expH.Compact(0).Equals(v.H) { return fmt.Errorf("expected %v for %s but got %s", HistogramTestExpression(expH), v.Metric, HistogramTestExpression(v.H)) } if !almostEqual(exp0.Value, v.F, defaultEpsilon) { From 65b4696b88521197668c09dd08dd5e46777c6845 Mon Sep 17 00:00:00 2001 From: beorn7 Date: Wed, 27 Mar 2024 19:02:27 +0100 Subject: [PATCH 2/2] promql: Remove leftover debug output Signed-off-by: beorn7 --- promql/test.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/promql/test.go b/promql/test.go index a7b5b8b99..ba716d1ee 100644 --- a/promql/test.go +++ b/promql/test.go @@ -606,10 +606,6 @@ func (ev *evalCmd) compareResult(result parser.Value) error { } for fp, expVals := range ev.expected { if !seen[fp] { - fmt.Println("vector result", len(val), ev.expr) - for _, ss := range val { - fmt.Println(" ", ss.Metric, ss.T, ss.F) - } return fmt.Errorf("expected metric %s with %v not found", ev.metrics[fp], expVals) } }