Skip to content

Commit b948992

Browse files
authored
ref(aci): Rename metric detector "kind" to detectionType (#95610)
1 parent 77fb305 commit b948992

File tree

4 files changed

+49
-44
lines changed

4 files changed

+49
-44
lines changed

static/app/components/workflowEngine/form/control/priorityControl.tsx

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,9 @@ interface PriorityControlProps {
8888
}
8989

9090
export default function PriorityControl({minimumPriority}: PriorityControlProps) {
91-
const detectorKind = useMetricDetectorFormField(METRIC_DETECTOR_FORM_FIELDS.kind);
91+
const detectionType = useMetricDetectorFormField(
92+
METRIC_DETECTOR_FORM_FIELDS.detectionType
93+
);
9294
const initialPriorityLevel = useMetricDetectorFormField(
9395
METRIC_DETECTOR_FORM_FIELDS.initialPriorityLevel
9496
);
@@ -100,7 +102,7 @@ export default function PriorityControl({minimumPriority}: PriorityControlProps)
100102
);
101103
const thresholdSuffix = getStaticDetectorThresholdSuffix(aggregate);
102104

103-
if (detectorKind === 'dynamic') {
105+
if (detectionType === 'dynamic') {
104106
return null;
105107
}
106108

@@ -109,11 +111,7 @@ export default function PriorityControl({minimumPriority}: PriorityControlProps)
109111
<PrioritizeRow
110112
left={
111113
<Flex align="center" direction="column">
112-
{!detectorKind || detectorKind === 'static' ? (
113-
<ThresholdPriority />
114-
) : (
115-
<ChangePriority />
116-
)}
114+
{detectionType === 'static' ? <ThresholdPriority /> : <ChangePriority />}
117115
<SecondaryLabel>({t('issue created')})</SecondaryLabel>
118116
</Flex>
119117
}
@@ -134,7 +132,7 @@ export default function PriorityControl({minimumPriority}: PriorityControlProps)
134132
name={METRIC_DETECTOR_FORM_FIELDS.mediumThreshold}
135133
aria-label={t('Medium threshold')}
136134
/>
137-
<div>{conditionKindAndTypeToLabel[detectorKind][conditionType!]}</div>
135+
<div>{conditionKindAndTypeToLabel[detectionType][conditionType!]}</div>
138136
</Flex>
139137
}
140138
right={<GroupPriorityBadge showLabel priority={PriorityLevel.MEDIUM} />}
@@ -155,7 +153,7 @@ export default function PriorityControl({minimumPriority}: PriorityControlProps)
155153
name={METRIC_DETECTOR_FORM_FIELDS.highThreshold}
156154
aria-label={t('High threshold')}
157155
/>
158-
<div>{conditionKindAndTypeToLabel[detectorKind][conditionType!]}</div>
156+
<div>{conditionKindAndTypeToLabel[detectionType][conditionType!]}</div>
159157
</Flex>
160158
}
161159
right={<GroupPriorityBadge showLabel priority={PriorityLevel.HIGH} />}

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

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ export function NewMetricDetectorForm() {
7979
}
8080

