From 36a67eb08569da79c3d8b79c896186c95222b0b3 Mon Sep 17 00:00:00 2001 From: Michelle Fu Date: Thu, 15 May 2025 16:16:52 -0700 Subject: [PATCH 1/2] fix --- .../views/alerts/rules/metric/ruleForm.tsx | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/static/app/views/alerts/rules/metric/ruleForm.tsx b/static/app/views/alerts/rules/metric/ruleForm.tsx index b44a38a90c538d..5ee7c72739318c 100644 --- a/static/app/views/alerts/rules/metric/ruleForm.tsx +++ b/static/app/views/alerts/rules/metric/ruleForm.tsx @@ -1016,6 +1016,24 @@ class RuleFormContainer extends DeprecatedAsyncComponent { 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 ( @@ -1030,6 +1048,11 @@ class RuleFormContainer extends DeprecatedAsyncComponent { const {organization, project} = this.props; const {timeWindow, sensitivity, seasonality, thresholdType} = this.state; + // don't send the request if historical and current data have incorrect time windows + if (!this.TimeWindowsAreConsistent()) { + return; + } + const direction = thresholdType === AlertRuleThresholdType.ABOVE ? 'up' From 674d2602052bf4160d25e0cbb11193e6feaa5e78 Mon Sep 17 00:00:00 2001 From: Michelle Fu Date: Fri, 16 May 2025 14:58:44 -0700 Subject: [PATCH 2/2] fire request but don't set state --- static/app/views/alerts/rules/metric/ruleForm.tsx | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/static/app/views/alerts/rules/metric/ruleForm.tsx b/static/app/views/alerts/rules/metric/ruleForm.tsx index 5ee7c72739318c..dc1040c3e64e5f 100644 --- a/static/app/views/alerts/rules/metric/ruleForm.tsx +++ b/static/app/views/alerts/rules/metric/ruleForm.tsx @@ -1048,10 +1048,6 @@ class RuleFormContainer extends DeprecatedAsyncComponent { const {organization, project} = this.props; const {timeWindow, sensitivity, seasonality, thresholdType} = this.state; - // don't send the request if historical and current data have incorrect time windows - if (!this.TimeWindowsAreConsistent()) { - return; - } const direction = thresholdType === AlertRuleThresholdType.ABOVE @@ -1086,7 +1082,10 @@ class RuleFormContainer extends DeprecatedAsyncComponent { `/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) {