feat: db pool metrics + bounded threat cache#918
Open
Mkalbani wants to merge 3 commits into
Open
Conversation
…de#882) rinafcode#883: expose db_pool_active_connections, db_pool_idle_connections, db_pool_waiting_requests, db_pool_max_connections, db_pool_utilization on /metrics; add 80% utilization Prometheus alert rule; poll every 15s. rinafcode#882: replace unbounded Map in ThreatDetectionService with LRUCache capped at 50k entries, 15-min TTL, rate-limited eviction warning. Add unit test verifying LRU eviction at the cap boundary.
|
@Mkalbani Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
feat: DB pool metrics (#883) + bounded threat cache (#882)
#883 — DB connection pool metrics on Prometheus endpoint
db_pool_active_connections,db_pool_waiting_requests.db_pool_max_connections,db_pool_utilization(ratio active/max).DbPoolMetricsCollectorpolls every 15s;db_pool_max_connectionsanddb_pool_utilizationare set on every tick.DBPoolUtilizationHigh(warning, 5m) firing ondb_pool_utilization > 0.8ininfra/monitoring/alerts.yml. Existing 90% critical rule preserved.Acceptance criteria
/metrics).pool.totalCount / idleCount / waitingCountper poll.#882 — Bounded TTL cache in ThreatDetectionService
lru-cache@^11.0.0dependency.Map<string, number>withLRUCache<string, number>capped at 50,000 entries with 15-minute TTL (ttlAutopurge: true).Logger.warnfires on LRU eviction (≥60s between warnings) so a flood of evictions doesn't amplify load.analyzeRequest,recordFailure,reset) unchanged; addedgetCacheSize/hasfor test introspection.Acceptance criteria
Verification
npx tsc -p tsconfig.build.json --noEmit— clean.npx jest src/monitoring/metrics/db-pool-metrics.collector.spec.ts src/security/threats/threat-detection.service.spec.ts— 15/15 pass.Files changed
package.json/package-lock.json— addlru-cache@^11.0.0.src/monitoring/metrics/metrics-collection.service.ts— rename + add gauges.src/monitoring/metrics/db-pool-metrics.collector.ts— 15s cron, new gauge writes.src/monitoring/metrics/db-pool-metrics.collector.spec.ts— updated + new tests.src/security/threats/threat-detection.service.ts—Map→ boundedLRUCache.src/security/threats/threat-detection.service.spec.ts— new spec.infra/monitoring/alerts.yml—DBPoolUtilizationHigh80% rule.closes #882
closes #883