Skip to content

Commit

Permalink
Use simplified solution from prometheus#1609 for the data race
Browse files Browse the repository at this point in the history
Signed-off-by: György Krajcsovits <gyorgy.krajcsovits@grafana.com>
  • Loading branch information
krajorama committed Sep 2, 2024
1 parent 2686d12 commit dfbd8eb
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions prometheus/histogram.go
Original file line number Diff line number Diff line change
Expand Up @@ -1673,6 +1673,7 @@ func makeNativeExemplars(ttl time.Duration, maxCount int) nativeExemplars {

if maxCount < 0 {
maxCount = 0
ttl = -1
}

return nativeExemplars{
Expand All @@ -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

Expand Down

0 comments on commit dfbd8eb

Please sign in to comment.