Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import {Dataset} from 'sentry/views/alerts/rules/metric/types';
import {getAnomalyMarkerSeries} from 'sentry/views/alerts/rules/metric/utils/anomalyChart';
import {isCrashFreeAlert} from 'sentry/views/alerts/rules/metric/utils/isCrashFreeAlert';
import type {Anomaly} from 'sentry/views/alerts/types';
import {IncidentStatus} from 'sentry/views/alerts/types';
import {
ALERT_CHART_MIN_MAX_BUFFER,
alertAxisFormatter,
Expand Down Expand Up @@ -248,7 +247,8 @@ export function getMetricDetectorChartOption(
const statusChanges = openPeriod.activities
.filter(
({type, value}) =>
type === 'status_change' && (value === 'medium' || value === 'high')
(type === 'status_change' || type === 'opened') &&
(value === 'medium' || value === 'high')
)
.sort(
(a, b) =>
Expand All @@ -257,12 +257,11 @@ export function getMetricDetectorChartOption(

const incidentEnd = openPeriod.end ?? Date.now();

const timeWindowMs = snubaQuery.timeWindow * 60 * 1000;
const timeWindowMs = snubaQuery.timeWindow * 1000;
Copy link

Choose a reason for hiding this comment

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

Bug: The timeWindowMs calculation is incorrect, making it 60 times smaller than intended, which will cause incident status areas to render at incorrect timestamps.
Severity: CRITICAL | Confidence: 1.00

🔍 Detailed Analysis

The calculation for timeWindowMs was changed from snubaQuery.timeWindow * 60 * 1000 to snubaQuery.timeWindow * 1000. This change is incorrect because snubaQuery.timeWindow is in seconds, not minutes, and the timeWindowMs value is intended to represent a duration in milliseconds that was previously derived from a minute-based value. As a result, timeWindowMs will be 60 times smaller than expected, causing statusAreaStart and statusAreaEnd boundaries to be calculated incorrectly. This will lead to incident status areas being rendered approximately 60 times too early on the chart, making the visual representation misleading.

💡 Suggested Fix

Revert the change to timeWindowMs calculation at static/app/views/detectors/components/details/metric/charts/metricDetectorChartOptions.tsx:260 by restoring the multiplication by 60 to snubaQuery.timeWindow * 60 * 1000 to correctly convert the time window from minutes (as implicitly expected by the original calculation) to milliseconds.

🤖 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/detectors/components/details/metric/charts/metricDetectorChartOptions.tsx#L260

Potential issue: The calculation for `timeWindowMs` was changed from
`snubaQuery.timeWindow * 60 * 1000` to `snubaQuery.timeWindow * 1000`. This change is
incorrect because `snubaQuery.timeWindow` is in seconds, not minutes, and the
`timeWindowMs` value is intended to represent a duration in milliseconds that was
previously derived from a minute-based value. As a result, `timeWindowMs` will be 60
times smaller than expected, causing `statusAreaStart` and `statusAreaEnd` boundaries to
be calculated incorrectly. This will lead to incident status areas being rendered
approximately 60 times too early on the chart, making the visual representation
misleading.

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

Reference_id: 2633684

Copy link
Contributor Author

Choose a reason for hiding this comment

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

naur, I changed it BECAUSE it was rendering the status areas incorrectly.

const incidentColor =
warningCondition &&
statusChanges.some(({value}) => Number(value) === IncidentStatus.CRITICAL)
? theme.red300
: theme.yellow300;
warningCondition && !statusChanges.some(({value}) => value === 'high')
? theme.yellow300
: theme.red300;

const incidentStartDate = new Date(openPeriod.start).getTime();
const incidentCloseDate = openPeriod.end
Expand Down
Loading