-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
Copy pathcheckin.ts
108 lines (98 loc) · 3.71 KB
/
checkin.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import type { TraceContext } from './context';
interface CrontabSchedule {
type: 'crontab';
/** The crontab schedule string, e.g. 0 * * * *. */
value: string;
}
interface IntervalSchedule {
type: 'interval';
value: number;
unit: 'year' | 'month' | 'week' | 'day' | 'hour' | 'minute';
}
type MonitorSchedule = CrontabSchedule | IntervalSchedule;
export interface SerializedCheckIn {
/** Check-In ID (unique and client generated). */
check_in_id: string;
/** The distinct slug of the monitor. */
monitor_slug: string;
/** The status of the check-in. */
status: 'in_progress' | 'ok' | 'error';
/** The duration of the check-in in seconds. Will only take effect if the status is ok or error. */
duration?: number;
release?: string;
environment?: string;
monitor_config?: {
schedule: MonitorSchedule;
/**
* The allowed allowed margin of minutes after the expected check-in time that
* the monitor will not be considered missed for.
*/
checkin_margin?: number;
/**
* The allowed allowed duration in minutes that the monitor may be `in_progress`
* for before being considered failed due to timeout.
*/
max_runtime?: number;
/**
* A tz database string representing the timezone which the monitor's execution schedule is in.
* See: https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
*/
timezone?: string;
/** How many consecutive failed check-ins it takes to create an issue. */
failure_issue_threshold?: number;
/** How many consecutive OK check-ins it takes to resolve an issue. */
recovery_threshold?: number;
};
contexts?: {
trace?: TraceContext;
};
}
export interface HeartbeatCheckIn {
/** The distinct slug of the monitor. */
monitorSlug: SerializedCheckIn['monitor_slug'];
/** The status of the check-in. */
status: 'ok' | 'error';
}
export interface InProgressCheckIn {
/** The distinct slug of the monitor. */
monitorSlug: SerializedCheckIn['monitor_slug'];
/** The status of the check-in. */
status: 'in_progress';
}
export interface FinishedCheckIn {
/** The distinct slug of the monitor. */
monitorSlug: SerializedCheckIn['monitor_slug'];
/** The status of the check-in. */
status: 'ok' | 'error';
/** Check-In ID (unique and client generated). */
checkInId: SerializedCheckIn['check_in_id'];
/** The duration of the check-in in seconds. Will only take effect if the status is ok or error. */
duration?: SerializedCheckIn['duration'];
}
export type CheckIn = HeartbeatCheckIn | InProgressCheckIn | FinishedCheckIn;
type SerializedMonitorConfig = NonNullable<SerializedCheckIn['monitor_config']>;
export interface MonitorConfig {
/**
* The schedule on which the monitor should run. Either a crontab schedule string or an interval.
*/
schedule: MonitorSchedule;
/**
* The allowed allowed margin of minutes after the expected check-in time that
* the monitor will not be considered missed for.
*/
checkinMargin?: SerializedMonitorConfig['checkin_margin'];
/**
* The allowed allowed duration in minutes that the monitor may be `in_progress`
* for before being considered failed due to timeout.
*/
maxRuntime?: SerializedMonitorConfig['max_runtime'];
/**
* A tz database string representing the timezone which the monitor's execution schedule is in.
* See: https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
*/
timezone?: SerializedMonitorConfig['timezone'];
/** How many consecutive failed check-ins it takes to create an issue. */
failureIssueThreshold?: SerializedMonitorConfig['failure_issue_threshold'];
/** How many consecutive OK check-ins it takes to resolve an issue. */
recoveryThreshold?: SerializedMonitorConfig['recovery_threshold'];
}