ruleConditions.ts 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. import {IssueAlertRuleActionTemplate} from 'sentry/types/alerts';
  2. const DEFAULT_INTERVAL_CHOICES = [
  3. ['1m', 'one minute'],
  4. ['1h', 'one hour'],
  5. ['1d', 'one day'],
  6. ['1w', 'one week'],
  7. ['30d', '30 days'],
  8. ];
  9. const DEFAULT_PLACEHOLDER = 100;
  10. const EVENT_FREQUENCY_CONDITION =
  11. 'sentry.rules.conditions.event_frequency.EventFrequencyCondition';
  12. const UNIQUE_USER_FREQUENCY_CONDITION =
  13. 'sentry.rules.conditions.event_frequency.EventUniqueUserFrequencyCondition';
  14. export const MOCK_RESP_VERBOSE = [
  15. {
  16. id: 'sentry.rules.conditions.every_event.EveryEventCondition',
  17. label: 'An event occurs',
  18. },
  19. {
  20. id: 'sentry.rules.conditions.first_seen_event.FirstSeenEventCondition',
  21. label: 'A new issue is created',
  22. },
  23. {
  24. id: 'sentry.rules.conditions.regression_event.RegressionEventCondition',
  25. label: 'The issue changes state from resolved to unresolved',
  26. },
  27. {
  28. id: 'sentry.rules.conditions.reappeared_event.ReappearedEventCondition',
  29. label: 'The issue changes state from ignored to unresolved',
  30. },
  31. {
  32. formFields: {
  33. value: {
  34. placeholder: 'value',
  35. type: 'string',
  36. },
  37. match: {
  38. type: 'choice',
  39. choices: [
  40. ['eq', 'equals'],
  41. ['ne', 'does not equal'],
  42. ['sw', 'starts with'],
  43. ['ew', 'ends with'],
  44. ['co', 'contains'],
  45. ['nc', 'does not contain'],
  46. ['is', 'is set'],
  47. ['ns', 'is not set'],
  48. ],
  49. },
  50. key: {
  51. placeholder: 'key',
  52. type: 'string',
  53. },
  54. },
  55. id: 'sentry.rules.conditions.tagged_event.TaggedEventCondition',
  56. label: "An event's tags match {key} {match} {value}",
  57. },
  58. {
  59. formFields: {
  60. interval: {
  61. type: 'choice',
  62. choices: DEFAULT_INTERVAL_CHOICES,
  63. },
  64. value: {
  65. placeholder: DEFAULT_PLACEHOLDER,
  66. type: 'number',
  67. },
  68. },
  69. id: EVENT_FREQUENCY_CONDITION,
  70. label: 'The issue is seen more than {value} times in {interval}',
  71. },
  72. {
  73. formFields: {
  74. interval: {
  75. type: 'choice',
  76. choices: DEFAULT_INTERVAL_CHOICES,
  77. },
  78. value: {
  79. placeholder: DEFAULT_PLACEHOLDER,
  80. type: 'number',
  81. },
  82. },
  83. id: UNIQUE_USER_FREQUENCY_CONDITION,
  84. label: 'The issue is seen by more than {value} users in {interval}',
  85. },
  86. {
  87. formFields: {
  88. attribute: {
  89. placeholder: 'i.e. exception.type',
  90. type: 'choice',
  91. choices: [
  92. ['message', 'message'],
  93. ['platform', 'platform'],
  94. ['environment', 'environment'],
  95. ['type', 'type'],
  96. ['exception.type', 'exception.type'],
  97. ['exception.value', 'exception.value'],
  98. ['user.id', 'user.id'],
  99. ['user.email', 'user.email'],
  100. ['user.username', 'user.username'],
  101. ['user.ip_address', 'user.ip_address'],
  102. ['http.method', 'http.method'],
  103. ['http.url', 'http.url'],
  104. ['stacktrace.code', 'stacktrace.code'],
  105. ['stacktrace.module', 'stacktrace.module'],
  106. ['stacktrace.filename', 'stacktrace.filename'],
  107. ],
  108. },
  109. value: {
  110. placeholder: 'value',
  111. type: 'string',
  112. },
  113. match: {
  114. type: 'choice',
  115. choices: [
  116. ['eq', 'equals'],
  117. ['ne', 'does not equal'],
  118. ['sw', 'starts with'],
  119. ['ew', 'ends with'],
  120. ['co', 'contains'],
  121. ['nc', 'does not contain'],
  122. ['is', 'is set'],
  123. ['ns', 'is not set'],
  124. ],
  125. },
  126. },
  127. id: 'sentry.rules.conditions.event_attribute.EventAttributeCondition',
  128. label: "An event's {attribute} value {match} {value}",
  129. },
  130. {
  131. formFields: {
  132. match: {
  133. type: 'choice',
  134. choices: [
  135. ['eq', 'equal to'],
  136. ['lte', 'less than or equal to'],
  137. ['gte', 'greater than or equal to'],
  138. ],
  139. },
  140. level: {
  141. type: 'choice',
  142. choices: [
  143. ['50', 'fatal'],
  144. ['40', 'error'],
  145. ['30', 'warning'],
  146. ['20', 'info'],
  147. ['10', 'debug'],
  148. ['0', 'sample'],
  149. ],
  150. },
  151. },
  152. id: 'sentry.rules.conditions.level.LevelCondition',
  153. label: "An event's level is {match} {level}",
  154. },
  155. ];
  156. export const MOCK_RESP_ONLY_IGNORED_CONDITIONS_INVALID = [
  157. {
  158. formFields: {
  159. interval: {
  160. type: 'choice',
  161. choices: [['@*(&^#$!', 'Invalid choice']],
  162. },
  163. value: {
  164. placeholder: DEFAULT_PLACEHOLDER,
  165. type: 'number',
  166. },
  167. },
  168. id: 'cinnamon.rules.conditions.infinite_eclair.A19SeanBanIsabelle',
  169. label: 'The issue is seen more than {value} times in {interval}',
  170. },
  171. {
  172. formFields: {
  173. interval: {
  174. type: 'choice',
  175. choices: [
  176. ['1m', 'one minute'],
  177. ['1h', 'one hour'],
  178. ['30d', '30 days'],
  179. ],
  180. },
  181. value: {
  182. placeholder: DEFAULT_PLACEHOLDER,
  183. type: 'number',
  184. },
  185. },
  186. id: UNIQUE_USER_FREQUENCY_CONDITION,
  187. label: 'The issue is seen by more than {value} users in {interval}',
  188. },
  189. ];
  190. export const MOCK_RESP_INCONSISTENT_PLACEHOLDERS = [
  191. {
  192. formFields: {
  193. interval: {
  194. type: 'choice',
  195. choices: DEFAULT_INTERVAL_CHOICES,
  196. },
  197. value: {
  198. placeholder: 80696,
  199. type: 'number',
  200. },
  201. },
  202. id: EVENT_FREQUENCY_CONDITION,
  203. label: 'The issue is seen more than {value} times in {interval}',
  204. },
  205. {
  206. formFields: {
  207. interval: {
  208. type: 'choice',
  209. choices: DEFAULT_INTERVAL_CHOICES,
  210. },
  211. value: {
  212. placeholder: DEFAULT_PLACEHOLDER,
  213. type: 'number',
  214. },
  215. },
  216. id: UNIQUE_USER_FREQUENCY_CONDITION,
  217. label: 'The issue is seen by more than {value} users in {interval}',
  218. },
  219. ];
  220. export const MOCK_RESP_INCONSISTENT_INTERVALS = [
  221. {
  222. formFields: {
  223. interval: {
  224. type: 'choice',
  225. choices: [
  226. ['1m', 'one minute'],
  227. ['1h', 'one hour'],
  228. ['12h', 'high noon'],
  229. ['1d', 'one day'],
  230. ['1w', 'one week'],
  231. ['30d', '30 days'],
  232. ],
  233. },
  234. value: {
  235. placeholder: DEFAULT_PLACEHOLDER,
  236. type: 'number',
  237. },
  238. },
  239. id: EVENT_FREQUENCY_CONDITION,
  240. label: 'The issue is seen more than {value} times in {interval}',
  241. },
  242. {
  243. formFields: {
  244. interval: {
  245. type: 'choice',
  246. choices: DEFAULT_INTERVAL_CHOICES,
  247. },
  248. value: {
  249. placeholder: DEFAULT_PLACEHOLDER,
  250. type: 'number',
  251. },
  252. },
  253. id: UNIQUE_USER_FREQUENCY_CONDITION,
  254. label: 'The issue is seen by more than {value} users in {interval}',
  255. },
  256. ];
  257. export type MockRuleCondition = Pick<
  258. IssueAlertRuleActionTemplate,
  259. 'formFields' | 'id' | 'label'
  260. >;