Skip to content
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: 26 additions & 6 deletions static/app/views/detectors/components/forms/metric/metric.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,23 @@ import {
DataConditionType,
DetectorPriorityLevel,
} from 'sentry/types/workflowEngine/dataConditions';
import type {Detector, MetricDetectorConfig} from 'sentry/types/workflowEngine/detectors';
import type {
Detector,
MetricDetector,
MetricDetectorConfig,
} from 'sentry/types/workflowEngine/detectors';
import {generateFieldAsString} from 'sentry/utils/discover/fields';
import useOrganization from 'sentry/utils/useOrganization';
import {
AlertRuleSensitivity,
AlertRuleThresholdType,
Dataset,
} from 'sentry/views/alerts/rules/metric/types';
import {hasLogAlerts} from 'sentry/views/alerts/wizard/utils';
import {TransactionsDatasetWarning} from 'sentry/views/detectors/components/details/metric/transactionsDatasetWarning';
import {AutomateSection} from 'sentry/views/detectors/components/forms/automateSection';
import {AssignSection} from 'sentry/views/detectors/components/forms/common/assignSection';
import {useDetectorFormContext} from 'sentry/views/detectors/components/forms/context';
import {EditDetectorLayout} from 'sentry/views/detectors/components/forms/editDetectorLayout';
import type {MetricDetectorFormData} from 'sentry/views/detectors/components/forms/metric/metricFormData';
import {
Expand All @@ -48,6 +54,7 @@ import {SectionLabel} from 'sentry/views/detectors/components/forms/sectionLabel
import {getDatasetConfig} from 'sentry/views/detectors/datasetConfig/getDatasetConfig';
import {DetectorDataset} from 'sentry/views/detectors/datasetConfig/types';
import {getStaticDetectorThresholdSuffix} from 'sentry/views/detectors/utils/metricDetectorSuffix';
import {deprecateTransactionAlerts} from 'sentry/views/insights/common/utils/hasEAPAlerts';

function MetricDetectorForm() {
return (
Expand Down Expand Up @@ -212,16 +219,29 @@ function IntervalPicker() {
function useDatasetChoices() {
const organization = useOrganization();

const {detector} = useDetectorFormContext();
const savedDataset = (detector as MetricDetector | undefined)?.dataSources[0]?.queryObj
?.snubaQuery?.dataset;
const isExistingTransactionsDetector =
Boolean(detector) &&
[Dataset.TRANSACTIONS, Dataset.GENERIC_METRICS].includes(savedDataset as Dataset);
const shouldHideTransactionsDataset =
!isExistingTransactionsDetector && deprecateTransactionAlerts(organization);

return useMemo(() => {
const datasetChoices: Array<SelectValue<DetectorDataset>> = [
{
value: DetectorDataset.ERRORS,
label: t('Errors'),
},
{
value: DetectorDataset.TRANSACTIONS,
label: t('Transactions'),
},
...(shouldHideTransactionsDataset
? []
: [
{
value: DetectorDataset.TRANSACTIONS,
label: t('Transactions'),
},
]),
...(organization.features.includes('visibility-explore-view')
? [{value: DetectorDataset.SPANS, label: t('Spans')}]
: []),
Expand All @@ -238,7 +258,7 @@ function useDatasetChoices() {
];

return datasetChoices;
}, [organization]);
}, [organization, shouldHideTransactionsDataset]);
}

function DetectSection() {
Expand Down
68 changes: 68 additions & 0 deletions static/app/views/detectors/edit.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -741,5 +741,73 @@ describe('DetectorEdit', () => {
});
});
});

it('shows transactions dataset when editing existing transactions detector even with deprecation flag enabled', async () => {
const organizationWithDeprecation = OrganizationFixture({
features: [
'workflow-engine-ui',
'visibility-explore-view',
'discover-saved-queries-deprecation',
],
});

const existingTransactionsDetector = MetricDetectorFixture({
id: '123',
name: 'Transactions Detector',
dataSources: [
SnubaQueryDataSourceFixture({
queryObj: {
id: '1',
status: 1,
subscription: '1',
snubaQuery: {
aggregate: 'count()',
dataset: Dataset.GENERIC_METRICS,
id: '',
query: '',
timeWindow: 60,
eventTypes: [EventTypes.TRANSACTION],
},
},
}),
],
});

MockApiClient.addMockResponse({
url: `/organizations/${organizationWithDeprecation.slug}/detectors/123/`,
body: existingTransactionsDetector,
});

const editRouterConfig = {
route: '/organizations/:orgId/issues/monitors/:detectorId/edit/',
location: {
pathname: `/organizations/${organizationWithDeprecation.slug}/issues/monitors/123/edit/`,
},
};

render(<DetectorEdit />, {
organization: organizationWithDeprecation,
initialRouterConfig: editRouterConfig,
});

// Wait for the detector to load
expect(
await screen.findByRole('link', {name: 'Transactions Detector'})
).toBeInTheDocument();

// Open dataset dropdown
const datasetField = screen.getByLabelText('Dataset');
await userEvent.click(datasetField);

// Verify transactions option IS available when editing existing transactions detector
expect(
screen.getByRole('menuitemradio', {name: 'Transactions'})
).toBeInTheDocument();

// Verify other datasets are also available
expect(screen.getByRole('menuitemradio', {name: 'Errors'})).toBeInTheDocument();
expect(screen.getByRole('menuitemradio', {name: 'Spans'})).toBeInTheDocument();
expect(screen.getByRole('menuitemradio', {name: 'Releases'})).toBeInTheDocument();
});
});
});
28 changes: 28 additions & 0 deletions static/app/views/detectors/new-setting.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,34 @@ describe('DetectorEdit', () => {
})
);
});

it('hides transactions dataset when deprecateTransactionAlerts feature flag is enabled for new detectors', async () => {
const organizationWithDeprecation = OrganizationFixture({
features: [
'workflow-engine-ui',
'visibility-explore-view',
'discover-saved-queries-deprecation',
],
});

render(<DetectorNewSettings />, {
organization: organizationWithDeprecation,
initialRouterConfig: metricRouterConfig,
});

// Open dataset dropdown
await userEvent.click(screen.getByText('Spans'));

// Verify transactions option is not available for new detectors
expect(
screen.queryByRole('menuitemradio', {name: 'Transactions'})
).not.toBeInTheDocument();

// Verify other datasets are still available
expect(screen.getByRole('menuitemradio', {name: 'Errors'})).toBeInTheDocument();
expect(screen.getByRole('menuitemradio', {name: 'Spans'})).toBeInTheDocument();
expect(screen.getByRole('menuitemradio', {name: 'Releases'})).toBeInTheDocument();
});
});

describe('Uptime Detector', () => {
Expand Down
Loading