getMetricDatasetQueryExtras.tsx 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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 {Dataset, type MetricRule} from '../types';
  8. export function getMetricDatasetQueryExtras({
  9. organization,
  10. location,
  11. dataset,
  12. newAlertOrQuery,
  13. useOnDemandMetrics,
  14. }: {
  15. dataset: MetricRule['dataset'];
  16. newAlertOrQuery: boolean;
  17. organization: Organization;
  18. location?: Location;
  19. useOnDemandMetrics?: boolean;
  20. }) {
  21. if (dataset === Dataset.EVENTS_ANALYTICS_PLATFORM) {
  22. return {
  23. dataset: 'spans',
  24. };
  25. }
  26. const hasMetricDataset =
  27. hasOnDemandMetricAlertFeature(organization) ||
  28. hasCustomMetrics(organization) ||
  29. organization.features.includes('mep-rollout-flag') ||
  30. organization.features.includes('dashboards-metrics-transition');
  31. const disableMetricDataset =
  32. decodeScalar(location?.query?.disableMetricDataset) === 'true';
  33. const queryExtras: Record<string, string> = {};
  34. if (hasMetricDataset && !disableMetricDataset) {
  35. queryExtras.dataset = getMEPAlertsDataset(dataset, newAlertOrQuery);
  36. }
  37. if (location?.query?.aggregate?.includes('ai.total')) {
  38. queryExtras.dataset = 'spansMetrics';
  39. queryExtras.query = '';
  40. }
  41. if (useOnDemandMetrics) {
  42. queryExtras.useOnDemandMetrics = 'true';
  43. }
  44. return queryExtras;
  45. }