Skip to content

Commit 1dc6c2a

Browse files
malwilleyandrewshie-sentry
authored andcommitted
ref(aci): Add supported detection types to dataset config (#97709)
- Remove a couple checks for `dataset === RELEASES` by adding `supportedDetectorTypes` to the dataset config - Add a separate default value for the releases dataset so that we no longer rely on the one from the dashboards config
1 parent 8a3840f commit 1dc6c2a

File tree

7 files changed

+53
-20
lines changed

7 files changed

+53
-20
lines changed

static/app/views/detectors/components/forms/metric/metric.tsx

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import styled from '@emotion/styled';
44
import {FeatureBadge} from 'sentry/components/core/badge/featureBadge';
55
import {Flex} from 'sentry/components/core/layout';
66
import {Tooltip} from 'sentry/components/core/tooltip';
7+
import type {RadioOption} from 'sentry/components/forms/controls/radioGroup';
78
import NumberField from 'sentry/components/forms/fields/numberField';
89
import SegmentedRadioField from 'sentry/components/forms/fields/segmentedRadioField';
910
import SelectField from 'sentry/components/forms/fields/selectField';
@@ -18,7 +19,7 @@ import {
1819
DataConditionType,
1920
DetectorPriorityLevel,
2021
} from 'sentry/types/workflowEngine/dataConditions';
21-
import type {Detector} from 'sentry/types/workflowEngine/detectors';
22+
import type {Detector, MetricDetectorConfig} from 'sentry/types/workflowEngine/detectors';
2223
import {generateFieldAsString} from 'sentry/utils/discover/fields';
2324
import useOrganization from 'sentry/utils/useOrganization';
2425
import {
@@ -85,22 +86,34 @@ export function NewMetricDetectorForm() {
8586
);
8687
}
8788

88-
function DetectionType() {
89-
const options: Array<[MetricDetectorFormData['detectionType'], string, string]> = [
90-
['static', t('Threshold'), t('Absolute-valued thresholds, for non-seasonal data.')],
91-
['percent', t('Change'), t('Percentage changes over defined time windows.')],
92-
[
93-
'dynamic',
94-
t('Dynamic'),
95-
t('Auto-detect anomalies and mean deviation, for seasonal/noisy data.'),
96-
],
97-
];
89+
const DETECTION_TYPE_MAP: Record<
90+
MetricDetectorConfig['detectionType'],
91+
{description: string; label: string}
92+
> = {
93+
static: {
94+
label: t('Threshold'),
95+
description: t('Absolute-valued thresholds, for non-seasonal data.'),
96+
},
97+
percent: {
98+
label: t('Change'),
99+
description: t('Percentage changes over defined time windows.'),
100+
},
101+
dynamic: {
102+
label: t('Dynamic'),
103+
description: t('Auto-detect anomalies and mean deviation, for seasonal/noisy data.'),
104+
},
105+
};
98106

107+
function DetectionType() {
99108
const dataset = useMetricDetectorFormField(METRIC_DETECTOR_FORM_FIELDS.dataset);
100-
// Disable choices for releases dataset, does not support
101-
if (dataset === DetectorDataset.RELEASES) {
102-
return null;
103-
}
109+
const datasetConfig = getDatasetConfig(dataset);
110+
const options: RadioOption[] = datasetConfig.supportedDetectionTypes.map(
111+
detectionType => [
112+
detectionType,
113+
DETECTION_TYPE_MAP[detectionType].label,
114+
DETECTION_TYPE_MAP[detectionType].description,
115+
]
116+
);
104117

105118
return (
106119
<DetectionTypeField
@@ -293,11 +306,11 @@ function DetectSection() {
293306
defaultAggregate
294307
);
295308

296-
// Reset detection type to static for releases dataset
297-
if (newDataset === DetectorDataset.RELEASES) {
309+
const supportedDetectionTypes = datasetConfig.supportedDetectionTypes;
310+
if (!supportedDetectionTypes.includes(detectionType)) {
298311
formContext.form?.setValue(
299312
METRIC_DETECTOR_FORM_FIELDS.detectionType,
300-
'static'
313+
supportedDetectionTypes[0]
301314
);
302315
}
303316
}}

static/app/views/detectors/datasetConfig/base.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type {SelectValue} from 'sentry/types/core';
22
import type {Series} from 'sentry/types/echarts';
33
import type {TagCollection} from 'sentry/types/group';
44
import type {Organization} from 'sentry/types/organization';
5+
import type {MetricDetectorConfig} from 'sentry/types/workflowEngine/detectors';
56
import type {CustomMeasurementCollection} from 'sentry/utils/customMeasurements/customMeasurements';
67
import type {QueryFieldValue} from 'sentry/utils/discover/fields';
78
import type {DiscoverDatasets} from 'sentry/utils/discover/types';
@@ -72,6 +73,7 @@ export interface DetectorDatasetConfig<SeriesResponse> {
7273
customMeasurements?: CustomMeasurementCollection
7374
) => Record<string, SelectValue<FieldValue>>;
7475
getSeriesQueryOptions: (options: DetectorSeriesQueryOptions) => ApiQueryKey;
76+
supportedDetectionTypes: Array<MetricDetectorConfig['detectionType']>;
7577
/**
7678
* Transform the user-friendly aggregate function to the API aggregate function.
7779
* This is currently only used for the releases dataset.

static/app/views/detectors/datasetConfig/errors.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,5 @@ export const DetectorErrorsConfig: DetectorDatasetConfig<ErrorsSeriesResponse> =
2929
},
3030
fromApiAggregate: aggregate => aggregate,
3131
toApiAggregate: aggregate => aggregate,
32+
supportedDetectionTypes: ['static', 'percent', 'dynamic'],
3233
};

static/app/views/detectors/datasetConfig/logs.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,5 @@ export const DetectorLogsConfig: DetectorDatasetConfig<LogsSeriesRepsonse> = {
2424
},
2525
fromApiAggregate: aggregate => aggregate,
2626
toApiAggregate: aggregate => aggregate,
27+
supportedDetectionTypes: ['static', 'percent', 'dynamic'],
2728
};

static/app/views/detectors/datasetConfig/releases.tsx

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import type {SelectValue} from 'sentry/types/core';
22
import type {SessionApiResponse} from 'sentry/types/organization';
33
import {SessionField} from 'sentry/types/sessions';
4-
import {ReleasesConfig} from 'sentry/views/dashboards/datasetConfig/releases';
4+
import type {
5+
AggregationKeyWithAlias,
6+
QueryFieldValue,
7+
} from 'sentry/utils/discover/fields';
58
import {ReleaseSearchBar} from 'sentry/views/detectors/datasetConfig/components/releaseSearchBar';
69
import {
710
getReleasesSeriesQueryOptions,
@@ -63,6 +66,16 @@ const AGGREGATE_FUNCTION_MAP: Record<string, string> = {
6366
'percentage(users_crashed, users) AS _crash_rate_alert_aggregate',
6467
};
6568

69+
const DEFAULT_FIELD: QueryFieldValue = {
70+
function: [
71+
'crash_free_rate' as AggregationKeyWithAlias,
72+
SessionField.SESSION,
73+
undefined,
74+
undefined,
75+
],
76+
kind: FieldValueKind.FUNCTION,
77+
};
78+
6679
const fromApiAggregate = (aggregate: string) => {
6780
return (
6881
Object.keys(AGGREGATE_FUNCTION_MAP).find(
@@ -76,7 +89,7 @@ const toApiAggregate = (aggregate: string) => {
7689
};
7790

7891
export const DetectorReleasesConfig: DetectorDatasetConfig<ReleasesSeriesResponse> = {
79-
defaultField: ReleasesConfig.defaultField,
92+
defaultField: DEFAULT_FIELD,
8093
getAggregateOptions: () => AGGREGATE_OPTIONS,
8194
SearchBar: ReleaseSearchBar,
8295
getSeriesQueryOptions: getReleasesSeriesQueryOptions,
@@ -89,4 +102,5 @@ export const DetectorReleasesConfig: DetectorDatasetConfig<ReleasesSeriesRespons
89102
// Releases cannot have a comparison series currently
90103
return [];
91104
},
105+
supportedDetectionTypes: ['static'],
92106
};

static/app/views/detectors/datasetConfig/spans.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,5 @@ export const DetectorSpansConfig: DetectorDatasetConfig<SpansSeriesResponse> = {
2424
},
2525
fromApiAggregate: aggregate => aggregate,
2626
toApiAggregate: aggregate => aggregate,
27+
supportedDetectionTypes: ['static', 'percent', 'dynamic'],
2728
};

static/app/views/detectors/datasetConfig/transactions.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,5 @@ export const DetectorTransactionsConfig: DetectorDatasetConfig<TransactionsSerie
3030
},
3131
fromApiAggregate: aggregate => aggregate,
3232
toApiAggregate: aggregate => aggregate,
33+
supportedDetectionTypes: ['static', 'percent', 'dynamic'],
3334
};

0 commit comments

Comments
 (0)