Skip to content

Commit

Permalink
fix: metrics order by avg (#5029)
Browse files Browse the repository at this point in the history
  • Loading branch information
srikanthccv authored May 20, 2024
1 parent 9ff0e34 commit cf64da2
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion pkg/query-service/app/limit.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
if math.IsNaN(point.Value) || math.IsInf(point.Value, 0) {
continue
Expand All @@ -57,6 +57,10 @@ func applyMetricLimit(results []*v3.Result, queryRangeParams *v3.QueryRangeParam
jthCount++
}

// avoid division by zero
ithCount = math.Max(ithCount, 1)
jthCount = math.Max(jthCount, 1)

if orderBy.Order == "asc" {
return ithSum/ithCount < jthSum/jthCount
} else if orderBy.Order == "desc" {
Expand Down

0 comments on commit cf64da2

Please sign in to comment.