onDemandMetricAlert.tsx 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. import {AggregationKey} from 'sentry/utils/fields';
  2. import {isOnDemandAggregate, isOnDemandQueryString} from 'sentry/utils/onDemandMetrics';
  3. import {Dataset} from 'sentry/views/alerts/rules/metric/types';
  4. import {isCustomMetricField} from 'sentry/views/alerts/rules/metric/utils/isCustomMetricField';
  5. export function isValidOnDemandMetricAlert(
  6. dataset: Dataset,
  7. aggregate: string,
  8. query: string
  9. ): boolean {
  10. if (!isOnDemandMetricAlert(dataset, aggregate, query)) {
  11. return true;
  12. }
  13. // On demand metric alerts do not support generic percentile aggregations
  14. return !aggregate.includes(AggregationKey.PERCENTILE);
  15. }
  16. /**
  17. * We determine that an alert is an on-demand metric alert if the query contains
  18. * one of the tags that are not supported by the standard metrics.
  19. */
  20. export function isOnDemandMetricAlert(
  21. dataset: Dataset,
  22. aggregate: string,
  23. query: string
  24. ): boolean {
  25. if (isOnDemandAggregate(aggregate)) {
  26. return true;
  27. }
  28. // TODO: extend to also support other MRI use-cases
  29. if (isCustomMetricField(aggregate)) {
  30. return false;
  31. }
  32. return dataset === Dataset.GENERIC_METRICS && isOnDemandQueryString(query);
  33. }