From e57a380749ec7feadf519e1240359681d1c6b17d Mon Sep 17 00:00:00 2001 From: Nidhi Work Date: Tue, 23 Jan 2024 13:24:47 +0000 Subject: [PATCH] refactor: revert pw engine and set sleep in otel --- packages/artillery-engine-playwright/index.js | 29 +++++++++++++++++-- .../lib/open-telemetry/tracing/base.js | 1 + .../platform/aws-ecs/legacy/run-cluster.js | 4 +++ 3 files changed, 31 insertions(+), 3 deletions(-) diff --git a/packages/artillery-engine-playwright/index.js b/packages/artillery-engine-playwright/index.js index c258d3d2e7..c75d09c77f 100644 --- a/packages/artillery-engine-playwright/index.js +++ b/packages/artillery-engine-playwright/index.js @@ -30,6 +30,10 @@ class PlaywrightEngine { typeof script.config.engines.playwright.showAllPageMetrics !== 'undefined'; + this.useSeparateBrowserPerVU = + typeof script.config.engines.playwright.useSeparateBrowserPerVU === 'boolean' ? + script.config.engines.playwright.useSeparateBrowserPerVU : false; + return this; } @@ -64,8 +68,18 @@ class PlaywrightEngine { const contextOptions = self.contextOptions || {}; - const browser = await chromium.launch(launchOptions); - debug('browser created'); + let browser; + if (self.useSeparateBrowserPerVU) { + browser = await chromium.launch(launchOptions); + debug('new browser created'); + } else { + if (!global.artillery.__browser) { + global.artillery.__browser = await chromium.launch(launchOptions); + debug('shared browser created'); + } + browser = global.artillery.__browser; + } + const context = await browser.newContext(contextOptions); context.setDefaultNavigationTimeout(self.defaultNavigationTimeout); @@ -96,7 +110,13 @@ class PlaywrightEngine { debug('page created'); + page.on('response', (response) => { + const status = response.status(); + events.emit('counter', 'browser.page.codes.' + status, 1); + }); + page.on('domcontentloaded', async (page) => { + if (!self.extendedMetrics) { return; } @@ -226,7 +246,10 @@ class PlaywrightEngine { } } finally { await context.close(); - await browser.close(); + + if (self.useSeparateBrowserPerVU) { + await browser.close(); // TODO: check if need to remove browser from global object/set to false + } } }; } diff --git a/packages/artillery-plugin-publish-metrics/lib/open-telemetry/tracing/base.js b/packages/artillery-plugin-publish-metrics/lib/open-telemetry/tracing/base.js index 08c580aacb..76f351c74d 100644 --- a/packages/artillery-plugin-publish-metrics/lib/open-telemetry/tracing/base.js +++ b/packages/artillery-plugin-publish-metrics/lib/open-telemetry/tracing/base.js @@ -147,6 +147,7 @@ class OTelTraceBase { debug('Waiting for pending traces ...'); await new Promise((resolve) => setTimeout(resolve, 500)); } + await new Promise((resolve) => setTimeout(resolve, 10000)); debug('Pending traces done'); } } diff --git a/packages/artillery/lib/platform/aws-ecs/legacy/run-cluster.js b/packages/artillery/lib/platform/aws-ecs/legacy/run-cluster.js index 739c67a374..2efd10bbfe 100644 --- a/packages/artillery/lib/platform/aws-ecs/legacy/run-cluster.js +++ b/packages/artillery/lib/platform/aws-ecs/legacy/run-cluster.js @@ -1118,6 +1118,10 @@ async function ensureTaskExists(context) { { name: 'DD_SITE', value: 'datadoghq.com' + }, + { + name: 'DD_LOG_LEVEL', + value: 'WARN' } ], logConfiguration: {