From 6570a1fc6eca3118dfd4ec332fcad6319718ee3c Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 22 Jan 2026 13:31:32 +0000 Subject: [PATCH] fix: add buffer_cache_cleanup_total metric increment The metric was defined but never incremented when LRU cleanup happened. Added recordCacheCleanup() function and call it from cleanupHistoryCache() when cache entries are removed due to exceeding maxHistoryCacheSize. --- src/Utils/event-buffer.ts | 4 ++++ src/Utils/prometheus-metrics.ts | 12 ++++++++++++ 2 files changed, 16 insertions(+) diff --git a/src/Utils/event-buffer.ts b/src/Utils/event-buffer.ts index b701542f..5ae8614b 100644 --- a/src/Utils/event-buffer.ts +++ b/src/Utils/event-buffer.ts @@ -482,6 +482,10 @@ export const makeEventBuffer = ( removed: removed.length, remaining: historyCache.size }) + // Record metrics for cache cleanup + if (metricsModule) { + metricsModule.recordCacheCleanup(removed.length) + } } } diff --git a/src/Utils/prometheus-metrics.ts b/src/Utils/prometheus-metrics.ts index d5690329..3708f456 100644 --- a/src/Utils/prometheus-metrics.ts +++ b/src/Utils/prometheus-metrics.ts @@ -1898,6 +1898,18 @@ export function updateBufferStatistics(stats: { } } +/** + * Record a cache cleanup operation + * Used by event-buffer.ts when LRU cleanup is performed + */ +export function recordCacheCleanup(removedCount: number): void { + try { + metrics.bufferCacheCleanup?.inc({}) + } catch { + // Metrics not initialized, ignore silently + } +} + // ============================================ // Global Instance // ============================================