Skip to content

Commit fae8896

Browse files
author
beorn7
committed
Fix #512
Signed-off-by: beorn7 <[email protected]>
1 parent 9542e40 commit fae8896

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

prometheus/registry.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -872,7 +872,13 @@ func checkMetricConsistency(
872872
h = hashAddByte(h, separatorByte)
873873
// Make sure label pairs are sorted. We depend on it for the consistency
874874
// check.
875-
sort.Sort(labelPairSorter(dtoMetric.Label))
875+
if !sort.IsSorted(labelPairSorter(dtoMetric.Label)) {
876+
// We cannot sort dtoMetric.Label in place as it is immutable by contract.
877+
copiedLabels := make([]*dto.LabelPair, len(dtoMetric.Label))
878+
copy(copiedLabels, dtoMetric.Label)
879+
sort.Sort(labelPairSorter(copiedLabels))
880+
dtoMetric.Label = copiedLabels
881+
}
876882
for _, lp := range dtoMetric.Label {
877883
h = hashAdd(h, lp.GetName())
878884
h = hashAddByte(h, separatorByte)

0 commit comments

Comments
 (0)