Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/sentry/incidents/charts.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
SESSION_AGGREGATE_TO_FIELD = {
CRASH_FREE_SESSIONS: "sum(session)",
CRASH_FREE_USERS: "count_unique(user)",
"percentage(sessions_crashed, sessions)": "sum(session)",
"percentage(users_crashed, users)": "count_unique(user)",
}


Expand Down
8 changes: 7 additions & 1 deletion static/app/views/alerts/utils/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,18 @@ export function getQueryDatasource(
}

export function isSessionAggregate(aggregate: string) {
return Object.values(SessionsAggregate).includes(aggregate as SessionsAggregate);
return (
Object.values(SessionsAggregate).includes(aggregate as SessionsAggregate) ||
aggregate === 'percentage(sessions_crashed, sessions)' ||
aggregate === 'percentage(users_crashed, users)'
);
}

export const SESSION_AGGREGATE_TO_FIELD: Record<string, SessionFieldWithOperation> = {
[SessionsAggregate.CRASH_FREE_SESSIONS]: SessionFieldWithOperation.SESSIONS,
[SessionsAggregate.CRASH_FREE_USERS]: SessionFieldWithOperation.USERS,
'percentage(sessions_crashed, sessions)': SessionFieldWithOperation.SESSIONS,
'percentage(users_crashed, users)': SessionFieldWithOperation.USERS,
};

Comment on lines 122 to 126

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Chart rendering for metric alerts with unaliased session aggregates is broken, resulting in a missing heading and an incorrect series name due to incomplete lookup objects and faulty string matching.
Severity: MEDIUM

Suggested Fix

Update SESSION_AGGREGATE_TO_HEADING in chart/index.tsx to include mappings for the unaliased aggregate strings. In wizard/utils.tsx, modify getAlertTypeFromAggregateDataset to correctly match unaliased aggregates, possibly by checking if the identifier includes the aggregate or by using a more robust matching method instead of aggregate.includes(identifier).

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.

Location: static/app/views/alerts/utils/index.tsx#L122-L126

Potential issue: When a metric alert rule with an unaliased session aggregate (e.g.,
`'percentage(sessions_crashed, sessions)'`) is rendered, two issues occur in the chart.
First, the `SESSION_AGGREGATE_TO_HEADING` object lacks entries for these unaliased
strings, causing the chart's `totalCountLabel` to be `undefined` and rendering an empty
heading. Second, the `getAlertTypeFromAggregateDataset` function fails to correctly
identify the alert type because its string matching logic
(`aggregate.includes(aliased_identifier)`) does not work when the `aggregate` is shorter
than the identifier. This results in the function returning a default value, causing the
chart series to be labeled with an incorrect name, such as 'Custom Transactions'. Both
issues stem from incomplete handling of unaliased aggregates introduced for API- or
Terraform-created alerts.

Also affects:

  • static/app/views/alerts/rules/metric/triggers/chart/index.tsx:121~122
  • static/app/views/alerts/wizard/utils.tsx

Did we get this right? 👍 / 👎 to inform future reviews.

export function alertAxisFormatter(value: number, seriesName: string, aggregate: string) {
Expand Down
Loading