Skip to content

Commit 5b005fe

Browse files
committed
Do not use atomics
Signed-off-by: György Krajcsovits <[email protected]>
1 parent e9cbc7b commit 5b005fe

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

Diff for: prometheus/histogram.go

+4-5
Original file line numberDiff line numberDiff line change
@@ -1658,7 +1658,7 @@ func addAndResetCounts(hot, cold *histogramCounts) {
16581658
type nativeExemplars struct {
16591659
sync.Mutex
16601660

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

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

1679-
exemplars.ttl.Store(int64(ttl))
1679+
exemplars.ttl = ttl
16801680
exemplars.exemplars = make([]*dto.Exemplar, 0, maxCount)
16811681
}
16821682

16831683
func (n *nativeExemplars) addExemplar(e *dto.Exemplar) {
1684-
ttl := n.ttl.Load()
1685-
if ttl == -1 {
1684+
if n.ttl == -1 {
16861685
return
16871686
}
16881687

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

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

0 commit comments

Comments
 (0)