Skip to content

Commit 0d3fb45

Browse files
committed
ensure memory and flush management for timers
1 parent 5dd8757 commit 0d3fb45

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

stats.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ func (ts *timespan) CompleteWithDuration(value time.Duration) {
404404
}
405405

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

454+
// todo: if we're not deleting the data we flush from these maps, won't we just keep resending them?
455+
454456
s.counters.Range(func(key, v interface{}) bool {
455457
// do not flush counters that are set to zero
456458
if value := v.(*counter).latch(); value != 0 {
@@ -470,7 +472,9 @@ func (s *statStore) Flush() {
470472
for _, value := range timer.CollectedValue() {
471473
s.sink.FlushAggregatedTimer(key.(string), value, sampleRate)
472474
}
475+
s.timers.Delete(key) // delete it from the map so it's not flushed again
473476
}
477+
474478
return true
475479
})
476480

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

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

0 commit comments

Comments
 (0)