From 6f6d362c20cb6d60d26dbe09f63c3e9d72b26353 Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Thu, 7 Nov 2024 16:49:16 +0300 Subject: [PATCH] experimental race free labels Signed-off-by: Vasiliy Tolstov --- prometheus.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/prometheus.go b/prometheus.go index adf8232..45bb864 100644 --- a/prometheus.go +++ b/prometheus.go @@ -328,11 +328,13 @@ func (m *prometheusMeter) Set(opts ...meter.Option) meter.Meter { } func labelMetric(labels []string) []*dto.LabelPair { - dtoLabels := make([]*dto.LabelPair, 0, len(labels)/2) - for idx := 0; idx < len(labels); idx += 2 { + nl := make([]string, len(labels)) + copy(nl, labels) + dtoLabels := make([]*dto.LabelPair, 0, len(nl)/2) + for idx := 0; idx < len(nl); idx += 2 { dtoLabels = append(dtoLabels, &dto.LabelPair{ - Name: &(labels[idx]), - Value: &(labels[idx+1]), + Name: &(nl[idx]), + Value: &(nl[idx+1]), }) } return dtoLabels