Skip to content

Commit

Permalink
make range command (that might be broken?)
Browse files Browse the repository at this point in the history
  • Loading branch information
crockeo committed Jun 23, 2023
1 parent d2e64d2 commit 1586642
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
10 changes: 10 additions & 0 deletions internal/vendored/hashicorp/golang-lru/lru.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,16 @@ func (c *Cache[K, V]) GetOldest() (key K, value V, ok bool) {
return
}

func (c *Cache[K, V]) Range(fn func (k K, v V)) {
c.lock.RLock()
keys := c.lru.Keys()
values := c.lru.Values()
c.lock.RUnlock()
for i := 0; i < len(keys); i++ {
fn(keys[i], values[i])
}
}

// Keys returns a slice of the keys in the cache, from oldest to newest.
func (c *Cache[K, V]) Keys() []K {
c.lock.RLock()
Expand Down
11 changes: 1 addition & 10 deletions stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -379,16 +379,7 @@ func (s *statStore) Flush() {
}
s.mu.RUnlock()

for _, name := range s.counters.Keys() {
counter, ok := s.counters.Peek(name)
if !ok {
// This counter was removed between retrieving the names
// and finding this specific counter.
continue
}
s.flushCounter(name, counter)
}

s.counters.Range(s.flushCounter)
s.gauges.Range(func(key, v interface{}) bool {
s.sink.FlushGauge(key.(string), v.(*gauge).Value())
return true
Expand Down

0 comments on commit 1586642

Please sign in to comment.