artillery-plugin-apdex 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +85 -0
- package/package.json +12 -0
package/index.js
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
2
|
+
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
3
|
+
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
4
|
+
|
|
5
|
+
'use strict';
|
|
6
|
+
|
|
7
|
+
const debug = require('debug')('plugin:apdex');
|
|
8
|
+
|
|
9
|
+
const METRICS = {
|
|
10
|
+
satisfied: 'apdex.satisfied',
|
|
11
|
+
tolerated: 'apdex.tolerated',
|
|
12
|
+
frustrated: 'apdex.frustrated',
|
|
13
|
+
}
|
|
14
|
+
class ApdexPlugin {
|
|
15
|
+
constructor(script, _events) {
|
|
16
|
+
this.script = script;
|
|
17
|
+
|
|
18
|
+
const t = script.config.apdex?.threshold || script.config.plugins.apdex?.threshold || 500;
|
|
19
|
+
|
|
20
|
+
if (!script.config.processor) {
|
|
21
|
+
script.config.processor = {};
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
script.scenarios.forEach(function (scenario) {
|
|
25
|
+
scenario.afterResponse = [].concat(scenario.afterResponse || []);
|
|
26
|
+
scenario.afterResponse.push('apdexAfterResponse');
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
function apdexAfterResponse(req, res, userContext, events, done) {
|
|
30
|
+
const total = res.timings.phases.total;
|
|
31
|
+
if (total <= t) {
|
|
32
|
+
events.emit('counter', METRICS.satisfied, 1);
|
|
33
|
+
} else if (total <= 4 * t) {
|
|
34
|
+
events.emit('counter', METRICS.tolerated, 1);
|
|
35
|
+
} else {
|
|
36
|
+
events.emit('counter', METRICS.frustrated, 1);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return done();
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
script.config.processor.apdexAfterResponse = apdexAfterResponse;
|
|
43
|
+
|
|
44
|
+
global.artillery.ext({
|
|
45
|
+
ext: 'beforeExit',
|
|
46
|
+
method: async (testInfo) => {
|
|
47
|
+
if (typeof this.script?.config?.apdex === 'undefined' ||
|
|
48
|
+
typeof process.env.ARTILLERY_DISABLE_ENSURE !== 'undefined') {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const s = testInfo.report.counters[METRICS.satisfied] || 0;
|
|
53
|
+
const t = testInfo.report.counters[METRICS.tolerated] || 0;
|
|
54
|
+
const f = testInfo.report.counters[METRICS.frustrated] || 0;
|
|
55
|
+
const total = s + t + f;
|
|
56
|
+
if (total > 0) {
|
|
57
|
+
const apdexScore = (s + t / 2) / total;
|
|
58
|
+
let ranking = '';
|
|
59
|
+
if (apdexScore >= 0.94) {
|
|
60
|
+
ranking = 'excellent';
|
|
61
|
+
} else if (apdexScore >= 0.85) {
|
|
62
|
+
ranking = 'good';
|
|
63
|
+
} else if (apdexScore >= 0.7) {
|
|
64
|
+
ranking = 'fair';
|
|
65
|
+
} else if (apdexScore >= 0.49) {
|
|
66
|
+
ranking = 'poor';
|
|
67
|
+
} else {
|
|
68
|
+
ranking = 'unacceptable';
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
global.artillery.apdexPlugin = {
|
|
72
|
+
apdex: apdexScore,
|
|
73
|
+
ranking
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
console.log(`\nApdex score: ${apdexScore} (${ranking})`);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
module.exports = {
|
|
84
|
+
Plugin: ApdexPlugin
|
|
85
|
+
}
|
package/package.json
ADDED