Repository navigation
feat(backend): telemetry, retry, distributed locking and stress tests for Log Retention & Archival Service - #1604
Open
Olorunfemi20 wants to merge 1 commit into
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. |
This branch has not been deployed
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.
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