Skip to content

Commit b14695f

Browse files
sustrikjuagargi
authored andcommitted
prometheus: fix copying of metrics labels (scionproto#4450)
When copying metric labels we assumed that `append` will always create a copy of the label array. This is not necessarily the case. In such case two metrics may end up with the same underlaying array of labels and change to one of them also overwrites the labels in the other one.
1 parent 37ef752 commit b14695f

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

pkg/metrics/prometheus.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,9 @@ func (lvs labelValuesSlice) With(labelValues ...string) labelValuesSlice {
9191
if len(labelValues)%2 != 0 {
9292
labelValues = append(labelValues, "unknown")
9393
}
94-
return append(lvs, labelValues...)
94+
result := make(labelValuesSlice, len(lvs))
95+
copy(result, lvs)
96+
return append(result, labelValues...)
9597
}
9698

9799
// gauge implements Gauge, via a Prometheus GaugeVec.

0 commit comments

Comments
 (0)