123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- import type {Location} from 'history';
- import type {Organization} from 'sentry/types/organization';
- import {hasCustomMetrics} from 'sentry/utils/metrics/features';
- import {hasOnDemandMetricAlertFeature} from 'sentry/utils/onDemandMetrics/features';
- import {decodeScalar} from 'sentry/utils/queryString';
- import {getMEPAlertsDataset} from 'sentry/views/alerts/wizard/options';
- import {hasInsightsAlerts} from 'sentry/views/insights/common/utils/hasInsightsAlerts';
- import {Dataset, type MetricRule} from '../types';
- export function getMetricDatasetQueryExtras({
- organization,
- location,
- dataset,
- newAlertOrQuery,
- useOnDemandMetrics,
- }: {
- dataset: MetricRule['dataset'];
- newAlertOrQuery: boolean;
- organization: Organization;
- location?: Location;
- useOnDemandMetrics?: boolean;
- }) {
- if (dataset === Dataset.EVENTS_ANALYTICS_PLATFORM) {
- return {
- dataset: 'spans',
- };
- }
- const hasMetricDataset =
- hasOnDemandMetricAlertFeature(organization) ||
- hasCustomMetrics(organization) ||
- organization.features.includes('mep-rollout-flag') ||
- organization.features.includes('dashboards-metrics-transition') ||
- hasInsightsAlerts(organization);
- const disableMetricDataset =
- decodeScalar(location?.query?.disableMetricDataset) === 'true';
- const queryExtras: Record<string, string> = {};
- if (hasMetricDataset && !disableMetricDataset) {
- queryExtras.dataset = getMEPAlertsDataset(dataset, newAlertOrQuery);
- }
- if (location?.query?.aggregate?.includes('ai.total')) {
- queryExtras.dataset = 'spansMetrics';
- queryExtras.query = '';
- }
- if (useOnDemandMetrics) {
- queryExtras.useOnDemandMetrics = 'true';
- }
- return queryExtras;
- }
|