From 96196b1add5f1c8646fe3b92c69aec2ec5bdd0db Mon Sep 17 00:00:00 2001 From: Anthony Shull Date: Tue, 7 Jan 2025 13:44:26 -0600 Subject: [PATCH 1/2] small changes and restart at midnight --- integration/monitor/all-scenarios.js | 36 +++++++++++++++---------- integration/monitor/ecosystem.config.js | 4 +-- integration/monitor/worker.js | 7 +++-- playwright.config.js | 2 +- 4 files changed, 28 insertions(+), 21 deletions(-) diff --git a/integration/monitor/all-scenarios.js b/integration/monitor/all-scenarios.js index a500847a9d..f3524ff95d 100644 --- a/integration/monitor/all-scenarios.js +++ b/integration/monitor/all-scenarios.js @@ -1,4 +1,5 @@ const cron = require("node-cron"); +const { exec } = require("child_process"); const fs = require("fs"); const path = require("path"); const Sentry = require("@sentry/node"); @@ -39,12 +40,23 @@ const workers = fs.readdirSync(filesPath).map((file) => { workerData: { name, path: path.join(filesPath, file) }, }); + worker.on("message", ({ exception, metric, screenshot }) => { + Sentry.getCurrentScope().addAttachment({ + filename: `${metric}-${Date.now()}.jpeg`, + data: screenshot, + }); + + Sentry.captureException(exception); + + Sentry.getCurrentScope().clearAttachments(); + }); + return worker; }); /* - * A task runs every minute on the minute between the hours of 5am and midnight - * EST. Spread out the worker runs over the minute to avoid overwhelming the + * A task runs every 15 minutes between the hours of 5am and midnight EST. + * Spread out the worker runs over the minute to avoid overwhelming the * system. If we receive a message from a worker, it means that there was a * failure. Capture the exception with Sentry and attach a screenshot to the * event. @@ -55,21 +67,17 @@ cron.schedule("* 5-23 * * *", (_) => { (_) => { worker.postMessage(null); }, - (60000 / workers.length) * index, + (60 * 1000 / workers.length) * index, ); - - worker.on("message", ({ exception, metric, screenshot }) => { - Sentry.getCurrentScope().addAttachment({ - filename: `${metric}-${Date.now()}.jpeg`, - data: screenshot, - }); - - Sentry.captureException(exception); - - Sentry.getCurrentScope().clearAttachments(); - }); }); }, { scheduled: true, timezone: "America/New_York" }); + +/* + * Restart all the scenarios every day at midnight. + */ +cron.schedule("0 0 * * *", (_) => { + exec("pm2 restart all-scenarios", (_error, _stdout, _stderr) => {}); +}); diff --git a/integration/monitor/ecosystem.config.js b/integration/monitor/ecosystem.config.js index d07202c170..b9116deaea 100644 --- a/integration/monitor/ecosystem.config.js +++ b/integration/monitor/ecosystem.config.js @@ -4,14 +4,14 @@ module.exports = { name: "all-health-checks", script: "./integration/monitor/all-health-checks.js", instances: 1, - max_memory_restart: "256M", + max_memory_restart: "128M", exec_mode : "cluster" }, { name: "all-scenarios", script: "./integration/monitor/all-scenarios.js", instances: 1, - max_memory_restart: "1024M", + max_memory_restart: "512M", exec_mode : "cluster" }, ], diff --git a/integration/monitor/worker.js b/integration/monitor/worker.js index 9fbb3ec780..48ce78f7f0 100644 --- a/integration/monitor/worker.js +++ b/integration/monitor/worker.js @@ -13,15 +13,14 @@ const baseURL = process.env.HOST ? `https://${process.env.HOST}` : "http://localhost:4001"; -parentPort.on("message", async (_) => { - const { scenario } = require(workerData.path); +const { scenario } = require(workerData.path); +const metric = `${prefix}${workerData.name}`; +parentPort.on("message", async (_) => { const browser = await chromium.launch(); const context = await browser.newContext({ userAgent: 'Playwright' }); const page = await context.newPage(); - const metric = `${prefix}${workerData.name}`; - const start = performance.now(); try { diff --git a/playwright.config.js b/playwright.config.js index 6738c3b223..4bd5d64e85 100644 --- a/playwright.config.js +++ b/playwright.config.js @@ -20,7 +20,7 @@ module.exports = defineConfig({ trace: 'on-first-retry', }, /* set the expect timeout to 30s */ - expect: { timeout: 30000 }, + expect: { timeout: 5000 }, /* Configure projects for major browsers */ projects: [ { From e7fa115cab5c235aee6ffd041e77a7920ddd154f Mon Sep 17 00:00:00 2001 From: Anthony Shull Date: Tue, 7 Jan 2025 13:46:40 -0600 Subject: [PATCH 2/2] docs --- integration/monitor/all-scenarios.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integration/monitor/all-scenarios.js b/integration/monitor/all-scenarios.js index f3524ff95d..d6d9263114 100644 --- a/integration/monitor/all-scenarios.js +++ b/integration/monitor/all-scenarios.js @@ -55,7 +55,7 @@ const workers = fs.readdirSync(filesPath).map((file) => { }); /* - * A task runs every 15 minutes between the hours of 5am and midnight EST. + * A task runs every minute between the hours of 5am and midnight EST. * Spread out the worker runs over the minute to avoid overwhelming the * system. If we receive a message from a worker, it means that there was a * failure. Capture the exception with Sentry and attach a screenshot to the