Skip to content

Commit

Permalink
ensure memory and flush management for timers
Browse files Browse the repository at this point in the history
  • Loading branch information
maciuszek committed Jan 13, 2025
1 parent 5dd8757 commit 0d3fb45
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ func (ts *timespan) CompleteWithDuration(value time.Duration) {
}

type statStore struct {
// todo: no idea how memory was managed here, when is are the entries ever gc'd?
// todo: no idea how memory is managed here, when are the map entries ever deleted?
counters sync.Map
gauges sync.Map
timers sync.Map
Expand Down Expand Up @@ -451,6 +451,8 @@ func (s *statStore) Flush() {
}
s.mu.RUnlock()

// todo: if we're not deleting the data we flush from these maps, won't we just keep resending them?

s.counters.Range(func(key, v interface{}) bool {
// do not flush counters that are set to zero
if value := v.(*counter).latch(); value != 0 {
Expand All @@ -470,7 +472,9 @@ func (s *statStore) Flush() {
for _, value := range timer.CollectedValue() {
s.sink.FlushAggregatedTimer(key.(string), value, sampleRate)
}
s.timers.Delete(key) // delete it from the map so it's not flushed again
}

return true
})

Expand Down Expand Up @@ -593,7 +597,6 @@ func (s *statStore) newTimer(serializedName string, base time.Duration) timer {
}
}

// todo: do we need special rules to not lose active reservoirs
if v, loaded := s.timers.LoadOrStore(serializedName, t); loaded {
return v.(timer)
}
Expand Down

0 comments on commit 0d3fb45

Please # to comment.