Skip to content

Commit 60cdff3

Browse files
authored
fix(aci): Hide failure rate and hide string options for p50 (#103697)
- hides failure rate and failure count options from metric monitors - hides string tags for aggregate functions like p50, p90
1 parent 85d0f9f commit 60cdff3

File tree

1 file changed

+44
-11
lines changed

1 file changed

+44
-11
lines changed

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

Lines changed: 44 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import {parseFunction} from 'sentry/utils/discover/fields';
1515
import {
1616
AggregationKey,
1717
ALLOWED_EXPLORE_VISUALIZE_AGGREGATES,
18+
FieldValueType,
19+
getFieldDefinition,
1820
prettifyTagKey,
1921
} from 'sentry/utils/fields';
2022
import {unreachable} from 'sentry/utils/unreachable';
@@ -91,13 +93,27 @@ function renderTag(kind: FieldValueKind): React.ReactNode {
9193
return <Tag type={tagType}>{text}</Tag>;
9294
}
9395

96+
const LOGS_NOT_ALLOWED_AGGREGATES = [
97+
AggregationKey.FAILURE_RATE,
98+
AggregationKey.FAILURE_COUNT,
99+
];
100+
101+
function getEAPAllowedAggregates(dataset: DetectorDataset): Array<[string, string]> {
102+
return ALLOWED_EXPLORE_VISUALIZE_AGGREGATES.filter(aggregate => {
103+
if (dataset === DetectorDataset.LOGS) {
104+
return !LOGS_NOT_ALLOWED_AGGREGATES.includes(aggregate);
105+
}
106+
return true;
107+
}).map(aggregate => [aggregate, aggregate]);
108+
}
109+
94110
function getAggregateOptions(
95111
dataset: DetectorDataset,
96112
tableFieldOptions: Record<string, SelectValue<FieldValue>>
97113
): Array<[string, string]> {
98114
// For spans dataset, use the predefined aggregates
99115
if (dataset === DetectorDataset.SPANS || dataset === DetectorDataset.LOGS) {
100-
return ALLOWED_EXPLORE_VISUALIZE_AGGREGATES.map(aggregate => [aggregate, aggregate]);
116+
return getEAPAllowedAggregates(dataset);
101117
}
102118

103119
// For other datasets, extract function-type options from tableFieldOptions
@@ -107,7 +123,7 @@ function getAggregateOptions(
107123

108124
// If no function options available, fall back to the predefined aggregates
109125
if (functionOptions.length === 0) {
110-
return ALLOWED_EXPLORE_VISUALIZE_AGGREGATES.map(aggregate => [aggregate, aggregate]);
126+
return getEAPAllowedAggregates(dataset);
111127
}
112128

113129
return functionOptions.sort((a, b) => a[1].localeCompare(b[1]));
@@ -218,15 +234,32 @@ export function Visualize() {
218234
const fieldOptions = useMemo(() => {
219235
// For Spans dataset, use span-specific options from the provider
220236
if (dataset === DetectorDataset.SPANS || dataset === DetectorDataset.LOGS) {
237+
// Use field definition to determine what options should be displayed
238+
const fieldDefinition = getFieldDefinition(
239+
aggregate,
240+
dataset === DetectorDataset.SPANS ? 'span' : 'log'
241+
);
242+
let isTypeAllowed = (_valueType: FieldValueType) => true;
243+
if (fieldDefinition?.parameters?.[0]?.kind === 'column') {
244+
const columnTypes = fieldDefinition?.parameters[0]?.columnTypes;
245+
isTypeAllowed = (valueType: FieldValueType) =>
246+
typeof columnTypes === 'function'
247+
? columnTypes({key: '', valueType})
248+
: columnTypes.includes(valueType);
249+
}
221250
const spanColumnOptions: Array<[string, string]> = [
222-
...Object.values(stringSpanTags).map((tag): [string, string] => [
223-
tag.key,
224-
prettifyTagKey(tag.name),
225-
]),
226-
...Object.values(numericSpanTags).map((tag): [string, string] => [
227-
tag.key,
228-
prettifyTagKey(tag.name),
229-
]),
251+
...(isTypeAllowed(FieldValueType.STRING)
252+
? Object.values(stringSpanTags).map((tag): [string, string] => [
253+
tag.key,
254+
prettifyTagKey(tag.name),
255+
])
256+
: []),
257+
...(isTypeAllowed(FieldValueType.NUMBER)
258+
? Object.values(numericSpanTags).map((tag): [string, string] => [
259+
tag.key,
260+
prettifyTagKey(tag.name),
261+
])
262+
: []),
230263
];
231264
return spanColumnOptions.sort((a, b) => a[1].localeCompare(b[1]));
232265
}
@@ -239,7 +272,7 @@ export function Visualize() {
239272
)
240273
.map((option): [string, string] => [option.value.meta.name, option.value.meta.name])
241274
.sort((a, b) => a[1].localeCompare(b[1]));
242-
}, [dataset, stringSpanTags, numericSpanTags, aggregateOptions]);
275+
}, [dataset, stringSpanTags, numericSpanTags, aggregateOptions, aggregate]);
243276

244277
const fieldOptionsDropdown = useMemo(() => {
245278
return fieldOptions.map(([value, label]) => ({

0 commit comments

Comments
 (0)