diff --git a/collect/cache/cuckooSentCache.go b/collect/cache/cuckooSentCache.go index 7c3b9bfa09..281a3178ba 100644 --- a/collect/cache/cuckooSentCache.go +++ b/collect/cache/cuckooSentCache.go @@ -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] @@ -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, @@ -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 } diff --git a/generics/setttl.go b/generics/setttl.go index be4aa4d2e4..eef285ec23 100644 --- a/generics/setttl.go +++ b/generics/setttl.go @@ -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