fix: drop metrics for unmatched routes to prevent cardinality explosion#152
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Caution Review failedPull request was closed or merged during review 📝 WalkthroughSummary by CodeRabbit
WalkthroughThe telemetry plugin now normalizes 404 responses to a uniform endpoint label across SSR render and HTTP request metrics. When status is 404, both metric recording points use Changes404 Metrics Endpoint Normalization
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~2 minutes Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
packages/chronicle/src/server/plugins/telemetry.test.ts (1)
43-55: ⚡ Quick winAdd regression cases for docs root endpoints.
Please add assertions for
/docs,/developer, and/v1mapping to'/docs/:slug'so root docs paths don’t regress tonull.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/chronicle/src/server/plugins/telemetry.test.ts` around lines 43 - 55, The test missing regression cases is in the "versioned docs map to /docs/:slug" block using the toEndpoint() helper; add assertions that toEndpoint('/docs'), toEndpoint('/developer'), and toEndpoint('/v1') each return '/docs/:slug' so those root docs paths don't regress to null. Update the test cases inside the same test function (referencing toEndpoint) to include these three expectations.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/chronicle/src/server/plugins/telemetry.ts`:
- Around line 40-49: The DOC_PATH_PREFIX regex in telemetry.ts currently
requires a trailing slash so endpoints like "/docs", "/developer", and "/v1"
don't match and are dropped; update the DOC_PATH_PREFIX constant used by
toEndpoint to match either a trailing slash or end-of-string (e.g., change
/^\/(?:docs|developer|v\d+)\// to /^\/(?:docs|developer|v\d+)(?:\/|$)/) so
DOC_PATH_PREFIX.test(pathname) will return true for both the root docs paths and
their subpaths, ensuring toEndpoint returns ROUTES.DOCS for those URLs.
---
Nitpick comments:
In `@packages/chronicle/src/server/plugins/telemetry.test.ts`:
- Around line 43-55: The test missing regression cases is in the "versioned docs
map to /docs/:slug" block using the toEndpoint() helper; add assertions that
toEndpoint('/docs'), toEndpoint('/developer'), and toEndpoint('/v1') each return
'/docs/:slug' so those root docs paths don't regress to null. Update the test
cases inside the same test function (referencing toEndpoint) to include these
three expectations.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 13d49542-fac1-4eea-9ddd-aa4dec9537d3
📒 Files selected for processing (2)
packages/chronicle/src/server/plugins/telemetry.test.tspackages/chronicle/src/server/plugins/telemetry.ts
|
|
||
| requestCounter.add(1, { method, endpoint, status: res.status }) | ||
| requestDuration.record(duration, { method, endpoint, status: res.status }) | ||
| if (res.status !== 404) { |
There was a problem hiding this comment.
We can just remove the endpoint. We shouldn't remove the metrics capture.
Summary
/.env,/.aws/credentials) creates thousands of unique route label values in metricsper_user_series_limitdiscards for all servicesCloses #151
Test plan
toEndpointtests still pass/docs/:slug(toEndpoint unchanged)