From 683e569ffd2e6a336ce5f662a532c961109d403d Mon Sep 17 00:00:00 2001 From: Ines Fazlic Date: Fri, 13 Oct 2023 09:41:03 +0100 Subject: [PATCH] fix(apdex): show all metrics in report (#2210) --- packages/artillery-plugin-apdex/index.js | 10 +++++--- .../artillery-plugin-apdex/test/index.spec.js | 25 +++++++++++++++++++ 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/packages/artillery-plugin-apdex/index.js b/packages/artillery-plugin-apdex/index.js index cdc94df780..7621ba6bfb 100644 --- a/packages/artillery-plugin-apdex/index.js +++ b/packages/artillery-plugin-apdex/index.js @@ -36,13 +36,17 @@ class ApdexPlugin { function apdexAfterResponse(req, res, userContext, events, done) { const total = res.timings.phases.total; + const counts = {}; 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..5f01fb4ee1 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 +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' + ); +});