Browse Source

feat(ui): Add 30 minutes window to crash rate alerts (#28938)

Matej Minar 3 years ago
parent
commit
e031baec72

+ 1 - 0
static/app/views/alerts/incidentRules/ruleConditionsForm.tsx

@@ -88,6 +88,7 @@ class RuleConditionsForm extends React.PureComponent<Props, State> {
 
     if (this.props.dataset === Dataset.SESSIONS) {
       options = pick(TIME_WINDOW_MAP, [
+        TimeWindow.THIRTY_MINUTES,
         TimeWindow.ONE_HOUR,
         TimeWindow.TWO_HOURS,
         TimeWindow.FOUR_HOURS,

+ 16 - 2
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<Props, State> {
     }
   }
 
+  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<Props, State> {
   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<Props, State> {
     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 (
       <React.Fragment>