19.6.1
Some checks failed
Default (tags) / security (push) Successful in 41s
Default (tags) / test (push) Failing after 31m49s
Default (tags) / release (push) Has been skipped
Default (tags) / metadata (push) Has been skipped

This commit is contained in:
Juergen Kunz
2025-06-09 16:37:43 +00:00
parent 4c847fd3d7
commit fc09af9afd
10 changed files with 456 additions and 12 deletions

View File

@ -10,6 +10,7 @@ export class MetricsCollector implements IProxyStatsExtended {
// RPS tracking (the only state we need to maintain)
private requestTimestamps: number[] = [];
private readonly RPS_WINDOW_SIZE = 60000; // 1 minute window
private readonly MAX_TIMESTAMPS = 5000; // Maximum timestamps to keep
// Optional caching for performance
private cachedMetrics: {
@ -148,11 +149,14 @@ export class MetricsCollector implements IProxyStatsExtended {
* Record a new request for RPS tracking
*/
public recordRequest(): void {
this.requestTimestamps.push(Date.now());
const now = Date.now();
this.requestTimestamps.push(now);
// Prevent unbounded growth
if (this.requestTimestamps.length > 10000) {
this.cleanupOldRequests();
// Prevent unbounded growth - clean up more aggressively
if (this.requestTimestamps.length > this.MAX_TIMESTAMPS) {
// Keep only timestamps within the window
const cutoff = now - this.RPS_WINDOW_SIZE;
this.requestTimestamps = this.requestTimestamps.filter(ts => ts > cutoff);
}
}