8181
function MonitorKind() {
82-
const options: Array<[MetricDetectorFormData['kind'], string, string]> = [
82+
const options: Array<[MetricDetectorFormData['detectionType'], string, string]> = [
8383
['static', t('Threshold'), t('Absolute-valued thresholds, for non-seasonal data.')],
8484
['percent', t('Change'), t('Percentage changes over defined time windows.')],
8585
[
@@ -94,15 +94,17 @@ function MonitorKind() {
9494
label={t('\u2026and monitor for changes in the following way:')}
9595
flexibleControlStateSize
9696
inline={false}
97-
name={METRIC_DETECTOR_FORM_FIELDS.kind}
97+
name={METRIC_DETECTOR_FORM_FIELDS.detectionType}
9898
defaultValue="threshold"
9999
choices={options}
100100
/>
101101
);
102102
}
103103

104104
function ResolveSection() {
105-
const kind = useMetricDetectorFormField(METRIC_DETECTOR_FORM_FIELDS.kind);
105+
const detectionType = useMetricDetectorFormField(
106+
METRIC_DETECTOR_FORM_FIELDS.detectionType
107+
);
106108
const conditionValue = useMetricDetectorFormField(
107109
METRIC_DETECTOR_FORM_FIELDS.conditionValue
108110
);
@@ -118,15 +120,15 @@ function ResolveSection() {
118120
const thresholdSuffix = getStaticDetectorThresholdSuffix(aggregate);
119121

120122
const description = getResolutionDescription(
121-
kind === 'percent'
123+
detectionType === 'percent'
122124
? {
123125
detectionType: 'percent',
124126
conditionType,
125127
conditionValue,
126128
comparisonDelta: conditionComparisonAgo ?? 3600, // Default to 1 hour if not set
127129
thresholdSuffix,
128130
}
129-
: kind === 'static'
131+
: detectionType === 'static'
130132
? {
131133
detectionType: 'static',
132134
conditionType,
@@ -159,18 +161,20 @@ function AssignSection() {
159161
}
160162

161163
function PrioritizeSection() {
162-
const kind = useMetricDetectorFormField(METRIC_DETECTOR_FORM_FIELDS.kind);
164+
const detectionType = useMetricDetectorFormField(
165+
METRIC_DETECTOR_FORM_FIELDS.detectionType
166+
);
163167
return (
164168
<Container>
165169
<Section
166170
title={t('Prioritize')}
167171
description={
168-
kind === 'dynamic'
172+
detectionType === 'dynamic'
169173
? t('Sentry will automatically update priority.')
170174
: t('Update issue priority when the following thresholds are met:')
171175
}
172176
>
173-
{kind !== 'dynamic' && (
177+
{detectionType !== 'dynamic' && (
174178
<PriorityControl minimumPriority={DetectorPriorityLevel.MEDIUM} />
175179
)}
176180
</Section>
@@ -211,7 +215,9 @@ function useDatasetChoices() {
211215
}
212216

213217
function DetectSection() {
214-
const kind = useMetricDetectorFormField(METRIC_DETECTOR_FORM_FIELDS.kind);
218+
const detectionType = useMetricDetectorFormField(
219+
METRIC_DETECTOR_FORM_FIELDS.detectionType
220+
);
215221
const datasetChoices = useDatasetChoices();
216222
const formContext = useContext(FormContext);
217223
const aggregate = useMetricDetectorFormField(
@@ -278,7 +284,7 @@ function DetectSection() {
278284
<Visualize />
279285
<MonitorKind />
280286
<Flex direction="column">
281-
{(!kind || kind === 'static') && (
287+
{(!detectionType || detectionType === 'static') && (
282288
<Flex direction="column">
283289
<MutedText>{t('An issue will be created when query value is:')}</MutedText>
284290
<Flex align="center" gap={space(1)}>
@@ -309,7 +315,7 @@ function DetectSection() {
309315
</Flex>
310316
</Flex>
311317
)}
312-
{kind === 'percent' && (
318+
{detectionType === 'percent' && (
313319
<Flex direction="column">
314320
<MutedText>{t('An issue will be created when query value is:')}</MutedText>
315321
<Flex align="center" gap={space(1)}>
@@ -360,7 +366,7 @@ function DetectSection() {
360366
</Flex>
361367
</Flex>
362368
)}
363-
{kind === 'dynamic' && (
369+
{detectionType === 'dynamic' && (
364370
<Flex direction="column">
365371
<SelectField
366372
required

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

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ export interface MetricDetectorFormData
9494
MetricDetectorConditionFormData,
9595
MetricDetectorDynamicFormData,
9696
SnubaQueryFormData {
97-
kind: 'static' | 'percent' | 'dynamic';
97+
detectionType: MetricDetectorConfig['detectionType'];
9898
name: string;
9999
owner: string;
100100
projectId: string;
@@ -109,7 +109,7 @@ type MetricDetectorFormFieldName = keyof MetricDetectorFormData;
109109
*/
110110
export const METRIC_DETECTOR_FORM_FIELDS = {
111111
// Core detector fields
112-
kind: 'kind',
112+
detectionType: 'detectionType',
113113
environment: 'environment',
114114
projectId: 'projectId',
115115
owner: 'owner',
@@ -138,7 +138,7 @@ export const METRIC_DETECTOR_FORM_FIELDS = {
138138
} satisfies Record<MetricDetectorFormFieldName, MetricDetectorFormFieldName>;
139139

140140
export const DEFAULT_THRESHOLD_METRIC_FORM_DATA = {
141-
kind: 'static',
141+
detectionType: 'static',
142142

143143
// Priority level fields
144144
// Metric detectors only support MEDIUM and HIGH priority levels
@@ -154,7 +154,6 @@ export const DEFAULT_THRESHOLD_METRIC_FORM_DATA = {
154154
dataset: DetectorDataset.SPANS,
155155
aggregateFunction: 'avg(span.duration)',
156156
interval: 60 * 60, // One hour in seconds
157-
query: '',
158157
} satisfies Partial<MetricDetectorFormData>;
159158

160159
/**
@@ -338,7 +337,7 @@ export function metricDetectorFormDataToEndpointPayload(
338337

339338
// Create config based on detection type
340339
let config: MetricDetectorConfig;
341-
switch (data.kind) {
340+
switch (data.detectionType) {
342341
case 'percent':
343342
config = {
344343
thresholdPeriod: 1,
@@ -440,12 +439,9 @@ export function metricSavedDetectorToFormData(
440439
throw new Error('Detector type mismatch');
441440
}
442441

443-
const dataSource = detector.dataSources?.[0];
442+
const dataSource = detector.dataSources[0];
444443
const snubaQuery = dataSource.queryObj?.snubaQuery;
445444

446-
// Use the full aggregate string directly
447-
const aggregateFunction = snubaQuery?.aggregate || 'count()';
448-
449445
const conditionData = processDetectorConditions(detector);
450446

451447
const dataset = snubaQuery?.dataset
@@ -460,28 +456,31 @@ export function metricSavedDetectorToFormData(
460456
environment: getDetectorEnvironment(detector) || '',
461457
owner: detector.owner || '',
462458
query: snubaQuery?.query || '',
463-
aggregateFunction,
459+
aggregateFunction:
460+
snubaQuery?.aggregate || DEFAULT_THRESHOLD_METRIC_FORM_DATA.aggregateFunction,
464461
dataset,
465462
interval: snubaQuery?.timeWindow ?? DEFAULT_THRESHOLD_METRIC_FORM_DATA.interval,
466463

467464
// Priority level and condition fields from processed conditions
468465
...conditionData,
469-
kind: detector.config.detectionType,
466+
detectionType: detector.config.detectionType,
470467

471468
// Condition fields - get comparison delta from detector config (already in seconds)
472469
conditionComparisonAgo:
473-
(detector.config.detectionType === 'percent'
470+
detector.config.detectionType === 'percent' &&
471+
defined(detector.config.comparisonDelta)
474472
? detector.config.comparisonDelta
475-
: null) || 3600,
473+
: DEFAULT_THRESHOLD_METRIC_FORM_DATA.conditionComparisonAgo,
476474

477475
// Dynamic fields - extract from config for dynamic detectors
478476
sensitivity:
479-
detector.config.detectionType === 'dynamic'
480-
? detector.config.sensitivity || AlertRuleSensitivity.LOW
481-
: AlertRuleSensitivity.LOW,
477+
detector.config.detectionType === 'dynamic' && defined(detector.config.sensitivity)
478+
? detector.config.sensitivity
479+
: DEFAULT_THRESHOLD_METRIC_FORM_DATA.sensitivity,
482480
thresholdType:
483-
detector.config.detectionType === 'dynamic'
484-
? detector.config.thresholdType || AlertRuleThresholdType.ABOVE
485-
: AlertRuleThresholdType.ABOVE,
481+
detector.config.detectionType === 'dynamic' &&
482+
defined(detector.config.thresholdType)
483+
? detector.config.thresholdType
484+
: DEFAULT_THRESHOLD_METRIC_FORM_DATA.thresholdType,
486485
};
487486
}

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,14 @@ export function MetricDetectorPreviewChart() {
3232
const initialPriorityLevel = useMetricDetectorFormField(
3333
METRIC_DETECTOR_FORM_FIELDS.initialPriorityLevel
3434
);
35-
const kind = useMetricDetectorFormField(METRIC_DETECTOR_FORM_FIELDS.kind);
35+
const detectionType = useMetricDetectorFormField(
36+
METRIC_DETECTOR_FORM_FIELDS.detectionType
37+
);
3638

3739
// Create condition group from form data using the helper function
3840
const conditions = useMemo(() => {
3941
// Wait for a condition value to be defined
40-
if (kind === 'static' && !conditionValue) {
42+
if (detectionType === 'static' && !conditionValue) {
4143
return [];
4244
}
4345

@@ -47,7 +49,7 @@ export function MetricDetectorPreviewChart() {
4749
initialPriorityLevel,
4850
highThreshold,
4951
});
50-
}, [conditionType, conditionValue, initialPriorityLevel, highThreshold, kind]);
52+
}, [conditionType, conditionValue, initialPriorityLevel, highThreshold, detectionType]);
5153

5254
return (
5355
<ChartContainer>
@@ -59,7 +61,7 @@ export function MetricDetectorPreviewChart() {
5961
environment={environment}
6062
projectId={projectId}
6163
conditions={conditions}
62-
detectionType={kind}
64+
detectionType={detectionType}
6365
/>
6466
</ChartContainer>
6567
);

0 commit comments

Comments
 (0)