Skip to content

feat(alerts): Add migration warnings on detail and edit view #58431

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions static/app/views/alerts/rules/metric/details/body.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ import moment from 'moment';

import type {Client} from 'sentry/api';
import {Alert} from 'sentry/components/alert';
import {LinkButton} from 'sentry/components/button';
import {getInterval} from 'sentry/components/charts/utils';
import * as Layout from 'sentry/components/layouts/thirds';
import type {ChangeData} from 'sentry/components/organizations/timeRangeSelector';
import PageTimeRangeSelector from 'sentry/components/pageTimeRangeSelector';
import Panel from 'sentry/components/panels/panel';
import PanelBody from 'sentry/components/panels/panelBody';
import Placeholder from 'sentry/components/placeholder';
import {IconEdit} from 'sentry/icons';
import {t, tct} from 'sentry/locale';
import {space} from 'sentry/styles/space';
import type {Organization, Project} from 'sentry/types';
Expand All @@ -23,6 +25,10 @@ import {extractEventTypeFilterFromRule} from 'sentry/views/alerts/rules/metric/u
import {isOnDemandMetricAlert} from 'sentry/views/alerts/rules/metric/utils/onDemandMetricAlert';
import {getAlertRuleActionCategory} from 'sentry/views/alerts/rules/utils';
import {AlertRuleStatus, Incident} from 'sentry/views/alerts/types';
import {
hasMigrationFeatureFlag,
ruleNeedsMigration,
} from 'sentry/views/alerts/utils/migrationUi';

import {isCrashFreeAlert} from '../utils/isCrashFreeAlert';

Expand Down Expand Up @@ -146,6 +152,14 @@ export default function MetricDetailsBody({
const ruleActionCategory = getAlertRuleActionCategory(rule);

const isOnDemandAlert = isOnDemandMetricAlert(dataset, aggregate, query);
const showMigrationWarning =
hasMigrationFeatureFlag(organization) && ruleNeedsMigration(rule);

const editThresholdLink =
rule &&
`/organizations/${organization.slug}/alerts/metric-rules/${
project?.slug ?? rule?.projects?.[0]
}/${rule.id}/`;

return (
<Fragment>
Expand Down Expand Up @@ -186,6 +200,24 @@ export default function MetricDetailsBody({
disallowArbitraryRelativeRanges
/>

{showMigrationWarning ? (
<Alert
type="warning"
showIcon
trailingItems={
<LinkButton
to={editThresholdLink}
size="xs"
icon={<IconEdit size="xs" />}
>
{t('Edit')}
</LinkButton>
}
>
{t('The current thresholds for this alert could use some review')}
</Alert>
) : null}

<MetricChart
api={api}
rule={rule}
Expand Down
48 changes: 46 additions & 2 deletions static/app/views/alerts/rules/metric/ruleForm.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {ReactNode} from 'react';
import {Fragment, ReactNode} from 'react';
import {PlainRoute, RouteComponentProps} from 'react-router';
import styled from '@emotion/styled';

Expand All @@ -10,6 +10,7 @@ import {
} from 'sentry/actionCreators/indicator';
import {fetchOrganizationTags} from 'sentry/actionCreators/tags';
import {hasEveryAccess} from 'sentry/components/acl/access';
import Alert from 'sentry/components/alert';
import {Button} from 'sentry/components/button';
import {HeaderTitleLegend} from 'sentry/components/charts/styles';
import CircleIndicator from 'sentry/components/circleIndicator';
Expand All @@ -18,9 +19,11 @@ import DeprecatedAsyncComponent from 'sentry/components/deprecatedAsyncComponent
import Form, {FormProps} from 'sentry/components/forms/form';
import FormModel from 'sentry/components/forms/model';
import * as Layout from 'sentry/components/layouts/thirds';
import ExternalLink from 'sentry/components/links/externalLink';
import List from 'sentry/components/list';
import ListItem from 'sentry/components/list/listItem';
import {t} from 'sentry/locale';
import {Tooltip} from 'sentry/components/tooltip';
import {t, tct} from 'sentry/locale';
import IndicatorStore from 'sentry/stores/indicatorStore';
import {space} from 'sentry/styles/space';
import {EventsStats, MultiSeriesEventsStats, Organization, Project} from 'sentry/types';
Expand All @@ -45,6 +48,10 @@ import {
isValidOnDemandMetricAlert,
} from 'sentry/views/alerts/rules/metric/utils/onDemandMetricAlert';
import {AlertRuleType} from 'sentry/views/alerts/types';
import {
hasMigrationFeatureFlag,
ruleNeedsMigration,
} from 'sentry/views/alerts/utils/migrationUi';
import {
AlertWizardAlertNames,
DatasetMEPAlertQueryTypes,
Expand Down Expand Up @@ -969,6 +976,9 @@ class RuleFormContainer extends DeprecatedAsyncComponent<Props, State> {
const formDisabled = loading || !hasAlertWrite;
const submitDisabled = formDisabled || !this.state.isQueryValid;

const showMigrationWarning =
hasMigrationFeatureFlag(organization) && ruleNeedsMigration(rule);

return (
<Main fullWidth>
<PermissionAlert access={['alerts:write']} project={project} />
Expand Down Expand Up @@ -1042,6 +1052,40 @@ class RuleFormContainer extends DeprecatedAsyncComponent<Props, State> {
/>
<AlertListItem>{t('Set thresholds')}</AlertListItem>
{thresholdTypeForm(formDisabled)}
{showMigrationWarning && (
<Alert
type="warning"
showIcon
trailingItems={
<Button size="xs" type="submit">
{t('Looks good to me!')}
</Button>
Comment on lines +1060 to +1062
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does submit do something?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The BE takes care that the dataset is updated to generic_metrics once an alert is being saved.

}
>
{tct(
'Check the chart above and make sure the current thresholds are still valid, given that this alert is now based on [tooltip:total events].',
{
tooltip: (
<Tooltip
showUnderline
isHoverable
title={
<Fragment>
{t(
'Performance alerts are based on all the events you send to Sentry, not just the ones that are stored'
)}
<br />
<ExternalLink href="https://docs.sentry.io/product/performance/retention-priorities/">
{t('Learn more')}
</ExternalLink>
</Fragment>
}
/>
),
}
)}
</Alert>
)}
{triggerForm(formDisabled)}
{ruleNameOwnerForm(formDisabled)}
</List>
Expand Down
6 changes: 4 additions & 2 deletions static/app/views/alerts/utils/migrationUi.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import {Organization} from 'sentry/types';
import {useApiQuery} from 'sentry/utils/queryClient';
import useOrganization from 'sentry/utils/useOrganization';
import {Dataset} from 'sentry/views/alerts/rules/metric/types';
import {Dataset, MetricRule} from 'sentry/views/alerts/rules/metric/types';
import {CombinedMetricIssueAlerts} from 'sentry/views/alerts/types';

// TODO(telemetry-experience): remove when the migration is complete
export const hasMigrationFeatureFlag = (organization: Organization): boolean =>
organization.features.includes('alert-migration-ui');

// TODO(telemetry-experience): remove when the migration is complete
export const ruleNeedsMigration = (rule: CombinedMetricIssueAlerts): boolean => {
export const ruleNeedsMigration = (
rule: CombinedMetricIssueAlerts | MetricRule
): boolean => {
return 'dataset' in rule && rule.dataset === Dataset.TRANSACTIONS;
};
// TODO(telemetry-experience): remove when the migration is complete
Expand Down