From 58043584e836b342bc447c2f4d287149170e64a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Guillois?= Date: Wed, 6 Nov 2024 13:38:30 +0100 Subject: [PATCH 1/3] feat: add monitoring for Brevo service in healthcheck endpoint --- .talismanrc | 2 ++ packages/healthcheck/src/checks/brevo.ts | 24 ++++++++++++++++++++++++ packages/healthcheck/src/index.ts | 1 + server/src/infra/server.ts | 2 ++ 4 files changed, 29 insertions(+) create mode 100644 packages/healthcheck/src/checks/brevo.ts diff --git a/.talismanrc b/.talismanrc index 9ec4f3fb9..7803cb249 100644 --- a/.talismanrc +++ b/.talismanrc @@ -11,6 +11,8 @@ fileignoreconfig: checksum: 25a58ba4ecfb8606daf5efbae6a1f0f2efe4e87a4a8a18e745712b39198d93a5 - filename: packages/api-sdk/src/test/campaign-api.test.ts checksum: b200d9e1fec310660a91e99cd048b24cbe983e0f9f965861d061a7f0992af43e +- filename: packages/healthcheck/src/checks/brevo.ts + checksum: a1fbeb01d83167b791eb8175eeb80178cc6da19bb83a6ba3cb2077ca96ebda5e - filename: packages/utils/src/object.ts checksum: 9893602dd7197e44a7c361e44c31b5fb86a025227af95c02998a6857bd1a694b - filename: server/.env.example diff --git a/packages/healthcheck/src/checks/brevo.ts b/packages/healthcheck/src/checks/brevo.ts new file mode 100644 index 000000000..1eccc0715 --- /dev/null +++ b/packages/healthcheck/src/checks/brevo.ts @@ -0,0 +1,24 @@ +import { Check } from './check'; + +export function brevoCheck(apiKey: string): Check { + return { + name: 'brevo', + async test() { + const url = + 'https://api.breveo.com/v3/smtp/statistics/aggregatedReport'; + const options = { + method: 'GET', + headers: { + accept: 'application/json', + 'api-key': apiKey + } + }; + await fetch(url, options).then(res => { + console.log(apiKey, res.status, JSON.stringify(res.json())); + if(res.status !== 200) { + throw new Error('Brevo API is not available'); + } + }); + } + }; +} diff --git a/packages/healthcheck/src/index.ts b/packages/healthcheck/src/index.ts index ea7ccb5f0..425ba91bf 100644 --- a/packages/healthcheck/src/index.ts +++ b/packages/healthcheck/src/index.ts @@ -1,3 +1,4 @@ +export * from './checks/brevo'; export * from './checks/postgres'; export * from './checks/redis'; export * from './checks/s3'; diff --git a/server/src/infra/server.ts b/server/src/infra/server.ts index 6a0c7e80e..e8cd1311d 100644 --- a/server/src/infra/server.ts +++ b/server/src/infra/server.ts @@ -7,6 +7,7 @@ import util from 'node:util'; import { healthcheck, + brevoCheck, postgresCheck, redisCheck, s3Check @@ -121,6 +122,7 @@ export function createServer(): Server { '/', healthcheck({ checks: [ + brevoCheck(config.mailer.apiKey ?? ''), redisCheck(config.redis.url), postgresCheck(config.db.url), s3Check(config.s3) From 2ca3a6707470cac94f533527f9d113ecc3b3762b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Guillois?= Date: Wed, 6 Nov 2024 13:38:30 +0100 Subject: [PATCH 2/3] feat: add monitoring for Brevo service in healthcheck endpoint --- packages/healthcheck/src/checks/brevo.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/healthcheck/src/checks/brevo.ts b/packages/healthcheck/src/checks/brevo.ts index 1eccc0715..e6ac8ab5e 100644 --- a/packages/healthcheck/src/checks/brevo.ts +++ b/packages/healthcheck/src/checks/brevo.ts @@ -14,7 +14,6 @@ export function brevoCheck(apiKey: string): Check { } }; await fetch(url, options).then(res => { - console.log(apiKey, res.status, JSON.stringify(res.json())); if(res.status !== 200) { throw new Error('Brevo API is not available'); } From e78ae2a98fb89c8d89c477100362ad2da5c9a6bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20GUILLOIS?= Date: Wed, 6 Nov 2024 15:40:04 +0100 Subject: [PATCH 3/3] fix: typo in brevo URL --- packages/healthcheck/src/checks/brevo.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/healthcheck/src/checks/brevo.ts b/packages/healthcheck/src/checks/brevo.ts index e6ac8ab5e..8e5044c04 100644 --- a/packages/healthcheck/src/checks/brevo.ts +++ b/packages/healthcheck/src/checks/brevo.ts @@ -5,7 +5,7 @@ export function brevoCheck(apiKey: string): Check { name: 'brevo', async test() { const url = - 'https://api.breveo.com/v3/smtp/statistics/aggregatedReport'; + 'https://api.brevo.com/v3/smtp/statistics/aggregatedReport'; const options = { method: 'GET', headers: {