artillery-plugin-apdex 1.23.0 → 1.24.0-670d2fa
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/.turbo/turbo-build.log +4 -0
- package/dist/index.js +93 -0
- package/{index.js → index.ts} +15 -5
- package/package.json +6 -14
- package/tsconfig.build.json +9 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
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
|
+
import createDebug from 'debug';
|
|
5
|
+
const _debug = createDebug('plugin:apdex');
|
|
6
|
+
const METRICS = {
|
|
7
|
+
satisfied: 'apdex.satisfied',
|
|
8
|
+
tolerated: 'apdex.tolerated',
|
|
9
|
+
frustrated: 'apdex.frustrated'
|
|
10
|
+
};
|
|
11
|
+
class ApdexPlugin {
|
|
12
|
+
constructor(script, _events) {
|
|
13
|
+
this.script = script;
|
|
14
|
+
if (global.artillery &&
|
|
15
|
+
Number(global.artillery.version.slice(0, 1)) > 1 &&
|
|
16
|
+
typeof process.env.LOCAL_WORKER_ID !== 'undefined') {
|
|
17
|
+
const t = script.config.apdex?.threshold ??
|
|
18
|
+
script.config.plugins?.apdex?.threshold ??
|
|
19
|
+
500;
|
|
20
|
+
if (!script.config.processor) {
|
|
21
|
+
script.config.processor = {};
|
|
22
|
+
}
|
|
23
|
+
// In the main thread config.processor may still be an unresolved
|
|
24
|
+
// path (a string). Attaching functions to it was a silent no-op
|
|
25
|
+
// under sloppy mode; ES modules are strict, so guard explicitly.
|
|
26
|
+
// Workers load the processor into an object before plugins run.
|
|
27
|
+
const canAttach = typeof script.config.processor === 'object';
|
|
28
|
+
script.scenarios.forEach((scenario) => {
|
|
29
|
+
scenario.afterResponse = [].concat(scenario.afterResponse || []);
|
|
30
|
+
scenario.afterResponse.push('apdexAfterResponse');
|
|
31
|
+
});
|
|
32
|
+
function apdexAfterResponse(_req, res, _userContext, events, done) {
|
|
33
|
+
const total = res.timings.phases.total;
|
|
34
|
+
events.emit('counter', METRICS.satisfied, 0);
|
|
35
|
+
events.emit('counter', METRICS.tolerated, 0);
|
|
36
|
+
events.emit('counter', METRICS.frustrated, 0);
|
|
37
|
+
if (total <= t) {
|
|
38
|
+
events.emit('counter', METRICS.satisfied, 1);
|
|
39
|
+
}
|
|
40
|
+
else if (total <= 4 * t) {
|
|
41
|
+
events.emit('counter', METRICS.tolerated, 1);
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
events.emit('counter', METRICS.frustrated, 1);
|
|
45
|
+
}
|
|
46
|
+
return done();
|
|
47
|
+
}
|
|
48
|
+
if (canAttach) {
|
|
49
|
+
script.config.processor.apdexAfterResponse = apdexAfterResponse;
|
|
50
|
+
}
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
global.artillery.ext({
|
|
54
|
+
ext: 'beforeExit',
|
|
55
|
+
method: async (testInfo) => {
|
|
56
|
+
const hasApdexConfig = this.script?.config?.apdex !== undefined ||
|
|
57
|
+
this.script?.config?.plugins?.apdex !== undefined;
|
|
58
|
+
if (!hasApdexConfig) {
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
const s = testInfo.report.counters[METRICS.satisfied] || 0;
|
|
62
|
+
const t = testInfo.report.counters[METRICS.tolerated] || 0;
|
|
63
|
+
const f = testInfo.report.counters[METRICS.frustrated] || 0;
|
|
64
|
+
const total = s + t + f;
|
|
65
|
+
if (total > 0) {
|
|
66
|
+
const apdexScore = (s + t / 2) / total;
|
|
67
|
+
let ranking = '';
|
|
68
|
+
if (apdexScore >= 0.94) {
|
|
69
|
+
ranking = 'excellent';
|
|
70
|
+
}
|
|
71
|
+
else if (apdexScore >= 0.85) {
|
|
72
|
+
ranking = 'good';
|
|
73
|
+
}
|
|
74
|
+
else if (apdexScore >= 0.7) {
|
|
75
|
+
ranking = 'fair';
|
|
76
|
+
}
|
|
77
|
+
else if (apdexScore >= 0.49) {
|
|
78
|
+
ranking = 'poor';
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
ranking = 'unacceptable';
|
|
82
|
+
}
|
|
83
|
+
global.artillery.apdexPlugin = {
|
|
84
|
+
apdex: apdexScore,
|
|
85
|
+
ranking
|
|
86
|
+
};
|
|
87
|
+
console.log(`\nApdex score: ${apdexScore} (${ranking})`);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
export { ApdexPlugin as Plugin };
|
package/{index.js → index.ts}
RENAMED
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
3
3
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
import createDebug from 'debug';
|
|
6
|
+
|
|
7
|
+
const _debug = createDebug('plugin:apdex');
|
|
6
8
|
|
|
7
9
|
const METRICS = {
|
|
8
10
|
satisfied: 'apdex.satisfied',
|
|
@@ -11,6 +13,9 @@ const METRICS = {
|
|
|
11
13
|
};
|
|
12
14
|
|
|
13
15
|
class ApdexPlugin {
|
|
16
|
+
// Untyped JS class - properties assigned dynamically
|
|
17
|
+
[key: string]: any;
|
|
18
|
+
|
|
14
19
|
constructor(script, _events) {
|
|
15
20
|
this.script = script;
|
|
16
21
|
|
|
@@ -27,6 +32,11 @@ class ApdexPlugin {
|
|
|
27
32
|
if (!script.config.processor) {
|
|
28
33
|
script.config.processor = {};
|
|
29
34
|
}
|
|
35
|
+
// In the main thread config.processor may still be an unresolved
|
|
36
|
+
// path (a string). Attaching functions to it was a silent no-op
|
|
37
|
+
// under sloppy mode; ES modules are strict, so guard explicitly.
|
|
38
|
+
// Workers load the processor into an object before plugins run.
|
|
39
|
+
const canAttach = typeof script.config.processor === 'object';
|
|
30
40
|
|
|
31
41
|
script.scenarios.forEach((scenario) => {
|
|
32
42
|
scenario.afterResponse = [].concat(scenario.afterResponse || []);
|
|
@@ -50,7 +60,9 @@ class ApdexPlugin {
|
|
|
50
60
|
return done();
|
|
51
61
|
}
|
|
52
62
|
|
|
53
|
-
|
|
63
|
+
if (canAttach) {
|
|
64
|
+
script.config.processor.apdexAfterResponse = apdexAfterResponse;
|
|
65
|
+
}
|
|
54
66
|
|
|
55
67
|
return;
|
|
56
68
|
}
|
|
@@ -97,6 +109,4 @@ class ApdexPlugin {
|
|
|
97
109
|
}
|
|
98
110
|
}
|
|
99
111
|
|
|
100
|
-
|
|
101
|
-
Plugin: ApdexPlugin
|
|
102
|
-
};
|
|
112
|
+
export { ApdexPlugin as Plugin };
|
package/package.json
CHANGED
|
@@ -1,23 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "artillery-plugin-apdex",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.24.0-670d2fa",
|
|
4
4
|
"description": "Calculate and report Apdex scores",
|
|
5
|
-
"main": "index.js",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
6
|
"scripts": {
|
|
7
|
-
"test": "
|
|
8
|
-
|
|
9
|
-
"tap": {
|
|
10
|
-
"disable-coverage": true,
|
|
11
|
-
"allow-empty-coverage": true,
|
|
12
|
-
"color": true,
|
|
13
|
-
"test-env": [
|
|
14
|
-
"ARTILLERY_TELEMETRY_DEFAULTS={\"source\":\"test-suite\"}"
|
|
15
|
-
]
|
|
7
|
+
"test": "node --test --test-timeout=300000 --require ./test/setup-env.cjs \"test/*.spec.js\"",
|
|
8
|
+
"build": "tsc -p tsconfig.build.json"
|
|
16
9
|
},
|
|
17
10
|
"keywords": [],
|
|
18
11
|
"author": "",
|
|
19
12
|
"license": "MPL-2.0",
|
|
20
|
-
"devDependencies": {
|
|
21
|
-
|
|
22
|
-
}
|
|
13
|
+
"devDependencies": {},
|
|
14
|
+
"type": "module"
|
|
23
15
|
}
|