Browse Source

Don't display Activated Metric Alerts in the Alerts list yet (#67029)

## Description
Part of the activated alert rules work, this is the first phase of
hooking up the UI to use the new API. This will be a noop in production
because we are currently unable to create this alert type in the UI. The
next PR will be to enable that.

This will omit the ACTIVATED monitor types in the UI until we're ready
to edit / create this new alert type in the Alerts UI. This is a
temporary measure while we update the `Releases` code to create
Activated Alerts.
Josh Callender 11 months ago
parent
commit
390d43b43c

+ 5 - 0
static/app/types/alerts.tsx

@@ -286,3 +286,8 @@ export enum RuleActionsCategories {
   SOME_DEFAULT = 'some_default',
   NO_DEFAULT = 'no_default',
 }
+
+export enum MonitorType {
+  CONTINUOUS = 0,
+  ACTIVATED = 1,
+}

+ 41 - 0
static/app/views/alerts/list/rules/alertRulesList.spec.tsx

@@ -29,6 +29,7 @@ describe('AlertRulesList', () => {
   const defaultOrg = OrganizationFixture({
     access: ['alerts:write'],
   });
+
   TeamStore.loadInitialData([TeamFixture()], false, null);
   let rulesMock!: jest.Mock;
   let projectMock!: jest.Mock;
@@ -61,6 +62,7 @@ describe('AlertRulesList', () => {
         }),
       ],
     });
+
     projectMock = MockApiClient.addMockResponse({
       url: '/organizations/org-slug/projects/',
       body: [
@@ -446,4 +448,43 @@ describe('AlertRulesList', () => {
       })
     );
   });
+
+  it('does not display ACTIVATED Metric Alerts', async () => {
+    rulesMock = MockApiClient.addMockResponse({
+      url: '/organizations/org-slug/combined-rules/',
+      headers: {Link: pageLinks},
+      body: [
+        ProjectAlertRuleFixture({
+          id: '123',
+          name: 'First Issue Alert',
+          projects: ['earth'],
+          createdBy: {name: 'Samwise', id: 1, email: ''},
+        }),
+        MetricRuleFixture({
+          id: '345',
+          projects: ['earth'],
+          name: 'Omitted Test Metric Alert',
+          monitorType: 1,
+          latestIncident: IncidentFixture({
+            status: IncidentStatus.CRITICAL,
+          }),
+        }),
+        MetricRuleFixture({
+          id: '678',
+          name: 'Test Metric Alert 2',
+          monitorType: 0,
+          projects: ['earth'],
+          latestIncident: null,
+        }),
+      ],
+    });
+
+    const {routerContext, organization} = initializeOrg({organization: defaultOrg});
+    render(<AlertRulesList />, {context: routerContext, organization});
+
+    expect(await screen.findByText('Test Metric Alert 2')).toBeInTheDocument();
+    expect(await screen.findByText('First Issue Alert')).toBeInTheDocument();
+
+    expect(screen.queryByText('Omitted Test Metric Alert')).not.toBeInTheDocument();
+  });
 });

+ 28 - 15
static/app/views/alerts/list/rules/alertRulesList.tsx

@@ -18,6 +18,7 @@ import {IconArrow} from 'sentry/icons';
 import {t} from 'sentry/locale';
 import {space} from 'sentry/styles/space';
 import type {Project} from 'sentry/types';
+import {MonitorType} from 'sentry/types/alerts';
 import {defined} from 'sentry/utils';
 import {uniq} from 'sentry/utils/array/uniq';
 import {VisuallyCompleteWithData} from 'sentry/utils/performanceForSentry';
@@ -235,21 +236,33 @@ function AlertRulesList() {
               >
                 <Projects orgId={organization.slug} slugs={projectsFromResults}>
                   {({initiallyLoaded, projects}) =>
-                    ruleList.map(rule => (
-                      <RuleListRow
-                        // Metric and issue alerts can have the same id
-                        key={`${
-                          isIssueAlert(rule) ? AlertRuleType.METRIC : AlertRuleType.ISSUE
-                        }-${rule.id}`}
-                        projectsLoaded={initiallyLoaded}
-                        projects={projects as Project[]}
-                        rule={rule}
-                        orgId={organization.slug}
-                        onOwnerChange={handleOwnerChange}
-                        onDelete={handleDeleteRule}
-                        hasEditAccess={hasEditAccess}
-                      />
-                    ))
+                    ruleList.map(rule => {
+                      const isIssueAlertInstance = isIssueAlert(rule);
+                      const keyPrefix = isIssueAlertInstance
+                        ? AlertRuleType.ISSUE
+                        : AlertRuleType.METRIC;
+
+                      if (
+                        !isIssueAlertInstance &&
+                        rule.monitorType === MonitorType.ACTIVATED
+                      ) {
+                        return null;
+                      }
+
+                      return (
+                        <RuleListRow
+                          // Metric and issue alerts can have the same id
+                          key={`${keyPrefix}-${rule.id}`}
+                          projectsLoaded={initiallyLoaded}
+                          projects={projects as Project[]}
+                          rule={rule}
+                          orgId={organization.slug}
+                          onOwnerChange={handleOwnerChange}
+                          onDelete={handleDeleteRule}
+                          hasEditAccess={hasEditAccess}
+                        />
+                      );
+                    })
                   }
                 </Projects>
               </VisuallyCompleteWithData>

+ 2 - 0
static/app/views/alerts/rules/metric/types.tsx

@@ -1,4 +1,5 @@
 import {t} from 'sentry/locale';
+import type {MonitorType} from 'sentry/types/alerts';
 import type {MEPAlertsQueryType} from 'sentry/views/alerts/wizard/options';
 import type {SchemaFormConfig} from 'sentry/views/settings/organizationIntegrations/sentryAppExternalForm';
 
@@ -97,6 +98,7 @@ export type UnsavedMetricRule = {
   triggers: Trigger[];
   comparisonDelta?: number | null;
   eventTypes?: EventTypes[];
+  monitorType?: MonitorType;
   owner?: string | null;
   queryType?: MEPAlertsQueryType | null;
 };

+ 1 - 0
static/app/views/alerts/types.tsx

@@ -91,6 +91,7 @@ interface IssueAlert extends IssueAlertRule {
   type: CombinedAlertType.ISSUE;
   latestIncident?: Incident | null;
 }
+
 interface MetricAlert extends MetricRule {
   type: CombinedAlertType.METRIC;
   latestIncident?: Incident | null;