From c685cf49b9ef46630d74073adb8d439df9de24a1 Mon Sep 17 00:00:00 2001 From: Harry John Date: Thu, 2 Jan 2025 16:51:51 -0800 Subject: [PATCH] Fix flaky fuzz tests with count_values (#6474) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 🌲 Harry 🌊 John 🏔 --- integration/query_fuzz_test.go | 39 ++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/integration/query_fuzz_test.go b/integration/query_fuzz_test.go index 1e1485f219..85fe9fca2e 100644 --- a/integration/query_fuzz_test.go +++ b/integration/query_fuzz_test.go @@ -801,7 +801,46 @@ var comparer = cmp.Comparer(func(x, y model.Value) bool { const fraction = 1.e-10 // 0.00000001% return cmp.Equal(l, r, cmpopts.EquateNaNs(), cmpopts.EquateApprox(fraction, epsilon)) } + // count_values returns a metrics with one label {"value": "1.012321"} + compareValueMetrics := func(l, r model.Metric) (valueMetric bool, equals bool) { + lLabels := model.LabelSet(l).Clone() + rLabels := model.LabelSet(r).Clone() + var ( + lVal, rVal model.LabelValue + lFloat, rFloat float64 + ok bool + err error + ) + + if lVal, ok = lLabels["value"]; !ok { + return false, false + } + + if rVal, ok = rLabels["value"]; !ok { + return false, false + } + + if lFloat, err = strconv.ParseFloat(string(lVal), 64); err != nil { + return false, false + } + if rFloat, err = strconv.ParseFloat(string(rVal), 64); err != nil { + return false, false + } + + // Exclude the value label in comparison. + delete(lLabels, "value") + delete(rLabels, "value") + + if !lLabels.Equal(rLabels) { + return false, false + } + + return true, compareFloats(lFloat, rFloat) + } compareMetrics := func(l, r model.Metric) bool { + if valueMetric, equals := compareValueMetrics(l, r); valueMetric { + return equals + } return l.Equal(r) }