Skip to content

Commit db013df

Browse files
authored
feat(node): Add monitor upsert types (#7914)
1 parent 7896c68 commit db013df

File tree

2 files changed

+111
-19
lines changed

2 files changed

+111
-19
lines changed

packages/node/test/checkin.test.ts

Lines changed: 85 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
import type { CheckIn } from '@sentry/types';
2+
13
import { createCheckInEnvelope } from '../src/checkin';
24

3-
describe('userFeedback', () => {
4-
test('creates user feedback envelope header', () => {
5+
describe('CheckIn', () => {
6+
test('creates a check in envelope header', () => {
57
const envelope = createCheckInEnvelope(
68
{
79
check_in_id: '83a7c03ed0a04e1b97e2e3b18d38f244',
@@ -32,29 +34,93 @@ describe('userFeedback', () => {
3234
});
3335
});
3436

35-
test('creates user feedback envelope item', () => {
36-
const envelope = createCheckInEnvelope({
37-
check_in_id: '83a7c03ed0a04e1b97e2e3b18d38f244',
38-
monitor_slug: 'b7645b8e-b47d-4398-be9a-d16b0dac31cb',
39-
status: 'ok',
40-
duration: 10.0,
41-
release: '1.0.0',
42-
environment: 'production',
43-
});
37+
test.each([
38+
[
39+
'no monitor config',
40+
{
41+
check_in_id: '83a7c03ed0a04e1b97e2e3b18d38f244',
42+
monitor_slug: 'b7645b8e-b47d-4398-be9a-d16b0dac31cb',
43+
status: 'ok',
44+
duration: 10.0,
45+
release: '1.0.0',
46+
environment: 'production',
47+
} as CheckIn,
48+
{
49+
check_in_id: '83a7c03ed0a04e1b97e2e3b18d38f244',
50+
monitor_slug: 'b7645b8e-b47d-4398-be9a-d16b0dac31cb',
51+
status: 'ok',
52+
duration: 10.0,
53+
release: '1.0.0',
54+
environment: 'production',
55+
},
56+
],
57+
[
58+
'crontab monitor config',
59+
{
60+
check_in_id: '83a7c03ed0a04e1b97e2e3b18d38f244',
61+
monitor_slug: 'b7645b8e-b47d-4398-be9a-d16b0dac31cb',
62+
status: 'in_progress',
63+
monitor_config: {
64+
schedule: {
65+
type: 'crontab',
66+
value: '0 * * * *',
67+
},
68+
checkin_margin: 5,
69+
max_runtime: 30,
70+
timezone: 'America/Los_Angeles',
71+
},
72+
} as CheckIn,
73+
{
74+
check_in_id: '83a7c03ed0a04e1b97e2e3b18d38f244',
75+
monitor_slug: 'b7645b8e-b47d-4398-be9a-d16b0dac31cb',
76+
status: 'in_progress',
77+
monitor_config: {
78+
schedule: {
79+
type: 'crontab',
80+
value: '0 * * * *',
81+
},
82+
checkin_margin: 5,
83+
max_runtime: 30,
84+
timezone: 'America/Los_Angeles',
85+
},
86+
},
87+
],
88+
[
89+
'interval monitor config',
90+
{
91+
check_in_id: '83a7c03ed0a04e1b97e2e3b18d38f244',
92+
monitor_slug: 'b7645b8e-b47d-4398-be9a-d16b0dac31cb',
93+
status: 'in_progress',
94+
monitor_config: {
95+
schedule: {
96+
type: 'interval',
97+
value: 1234,
98+
unit: 'minute',
99+
},
100+
},
101+
} as CheckIn,
102+
{
103+
check_in_id: '83a7c03ed0a04e1b97e2e3b18d38f244',
104+
monitor_slug: 'b7645b8e-b47d-4398-be9a-d16b0dac31cb',
105+
status: 'in_progress',
106+
monitor_config: {
107+
schedule: {
108+
type: 'interval',
109+
value: 1234,
110+
unit: 'minute',
111+
},
112+
},
113+
},
114+
],
115+
])('creates a check in envelope header with %s', (_, checkIn, envelopeItem) => {
116+
const envelope = createCheckInEnvelope(checkIn);
44117

45118
expect(envelope[1]).toEqual([
46119
[
47120
{
48121
type: 'check_in',
49122
},
50-
{
51-
check_in_id: '83a7c03ed0a04e1b97e2e3b18d38f244',
52-
monitor_slug: 'b7645b8e-b47d-4398-be9a-d16b0dac31cb',
53-
status: 'ok',
54-
duration: 10.0,
55-
release: '1.0.0',
56-
environment: 'production',
57-
},
123+
envelopeItem,
58124
],
59125
]);
60126
});

packages/types/src/checkin.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
interface CrontabSchedule {
2+
type: 'crontab';
3+
// The crontab schedule string, e.g. 0 * * * *.
4+
value: string;
5+
}
6+
7+
interface IntervalSchedule {
8+
type: 'interval';
9+
value: number;
10+
unit: 'year' | 'month' | 'week' | 'day' | 'hour' | 'minute';
11+
}
12+
13+
type MonitorSchedule = CrontabSchedule | IntervalSchedule;
14+
115
// https://develop.sentry.dev/sdk/check-ins/
216
export interface CheckIn {
317
// Check-In ID (unique and client generated).
@@ -10,4 +24,16 @@ export interface CheckIn {
1024
duration?: number;
1125
release?: string;
1226
environment?: string;
27+
monitor_config?: {
28+
schedule: MonitorSchedule;
29+
// The allowed allowed margin of minutes after the expected check-in time that
30+
// the monitor will not be considered missed for.
31+
checkin_margin?: number;
32+
// The allowed allowed duration in minutes that the monitor may be `in_progress`
33+
// for before being considered failed due to timeout.
34+
max_runtime?: number;
35+
// A tz database string representing the timezone which the monitor's execution schedule is in.
36+
// See: https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
37+
timezone?: string;
38+
};
1339
}

0 commit comments

Comments
 (0)