Use simplified solution from #1609 for the data race

Signed-off-by: György Krajcsovits <gyorgy.krajcsovits@grafana.com>
This commit is contained in:
György Krajcsovits 2024-09-02 14:58:23 +02:00
parent dc8e9a4d8a
commit 504566f07c
1 changed files with 5 additions and 4 deletions

View File

@ -1673,6 +1673,7 @@ func makeNativeExemplars(ttl time.Duration, maxCount int) nativeExemplars {
if maxCount < 0 { if maxCount < 0 {
maxCount = 0 maxCount = 0
ttl = -1
} }
return nativeExemplars{ return nativeExemplars{
@ -1682,13 +1683,13 @@ func makeNativeExemplars(ttl time.Duration, maxCount int) nativeExemplars {
} }
func (n *nativeExemplars) addExemplar(e *dto.Exemplar) { func (n *nativeExemplars) addExemplar(e *dto.Exemplar) {
n.Lock() if n.ttl == -1 {
defer n.Unlock()
if cap(n.exemplars) == 0 {
return return
} }
n.Lock()
defer n.Unlock()
// The index where to insert the new exemplar. // The index where to insert the new exemplar.
var nIdx int = -1 var nIdx int = -1