From 504566f07c680f68743c3a5d239dede48538c7ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gy=C3=B6rgy=20Krajcsovits?= Date: Mon, 2 Sep 2024 14:58:23 +0200 Subject: [PATCH] Use simplified solution from #1609 for the data race MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: György Krajcsovits --- prometheus/histogram.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/prometheus/histogram.go b/prometheus/histogram.go index eb0eb8871..1690a5695 100644 --- a/prometheus/histogram.go +++ b/prometheus/histogram.go @@ -1673,6 +1673,7 @@ func makeNativeExemplars(ttl time.Duration, maxCount int) nativeExemplars { if maxCount < 0 { maxCount = 0 + ttl = -1 } return nativeExemplars{ @@ -1682,13 +1683,13 @@ func makeNativeExemplars(ttl time.Duration, maxCount int) nativeExemplars { } func (n *nativeExemplars) addExemplar(e *dto.Exemplar) { - n.Lock() - defer n.Unlock() - - if cap(n.exemplars) == 0 { + if n.ttl == -1 { return } + n.Lock() + defer n.Unlock() + // The index where to insert the new exemplar. var nIdx int = -1