types.tsx 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  1. import type {Actor, ObjectStatus, Project} from 'sentry/types';
  2. import type {ColorOrAlias} from 'sentry/utils/theme';
  3. export enum MonitorType {
  4. UNKNOWN = 'unknown',
  5. CRON_JOB = 'cron_job',
  6. }
  7. /**
  8. * Some old monitor configurations do NOT have a schedule_type
  9. *
  10. * TODO: This should be removed once we've cleaned up our old data and can
  11. * verify we don't have any config objects missing schedule_type
  12. */
  13. type LegacyDefaultSchedule = undefined;
  14. export enum ScheduleType {
  15. CRONTAB = 'crontab',
  16. INTERVAL = 'interval',
  17. }
  18. export enum MonitorStatus {
  19. OK = 'ok',
  20. ERROR = 'error',
  21. DISABLED = 'disabled',
  22. ACTIVE = 'active',
  23. }
  24. export enum CheckInStatus {
  25. OK = 'ok',
  26. ERROR = 'error',
  27. IN_PROGRESS = 'in_progress',
  28. MISSED = 'missed',
  29. TIMEOUT = 'timeout',
  30. }
  31. interface BaseConfig {
  32. /**
  33. * How long (in minutes) after the expected check-in time will we wait until
  34. * we consider the check-in to have been missed.
  35. */
  36. checkin_margin: number;
  37. /**
  38. * How long (in minutes) is the check-in allowed to run for in
  39. * CheckInStatus.IN_PROGRESS before it is considered failed.
  40. */
  41. max_runtime: number;
  42. /**
  43. * tz database style timezone string
  44. */
  45. timezone: string;
  46. /**
  47. * The id of thee "shadow" alert rule generated when alert assignees are
  48. * selected
  49. */
  50. alert_rule_id?: number;
  51. /**
  52. * How many consecutive missed or failed check-ins in a row before creating a
  53. * new issue.
  54. */
  55. failure_issue_threshold?: number | null;
  56. /**
  57. * How many successful check-ins in a row before resolving an issue.
  58. */
  59. recovery_threshold?: number | null;
  60. }
  61. /**
  62. * The configuration object used when the schedule is a CRONTAB
  63. */
  64. export interface CrontabConfig extends BaseConfig {
  65. /**
  66. * The crontab schedule
  67. */
  68. schedule: string;
  69. schedule_type: ScheduleType.CRONTAB | LegacyDefaultSchedule;
  70. }
  71. /**
  72. * The configuration object used when the schedule is an INTERVAL
  73. */
  74. export interface IntervalConfig extends BaseConfig {
  75. /**
  76. * The interval style schedule
  77. */
  78. schedule: [
  79. value: number,
  80. interval: 'year' | 'month' | 'week' | 'day' | 'hour' | 'minute',
  81. ];
  82. schedule_type: ScheduleType.INTERVAL;
  83. }
  84. export type MonitorConfig = CrontabConfig | IntervalConfig;
  85. export interface MonitorEnvBrokenDetection {
  86. environmentMutedTimestamp: string;
  87. userNotifiedTimestamp: string;
  88. }
  89. export interface MonitorIncident {
  90. brokenNotice: MonitorEnvBrokenDetection | null;
  91. resolvingTimestamp: string;
  92. startingTimestamp: string;
  93. }
  94. export interface MonitorEnvironment {
  95. activeIncident: MonitorIncident | null;
  96. dateCreated: string;
  97. isMuted: boolean;
  98. lastCheckIn: string | null;
  99. name: string;
  100. nextCheckIn: string | null;
  101. nextCheckInLatest: string | null;
  102. status: MonitorStatus;
  103. }
  104. export interface Monitor {
  105. config: MonitorConfig;
  106. dateCreated: string;
  107. environments: MonitorEnvironment[];
  108. id: string;
  109. isMuted: boolean;
  110. name: string;
  111. owner: Actor;
  112. project: Project;
  113. slug: string;
  114. status: ObjectStatus;
  115. type: MonitorType;
  116. alertRule?: {
  117. targets: Array<{
  118. targetIdentifier: number;
  119. targetType: 'Member' | 'Team';
  120. }>;
  121. environment?: string;
  122. };
  123. }
  124. export interface MonitorStat {
  125. duration: number;
  126. error: number;
  127. missed: number;
  128. ok: number;
  129. timeout: number;
  130. ts: number;
  131. }
  132. export interface CheckIn {
  133. /**
  134. * Attachment ID for attachments sent via the legacy attachment HTTP
  135. * endpoint. This will likely be removed in the future.
  136. *
  137. * @deprecated
  138. */
  139. attachmentId: number | null;
  140. /**
  141. * Date the opening check-in was sent
  142. */
  143. dateCreated: string;
  144. /**
  145. * Duration (in milliseconds)
  146. */
  147. duration: number;
  148. /**
  149. * environment the check-in was sent to
  150. */
  151. environment: string;
  152. /**
  153. * What was the monitors nextCheckIn value when this check-in occured, this
  154. * is when we expected the check-in to happen.
  155. */
  156. expectedTime: string;
  157. /**
  158. * Check-in GUID
  159. */
  160. id: string;
  161. /**
  162. * A snapshot of the monitor configuration at the time of the check-in
  163. */
  164. monitorConfig: MonitorConfig;
  165. /**
  166. * Status of the check-in
  167. */
  168. status: CheckInStatus;
  169. /**
  170. * Groups associated to this check-in (determiend by traceId)
  171. */
  172. groups?: {id: number; shortId: string}[];
  173. }
  174. /**
  175. * Object used to store config for the display next to an environment in the
  176. * timeline view
  177. */
  178. export interface StatusNotice {
  179. color: ColorOrAlias;
  180. icon: React.ReactNode;
  181. label?: React.ReactNode;
  182. }
  183. // Derived from backend enum: /src/sentry/monitors/processing_errors/errors.py
  184. export enum ProcessingErrorType {
  185. CHECKIN_ENVIRONMENT_MISMATCH = 0,
  186. CHECKIN_FINISHED = 1,
  187. CHECKIN_GUID_PROJECT_MISMATCH = 2,
  188. CHECKIN_INVALID_DURATION = 3,
  189. CHECKIN_INVALID_GUID = 4,
  190. CHECKIN_VALIDATION_FAILED = 5,
  191. MONITOR_DISABLED = 6,
  192. MONITOR_DISABLED_NO_QUOTA = 7,
  193. MONITOR_INVALID_CONFIG = 8,
  194. MONITOR_INVALID_ENVIRONMENT = 9,
  195. MONITOR_LIMIT_EXCEEDED = 10,
  196. MONITOR_NOT_FOUND = 11,
  197. MONITOR_OVER_QUOTA = 12,
  198. MONITOR_ENVIRONMENT_LIMIT_EXCEEDED = 13,
  199. MONITOR_ENVIRONMENT_RATELIMITED = 14,
  200. ORGANIZATION_KILLSWITCH_ENABLED = 15,
  201. }
  202. interface CheckinEnvironmentMismatch {
  203. existingEnvironment: string;
  204. type: ProcessingErrorType.CHECKIN_ENVIRONMENT_MISMATCH;
  205. }
  206. interface CheckinGuidProjectMismatch {
  207. guid: string;
  208. type: ProcessingErrorType.CHECKIN_GUID_PROJECT_MISMATCH;
  209. }
  210. interface CheckinInvalidDuration {
  211. duration: string;
  212. type: ProcessingErrorType.CHECKIN_INVALID_DURATION;
  213. }
  214. interface CheckinValidationFailed {
  215. errors: Record<string, string[]>;
  216. type: ProcessingErrorType.CHECKIN_VALIDATION_FAILED;
  217. }
  218. interface MonitorInvalidConfig {
  219. errors: Record<string, string[]>;
  220. type: ProcessingErrorType.MONITOR_INVALID_CONFIG;
  221. }
  222. interface MonitorInvalidEnvironment {
  223. reason: string;
  224. type: ProcessingErrorType.MONITOR_INVALID_ENVIRONMENT;
  225. }
  226. interface MonitorLimitExceeded {
  227. reason: string;
  228. type: ProcessingErrorType.MONITOR_LIMIT_EXCEEDED;
  229. }
  230. interface MonitorEnvironmentLimitExceeded {
  231. reason: string;
  232. type: ProcessingErrorType.MONITOR_ENVIRONMENT_LIMIT_EXCEEDED;
  233. }
  234. type ProcessingErrorWithExtra =
  235. | CheckinEnvironmentMismatch
  236. | CheckinGuidProjectMismatch
  237. | CheckinInvalidDuration
  238. | CheckinValidationFailed
  239. | MonitorInvalidConfig
  240. | MonitorInvalidEnvironment
  241. | MonitorLimitExceeded
  242. | MonitorEnvironmentLimitExceeded;
  243. interface SimpleProcessingError {
  244. type: Exclude<ProcessingErrorType, ProcessingErrorWithExtra['type']>;
  245. }
  246. export type ProcessingError = SimpleProcessingError | ProcessingErrorWithExtra;
  247. export interface CheckInPayload {
  248. message: {
  249. message_type: 'check_in';
  250. payload: string;
  251. project_id: number;
  252. retention_days: number;
  253. sdk: string;
  254. start_time: number;
  255. type: 'check_in';
  256. };
  257. partition: number;
  258. payload: {
  259. check_in_id: string;
  260. environment: string;
  261. monitor_slug: string;
  262. status: string;
  263. monitor_config?: MonitorConfig;
  264. };
  265. ts: string;
  266. }
  267. export interface CheckinProcessingError {
  268. checkin: CheckInPayload;
  269. errors: ProcessingError[];
  270. id: string;
  271. }