onDemandMetricAlert.tsx 965 B

123456789101112131415161718192021222324252627
  1. import {isOnDemandAggregate, isOnDemandQueryString} from 'sentry/utils/onDemandMetrics';
  2. import {Dataset} from 'sentry/views/alerts/rules/metric/types';
  3. import {isCustomMetricField} from 'sentry/views/alerts/rules/metric/utils/isCustomMetricField';
  4. import {getAlertTypeFromAggregateDataset} from 'sentry/views/alerts/wizard/utils';
  5. /**
  6. * We determine that an alert is an on-demand metric alert if the query contains
  7. * one of the tags that are not supported by the standard metrics.
  8. */
  9. export function isOnDemandMetricAlert(
  10. dataset: Dataset,
  11. aggregate: string,
  12. query: string
  13. ): boolean {
  14. if (getAlertTypeFromAggregateDataset({aggregate, dataset}) === 'insights_metrics') {
  15. return false;
  16. }
  17. if (isOnDemandAggregate(aggregate)) {
  18. return true;
  19. }
  20. // TODO: extend to also support other MRI use-cases
  21. if (isCustomMetricField(aggregate)) {
  22. return false;
  23. }
  24. return dataset === Dataset.GENERIC_METRICS && isOnDemandQueryString(query);
  25. }