Skip to content

Commit ed17b7f

Browse files
authored
fix(aci): Simplify metric detector snuba query types (#95606)
1 parent 3cf5acf commit ed17b7f

File tree

5 files changed

+14
-45
lines changed

5 files changed

+14
-45
lines changed

static/app/types/workflowEngine/detectors.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ type BaseDetector = Readonly<{
125125
export interface MetricDetector extends BaseDetector {
126126
readonly conditionGroup: DataConditionGroup | null;
127127
readonly config: MetricDetectorConfig;
128-
readonly dataSources: SnubaQueryDataSource[];
128+
readonly dataSources: [SnubaQueryDataSource];
129129
readonly type: 'metric_issue';
130130
}
131131

static/app/views/detectors/components/details/metric/chart.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,7 @@ interface MetricDetectorDetailsChartProps {
1010

1111
export function MetricDetectorDetailsChart({detector}: MetricDetectorDetailsChartProps) {
1212
const dataSource = detector.dataSources[0];
13-
const snubaQuery =
14-
dataSource?.type === 'snuba_query_subscription'
15-
? dataSource.queryObj?.snubaQuery
16-
: undefined;
13+
const snubaQuery = dataSource.queryObj?.snubaQuery;
1714

1815
if (!snubaQuery) {
1916
// Unlikely, helps narrow types

static/app/views/detectors/components/details/metric/detect.tsx

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -45,22 +45,7 @@ function SnubaQueryDetails({dataSource}: {dataSource: SnubaQueryDataSource}) {
4545

4646
export function MetricDetectorDetailsDetect({detector}: MetricDetectorDetectProps) {
4747
const dataSource = detector.dataSources?.[0];
48-
if (dataSource?.type === 'snuba_query_subscription') {
49-
return <SnubaQueryDetails dataSource={dataSource} />;
50-
}
51-
52-
return (
53-
<Container>
54-
<Flex direction="column" gap={space(0.5)}>
55-
<Heading>{t('Query:')}</Heading>
56-
<Query>
57-
<Label>{t('visualize:')}</Label> <Value>placeholder</Value>
58-
<Label>{t('where:')}</Label> <Value>placeholder</Value>
59-
</Query>
60-
</Flex>
61-
<Heading>{t('Threshold:')}</Heading>
62-
</Container>
63-
);
48+
return <SnubaQueryDetails dataSource={dataSource} />;
6449
}
6550

6651
const Heading = styled('h4')`

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,8 @@ export function MetricDetectorChart({
134134
// Hide the maximum y-axis label to avoid showing arbitrary threshold values
135135
showMaxLabel: false,
136136
},
137+
// Disable the y-axis grid lines
138+
splitLine: {show: false},
137139
}}
138140
grid={{
139141
left: space(0.25),

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

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -440,33 +440,18 @@ export function metricSavedDetectorToFormData(
440440
throw new Error('Detector type mismatch');
441441
}
442442

443-
// Get the first data source (assuming metric detectors have one)
444443
const dataSource = detector.dataSources?.[0];
445-
446-
// Check if this is a snuba query data source
447-
const snubaQuery =
448-
dataSource?.type === 'snuba_query_subscription'
449-
? dataSource.queryObj?.snubaQuery
450-
: undefined;
444+
const snubaQuery = dataSource.queryObj?.snubaQuery;
451445

452446
// Use the full aggregate string directly
453447
const aggregateFunction = snubaQuery?.aggregate || 'count()';
454448

455-
// Process conditions using the extracted function
456449
const conditionData = processDetectorConditions(detector);
457450

458451
const dataset = snubaQuery?.dataset
459452
? getDetectorDataset(snubaQuery.dataset, snubaQuery.eventTypes)
460453
: DetectorDataset.SPANS;
461454

462-
const metricDetectorConfig =
463-
'detectionType' in detector.config
464-
? detector.config
465-
: {
466-
detectionType: 'static' as const,
467-
thresholdPeriod: 1,
468-
};
469-
470455
return {
471456
// Core detector fields
472457
name: detector.name,
@@ -477,26 +462,26 @@ export function metricSavedDetectorToFormData(
477462
query: snubaQuery?.query || '',
478463
aggregateFunction,
479464
dataset,
480-
interval: 60 * 60, // Default to 1 hour
465+
interval: snubaQuery?.timeWindow ?? DEFAULT_THRESHOLD_METRIC_FORM_DATA.interval,
481466

482467
// Priority level and condition fields from processed conditions
483468
...conditionData,
484-
kind: metricDetectorConfig.detectionType,
469+
kind: detector.config.detectionType,
485470

486471
// Condition fields - get comparison delta from detector config (already in seconds)
487472
conditionComparisonAgo:
488-
(metricDetectorConfig.detectionType === 'percent'
489-
? metricDetectorConfig.comparisonDelta
473+
(detector.config.detectionType === 'percent'
474+
? detector.config.comparisonDelta
490475
: null) || 3600,
491476

492477
// Dynamic fields - extract from config for dynamic detectors
493478
sensitivity:
494-
metricDetectorConfig.detectionType === 'dynamic'
495-
? metricDetectorConfig.sensitivity || AlertRuleSensitivity.LOW
479+
detector.config.detectionType === 'dynamic'
480+
? detector.config.sensitivity || AlertRuleSensitivity.LOW
496481
: AlertRuleSensitivity.LOW,
497482
thresholdType:
498-
metricDetectorConfig.detectionType === 'dynamic'
499-
? metricDetectorConfig.thresholdType || AlertRuleThresholdType.ABOVE
483+
detector.config.detectionType === 'dynamic'
484+
? detector.config.thresholdType || AlertRuleThresholdType.ABOVE
500485
: AlertRuleThresholdType.ABOVE,
501486
};
502487
}

0 commit comments

Comments
 (0)