diff --git a/prometheus/vec.go b/prometheus/vec.go index b405a64de..e4adbfbf4 100644 --- a/prometheus/vec.go +++ b/prometheus/vec.go @@ -15,6 +15,7 @@ package prometheus import ( "fmt" + "maps" "sync" "github.com/prometheus/common/model" @@ -667,7 +668,8 @@ var labelsPool = &sync.Pool{ func constrainLabels(desc *Desc, labels Labels) (Labels, func()) { if len(desc.variableLabels.labelConstraints) == 0 { // Fast path when there's no constraints - return labels, func() {} + // Returning a shallow copy of `labels` + return maps.Clone(labels), func() {} } constrainedLabels := labelsPool.Get().(Labels) @@ -686,7 +688,8 @@ func constrainLabels(desc *Desc, labels Labels) (Labels, func()) { func constrainLabelValues(desc *Desc, lvs []string, curry []curriedLabelValue) []string { if len(desc.variableLabels.labelConstraints) == 0 { // Fast path when there's no constraints - return lvs + // Returning a shallow copy of `lvs` + return append(make([]string, 0, len(lvs)), lvs...) } constrainedValues := make([]string, len(lvs))