Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions prometheus/vec.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ package prometheus

import (
"fmt"
"maps"
"sync"

"github.com/prometheus/common/model"
Expand Down Expand Up @@ -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)
Expand All @@ -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))
Expand Down
Loading