Repository navigation
feat(backend): telemetry, retry, distributed locking and stress tests for Log Retention & Archival Service - #1604
Conversation
…ests to Log Retention & Archival Service Add Prometheus alert metrics, health telemetry and alert rules for the webhook log purge. Retry transient database failures with full-jitter exponential backoff. Serialize purges across instances with a Postgres advisory lock and FOR UPDATE SKIP LOCKED batches. Add integration and stress suites over an in-memory Postgres double.
|
@Olorunfemi20 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! 🚀 |
|
@Olorunfemi20 is attempting to deploy a commit to the Emmanuel's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
| GitGuardian id | GitGuardian status | Secret | Commit | Filename | |
|---|---|---|---|---|---|
| 38822392 | Triggered | JSON Web Token | a15452c | backend/src/middleware/x402.test.js | View secret |
| 38865302 | Triggered | Generic High Entropy Secret | a15452c | backend/src/lib/sep0001-generator.sanitization.test.js | View secret |
| 38865486 | Triggered | Generic High Entropy Secret | a15452c | backend/src/lib/websocket-relay-retry.test.js | View secret |
| 38864685 | Triggered | Generic High Entropy Secret | a15452c | backend/src/lib/exchange-rate-oracle-sanitizer.test.js | View secret |
🛠 Guidelines to remediate hardcoded secrets
- Understand the implications of revoking this secret by investigating where it is used in your code.
- Replace and store your secrets safely. Learn here the best practices.
- Revoke and rotate these secrets.
- If possible, rewrite git history. Rewriting git history is not a trivial act. You might completely break other contributing developers' workflow and you risk accidentally deleting legitimate data.
To avoid such incidents in the future consider
- following these best practices for managing and storing secrets including API keys and other credentials
- install secret detection on pre-commit to catch secret before it leaves your machine and ease remediation.
🦉 GitGuardian detects secrets in your source code to help developers and security teams secure the modern development process. You are seeing this because you or someone else with access to this repository has authorized GitGuardian to scan your pull request.
Summary
#1473 Prometheus alert metrics and health telemetry
src/lib/log-retention-telemetry.js, with its own registry merged intoGET /metrics. Series:log_retention_purge_runs_total{outcome}(success, failure, skipped)log_retention_purge_duration_seconds{outcome}log_retention_purge_deleted_rows_total{table}andlog_retention_purge_batches_total{table}log_retention_purge_duration_exceeded_totallog_retention_purge_retries_total{result}log_retention_purge_lock_total{result}GET /health/log-retention(503 only when unhealthy).GET /healthlistsservices.log_retentionfor information only; it does not changeok.LOG_RETENTION_PUSHGATEWAY_URLis set, because the process exits before any scrape could reach it.docs/alerts/log-retention.rules.yml(unhealthy, failing, stale, duration exceeded, retries exhausted, lock errors).src/lib/log-retention-telemetry.test.jscovers every health transition, label sanitising, gauges refreshed at scrape time, and the Pushgateway success, refusal and failure paths.#1474 Automated retry with exponential backoff
src/lib/log-retention-retry.js. Every purge query runs throughwithLogRetentionRetry(): index check, FK check, each delete batch, lock connect and lock acquire.40001,40P01,55P03,57014,57P01-57P03,53300, class08, and socket errors.LogRetentionSafetyError,retryable: false) and any other SQLSTATE.random(0, min(max, base * 2^n)).LOG_PURGE_RETRY_MAX_ATTEMPTS/_BASE_DELAY_MS/_MAX_DELAY_MS, clamped to hard ceilings (8 attempts, 60 s). Retrying stops once the run passesLOG_PURGE_MAX_DURATION_MS.src/lib/log-retention-retry.test.js(classification, option clamping, backoff math, recovery, exhaustion, abort, log fields) and new cases insrc/lib/log-retention.test.js.#1475 Distributed concurrency control and locking
src/lib/log-retention-lock.js:pg_try_advisory_lock(hashtext(<fixed key>)), on a dedicated pooled connection. It never waits; contended means skipped, not failed.FOR UPDATE SKIP LOCKED, so even unlocked callers never block on, or double-delete, each other's rows.runLogRetentionPurge()wrapspurgeWebhookLogs()in the lock and returns{ skipped: true, reason: "locked" }when another run holds it.scripts/purge-webhook-logs.jsnow uses it.LOG_RETENTION_PURGE_CRON(off by default), safe on every instance.src/lib/log-retention-lock.test.js(acquire, contend, in-process skip, per-pool instances, acquire errors, retry, release failures, single client) andrunLogRetentionPurgecases insrc/lib/log-retention.test.js.#1476 Integration and stress test suite
tests/helpers/fake-log-retention-db.js: an in-memory Postgres double implementing the safety checks,DELETE ... FOR UPDATE SKIP LOCKED(rejects a delete without it), and session advisory locks. Several pools sharing one database simulate several instances. It records deleted ids, double deletes, peak lock holders, open connections and held locks.tests/integration/log-retention.test.jscovers the full lock, retry, purge and telemetry pipeline:/health/log-retention(idle, healthy, 503),/healthand/metrics.load-tests/log-retention-stress.test.js:Test output
Security notes
other/failure/error.Notes
src/lib/log-retention.jsand its cron script, the webhook delivery log purge. Payment archival inmaintenance.jsis untouched.purgeWebhookLogs()keeps its signature and return value, and still takes no lock. It gains an optionalretryoption.runLogRetentionPurge().FOR UPDATE SKIP LOCKED.idleunlessLOG_RETENTION_PURGE_CRONis set there; for the cron script, use the Pushgateway metrics.log-retention.test.jsare untouched; new cases were appended.closes #1473
closes #1474
closes #1475
closes #1476