Skip to content

Commit c9f30dc

Browse files
Shvejanyeya24SungJin1212
authored
bugfix sort after merging histogram metrics (#7380)
* bugfix sort after merging histogram metrics Signed-off-by: Shvejan Mutheboyina <shvejan@amazon.com> * Update CHANGELOG.md Co-authored-by: SungJin1212 <tjdwls1201@gmail.com> Signed-off-by: Ben Ye <yb532204897@gmail.com> --------- Signed-off-by: Shvejan Mutheboyina <shvejan@amazon.com> Signed-off-by: Ben Ye <yb532204897@gmail.com> Co-authored-by: Ben Ye <yb532204897@gmail.com> Co-authored-by: SungJin1212 <tjdwls1201@gmail.com>
1 parent 8fbfe5f commit c9f30dc

2 files changed

Lines changed: 5 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* [ENHANCEMENT] Tenant Federation: Add a local cache to regex resolver. #7363
77
* [ENHANCEMENT] Query Scheduler: Add `cortex_query_scheduler_tracked_requests` metric to track the current number of requests held by the scheduler. #7355
88
* [BUGFIX] Fix nil when ingester_query_max_attempts > 1. #7369
9+
* [BUGFIX] Metrics Helper: Fix non-deterministic bucket order in merged histograms by sorting buckets after map iteration, matching Prometheus client library behavior. #7380
910

1011
## 1.21.0 in progress
1112

pkg/util/metrics_helper.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1129,6 +1129,10 @@ func mergeHistogram(mf1, mf2 *dto.Metric) {
11291129
ccValue := cumulativeCount
11301130
newBucket = append(newBucket, &dto.Bucket{UpperBound: &ubValue, CumulativeCount: &ccValue})
11311131
}
1132+
// Sort buckets by UpperBound to ensure deterministic order
1133+
sort.Slice(newBucket, func(i, j int) bool {
1134+
return newBucket[i].GetUpperBound() < newBucket[j].GetUpperBound()
1135+
})
11321136
h1.Bucket = newBucket
11331137
}
11341138
}

0 commit comments

Comments
 (0)