-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
feat(aci): Use new metric detector charts in issue details #102996
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
feat(aci): Use new metric detector charts in issue details #102996
Conversation
| if (isDetectorLoading) { | ||
| return <MetricIssueChartPlaceholder />; | ||
| } | ||
|
|
||
| return ( | ||
| <MetricChartSection> | ||
| <MetricIssueChartContent | ||
| rule={rule} | ||
| timePeriod={timePeriod} | ||
| project={project} | ||
| incidents={incidents} | ||
| /> | ||
| </MetricChartSection> | ||
| ); | ||
| return <MetricIssueChartContent detector={detector} openPeriods={openPeriods} />; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: Accessing detector.dataSources without a null check can cause a TypeError when useDetectorQuery is disabled.
Severity: CRITICAL | Confidence: 1.00
🔍 Detailed Analysis
The useDetectorQuery hook is configured with a conditional enabled flag. If detectorId is falsy or detectorDetails?.detectorType is not 'metric_alert', the query will not execute, resulting in detector being undefined. The MetricIssueChartContent component then attempts to access properties like detector.dataSources[0].queryObj.snubaQuery without a preceding null check, which triggers a TypeError and causes the application to crash.
💡 Suggested Fix
Add a null check for the detector variable before rendering MetricIssueChartContent. If detector is undefined, render a placeholder component instead.
🤖 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/issueDetails/metricIssues/metricIssueChart.tsx#L50-L54
Potential issue: The `useDetectorQuery` hook is configured with a conditional `enabled`
flag. If `detectorId` is falsy or `detectorDetails?.detectorType` is not
`'metric_alert'`, the query will not execute, resulting in `detector` being `undefined`.
The `MetricIssueChartContent` component then attempts to access properties like
`detector.dataSources[0].queryObj.snubaQuery` without a preceding null check, which
triggers a `TypeError` and causes the application to crash.
Did we get this right? 👍 / 👎 to inform future reviews.
❌ 1 Tests Failed:
View the top 1 failed test(s) by shortest run time
To view more test analytics, go to the Test Analytics Dashboard |
| /> | ||
| </MetricChartSection> | ||
| ); | ||
| return <MetricIssueChartContent detector={detector} openPeriods={openPeriods} />; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: Safeguard against missing detector data crashes.
The detector might be undefined when passed to MetricIssueChartContent because the query can be disabled (enabled: false when detectorId is missing or detectorType is incorrect), causing the component to crash when attempting to access detector.dataSources[0] in useMetricDetectorChart. The code only checks isDetectorError and isDetectorPending but doesn't validate that detector is defined before rendering.
The issue details page for metric issues was still using the old charts which used the old incidents model. Issues made with new detectors would not have that data. Plus, we have updated charts that we want to use on this page.
While doing this, I refactored the metric alert chart to export
useMetricDetectorChart()which makes the data fetching queries and returns the chart props. That way issue details and the detector page can reuse that logic while still rendering the loading/error states differently.Before (chart did not load because incidents model does not exist):
After: