Skip to content

Commit

Permalink
prometheus: fix copying of metrics labels (#4450)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
sustrik authored Nov 30, 2023
1 parent 237794a commit 7fc08e4
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion pkg/metrics/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@ func (lvs labelValuesSlice) With(labelValues ...string) labelValuesSlice {
if len(labelValues)%2 != 0 {
labelValues = append(labelValues, "unknown")
}
return append(lvs, labelValues...)
result := make(labelValuesSlice, len(lvs))
copy(result, lvs)
return append(result, labelValues...)
}

// gauge implements Gauge, via a Prometheus GaugeVec.
Expand Down

0 comments on commit 7fc08e4

Please sign in to comment.