onDemandMetricAlert.tsx 943 B

12345678910111213141516171819202122232425262728293031
  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. export function isValidOnDemandMetricAlert(
  5. dataset: Dataset,
  6. aggregate: string,
  7. query: string
  8. ): boolean {
  9. if (!isOnDemandMetricAlert(dataset, aggregate, query)) {
  10. return true;
  11. }
  12. // On demand metric alerts do not support generic percentile aggregations
  13. return !aggregate.includes(AggregationKey.PERCENTILE);
  14. }
  15. /**
  16. * We determine that an alert is an on-demand metric alert if the query contains
  17. * one of the tags that are not supported by the standard metrics.
  18. */
  19. export function isOnDemandMetricAlert(
  20. dataset: Dataset,
  21. aggregate: string,
  22. query: string
  23. ): boolean {
  24. if (isOnDemandAggregate(aggregate)) {
  25. return true;
  26. }
  27. return dataset === Dataset.GENERIC_METRICS && isOnDemandQueryString(query);
  28. }