Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 1 addition & 37 deletions integration/monitor/all-scenarios.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,56 +2,20 @@ const cron = require("node-cron");
const { exec } = require("child_process");
const fs = require("fs");
const path = require("path");
const Sentry = require("@sentry/node");
const { Worker } = require("worker_threads");

const { fileToMetricName } = require("../utils");
const RateLimiter = require("./rate-limiter");

const filesPath = path.join(__dirname, "..", "scenarios");

/*
* Create a rate limiter that allows only one lease per hour.
*/
const rateLimiter = new RateLimiter(60 * 60 * 1000, 1);

/*
* Initialize Sentry with the DSN and environment from the environment variables.
* Add a beforeSend callback that will only send events if the rate limiter allows it.
*/
Sentry.init({
dsn: process.env.SENTRY_DSN,
environment: process.env.SENTRY_ENVIRONMENT,
beforeSend(event) {
if (process.env.SENTRY_ENVIRONMENT == "prod") {
return rateLimiter.lease() ? event : null;
}

return null;
}
});

/*
* Create a worker for each scenario file in the scenarios directory.
*/
const workers = fs.readdirSync(filesPath).map((file) => {
const name = fileToMetricName(file);
const worker = new Worker(path.join(__dirname, "worker.js"), {
return new Worker(path.join(__dirname, "worker.js"), {
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;
});

/*
Expand Down
35 changes: 0 additions & 35 deletions integration/monitor/rate-limiter.js

This file was deleted.

7 changes: 2 additions & 5 deletions integration/monitor/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,14 @@ const metric = `${prefix}${workerData.name}`;

parentPort.on("message", async (_) => {
const browser = await chromium.launch();
const context = await browser.newContext({ userAgent: 'Playwright' });
const context = await browser.newContext({ userAgent: "Playwright" });
const page = await context.newPage();

const start = performance.now();

try {
await scenario({ page, baseURL });
} catch(exception) {
const screenshot = await page.screenshot({quality: 50, type: "jpeg"});

parentPort.postMessage({exception, metric, screenshot});
} catch (exception) {
logger.error({ metric, error: exception.message });
}

Expand Down
23 changes: 0 additions & 23 deletions integration/tests/monitor/rate-limiter.test.cjs

This file was deleted.

59 changes: 0 additions & 59 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"name": "dotcom",
"dependencies": {
"@playwright/test": "1.58.1",
"@sentry/node": "7.109.0",
"artillery": "2.0.30",
"axios": "1.16.0",
"csv-parse": "^6.1.0",
Expand Down
Loading