fix: update buffer_cache_size metric with actual history cache size
The buffer_cache_size metric was defined but never updated, always showing 0. Fix: - Add historyCacheSize parameter to recordBufferFlush function - Pass historyCache.size from event-buffer.ts when recording flush metrics - Update both bufferCacheSize and bufferHistoryCacheSize metrics
This commit is contained in:
@@ -410,9 +410,9 @@ export const makeEventBuffer = (
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const recordFlushMetrics = (eventCount: number, forced: boolean) => {
|
const recordFlushMetrics = (eventCount: number, forced: boolean, cacheSize: number) => {
|
||||||
if (metricsModule) {
|
if (metricsModule) {
|
||||||
metricsModule.recordBufferFlush(eventCount, forced)
|
metricsModule.recordBufferFlush(eventCount, forced, cacheSize)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -553,7 +553,7 @@ export const makeEventBuffer = (
|
|||||||
stats.historyCacheSize = historyCache.size
|
stats.historyCacheSize = historyCache.size
|
||||||
|
|
||||||
// Record metrics
|
// Record metrics
|
||||||
recordFlushMetrics(eventCount, force)
|
recordFlushMetrics(eventCount, force, historyCache.size)
|
||||||
|
|
||||||
// Log with [BAILEYS] prefix - use getMode() to avoid duplicating mode calculation logic
|
// Log with [BAILEYS] prefix - use getMode() to avoid duplicating mode calculation logic
|
||||||
const flushDuration = Date.now() - flushStartTime
|
const flushDuration = Date.now() - flushStartTime
|
||||||
|
|||||||
@@ -1855,15 +1855,23 @@ export function recordEventBuffered(eventType: string, count: number = 1): void
|
|||||||
* Record a buffer flush operation
|
* Record a buffer flush operation
|
||||||
* Used by event-buffer.ts for metrics integration
|
* Used by event-buffer.ts for metrics integration
|
||||||
*/
|
*/
|
||||||
export function recordBufferFlush(eventCount: number, forced: boolean): void {
|
export function recordBufferFlush(eventCount: number, forced: boolean, historyCacheSize?: number): void {
|
||||||
try {
|
try {
|
||||||
// Use the main metrics object which has the correct labels ['type', 'reason']
|
// Use the main metrics object which has the correct labels ['type', 'reason']
|
||||||
metrics.bufferFlushes?.inc({ type: 'event', reason: forced ? 'forced' : 'normal' })
|
metrics.bufferFlushes?.inc({ type: 'event', reason: forced ? 'forced' : 'normal' })
|
||||||
|
|
||||||
|
// Update buffer cache size if provided
|
||||||
|
if (typeof historyCacheSize === 'number') {
|
||||||
|
metrics.bufferCacheSize?.set({}, historyCacheSize)
|
||||||
|
}
|
||||||
|
|
||||||
// Also update the lazy-loaded event buffer metrics for detailed tracking
|
// Also update the lazy-loaded event buffer metrics for detailed tracking
|
||||||
const ebMetrics = getEventBufferMetrics()
|
const ebMetrics = getEventBufferMetrics()
|
||||||
ebMetrics.bufferFlushEvents?.observe({}, eventCount)
|
ebMetrics.bufferFlushEvents?.observe({}, eventCount)
|
||||||
ebMetrics.bufferCurrentSize?.set({}, 0) // Reset after flush
|
ebMetrics.bufferCurrentSize?.set({}, 0) // Reset after flush
|
||||||
|
if (typeof historyCacheSize === 'number') {
|
||||||
|
ebMetrics.bufferHistoryCacheSize?.set({}, historyCacheSize)
|
||||||
|
}
|
||||||
} catch {
|
} catch {
|
||||||
// Metrics not initialized, ignore silently
|
// Metrics not initialized, ignore silently
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user