getMetricDatasetQueryExtras.tsx 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import type {Location} from 'history';
  2. import type {Organization} from 'sentry/types/organization';
  3. import {hasCustomMetrics} from 'sentry/utils/metrics/features';
  4. import {hasOnDemandMetricAlertFeature} from 'sentry/utils/onDemandMetrics/features';
  5. import {decodeScalar} from 'sentry/utils/queryString';
  6. import {getMEPAlertsDataset} from 'sentry/views/alerts/wizard/options';
  7. import {hasInsightsAlerts} from 'sentry/views/insights/common/utils/hasInsightsAlerts';
  8. import {Dataset, type MetricRule} from '../types';
  9. export function getMetricDatasetQueryExtras({
  10. organization,
  11. location,
  12. dataset,
  13. newAlertOrQuery,
  14. useOnDemandMetrics,
  15. }: {
  16. dataset: MetricRule['dataset'];
  17. newAlertOrQuery: boolean;
  18. organization: Organization;
  19. location?: Location;
  20. useOnDemandMetrics?: boolean;
  21. }) {
  22. if (dataset === Dataset.EVENTS_ANALYTICS_PLATFORM) {
  23. return {
  24. dataset: 'spans',
  25. };
  26. }
  27. const hasMetricDataset =
  28. hasOnDemandMetricAlertFeature(organization) ||
  29. hasCustomMetrics(organization) ||
  30. organization.features.includes('mep-rollout-flag') ||
  31. organization.features.includes('dashboards-metrics-transition') ||
  32. hasInsightsAlerts(organization);
  33. const disableMetricDataset =
  34. decodeScalar(location?.query?.disableMetricDataset) === 'true';
  35. const queryExtras: Record<string, string> = {};
  36. if (hasMetricDataset && !disableMetricDataset) {
  37. queryExtras.dataset = getMEPAlertsDataset(dataset, newAlertOrQuery);
  38. }
  39. if (location?.query?.aggregate?.includes('ai.total')) {
  40. queryExtras.dataset = 'spansMetrics';
  41. queryExtras.query = '';
  42. }
  43. if (useOnDemandMetrics) {
  44. queryExtras.useOnDemandMetrics = 'true';
  45. }
  46. return queryExtras;
  47. }