Repository navigation
fix(cli): Scope issue list counts to the release: filter #1512
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,113 @@ | ||
| /** | ||
| * Scoped issue counts via the Sentry events endpoint. | ||
| * | ||
| * The issues-list endpoint's per-group seen-stats (`count`, `userCount`) honor | ||
| * the `statsPeriod` but are NOT scoped to arbitrary query filters like | ||
| * `release:` — they report period-wide totals across every value of the key. | ||
| * The events endpoint, in contrast, returns counts that actually match the | ||
| * filter. We re-query it per issue with `issue:<shortId>` AND the user's query | ||
| * to replace the over-reported numbers. See getsentry/cli#1518. | ||
| */ | ||
|
|
||
| import pLimit from "p-limit"; | ||
| import { logger } from "../logger.js"; | ||
| import { queryEvents } from "./explore.js"; | ||
| import { ORG_FANOUT_CONCURRENCY } from "./infrastructure.js"; | ||
|
|
||
| const log = logger.withTag("issue-scoped-counts"); | ||
|
|
||
| /** Filter-scoped event and affected-user counts for a single issue. */ | ||
| export type ScopedCount = { | ||
| count: number; | ||
| userCount: number; | ||
| }; | ||
|
|
||
| /** Time range + project scope shared by scoped-count queries. */ | ||
| type ScopedCountTimeOptions = { | ||
| statsPeriod?: string; | ||
| start?: string; | ||
| end?: string; | ||
| }; | ||
|
|
||
| /** | ||
| * Fetch filter-scoped event & user counts for a single issue via the events | ||
| * endpoint. Returns `undefined` on any failure so the caller keeps the | ||
| * (unscoped) list-endpoint numbers rather than breaking the listing. | ||
| * | ||
| * @param orgSlug - Organization slug | ||
| * @param shortId - Issue short ID (scopes to the one group via `issue:`) | ||
| * @param options - The user's query plus time range and optional project ID | ||
| */ | ||
| export async function fetchScopedCount( | ||
| orgSlug: string, | ||
| shortId: string, | ||
| options: ScopedCountTimeOptions & { | ||
| /** The user's --query (already sanitized). */ | ||
| query: string; | ||
| /** Numeric project ID to scope the events query to. */ | ||
| projectId?: number; | ||
| }, | ||
| ): Promise<ScopedCount | undefined> { | ||
| const query = `issue:${shortId} ${options.query}`.trim(); | ||
| try { | ||
| const response = await queryEvents(orgSlug, { | ||
| fields: ["count()", "count_unique(user)"], | ||
| dataset: "errors", | ||
| query, | ||
| statsPeriod: options.statsPeriod, | ||
| start: options.start, | ||
| end: options.end, | ||
| project: | ||
| options.projectId === undefined | ||
| ? undefined | ||
| : [String(options.projectId)], | ||
| limit: 1, | ||
| }); | ||
| const row = response.data.data[0]; | ||
| if (!row) { | ||
| return; | ||
| } | ||
| return { | ||
| count: Number(row["count()"] ?? 0), | ||
| userCount: Number(row["count_unique(user)"] ?? 0), | ||
| }; | ||
| } catch (error) { | ||
| log.debug(`Scoped count refetch failed for ${shortId}: ${String(error)}`); | ||
| return; | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Fetch scoped counts for many issues in parallel (bounded concurrency), | ||
| * returning a Map keyed by issue short ID. Issues whose refetch fails are | ||
| * absent from the map so the caller keeps the unscoped fallback. | ||
| */ | ||
| export async function fetchScopedCounts( | ||
| orgSlug: string, | ||
| issues: { shortId: string; projectId?: number }[], | ||
| options: ScopedCountTimeOptions & { query: string }, | ||
| ): Promise<Map<string, ScopedCount>> { | ||
| const limit = pLimit(ORG_FANOUT_CONCURRENCY); | ||
| const results = await Promise.all( | ||
| issues.map((issue) => | ||
| limit(async () => { | ||
| const scoped = await fetchScopedCount(orgSlug, issue.shortId, { | ||
| query: options.query, | ||
| statsPeriod: options.statsPeriod, | ||
| start: options.start, | ||
| end: options.end, | ||
| projectId: issue.projectId, | ||
| }); | ||
| return { shortId: issue.shortId, scoped }; | ||
| }), | ||
| ), | ||
| ); | ||
|
|
||
| const map = new Map<string, ScopedCount>(); | ||
| for (const { shortId, scoped } of results) { | ||
| if (scoped) { | ||
| map.set(shortId, scoped); | ||
| } | ||
| } | ||
| return map; | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.