From 4f8888a30ac7f0274a705f61569d11f7478fe558 Mon Sep 17 00:00:00 2001 From: Abhijeet Prasad Date: Thu, 20 Apr 2023 10:21:05 +0200 Subject: [PATCH] feat(node): Add monitor upsert types --- packages/node/test/checkin.test.ts | 104 +++++++++++++++++++++++------ packages/types/src/checkin.ts | 26 ++++++++ 2 files changed, 111 insertions(+), 19 deletions(-) diff --git a/packages/node/test/checkin.test.ts b/packages/node/test/checkin.test.ts index da082207b00d..4bd1003097dc 100644 --- a/packages/node/test/checkin.test.ts +++ b/packages/node/test/checkin.test.ts @@ -1,7 +1,9 @@ +import type { CheckIn } from '@sentry/types'; + import { createCheckInEnvelope } from '../src/checkin'; -describe('userFeedback', () => { - test('creates user feedback envelope header', () => { +describe('CheckIn', () => { + test('creates a check in envelope header', () => { const envelope = createCheckInEnvelope( { check_in_id: '83a7c03ed0a04e1b97e2e3b18d38f244', @@ -32,29 +34,93 @@ describe('userFeedback', () => { }); }); - test('creates user feedback envelope item', () => { - const envelope = createCheckInEnvelope({ - check_in_id: '83a7c03ed0a04e1b97e2e3b18d38f244', - monitor_slug: 'b7645b8e-b47d-4398-be9a-d16b0dac31cb', - status: 'ok', - duration: 10.0, - release: '1.0.0', - environment: 'production', - }); + test.each([ + [ + 'no monitor config', + { + check_in_id: '83a7c03ed0a04e1b97e2e3b18d38f244', + monitor_slug: 'b7645b8e-b47d-4398-be9a-d16b0dac31cb', + status: 'ok', + duration: 10.0, + release: '1.0.0', + environment: 'production', + } as CheckIn, + { + check_in_id: '83a7c03ed0a04e1b97e2e3b18d38f244', + monitor_slug: 'b7645b8e-b47d-4398-be9a-d16b0dac31cb', + status: 'ok', + duration: 10.0, + release: '1.0.0', + environment: 'production', + }, + ], + [ + 'crontab monitor config', + { + check_in_id: '83a7c03ed0a04e1b97e2e3b18d38f244', + monitor_slug: 'b7645b8e-b47d-4398-be9a-d16b0dac31cb', + status: 'in_progress', + monitor_config: { + schedule: { + type: 'crontab', + value: '0 * * * *', + }, + checkin_margin: 5, + max_runtime: 30, + timezone: 'America/Los_Angeles', + }, + } as CheckIn, + { + check_in_id: '83a7c03ed0a04e1b97e2e3b18d38f244', + monitor_slug: 'b7645b8e-b47d-4398-be9a-d16b0dac31cb', + status: 'in_progress', + monitor_config: { + schedule: { + type: 'crontab', + value: '0 * * * *', + }, + checkin_margin: 5, + max_runtime: 30, + timezone: 'America/Los_Angeles', + }, + }, + ], + [ + 'interval monitor config', + { + check_in_id: '83a7c03ed0a04e1b97e2e3b18d38f244', + monitor_slug: 'b7645b8e-b47d-4398-be9a-d16b0dac31cb', + status: 'in_progress', + monitor_config: { + schedule: { + type: 'interval', + value: 1234, + unit: 'minute', + }, + }, + } as CheckIn, + { + check_in_id: '83a7c03ed0a04e1b97e2e3b18d38f244', + monitor_slug: 'b7645b8e-b47d-4398-be9a-d16b0dac31cb', + status: 'in_progress', + monitor_config: { + schedule: { + type: 'interval', + value: 1234, + unit: 'minute', + }, + }, + }, + ], + ])('creates a check in envelope header with %s', (_, checkIn, envelopeItem) => { + const envelope = createCheckInEnvelope(checkIn); expect(envelope[1]).toEqual([ [ { type: 'check_in', }, - { - check_in_id: '83a7c03ed0a04e1b97e2e3b18d38f244', - monitor_slug: 'b7645b8e-b47d-4398-be9a-d16b0dac31cb', - status: 'ok', - duration: 10.0, - release: '1.0.0', - environment: 'production', - }, + envelopeItem, ], ]); }); diff --git a/packages/types/src/checkin.ts b/packages/types/src/checkin.ts index 071afce9640d..a31a5632417c 100644 --- a/packages/types/src/checkin.ts +++ b/packages/types/src/checkin.ts @@ -1,3 +1,17 @@ +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; + // https://develop.sentry.dev/sdk/check-ins/ export interface CheckIn { // Check-In ID (unique and client generated). @@ -10,4 +24,16 @@ export interface CheckIn { 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; + }; }