getMetricDatasetQueryExtras.tsx 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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 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. const hasMetricDataset =
  22. hasOnDemandMetricAlertFeature(organization) ||
  23. hasCustomMetrics(organization) ||
  24. organization.features.includes('mep-rollout-flag');
  25. const disableMetricDataset =
  26. decodeScalar(location?.query?.disableMetricDataset) === 'true';
  27. const queryExtras: Record<string, string> = {};
  28. if (hasMetricDataset && !disableMetricDataset) {
  29. queryExtras.dataset = getMEPAlertsDataset(dataset, newAlertOrQuery);
  30. }
  31. if (location?.query?.aggregate?.includes('ai.total')) {
  32. queryExtras.dataset = 'spansMetrics';
  33. queryExtras.query = '';
  34. }
  35. if (useOnDemandMetrics) {
  36. queryExtras.useOnDemandMetrics = 'true';
  37. }
  38. return queryExtras;
  39. }