Skip to content

Commit 51714a5

Browse files
author
Arthur Silva Sens
authored
Merge pull request #1360 from colega/improve-performance-of-with-label-values
Improve performance of WithLabelValues(...)
2 parents dac14aa + 005d8de commit 51714a5

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

prometheus/labels.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,8 @@ func validateValuesInLabels(labels Labels, expectedNumberOfValues int) error {
165165

166166
func validateLabelValues(vals []string, expectedNumberOfValues int) error {
167167
if len(vals) != expectedNumberOfValues {
168+
// The call below makes vals escape, copy them to avoid that.
169+
vals := append([]string(nil), vals...)
168170
return fmt.Errorf(
169171
"%w: expected %d label values but got %d in %#v",
170172
errInconsistentCardinality, expectedNumberOfValues,

0 commit comments

Comments
 (0)