Skip to content

Commit e2156ba

Browse files
committed
fix(anomaly detection): cancel anomalies request if time windows are inconsistent
1 parent 66b9e57 commit e2156ba

File tree

1 file changed

+7
-11
lines changed

1 file changed

+7
-11
lines changed

static/app/views/alerts/rules/metric/ruleForm.tsx

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1016,15 +1016,13 @@ class RuleFormContainer extends DeprecatedAsyncComponent<Props, State> {
10161016
this.setState({historicalData}, () => this.fetchAnomalies());
10171017
}
10181018

1019-
TimeWindowsAreConsistent() {
1020-
const {currentData, historicalData, timeWindow} = this.state;
1021-
const currentDataPoint1 = currentData[1];
1022-
const currentDataPoint0 = currentData[0];
1019+
timeWindowsAreConsistent() {
1020+
const {currentData = [], historicalData = [], timeWindow} = this.state;
1021+
const [currentDataPoint0, currentDataPoint1] = currentData;
10231022
if (!currentDataPoint0 || !currentDataPoint1) {
10241023
return false;
10251024
}
1026-
const historicalDataPoint1 = historicalData[1];
1027-
const historicalDataPoint0 = historicalData[0];
1025+
const [historicalDataPoint0, historicalDataPoint1] = historicalData;
10281026
if (!historicalDataPoint0 || !historicalDataPoint1) {
10291027
return false;
10301028
}
@@ -1040,7 +1038,8 @@ class RuleFormContainer extends DeprecatedAsyncComponent<Props, State> {
10401038
comparisonType !== AlertRuleComparisonType.DYNAMIC ||
10411039
!(Array.isArray(currentData) && Array.isArray(historicalData)) ||
10421040
currentData.length === 0 ||
1043-
historicalData.length === 0
1041+
historicalData.length === 0 ||
1042+
!this.timeWindowsAreConsistent()
10441043
) {
10451044
return;
10461045
}
@@ -1082,10 +1081,7 @@ class RuleFormContainer extends DeprecatedAsyncComponent<Props, State> {
10821081
`/organizations/${organization.slug}/events/anomalies/`,
10831082
{method: 'POST', data: params}
10841083
);
1085-
// don't set the anomalies if historical and current data have incorrect time windows
1086-
if (!this.TimeWindowsAreConsistent()) {
1087-
this.setState({anomalies});
1088-
}
1084+
this.setState({anomalies});
10891085
} catch (e) {
10901086
let chartErrorMessage: string | undefined;
10911087
if (e.responseJSON) {

0 commit comments

Comments
 (0)