fix: metrics order by avg (#5029)

This commit is contained in:
Srikanth Chekuri 2024-05-20 14:22:44 +05:30 committed by GitHub
parent 9ff0e34038
commit cf64da2631
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -40,7 +40,7 @@ func applyMetricLimit(results []*v3.Result, queryRangeParams *v3.QueryRangeParam
} }
} }
ithSum, jthSum, ithCount, jthCount := 0.0, 0.0, 1.0, 1.0 ithSum, jthSum, ithCount, jthCount := 0.0, 0.0, 0.0, 0.0
for _, point := range result.Series[i].Points { for _, point := range result.Series[i].Points {
if math.IsNaN(point.Value) || math.IsInf(point.Value, 0) { if math.IsNaN(point.Value) || math.IsInf(point.Value, 0) {
continue continue
@ -57,6 +57,10 @@ func applyMetricLimit(results []*v3.Result, queryRangeParams *v3.QueryRangeParam
jthCount++ jthCount++
} }
// avoid division by zero
ithCount = math.Max(ithCount, 1)
jthCount = math.Max(jthCount, 1)
if orderBy.Order == "asc" { if orderBy.Order == "asc" {
return ithSum/ithCount < jthSum/jthCount return ithSum/ithCount < jthSum/jthCount
} else if orderBy.Order == "desc" { } else if orderBy.Order == "desc" {