feat(alert): add alert issues and metrics list commands#579
Draft
feat(alert): add alert issues and metrics list commands#579
Conversation
Adds two new list commands under `sentry alert`: - `sentry alert issues list` — list issue alert rules for one or more projects, with full multi-target resolution (DSN auto-detect, org-all, project-search, explicit org/project), compound cursor pagination, Phase 1 + Phase 2 budget redistribution, and graceful partial failure handling - `sentry alert metrics list` — list metric alert rules for an org Both commands support --json, --limit, --web, and -c next/prev pagination.
…ed lib Moves duplicated code from issue/list.ts and alert/issues/list.ts into shared modules so both commands use the same implementation: - lib/db/pagination.ts: exports CURSOR_SEP, encodeCompoundCursor, decodeCompoundCursor, buildMultiTargetContextKey - lib/resolve-target.ts: exports resolveTargetsFromParsedArg — handles all four target modes (auto-detect, explicit, org-all, project-search) with options for enrichProjectIds and checkIssueShortId (issue-list-specific) issue/list.ts drops ~260 lines of local duplicates; alert/issues/list.ts never needs to define them in the first place.
Contributor
Semver Impact of This PR🟡 Minor (new features) 📋 Changelog PreviewThis is how your changes will appear in the changelog. New Features ✨Dashboard
Init
Other
Bug Fixes 🐛Dashboard
Event
Other
Documentation 📚
Internal Changes 🔧Coverage
Event
Other
Other
🤖 This preview updates automatically when you update the PR. |
Contributor
|
Contributor
Codecov Results 📊✅ 126 passed | Total: 126 | Pass Rate: 100% | Execution Time: 0ms 📊 Comparison with Base Branch
✨ No test changes detected All tests are passing successfully. ❌ Patch coverage is 75.66%. Project has 1366 uncovered lines. Files with missing lines (4)
Coverage diff@@ Coverage Diff @@
## main #PR +/-##
==========================================
- Coverage 95.46% 95.18% -0.28%
==========================================
Files 194 200 +6
Lines 28040 28316 +276
Branches 0 0 —
==========================================
+ Hits 26766 26950 +184
- Misses 1274 1366 +92
- Partials 0 0 —Generated by Codecov Action |
…List Both alert/issues/list and alert/metrics/list were implementing their own 4-mode target dispatch and compound cursor machinery from scratch, bypassing the shared dispatchOrgScopedList infrastructure every other list command uses. Replace with the standard pattern: - dispatchOrgScopedList with ListCommandMeta + 4 mode handler overrides - Simple parallel fetch-all for auto-detect/explicit/project-search modes (no compound cursor — alert rule lists are small datasets) - Single-cursor pagination for org-all mode (metrics: listMetricAlertsPaginated with cursor; issues: resolveTargetsFromParsedArg for project list + fetch all) Removes ~320 lines of custom dispatch and compound cursor logic. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…ucture - Use jsonTransformListResult (shared) instead of custom JSON transforms - Separate raw rules into items (for JSON) and displayRows (for human output) - Add --query/-q flag for client-side name filtering on both alert commands - Restore api-client.ts alerts export to original shape Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…ssue list Full structural alignment with sentry issue list: - FetchResult success/failure wrapping per target - fetchWithBudget with two-phase surplus redistribution - Compound cursor pagination (encodeCompoundCursor/decodeCompoundCursor) - buildProjectAliasMap with buildOrgAwareAliases + setProjectAliases - trimWithProjectGuarantee for per-project representation - One handleResolvedTargets for all 4 modes (alert issues have no org-level API) - allowCursorInModes for all modes including org-all - parseCursorFlag explicitly in cursor flag definition - logger.warn for partial failures - IssueAlertListResult with title/footerMode/moreHint/footer - jsonTransformListResult (shared JSON transform) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…issue list Full structural alignment with sentry issue list and alert issues list: - FetchResult success/failure wrapping per org with withAuthGuard - fetchWithBudget with two-phase surplus redistribution (per-org) - Compound cursor pagination across multiple orgs (auto-detect/explicit/project-search) - trimWithOrgGuarantee for per-org representation - handleResolvedOrgs for multi-org modes; handleOrgAllMetricAlerts for single-org cursor - allowCursorInModes for auto-detect/explicit/project-search - parseCursorFlag explicitly in cursor flag definition - logger.warn for partial org failures - MetricAlertListResult with title/footerMode/moreHint/footer - jsonTransformListResult (shared JSON transform) - buildMultiOrgContextKey isolates cursors per unique org set + query Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…list Removes the separate handleOrgAllMetricAlerts handler and routes all 4 modes (including org-all) through handleResolvedOrgs. org-all resolves all projects in the specified org, deduplicates to unique orgs (just the one), then uses fetchWithBudget with compound cursor — same path as auto-detect/explicit/project-search. This makes the structure identical to alert issues list and supports multi-org results from DSN detection consistently across all modes. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Extract FetchResult<T>, trimWithGroupGuarantee<T>, buildProjectAliasMap<T>, and buildMultiOrgContextKey into lib/ so all three list commands (issue, alert issues, alert metrics) share the same implementations. Each command retains a thin domain-specific wrapper where needed. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
For metric alerts (org-scoped), explicit and org-all modes already provide the org slug in the parsed arg. Routing them through resolveTargetsFromParsedArg caused an unnecessary listProjects API call just to re-derive the org slug. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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.
Adds
sentry alert issues listandsentry alert metrics list.What this adds
sentry alert issues listlists issue alert rules (the per-project rules that fire when error events match conditions). Supports the same target resolution assentry issue list:org/project— explicit single projectorg/— all projects in an orgPagination uses a compound cursor (pipe-separated per-project cursors) so
-c next/-c prevworks correctly across multi-project results. Uses the same two-phase budget redistribution as issue list: Phase 1 distributesceil(limit/N)per project, Phase 2 redistributes surplus to projects that still have pages.sentry alert metrics listlists metric alert rules (org-scoped threshold alerts). Simpler: single org, standard cursor pagination.Both commands support
--json,--limit,--web, and-c next/prev.Shared infrastructure
While adding the alert list, pulled duplicated code out of
issue/list.tsinto shared lib modules so both commands use the same implementation rather than copy-pasting:lib/db/pagination.ts:encodeCompoundCursor,decodeCompoundCursor,buildMultiTargetContextKeylib/resolve-target.ts:resolveTargetsFromParsedArg— canonical multi-target resolution for all four modes, withenrichProjectIdsandcheckIssueShortIdoptions for command-specific behaviourissue/list.tsdrops ~260 lines of local duplicates.Test plan