getMetricDatasetQueryExtras.tsx 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. import type {Location} from 'history';
  2. import type {Organization} from 'sentry/types';
  3. import {hasOnDemandMetricAlertFeature} from 'sentry/utils/onDemandMetrics/features';
  4. import {decodeScalar} from 'sentry/utils/queryString';
  5. import {getMEPAlertsDataset} from 'sentry/views/alerts/wizard/options';
  6. import type {MetricRule} from '../types';
  7. export function getMetricDatasetQueryExtras({
  8. organization,
  9. location,
  10. dataset,
  11. newAlertOrQuery,
  12. useOnDemandMetrics,
  13. }: {
  14. dataset: MetricRule['dataset'];
  15. newAlertOrQuery: boolean;
  16. organization: Organization;
  17. location?: Location;
  18. useOnDemandMetrics?: boolean;
  19. }) {
  20. const hasMetricDataset =
  21. hasOnDemandMetricAlertFeature(organization) ||
  22. organization.features.includes('mep-rollout-flag');
  23. const disableMetricDataset =
  24. decodeScalar(location?.query?.disableMetricDataset) === 'true';
  25. const queryExtras: Record<string, string> =
  26. hasMetricDataset && !disableMetricDataset
  27. ? {dataset: getMEPAlertsDataset(dataset, newAlertOrQuery)}
  28. : {};
  29. if (useOnDemandMetrics) {
  30. queryExtras.useOnDemandMetrics = 'true';
  31. }
  32. return queryExtras;
  33. }