Feat/webhooks dlq postgres#369
Merged
Baskarayelu merged 2 commits intoMay 29, 2026
Merged
Conversation
…tore - Add 008_create_webhook_dlq migration with webhook_dlq table - Implement PostgresDlqStore with full DlqStore interface - Wire PostgresDlqStore into outbox job and WebhookService - Add webhook_dlq_size gauge metric via prom-client - Add unit tests with 100% coverage for PostgresDlqStore - Update webhooks documentation - Fix pre-existing test issues (audit tenant scoping, getLogs signatures) Closes CredenceOrg#324
|
@Vivian-04 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! 🚀 |
Contributor
Author
|
Hi, Please kindly note that the Integration Tests were failing before i started working on the both issues. Please kindly check. Thank youuu! |
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.
PR #324 [Backend] Webhooks DLQ: persist dead-letter entries in Postgres instead of MemoryDlqStore
Summary
Replaces the in-process
MemoryDlqStore(a plainMap) with a durablePostgresDlqStorebacked by awebhook_dlqPostgres table. Previously, any server restart would silently erase all dead-lettered webhook deliveries, making it impossible to inspect or replay permanently failed events. With this change, failed webhook deliveries survive deploys, are queryable via SQL, and integrate with the existing replay tooling.Motivation
MemoryDlqStorelived entirely in process memory. A deploy, crash, or scaling event wiped the DLQ with no recovery path.replayDeadLettersflow only worked within a single process lifetime, defeating its purpose for durable retry.Changes
New Files
src/migrations/008_create_webhook_dlq.tswebhook_dlqtable with columns for payload (JSONB), attempts, status code, error text, response snippet, and replay timestamp. Adds indexes onfailed_atandwebhook_id.src/services/webhooks/postgresDlqStore.tsPostgresDlqStoreclass implementing theDlqStoreinterface (push,list,get,markReplayed). Serializes payloads as JSONB, updates the DLQ size gauge on every push.src/services/webhooks/postgresDlqStore.test.tspg-memfor an in-memory Postgres simulation. Covers all four interface methods plus the metrics integration. 100% line coverage.Modified Files
src/jobs/outbox.tsPostgresDlqStore(pool)and passes it intoWebhookServiceinstead of the default in-memory store.src/middleware/metrics.tswebhook_dlq_sizePrometheus gauge and arecordWebhookDlqSize()helper, keeping metrics centralised.docs/webhooks.mdTest Fixes (pre-existing issues, not related to DLQ)
tests/routes/webhooks.test.tsaudit.getLogs()calls to use the new async tenant-scoped signature (await audit.getLogs(undefined, {}, 100, 0, { allowSuperScope: true })).tests/routes/apiKeys.test.tsgetLogssignature fix for audit assertions.tests/routes/members.test.tstenantId: 'tenant-1'to mock user, updated assertions to match the tenant-scopedMemberServicesignature.tests/routes/rateLimit.test.tsvi.doMock+ dynamic re-import pattern withvi.spyOnfor fail-open/fail-closed Redis tests.src/routes/admin/member.ts{ mergeParams: true }to the members Router so:orgIdpropagates from the parent route.Database Migration
Metrics
A new Prometheus gauge is exposed:
Updated automatically on every
push()call viarecordWebhookDlqSize().Testing
postgresDlqStore.test.ts— 100% line coverage of the store usingpg-mem.webhooks.test.ts,apiKeys.test.ts,members.test.ts, andrateLimit.test.tshave been fixed as part of this PR.How to Verify
Checklist
webhook_dlqmigration addedPostgresDlqStoreimplementsDlqStoreinterfacebuildDlqEntryredaction logic preserved (unchanged)outbox.ts→WebhookService)Closes #324