Skip to content

fix(anomaly detection): fix historical/current data time window inconsistency #91782

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 2 commits into from
May 16, 2025
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
24 changes: 23 additions & 1 deletion static/app/views/alerts/rules/metric/ruleForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1016,6 +1016,24 @@ class RuleFormContainer extends DeprecatedAsyncComponent<Props, State> {
this.setState({historicalData}, () => this.fetchAnomalies());
}

TimeWindowsAreConsistent() {
const {currentData, historicalData, timeWindow} = this.state;
const currentDataPoint1 = currentData[1];
const currentDataPoint0 = currentData[0];
if (!currentDataPoint0 || !currentDataPoint1) {
return false;
}
const historicalDataPoint1 = historicalData[1];
const historicalDataPoint0 = historicalData[0];
if (!historicalDataPoint0 || !historicalDataPoint1) {
return false;
}

const currentTimeWindow = (currentDataPoint1[0] - currentDataPoint0[0]) / 60;
const historicalTimeWindow = (historicalDataPoint1[0] - historicalDataPoint0[0]) / 60;
return currentTimeWindow === historicalTimeWindow && currentTimeWindow === timeWindow;
}

async fetchAnomalies() {
const {comparisonType, historicalData, currentData} = this.state;
if (
Expand All @@ -1030,6 +1048,7 @@ class RuleFormContainer extends DeprecatedAsyncComponent<Props, State> {

const {organization, project} = this.props;
const {timeWindow, sensitivity, seasonality, thresholdType} = this.state;

const direction =
thresholdType === AlertRuleThresholdType.ABOVE
? 'up'
Expand Down Expand Up @@ -1063,7 +1082,10 @@ class RuleFormContainer extends DeprecatedAsyncComponent<Props, State> {
`/organizations/${organization.slug}/events/anomalies/`,
{method: 'POST', data: params}
);
this.setState({anomalies});
// don't set the anomalies if historical and current data have incorrect time windows
if (!this.TimeWindowsAreConsistent()) {
this.setState({anomalies});
}
} catch (e) {
let chartErrorMessage: string | undefined;
if (e.responseJSON) {
Expand Down
Loading