From e031baec721db60f50e309bb3f008c64fa7a82ef Mon Sep 17 00:00:00 2001 From: Matej Minar Date: Thu, 30 Sep 2021 10:06:19 +0200 Subject: [PATCH] feat(ui): Add 30 minutes window to crash rate alerts (#28938) --- .../incidentRules/ruleConditionsForm.tsx | 1 + .../incidentRules/triggers/chart/index.tsx | 18 ++++++++++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/static/app/views/alerts/incidentRules/ruleConditionsForm.tsx b/static/app/views/alerts/incidentRules/ruleConditionsForm.tsx index c4e30f5480cd4e..80257dfb315197 100644 --- a/static/app/views/alerts/incidentRules/ruleConditionsForm.tsx +++ b/static/app/views/alerts/incidentRules/ruleConditionsForm.tsx @@ -88,6 +88,7 @@ class RuleConditionsForm extends React.PureComponent { if (this.props.dataset === Dataset.SESSIONS) { options = pick(TIME_WINDOW_MAP, [ + TimeWindow.THIRTY_MINUTES, TimeWindow.ONE_HOUR, TimeWindow.TWO_HOURS, TimeWindow.FOUR_HOURS, diff --git a/static/app/views/alerts/incidentRules/triggers/chart/index.tsx b/static/app/views/alerts/incidentRules/triggers/chart/index.tsx index d6c065fea8e204..799b776ebf3b51 100644 --- a/static/app/views/alerts/incidentRules/triggers/chart/index.tsx +++ b/static/app/views/alerts/incidentRules/triggers/chart/index.tsx @@ -121,6 +121,7 @@ const SESSION_AGGREGATE_TO_FIELD = { }; const TIME_WINDOW_TO_SESSION_INTERVAL = { + [TimeWindow.THIRTY_MINUTES]: '30m', [TimeWindow.ONE_HOUR]: '1h', [TimeWindow.TWO_HOURS]: '2h', [TimeWindow.FOUR_HOURS]: '4h', @@ -191,6 +192,19 @@ class TriggersChart extends React.PureComponent { } } + get availableTimePeriods() { + // We need to special case sessions, because sub-hour windows are available + // only when time period is six hours or less (backend limitation) + if (isSessionAggregate(this.props.aggregate)) { + return { + ...AVAILABLE_TIME_PERIODS, + [TimeWindow.THIRTY_MINUTES]: [TimePeriod.SIX_HOURS], + }; + } + + return AVAILABLE_TIME_PERIODS; + } + handleStatsPeriodChange = (timePeriod: string) => { this.setState({statsPeriod: timePeriod as TimePeriod}); }; @@ -198,7 +212,7 @@ class TriggersChart extends React.PureComponent { getStatsPeriod = () => { const {statsPeriod} = this.state; const {timeWindow} = this.props; - const statsPeriodOptions = AVAILABLE_TIME_PERIODS[timeWindow]; + const statsPeriodOptions = this.availableTimePeriods[timeWindow]; const period = statsPeriodOptions.includes(statsPeriod) ? statsPeriod : statsPeriodOptions[0]; @@ -278,7 +292,7 @@ class TriggersChart extends React.PureComponent { const {triggers, resolveThreshold, thresholdType, header, timeWindow, aggregate} = this.props; const {statsPeriod, totalCount} = this.state; - const statsPeriodOptions = AVAILABLE_TIME_PERIODS[timeWindow]; + const statsPeriodOptions = this.availableTimePeriods[timeWindow]; const period = this.getStatsPeriod(); return (