utils.spec.tsx 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. import {Dataset, SessionsAggregate} from 'sentry/views/alerts/rules/metric/types';
  2. import {getAlertTypeFromAggregateDataset} from 'sentry/views/alerts/wizard/utils';
  3. describe('Wizard utils', function () {
  4. it('extracts lcp alert', function () {
  5. expect(
  6. getAlertTypeFromAggregateDataset({
  7. aggregate: 'p95(measurements.lcp)',
  8. dataset: Dataset.TRANSACTIONS,
  9. })
  10. ).toEqual('lcp');
  11. expect(
  12. getAlertTypeFromAggregateDataset({
  13. aggregate: 'percentile(measurements.lcp,0.7)',
  14. dataset: Dataset.TRANSACTIONS,
  15. })
  16. ).toEqual('lcp');
  17. expect(
  18. getAlertTypeFromAggregateDataset({
  19. aggregate: 'avg(measurements.lcp)',
  20. dataset: Dataset.TRANSACTIONS,
  21. })
  22. ).toEqual('lcp');
  23. });
  24. it('extracts duration alert', function () {
  25. expect(
  26. getAlertTypeFromAggregateDataset({
  27. aggregate: 'p95(transaction.duration)',
  28. dataset: Dataset.TRANSACTIONS,
  29. })
  30. ).toEqual('trans_duration');
  31. expect(
  32. getAlertTypeFromAggregateDataset({
  33. aggregate: 'percentile(transaction.duration,0.3)',
  34. dataset: Dataset.TRANSACTIONS,
  35. })
  36. ).toEqual('trans_duration');
  37. expect(
  38. getAlertTypeFromAggregateDataset({
  39. aggregate: 'avg(transaction.duration)',
  40. dataset: Dataset.TRANSACTIONS,
  41. })
  42. ).toEqual('trans_duration');
  43. });
  44. it('extracts throughput alert', function () {
  45. expect(
  46. getAlertTypeFromAggregateDataset({
  47. aggregate: 'count()',
  48. dataset: Dataset.TRANSACTIONS,
  49. })
  50. ).toEqual('throughput');
  51. });
  52. it('extracts user error alert', function () {
  53. expect(
  54. getAlertTypeFromAggregateDataset({
  55. aggregate: 'count_unique(user)',
  56. dataset: Dataset.ERRORS,
  57. })
  58. ).toEqual('users_experiencing_errors');
  59. });
  60. it('extracts error count alert', function () {
  61. expect(
  62. getAlertTypeFromAggregateDataset({
  63. aggregate: 'count()',
  64. dataset: Dataset.ERRORS,
  65. })
  66. ).toEqual('num_errors');
  67. });
  68. it('extracts crash free sessions alert', function () {
  69. expect(
  70. getAlertTypeFromAggregateDataset({
  71. aggregate: SessionsAggregate.CRASH_FREE_SESSIONS,
  72. dataset: Dataset.METRICS,
  73. })
  74. ).toEqual('crash_free_sessions');
  75. });
  76. it('extracts crash free users alert', function () {
  77. expect(
  78. getAlertTypeFromAggregateDataset({
  79. aggregate: SessionsAggregate.CRASH_FREE_USERS,
  80. dataset: Dataset.METRICS,
  81. })
  82. ).toEqual('crash_free_users');
  83. });
  84. it('extracts crash free users alert from metrics', function () {
  85. expect(
  86. getAlertTypeFromAggregateDataset({
  87. aggregate: SessionsAggregate.CRASH_FREE_USERS,
  88. dataset: Dataset.METRICS,
  89. })
  90. ).toBe('crash_free_users');
  91. });
  92. it('extracts custom metric alert from custom mri aggregate', function () {
  93. expect(
  94. getAlertTypeFromAggregateDataset({
  95. aggregate: 'count(d:custom/my_metric@seconds)',
  96. dataset: Dataset.GENERIC_METRICS,
  97. })
  98. ).toBe('custom_metrics');
  99. });
  100. it('defaults to custom', function () {
  101. expect(
  102. getAlertTypeFromAggregateDataset({
  103. aggregate: 'count_unique(tags[sentry:user])',
  104. dataset: Dataset.TRANSACTIONS,
  105. })
  106. ).toEqual('custom_transactions');
  107. expect(
  108. getAlertTypeFromAggregateDataset({
  109. aggregate: 'p95(measurements.fp)',
  110. dataset: Dataset.TRANSACTIONS,
  111. })
  112. ).toEqual('custom_transactions');
  113. expect(
  114. getAlertTypeFromAggregateDataset({
  115. aggregate: 'p95(measurements.ttfb)',
  116. dataset: Dataset.TRANSACTIONS,
  117. })
  118. ).toEqual('custom_transactions');
  119. expect(
  120. getAlertTypeFromAggregateDataset({
  121. aggregate: 'count(d:transaction/measurement@seconds)',
  122. dataset: Dataset.GENERIC_METRICS,
  123. })
  124. ).toBe('custom_transactions');
  125. });
  126. it('extracts insights metric alerts', function () {
  127. expect(
  128. getAlertTypeFromAggregateDataset({
  129. aggregate: 'spm()',
  130. dataset: Dataset.GENERIC_METRICS,
  131. })
  132. ).toEqual('insights_metrics');
  133. expect(
  134. getAlertTypeFromAggregateDataset({
  135. aggregate: 'avg(d:spans/exclusive_time@millisecond)',
  136. dataset: Dataset.GENERIC_METRICS,
  137. })
  138. ).toEqual('insights_metrics');
  139. expect(
  140. getAlertTypeFromAggregateDataset({
  141. aggregate: 'avg(g:spans/mobile.slow_frames@none)',
  142. dataset: Dataset.GENERIC_METRICS,
  143. })
  144. ).toEqual('insights_metrics');
  145. });
  146. });