options.tsx 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. import {t} from 'sentry/locale';
  2. import {Organization} from 'sentry/types';
  3. import {
  4. Dataset,
  5. EventTypes,
  6. SessionsAggregate,
  7. } from 'sentry/views/alerts/rules/metric/types';
  8. export type AlertType =
  9. | 'issues'
  10. | 'num_errors'
  11. | 'users_experiencing_errors'
  12. | 'throughput'
  13. | 'trans_duration'
  14. | 'apdex'
  15. | 'failure_rate'
  16. | 'lcp'
  17. | 'fid'
  18. | 'cls'
  19. | 'custom'
  20. | 'crash_free_sessions'
  21. | 'crash_free_users';
  22. export enum MEPAlertsQueryType {
  23. ERROR = 0,
  24. PERFORMANCE = 1,
  25. CRASH_RATE = 2,
  26. }
  27. export enum MEPAlertsDataset {
  28. DISCOVER = 'discover',
  29. METRICS = 'metrics',
  30. METRICS_ENHANCED = 'metricsEnhanced',
  31. }
  32. export type MetricAlertType = Exclude<AlertType, 'issues'>;
  33. export const DatasetMEPAlertQueryTypes: Record<Dataset, MEPAlertsQueryType> = {
  34. [Dataset.ERRORS]: MEPAlertsQueryType.ERROR,
  35. [Dataset.TRANSACTIONS]: MEPAlertsQueryType.PERFORMANCE,
  36. [Dataset.GENERIC_METRICS]: MEPAlertsQueryType.PERFORMANCE,
  37. [Dataset.METRICS]: MEPAlertsQueryType.CRASH_RATE,
  38. [Dataset.SESSIONS]: MEPAlertsQueryType.CRASH_RATE,
  39. };
  40. export const AlertWizardAlertNames: Record<AlertType, string> = {
  41. issues: t('Issues'),
  42. num_errors: t('Number of Errors'),
  43. users_experiencing_errors: t('Users Experiencing Errors'),
  44. throughput: t('Throughput'),
  45. trans_duration: t('Transaction Duration'),
  46. apdex: t('Apdex'),
  47. failure_rate: t('Failure Rate'),
  48. lcp: t('Largest Contentful Paint'),
  49. fid: t('First Input Delay'),
  50. cls: t('Cumulative Layout Shift'),
  51. custom: t('Custom Metric'),
  52. crash_free_sessions: t('Crash Free Session Rate'),
  53. crash_free_users: t('Crash Free User Rate'),
  54. };
  55. type AlertWizardCategory = {
  56. categoryHeading: string;
  57. options: AlertType[];
  58. };
  59. export const getAlertWizardCategories = (org: Organization): AlertWizardCategory[] => [
  60. {
  61. categoryHeading: t('Errors'),
  62. options: ['issues', 'num_errors', 'users_experiencing_errors'],
  63. },
  64. ...(org.features.includes('crash-rate-alerts')
  65. ? [
  66. {
  67. categoryHeading: t('Sessions'),
  68. options: ['crash_free_sessions', 'crash_free_users'] as AlertType[],
  69. },
  70. ]
  71. : []),
  72. {
  73. categoryHeading: t('Performance'),
  74. options: [
  75. 'throughput',
  76. 'trans_duration',
  77. 'apdex',
  78. 'failure_rate',
  79. 'lcp',
  80. 'fid',
  81. 'cls',
  82. ],
  83. },
  84. {
  85. categoryHeading: t('Other'),
  86. options: ['custom'],
  87. },
  88. ];
  89. export type WizardRuleTemplate = {
  90. aggregate: string;
  91. dataset: Dataset;
  92. eventTypes: EventTypes;
  93. };
  94. export const AlertWizardRuleTemplates: Record<
  95. MetricAlertType,
  96. Readonly<WizardRuleTemplate>
  97. > = {
  98. num_errors: {
  99. aggregate: 'count()',
  100. dataset: Dataset.ERRORS,
  101. eventTypes: EventTypes.ERROR,
  102. },
  103. users_experiencing_errors: {
  104. aggregate: 'count_unique(user)',
  105. dataset: Dataset.ERRORS,
  106. eventTypes: EventTypes.ERROR,
  107. },
  108. throughput: {
  109. aggregate: 'count()',
  110. dataset: Dataset.TRANSACTIONS,
  111. eventTypes: EventTypes.TRANSACTION,
  112. },
  113. trans_duration: {
  114. aggregate: 'p95(transaction.duration)',
  115. dataset: Dataset.TRANSACTIONS,
  116. eventTypes: EventTypes.TRANSACTION,
  117. },
  118. apdex: {
  119. aggregate: 'apdex(300)',
  120. dataset: Dataset.TRANSACTIONS,
  121. eventTypes: EventTypes.TRANSACTION,
  122. },
  123. failure_rate: {
  124. aggregate: 'failure_rate()',
  125. dataset: Dataset.TRANSACTIONS,
  126. eventTypes: EventTypes.TRANSACTION,
  127. },
  128. lcp: {
  129. aggregate: 'p95(measurements.lcp)',
  130. dataset: Dataset.TRANSACTIONS,
  131. eventTypes: EventTypes.TRANSACTION,
  132. },
  133. fid: {
  134. aggregate: 'p95(measurements.fid)',
  135. dataset: Dataset.TRANSACTIONS,
  136. eventTypes: EventTypes.TRANSACTION,
  137. },
  138. cls: {
  139. aggregate: 'p95(measurements.cls)',
  140. dataset: Dataset.TRANSACTIONS,
  141. eventTypes: EventTypes.TRANSACTION,
  142. },
  143. custom: {
  144. aggregate: 'p95(measurements.fp)',
  145. dataset: Dataset.TRANSACTIONS,
  146. eventTypes: EventTypes.TRANSACTION,
  147. },
  148. crash_free_sessions: {
  149. aggregate: SessionsAggregate.CRASH_FREE_SESSIONS,
  150. // TODO(scttcper): Use Dataset.Metric on GA of alert-crash-free-metrics
  151. dataset: Dataset.SESSIONS,
  152. eventTypes: EventTypes.SESSION,
  153. },
  154. crash_free_users: {
  155. aggregate: SessionsAggregate.CRASH_FREE_USERS,
  156. // TODO(scttcper): Use Dataset.Metric on GA of alert-crash-free-metrics
  157. dataset: Dataset.SESSIONS,
  158. eventTypes: EventTypes.USER,
  159. },
  160. };
  161. export const DEFAULT_WIZARD_TEMPLATE = AlertWizardRuleTemplates.num_errors;
  162. export const hidePrimarySelectorSet = new Set<AlertType>([
  163. 'num_errors',
  164. 'users_experiencing_errors',
  165. 'throughput',
  166. 'apdex',
  167. 'failure_rate',
  168. 'crash_free_sessions',
  169. 'crash_free_users',
  170. ]);
  171. export const hideParameterSelectorSet = new Set<AlertType>([
  172. 'trans_duration',
  173. 'lcp',
  174. 'fid',
  175. 'cls',
  176. ]);
  177. export function getMEPAlertsDataset(
  178. dataset: Dataset,
  179. newAlert: boolean
  180. ): MEPAlertsDataset {
  181. // Dataset.ERRORS overrides all cases
  182. if (dataset === Dataset.ERRORS) {
  183. return MEPAlertsDataset.DISCOVER;
  184. }
  185. if (newAlert) {
  186. return MEPAlertsDataset.METRICS_ENHANCED;
  187. }
  188. if (dataset === Dataset.GENERIC_METRICS) {
  189. return MEPAlertsDataset.METRICS;
  190. }
  191. return MEPAlertsDataset.DISCOVER;
  192. }