From c0c671bebc8e037858fe4d1460b3e1a37513e842 Mon Sep 17 00:00:00 2001 From: Nidhi Work Date: Thu, 12 Oct 2023 17:35:40 +0100 Subject: [PATCH 1/3] fix(apdex): show all metrics in report --- packages/artillery-plugin-apdex/index.js | 14 ++++++++--- .../artillery-plugin-apdex/test/index.spec.js | 25 +++++++++++++++++++ 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/packages/artillery-plugin-apdex/index.js b/packages/artillery-plugin-apdex/index.js index cdc94df780..12ece027e7 100644 --- a/packages/artillery-plugin-apdex/index.js +++ b/packages/artillery-plugin-apdex/index.js @@ -36,13 +36,21 @@ class ApdexPlugin { function apdexAfterResponse(req, res, userContext, events, done) { const total = res.timings.phases.total; + const counts = { + satisfied: 0, + tolerated: 0, + frustrated: 0 + }; if (total <= t) { - events.emit('counter', METRICS.satisfied, 1); + counts.satisfied = 1; } else if (total <= 4 * t) { - events.emit('counter', METRICS.tolerated, 1); + counts.tolerated = 1; } else { - events.emit('counter', METRICS.frustrated, 1); + counts.frustrated = 1; } + events.emit('counter', METRICS.satisfied, counts.satisfied); + events.emit('counter', METRICS.tolerated, counts.tolerated); + events.emit('counter', METRICS.frustrated, counts.frustrated); return done(); } diff --git a/packages/artillery-plugin-apdex/test/index.spec.js b/packages/artillery-plugin-apdex/test/index.spec.js index 6398d2708b..bad256f0ad 100644 --- a/packages/artillery-plugin-apdex/test/index.spec.js +++ b/packages/artillery-plugin-apdex/test/index.spec.js @@ -34,3 +34,28 @@ test('apdex plugin works when other after response hooks are set', async (t) => 'After Response Handler did not run five times' ); }); + +// Related to the following discussion: https://github.com/artilleryio/artillery/discussions/2209#discussion-5729379 +test('apdex plugin reports all apdex metrics even if they never occured', async (t) => { + //Arrange: Plugin overrides + const override = JSON.stringify({ + config: { + plugins: { apdex: {} }, + apdex: { + threshold: 100 + } + } + }); + + //Act: run the test + const output = + await $`../artillery/bin/run run ./test/fixtures/scenario.yml --overrides ${override}`; + const allMetricsReported = + output.stdout.includes('apdex.satisfied:') && + output.stdout.includes('apdex.tolerated:') && + output.stdout.includes('apdex.frustrated:'); + t.ok( + allMetricsReported, + 'All Apdex metrics counters are displayed in the report' + ); +}); From bf76aaa20e62fd9fe3598ed82cc11d6cb1531870 Mon Sep 17 00:00:00 2001 From: Nidhi Work Date: Thu, 12 Oct 2023 18:39:57 +0100 Subject: [PATCH 2/3] refactor: clean up comment url --- packages/artillery-plugin-apdex/test/index.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/artillery-plugin-apdex/test/index.spec.js b/packages/artillery-plugin-apdex/test/index.spec.js index bad256f0ad..5f01fb4ee1 100644 --- a/packages/artillery-plugin-apdex/test/index.spec.js +++ b/packages/artillery-plugin-apdex/test/index.spec.js @@ -35,7 +35,7 @@ test('apdex plugin works when other after response hooks are set', async (t) => ); }); -// Related to the following discussion: https://github.com/artilleryio/artillery/discussions/2209#discussion-5729379 +// Related to the following discussion: https://github.com/artilleryio/artillery/discussions/2209 test('apdex plugin reports all apdex metrics even if they never occured', async (t) => { //Arrange: Plugin overrides const override = JSON.stringify({ From a6d0ddbf0d6ab1cecf3729714f7b7ce6d3af7136 Mon Sep 17 00:00:00 2001 From: Nidhi Work Date: Fri, 13 Oct 2023 09:20:38 +0100 Subject: [PATCH 3/3] refactor: clean up --- packages/artillery-plugin-apdex/index.js | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/packages/artillery-plugin-apdex/index.js b/packages/artillery-plugin-apdex/index.js index 12ece027e7..7621ba6bfb 100644 --- a/packages/artillery-plugin-apdex/index.js +++ b/packages/artillery-plugin-apdex/index.js @@ -36,11 +36,7 @@ class ApdexPlugin { function apdexAfterResponse(req, res, userContext, events, done) { const total = res.timings.phases.total; - const counts = { - satisfied: 0, - tolerated: 0, - frustrated: 0 - }; + const counts = {}; if (total <= t) { counts.satisfied = 1; } else if (total <= 4 * t) {