Skip to content

Commit

Permalink
dont export controls that can result in a deadlock or datarace
Browse files Browse the repository at this point in the history
  • Loading branch information
maciuszek committed Jan 16, 2025
1 parent 4e9611d commit 70cc61c
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,15 +319,15 @@ const (

type timer interface {
time(time.Duration)
lock()
unlock()
reset()
AddDuration(time.Duration)
AddValue(float64)
AllocateSpan() Timespan
GetValue(int) float64
ValueCount() int
SampleRate() float64
Lock()
Unlock()
Reset()
}

type standardTimer struct {
Expand Down Expand Up @@ -365,13 +365,13 @@ func (t *standardTimer) SampleRate() float64 {
}

// no support or need for concurrency
func (t *standardTimer) Lock() {}
func (t *standardTimer) lock() {}

// no support or need for concurrency
func (t *standardTimer) Unlock() {}
func (t *standardTimer) unlock() {}

// nothing to persisted in memroy for this timer
func (t *standardTimer) Reset() {}
func (t *standardTimer) reset() {}

type reservoirTimer struct {
mu sync.Mutex
Expand Down Expand Up @@ -427,15 +427,15 @@ func (t *reservoirTimer) SampleRate() float64 {
return float64(ringSize) / float64(count)
}

func (t *reservoirTimer) Lock() {
func (t *reservoirTimer) lock() {
t.mu.Lock()
}

func (t *reservoirTimer) Unlock() {
func (t *reservoirTimer) unlock() {
t.mu.Unlock()
}

func (t *reservoirTimer) Reset() {
func (t *reservoirTimer) reset() {
atomic.StoreUint64(&t.count, 0)
}

Expand Down Expand Up @@ -520,16 +520,16 @@ func (s *statStore) Flush() {
// 1. provide correct sample rate
// 2. allow for exit despite continuous writes
// 3. reduce metric loss from writes after flush and before reset
timer.Lock()
timer.lock()
sampleRate := timer.SampleRate()

// since the map memory is reused only process what we accumulated in the current processing itteration
for i := 0; i < timer.ValueCount(); i++ {
s.sink.FlushSampledTimer(key.(string), timer.GetValue(i), sampleRate)
}

timer.Reset()
timer.Unlock()
timer.reset()
timer.unlock()
}

return true
Expand Down

0 comments on commit 70cc61c

Please sign in to comment.