Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix flaky fuzz tests with count_values #6474

Merged
merged 1 commit into from
Jan 3, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions integration/query_fuzz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
Loading