MCPcopy
hub / github.com/netdata/netdata / cleanupExpiredEntries

Function cleanupExpiredEntries

packaging/tools/agent-events/server.go:216–247  ·  view source on GitHub ↗

cleanupExpiredEntries uses the hash ([32]byte) as the key type.

(interval time.Duration)

Source from the content-addressed store, hash-verified

214
215// cleanupExpiredEntries uses the hash ([32]byte) as the key type.
216func cleanupExpiredEntries(interval time.Duration) {
217 ticker := time.NewTicker(interval)
218 defer ticker.Stop()
219 cleanedCount := 0
220 lastCleanupLogTime := time.Now()
221 for range ticker.C {
222 mapMutex.Lock()
223 now := time.Now()
224 currentMapSize := len(seenIDs)
225 deletedInCycle := 0 // Track deletes per cycle for more granular debug
226 for h, entry := range seenIDs {
227 if now.Sub(entry.timestamp) >= dedupWindow {
228 delete(seenIDs, h)
229 cleanedCount++
230 deletedInCycle++
231 }
232 }
233 mapMutex.Unlock()
234
235 // Log hourly summary if any were cleaned in the last hour
236 if cleanedCount > 0 && time.Since(lastCleanupLogTime) >= time.Hour {
237 slog.Debug("cleaned up expired entries",
238 "count_past_hour", cleanedCount,
239 "remaining_entries", currentMapSize-deletedInCycle) // Use size before delete for consistency
240 cleanedCount = 0 // Reset hourly count
241 lastCleanupLogTime = time.Now()
242 } else if deletedInCycle > 0 {
243 // Optional: Log every cycle if debugging cleanup
244 // slog.Debug("cleanup cycle completed", "deleted", deletedInCycle, "remaining", currentMapSize-deletedInCycle)
245 }
246 }
247}
248
249// connectionTracker is middleware that wraps an http.Handler to track active connections
250func connectionTracker(next http.Handler) http.Handler {

Callers 1

mainFunction · 0.85

Calls 5

StopMethod · 0.95
LockMethod · 0.80
SubMethod · 0.80
UnlockMethod · 0.80
DebugMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…