Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: periodically clean up recent_dropped_traces cache #1312

Merged
merged 2 commits into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions collect/cache/cuckooSentCache.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ func (t *cuckooDroppedRecord) Reason() uint {
var _ TraceSentRecord = (*cuckooDroppedRecord)(nil)

type cuckooSentCache struct {
met metrics.Metrics
kept *lru.Cache[string, *keptTraceCacheEntry]
dropped *CuckooTraceChecker
recentDroppedIDs *generics.SetWithTTL[string]
Expand Down Expand Up @@ -179,7 +180,10 @@ func NewCuckooSentCache(cfg config.SampleCacheConfig, met metrics.Metrics) (Trac
// request.
recentDroppedIDs := generics.NewSetWithTTL[string](3 * time.Second)

met.Register("cache_recent_dropped_traces", "gauge")

cache := &cuckooSentCache{
met: met,
kept: stc,
dropped: dropped,
recentDroppedIDs: recentDroppedIDs,
Expand All @@ -198,6 +202,10 @@ func (c *cuckooSentCache) monitor() {
select {
case <-ticker.C:
c.dropped.Maintain()
// Length() returns the number of items in the cache and it will
// clean up any expired items.
numOfDroppedIDs := c.recentDroppedIDs.Length()
c.met.Gauge("cache_recent_dropped_traces", numOfDroppedIDs)
case <-c.done:
return
}
Expand Down
2 changes: 1 addition & 1 deletion generics/setttl.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
)

// SetWithTTL is a unique set of items with a TTL (time to live) for each item.
// After the TTL expires, the item is automatically removed from the set.
// After the TTL expires, the item is automatically removed from the set when either Members or Length is called.
// It is safe for concurrent use.
type SetWithTTL[T cmp.Ordered] struct {
Items map[T]time.Time
Expand Down
Loading