feat: metrics on /api/webhooks#542
Open
Paranoa-dev wants to merge 1 commit into
Open
Conversation
- Add webhooksEndpointRequestsTotal (Counter) and webhooksEndpointDuration
(Histogram) to src/metrics/registry.ts
- Create src/metrics/webhooksMetrics.ts middleware following the
usersMetrics.ts pattern (process.hrtime.bigint + res.on('finish'))
- Wire middleware into webhooks.ts and adminWebhooks.ts routers
- Labels: method, route, status (same as /api/users metrics)
- Route sanitization: UUIDs and numeric IDs collapsed to /:id
- Histogram buckets: [0.01, 0.05, 0.1, 0.5, 1, 2, 5, 10]
- Add 13 focused tests in tests/webhooksMetrics.test.ts
|
@Paranoa-dev 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: metrics on /api/webhooks
Summary
Adds Prometheus histogram and counter metrics for all
/api/webhooksendpoints, following the establishedusersMetrics.tspattern from/api/users.Changes
New file:
src/metrics/webhooksMetrics.tsExpress middleware that tracks per-request metrics using
process.hrtime.bigint()andres.on("finish", ...):webhooksEndpointRequestsTotal(Counter) — incremented on every response finish with labels{method, route, status}webhooksEndpointDuration(Histogram) — observed on every response finish with the same labelsRoute sanitization collapses UUIDs and numeric IDs to
/:idfor label cardinality control.Modified:
src/metrics/registry.tsAdded two new metrics:
Buckets:
[0.01, 0.05, 0.1, 0.5, 1, 2, 5, 10](same as all existing histograms).Modified:
src/routes/webhooks.tsandsrc/routes/adminWebhooks.tsWired
webhooksMetricsMiddlewarebeforerequireAdminso it captures all responses including auth failures (403), validation errors (400), and successful responses (200).Endpoints Covered
/api/webhooks/api/admin/webhooks/dlq/api/admin/webhooks/dlq/:id/replayTests
New file:
tests/webhooksMetrics.test.ts13 tests, all passing:
GET /api/webhooks (5 tests):
GET /api/admin/webhooks/dlq (3 tests):
POST /api/admin/webhooks/dlq/:id/replay (3 tests):
Label structure (2 tests):
Design Decisions
webhooksMetricsMiddlewareis placed beforerequireAdminso it captures all responses including auth failures — matching theusersMetricsMiddlewarepattern inusers.tsmethod,route,status— identical to the/api/usersmetrics for consistency/:idto prevent label cardinality explosionprocess.hrtime.bigint()for nanosecond precision, same as existing metricsFiles Changed
src/metrics/registry.tssrc/metrics/webhooksMetrics.tssrc/routes/webhooks.tssrc/routes/adminWebhooks.tstests/webhooksMetrics.test.tsChecklist
Closes #434