onDemandMetricAlert.spec.tsx 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import {Dataset} from 'sentry/views/alerts/rules/metric/types';
  2. import {isOnDemandMetricAlert} from 'sentry/views/alerts/rules/metric/utils/onDemandMetricAlert';
  3. describe('isOnDemandMetricAlert', () => {
  4. it('should return true for an alert that contains non standard fields', () => {
  5. const dataset = Dataset.GENERIC_METRICS;
  6. expect(
  7. isOnDemandMetricAlert(dataset, 'count()', 'transaction.duration:>1')
  8. ).toBeTruthy();
  9. expect(isOnDemandMetricAlert(dataset, 'count()', 'device.name:foo')).toBeTruthy();
  10. expect(isOnDemandMetricAlert(dataset, 'count()', 'geo.region:>US')).toBeTruthy();
  11. });
  12. it('should return false for an alert that has only standard fields', () => {
  13. const dataset = Dataset.GENERIC_METRICS;
  14. expect(isOnDemandMetricAlert(dataset, 'count()', 'release:1.0')).toBeFalsy();
  15. expect(isOnDemandMetricAlert(dataset, 'count()', 'browser.name:chrome')).toBeFalsy();
  16. });
  17. it('should return false if dataset is not generic_metrics', () => {
  18. const dataset = Dataset.TRANSACTIONS;
  19. expect(
  20. isOnDemandMetricAlert(dataset, 'count()', 'transaction.duration:>1')
  21. ).toBeFalsy();
  22. expect(isOnDemandMetricAlert(dataset, 'count()', 'device.name:foo')).toBeFalsy();
  23. expect(isOnDemandMetricAlert(dataset, 'count()', 'geo.region:>US')).toBeFalsy();
  24. });
  25. it('should return true if aggregate is apdex', () => {
  26. const dataset = Dataset.GENERIC_METRICS;
  27. expect(isOnDemandMetricAlert(dataset, 'apdex(300)', '')).toBeTruthy();
  28. expect(
  29. isOnDemandMetricAlert(dataset, 'apdex(300)', 'transaction.duration:>1')
  30. ).toBeTruthy();
  31. expect(isOnDemandMetricAlert(dataset, 'apdex(300)', 'device.name:foo')).toBeTruthy();
  32. });
  33. it('should return false for an alert that uses custom metrics', () => {
  34. const dataset = Dataset.GENERIC_METRICS;
  35. expect(
  36. isOnDemandMetricAlert(dataset, 'avg(c:custom/some.custom_counter)', 'release:1.0')
  37. ).toBeFalsy();
  38. expect(
  39. isOnDemandMetricAlert(
  40. dataset,
  41. 'count(d:custom/more.custom_stuff)',
  42. 'browser.name:chrome'
  43. )
  44. ).toBeFalsy();
  45. });
  46. it('should return false for an alert that uses insights metrics', () => {
  47. const dataset = Dataset.GENERIC_METRICS;
  48. expect(
  49. isOnDemandMetricAlert(
  50. dataset,
  51. 'avg(d:spans/exclusive_time@millisecond)',
  52. 'span.module:db'
  53. )
  54. ).toBeFalsy();
  55. expect(isOnDemandMetricAlert(dataset, 'spm()', 'browser.name:chrome')).toBeFalsy();
  56. });
  57. });