Skip to content

Commit

Permalink
Do not use atomics
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 e9cbc7b commit 5b005fe
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions prometheus/histogram.go
Original file line number Diff line number Diff line change
Expand Up @@ -1658,7 +1658,7 @@ func addAndResetCounts(hot, cold *histogramCounts) {
type nativeExemplars struct {
sync.Mutex

ttl atomic.Int64 // It is a duration, but also used to check concurrently if exemplars are enabled.
ttl time.Duration
exemplars []*dto.Exemplar
}

Expand All @@ -1676,13 +1676,12 @@ func makeNativeExemplars(exemplars *nativeExemplars, ttl time.Duration, maxCount
ttl = -1
}

exemplars.ttl.Store(int64(ttl))
exemplars.ttl = ttl
exemplars.exemplars = make([]*dto.Exemplar, 0, maxCount)
}

func (n *nativeExemplars) addExemplar(e *dto.Exemplar) {
ttl := n.ttl.Load()
if ttl == -1 {
if n.ttl == -1 {
return
}

Expand Down Expand Up @@ -1764,7 +1763,7 @@ func (n *nativeExemplars) addExemplar(e *dto.Exemplar) {
// Here, we have the following relationships:
// n.exemplars[nIdx-1].Value < e.Value <= n.exemplars[nIdx].Value

if otIdx != -1 && e.Timestamp.AsTime().Sub(ot) > time.Duration(ttl) {
if otIdx != -1 && e.Timestamp.AsTime().Sub(ot) > n.ttl {
// If the oldest exemplar has expired, then replace it with the new exemplar.
rIdx = otIdx
} else {
Expand Down

0 comments on commit 5b005fe

Please sign in to comment.