Skip to content

Commit 614f907

Browse files
authored
feat(aci): Setup dataset, interval, aggregate function, filter (#94002)
Adds a dataset + interval dropdown. Starts implementation for aggregate function heavily based on the new dashboard widget creation. On the form model itself the aggregate is stored as the full query function `count_unique(user.id)` and parsed into the fields. Some fields can get pretty complicated since some have multiple parameters or parameters are inputs instead of dropdowns. Can't seem to get crash alerts working yet, might need examples of the expected payloads. <img width="898" alt="image" src="https://github.com/user-attachments/assets/a893b201-8761-49a5-95dc-08449810c00c" />
1 parent dc4842f commit 614f907

File tree

7 files changed

+851
-197
lines changed

7 files changed

+851
-197
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import {useMemo} from 'react';
2+
import type {Query} from 'history';
3+
4+
import {getFieldTypeFromUnit} from 'sentry/components/events/eventCustomPerformanceMetrics';
5+
import {normalizeDateTimeParams} from 'sentry/components/organizations/pageFilters/parse';
6+
import type {PageFilters} from 'sentry/types/core';
7+
import type {Organization} from 'sentry/types/organization';
8+
import type {CustomMeasurementCollection} from 'sentry/utils/customMeasurements/customMeasurements';
9+
import {useApiQuery} from 'sentry/utils/queryClient';
10+
11+
type MeasurementsMetaResponse = Record<string, {functions: string[]; unit: string}>;
12+
13+
export function useCustomMeasurements(
14+
organization: Organization,
15+
selection?: PageFilters
16+
) {
17+
const query: Query = selection?.datetime
18+
? normalizeDateTimeParams(selection.datetime)
19+
: {};
20+
21+
if (selection?.projects) {
22+
query.project = selection.projects.map(String);
23+
}
24+
25+
const {data, isLoading, isError} = useApiQuery<MeasurementsMetaResponse>(
26+
[`/organizations/${organization.slug}/measurements-meta/`, {query}],
27+
{
28+
staleTime: Infinity,
29+
}
30+
);
31+
32+
const customMeasurements = useMemo(() => {
33+
if (!data) {
34+
return {};
35+
}
36+
37+
return Object.entries(data).reduce<CustomMeasurementCollection>(
38+
(acc, [customMeasurement, measurementData]) => {
39+
acc[customMeasurement] = {
40+
key: customMeasurement,
41+
name: customMeasurement,
42+
functions: measurementData.functions,
43+
unit: measurementData.unit,
44+
fieldType: getFieldTypeFromUnit(measurementData.unit),
45+
};
46+
return acc;
47+
},
48+
{}
49+
);
50+
}, [data]);
51+
52+
return {
53+
customMeasurements,
54+
isLoading,
55+
isError,
56+
};
57+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import {ErrorsConfig} from 'sentry/views/dashboards/datasetConfig/errors';
2+
import {ReleasesConfig} from 'sentry/views/dashboards/datasetConfig/releases';
3+
import {SpansConfig} from 'sentry/views/dashboards/datasetConfig/spans';
4+
import {TransactionsConfig} from 'sentry/views/dashboards/datasetConfig/transactions';
5+
import {DetectorDataset} from 'sentry/views/detectors/components/forms/metricFormData';
6+
7+
/**
8+
* @returns a configuration object used to display the aggregate function selector and the search bar
9+
*/
10+
export function getDatasetConfig(dataset: DetectorDataset) {
11+
switch (dataset) {
12+
case DetectorDataset.ERRORS:
13+
return ErrorsConfig;
14+
case DetectorDataset.TRANSACTIONS:
15+
return TransactionsConfig;
16+
case DetectorDataset.RELEASES:
17+
return ReleasesConfig;
18+
case DetectorDataset.SPANS:
19+
return SpansConfig;
20+
default:
21+
return ErrorsConfig;
22+
}
23+
}

0 commit comments

Comments
 (0)