@artilleryio/int-core 2.27.0 → 2.28.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 +13 -0
- package/dist/lib/engine_http.js +817 -0
- package/dist/lib/engine_socketio.js +347 -0
- package/dist/lib/engine_ws.js +278 -0
- package/dist/lib/is-idle-phase.js +9 -0
- package/dist/lib/phases.js +213 -0
- package/dist/lib/readers.js +58 -0
- package/dist/lib/runner.js +463 -0
- package/dist/lib/ssms.js +555 -0
- package/dist/lib/update-global-object.js +75 -0
- package/dist/lib/weighted-pick.js +54 -0
- package/index.ts +14 -0
- package/lib/{engine_http.js → engine_http.ts} +28 -28
- package/lib/{engine_socketio.js → engine_socketio.ts} +13 -11
- package/lib/{engine_ws.js → engine_ws.ts} +16 -10
- package/lib/{is-idle-phase.js → is-idle-phase.ts} +1 -3
- package/lib/{phases.js → phases.ts} +12 -10
- package/lib/{readers.js → readers.ts} +2 -4
- package/lib/{runner.js → runner.ts} +84 -69
- package/lib/{ssms.js → ssms.ts} +18 -18
- package/{index.js → lib/update-global-object.ts} +9 -14
- package/lib/{weighted-pick.js → weighted-pick.ts} +7 -3
- package/package.json +10 -17
- package/tsconfig.build.json +9 -0
- package/types.d.ts +12 -0
|
@@ -2,32 +2,32 @@
|
|
|
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
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
5
|
+
import crypto from 'node:crypto';
|
|
6
|
+
import fs from 'node:fs';
|
|
7
|
+
import path from 'node:path';
|
|
8
|
+
import qs from 'node:querystring';
|
|
9
|
+
import { parse as urlparse } from 'node:url';
|
|
10
|
+
import { callbackify, promisify } from 'node:util';
|
|
11
|
+
import { engine_util as engineUtil } from '@artilleryio/int-commons';
|
|
12
|
+
import HttpAgent from 'agentkeepalive';
|
|
13
|
+
import async from 'async';
|
|
14
|
+
import createDebug from 'debug';
|
|
15
|
+
import decompressResponse from 'decompress-response';
|
|
16
|
+
import filtrex from 'filtrex';
|
|
17
|
+
import FormData from 'form-data';
|
|
18
|
+
import { HttpProxyAgent, HttpsProxyAgent } from 'hpagent';
|
|
19
|
+
import _ from 'lodash';
|
|
20
|
+
import * as tough from 'tough-cookie';
|
|
21
|
+
|
|
22
|
+
const debug = createDebug('http');
|
|
23
|
+
const debugRequests = createDebug('http:request');
|
|
24
|
+
const debugResponse = createDebug('http:response');
|
|
11
25
|
const USER_AGENT = 'Artillery (https://artillery.io)';
|
|
12
|
-
const engineUtil = require('@artilleryio/int-commons').engine_util;
|
|
13
26
|
const ensurePropertyIsAList = engineUtil.ensurePropertyIsAList;
|
|
14
27
|
const template = engineUtil.template;
|
|
15
|
-
const qs = require('node:querystring');
|
|
16
|
-
const filtrex = require('filtrex');
|
|
17
|
-
const urlparse = require('node:url').parse;
|
|
18
|
-
const FormData = require('form-data');
|
|
19
|
-
const HttpAgent = require('agentkeepalive');
|
|
20
28
|
const { HttpsAgent } = HttpAgent;
|
|
21
|
-
const { HttpProxyAgent, HttpsProxyAgent } = require('hpagent');
|
|
22
|
-
const decompressResponse = require('decompress-response');
|
|
23
|
-
const fs = require('node:fs');
|
|
24
|
-
const path = require('node:path');
|
|
25
29
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
const crypto = require('node:crypto');
|
|
29
|
-
|
|
30
|
-
module.exports = HttpEngine;
|
|
30
|
+
export default HttpEngine;
|
|
31
31
|
|
|
32
32
|
const GOT_OPTION_NAMES = [
|
|
33
33
|
'url',
|
|
@@ -140,7 +140,7 @@ function HttpEngine(script) {
|
|
|
140
140
|
if (script.config.http?.pool) {
|
|
141
141
|
this.maxSockets = Number(script.config.http.pool);
|
|
142
142
|
}
|
|
143
|
-
const agentOpts = Object.assign(DEFAULT_AGENT_OPTIONS, {
|
|
143
|
+
const agentOpts: any = Object.assign(DEFAULT_AGENT_OPTIONS, {
|
|
144
144
|
maxSockets: this.maxSockets,
|
|
145
145
|
maxFreeSockets: this.maxSockets
|
|
146
146
|
});
|
|
@@ -172,7 +172,7 @@ HttpEngine.prototype.init = async function () {
|
|
|
172
172
|
this.request = (await import('got')).default;
|
|
173
173
|
};
|
|
174
174
|
|
|
175
|
-
HttpEngine.prototype._isDistributedTracingEnabled =
|
|
175
|
+
HttpEngine.prototype._isDistributedTracingEnabled = (config) => {
|
|
176
176
|
const dtConfig = config.http?.distributedTracing;
|
|
177
177
|
if (!dtConfig) {
|
|
178
178
|
return false;
|
|
@@ -191,7 +191,7 @@ HttpEngine.prototype._isDistributedTracingEnabled = function (config) {
|
|
|
191
191
|
return true;
|
|
192
192
|
};
|
|
193
193
|
|
|
194
|
-
HttpEngine.prototype._generateTraceparent =
|
|
194
|
+
HttpEngine.prototype._generateTraceparent = (config) => {
|
|
195
195
|
// W3C Trace Context format: version-trace-id-parent-id-trace-flags
|
|
196
196
|
const version = '00';
|
|
197
197
|
|
|
@@ -585,7 +585,7 @@ HttpEngine.prototype.step = function step(requestSpec, ee, opts) {
|
|
|
585
585
|
|
|
586
586
|
function responseProcessor(isLast, res, body, done) {
|
|
587
587
|
if (process.env.DEBUG) {
|
|
588
|
-
let requestInfo = {
|
|
588
|
+
let requestInfo: any = {
|
|
589
589
|
url: requestParams.url,
|
|
590
590
|
method: requestParams.method,
|
|
591
591
|
headers: requestParams.headers
|
|
@@ -1018,7 +1018,7 @@ HttpEngine.prototype.setInitialContext = function (initialContext) {
|
|
|
1018
1018
|
initialContext._httpsAgent = this._httpsAgent;
|
|
1019
1019
|
} else {
|
|
1020
1020
|
// Create agents just for this VU
|
|
1021
|
-
const agentOpts = Object.assign(DEFAULT_AGENT_OPTIONS, {
|
|
1021
|
+
const agentOpts: any = Object.assign(DEFAULT_AGENT_OPTIONS, {
|
|
1022
1022
|
maxSockets: 1,
|
|
1023
1023
|
maxFreeSockets: 1
|
|
1024
1024
|
});
|
|
@@ -1078,9 +1078,9 @@ function maybePrependBase(uri, config) {
|
|
|
1078
1078
|
/*
|
|
1079
1079
|
* Given a dictionary, return a dictionary with all keys lowercased.
|
|
1080
1080
|
*/
|
|
1081
|
-
function lowcaseKeys(h) {
|
|
1081
|
+
function lowcaseKeys(h): any {
|
|
1082
1082
|
return _.transform(h, (result, v, k) => {
|
|
1083
|
-
result[k.toLowerCase()] = v;
|
|
1083
|
+
result[String(k).toLowerCase()] = v;
|
|
1084
1084
|
});
|
|
1085
1085
|
}
|
|
1086
1086
|
|
|
@@ -2,19 +2,21 @@
|
|
|
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
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
const
|
|
5
|
+
import { engine_util as engineUtil } from '@artilleryio/int-commons';
|
|
6
|
+
import async from 'async';
|
|
7
|
+
import createDebug from 'debug';
|
|
8
|
+
import deepEqual from 'fast-deep-equal';
|
|
9
|
+
import _ from 'lodash';
|
|
10
|
+
import io from 'socket.io-client';
|
|
11
|
+
import sioWildcard from 'socketio-wildcard';
|
|
12
|
+
import EngineHttp from './engine_http.ts';
|
|
13
|
+
|
|
14
|
+
const wildcardPatch = sioWildcard((io as any).Manager);
|
|
15
|
+
|
|
16
|
+
const debug = createDebug('socketio');
|
|
15
17
|
const template = engineUtil.template;
|
|
16
18
|
|
|
17
|
-
|
|
19
|
+
export default SocketIoEngine;
|
|
18
20
|
|
|
19
21
|
function SocketIoEngine(script) {
|
|
20
22
|
this.config = script.config;
|
|
@@ -2,16 +2,22 @@
|
|
|
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
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
5
|
+
import url from 'node:url';
|
|
6
|
+
import { engine_util as engineUtil } from '@artilleryio/int-commons';
|
|
7
|
+
import async from 'async';
|
|
8
|
+
import createDebug from 'debug';
|
|
9
|
+
import HttpsProxyAgent from 'https-proxy-agent';
|
|
10
|
+
import _ from 'lodash';
|
|
11
|
+
import WebSocket from 'ws';
|
|
12
|
+
|
|
13
|
+
const debug = createDebug('ws');
|
|
12
14
|
const template = engineUtil.template;
|
|
13
15
|
|
|
14
|
-
module
|
|
16
|
+
// Injectable dependencies - module namespaces are frozen, so tests
|
|
17
|
+
// replace the WebSocket implementation through this mutable object
|
|
18
|
+
export const _deps = { WebSocket };
|
|
19
|
+
|
|
20
|
+
export default WSEngine;
|
|
15
21
|
|
|
16
22
|
function WSEngine(script) {
|
|
17
23
|
this.config = script.config;
|
|
@@ -306,7 +312,7 @@ WSEngine.prototype.compile = function (tasks, scenarioSpec, ee) {
|
|
|
306
312
|
|
|
307
313
|
function one(context, cb) {
|
|
308
314
|
const { wsArgs, ...contextWithoutWsArgs } = context;
|
|
309
|
-
const ws = new WebSocket(
|
|
315
|
+
const ws = new _deps.WebSocket(
|
|
310
316
|
wsArgs.target,
|
|
311
317
|
wsArgs.subprotocols,
|
|
312
318
|
wsArgs.options
|
|
@@ -354,7 +360,7 @@ function getWsConfig(config) {
|
|
|
354
360
|
|
|
355
361
|
debug('Set proxy: %s, options: %s', proxyUrl, proxyOptions);
|
|
356
362
|
|
|
357
|
-
const agent = new HttpsProxyAgent({
|
|
363
|
+
const agent = new (HttpsProxyAgent as any)({
|
|
358
364
|
...url.parse(proxyUrl),
|
|
359
365
|
...proxyOptions
|
|
360
366
|
});
|
|
@@ -2,7 +2,7 @@
|
|
|
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
|
-
function isIdlePhase(phase) {
|
|
5
|
+
export default function isIdlePhase(phase) {
|
|
6
6
|
return (
|
|
7
7
|
(phase.arrivalRate === 0 && !phase.rampTo) ||
|
|
8
8
|
phase.arrivalCount === 0 ||
|
|
@@ -10,5 +10,3 @@ function isIdlePhase(phase) {
|
|
|
10
10
|
phase.pause > 0
|
|
11
11
|
);
|
|
12
12
|
}
|
|
13
|
-
|
|
14
|
-
module.exports = isIdlePhase;
|
|
@@ -2,17 +2,19 @@
|
|
|
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
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
import { randomUUID } from 'node:crypto';
|
|
6
|
+
import arrivals from 'arrivals';
|
|
7
|
+
import async from 'async';
|
|
8
|
+
import createDebug from 'debug';
|
|
9
|
+
import driftless from 'driftless';
|
|
10
|
+
import { EventEmitter } from 'eventemitter3';
|
|
11
|
+
import _ from 'lodash';
|
|
12
|
+
import ms from 'ms';
|
|
13
|
+
|
|
14
|
+
const debug = createDebug('phases');
|
|
8
15
|
const isUndefined = _.isUndefined;
|
|
9
|
-
const arrivals = require('arrivals');
|
|
10
|
-
const debug = require('debug')('phases');
|
|
11
|
-
const { randomUUID } = require('node:crypto');
|
|
12
|
-
const driftless = require('driftless');
|
|
13
|
-
const ms = require('ms');
|
|
14
16
|
|
|
15
|
-
|
|
17
|
+
export default phaser;
|
|
16
18
|
|
|
17
19
|
async function sleep(ms) {
|
|
18
20
|
return new Promise((resolve) => {
|
|
@@ -21,7 +23,7 @@ async function sleep(ms) {
|
|
|
21
23
|
}
|
|
22
24
|
|
|
23
25
|
function phaser(phaseSpecs) {
|
|
24
|
-
const ee = new EventEmitter();
|
|
26
|
+
const ee: any = new EventEmitter();
|
|
25
27
|
|
|
26
28
|
const tasks = _.map(phaseSpecs, (spec, i) => {
|
|
27
29
|
[
|
|
@@ -2,11 +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 _ from 'lodash';
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
function createReader(order, spec) {
|
|
7
|
+
export default function createReader(order, spec?) {
|
|
10
8
|
if (order === 'sequence') {
|
|
11
9
|
return createSequencedReader();
|
|
12
10
|
} else if (
|
|
@@ -2,73 +2,87 @@
|
|
|
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
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
5
|
+
import { createRequire } from 'node:module';
|
|
6
|
+
import path from 'node:path';
|
|
7
|
+
import { pathToFileURL } from 'node:url';
|
|
8
|
+
import { engine_util as engineUtil } from '@artilleryio/int-commons';
|
|
9
|
+
import createDebug from 'debug';
|
|
10
|
+
import { EventEmitter } from 'eventemitter3';
|
|
11
|
+
import _ from 'lodash';
|
|
12
|
+
import { v4 as uuidv4 } from 'uuid';
|
|
13
|
+
import HttpEngine from './engine_http.ts';
|
|
14
|
+
import SocketIoEngine from './engine_socketio.ts';
|
|
15
|
+
import WSEngine from './engine_ws.ts';
|
|
16
|
+
import createPhaser from './phases.ts';
|
|
17
|
+
import createReader from './readers.ts';
|
|
18
|
+
import { SSMS } from './ssms.ts';
|
|
19
|
+
import wl from './weighted-pick.ts';
|
|
20
|
+
|
|
21
|
+
const debug = createDebug('runner');
|
|
22
|
+
const debugPerf = createDebug('perf');
|
|
23
|
+
|
|
24
|
+
const require = createRequire(import.meta.url);
|
|
17
25
|
|
|
18
26
|
const Engines = {
|
|
19
|
-
http:
|
|
20
|
-
ws:
|
|
21
|
-
socketio:
|
|
27
|
+
http: HttpEngine,
|
|
28
|
+
ws: WSEngine,
|
|
29
|
+
socketio: SocketIoEngine
|
|
22
30
|
};
|
|
23
31
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
loadProcessor
|
|
34
|
-
}
|
|
32
|
+
const contextFuncs = {
|
|
33
|
+
$randomString,
|
|
34
|
+
$randomNumber
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
const runnerFuncs = {
|
|
38
|
+
handleScriptHook,
|
|
39
|
+
prepareScript,
|
|
40
|
+
loadProcessor
|
|
35
41
|
};
|
|
36
42
|
|
|
37
|
-
|
|
43
|
+
export { runner, contextFuncs, runnerFuncs };
|
|
44
|
+
|
|
45
|
+
async function loadEngines(
|
|
38
46
|
script,
|
|
39
47
|
ee,
|
|
40
48
|
warnings = {
|
|
41
49
|
engines: {}
|
|
42
50
|
}
|
|
43
51
|
) {
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
'WARNING: engine %s specified but module %s could not be loaded',
|
|
61
|
-
engineName,
|
|
62
|
-
moduleName
|
|
63
|
-
);
|
|
64
|
-
console.log(err.stack);
|
|
65
|
-
warnings.engines[engineName] = {
|
|
66
|
-
message: 'Could not load',
|
|
67
|
-
error: err
|
|
68
|
-
};
|
|
52
|
+
const engineSpecs = Object.assign({}, Engines, script.config.engines);
|
|
53
|
+
const loadedEngines = [];
|
|
54
|
+
|
|
55
|
+
for (const engineName of Object.keys(engineSpecs)) {
|
|
56
|
+
const moduleName = `artillery-engine-${engineName}`;
|
|
57
|
+
try {
|
|
58
|
+
let Engine;
|
|
59
|
+
if (typeof Engines[engineName] !== 'undefined') {
|
|
60
|
+
Engine = Engines[engineName];
|
|
61
|
+
} else {
|
|
62
|
+
// Resolve with CJS semantics (bare specifiers, directories via
|
|
63
|
+
// package.json "main"), load with import() - handles both CJS
|
|
64
|
+
// and ESM engines, including ESM with top-level await
|
|
65
|
+
const enginePath = require.resolve(moduleName);
|
|
66
|
+
const ns = await import(pathToFileURL(enginePath).href);
|
|
67
|
+
Engine = ns.default ?? ns;
|
|
69
68
|
}
|
|
69
|
+
const engine = new Engine(script, ee, engineUtil);
|
|
70
|
+
engine.__name = engineName;
|
|
71
|
+
loadedEngines.push(engine);
|
|
72
|
+
} catch (err) {
|
|
73
|
+
console.log(
|
|
74
|
+
'WARNING: engine %s specified but module %s could not be loaded',
|
|
75
|
+
engineName,
|
|
76
|
+
moduleName
|
|
77
|
+
);
|
|
78
|
+
console.log(err.stack);
|
|
79
|
+
warnings.engines[engineName] = {
|
|
80
|
+
message: 'Could not load',
|
|
81
|
+
error: err
|
|
82
|
+
};
|
|
83
|
+
loadedEngines.push(undefined);
|
|
70
84
|
}
|
|
71
|
-
|
|
85
|
+
}
|
|
72
86
|
|
|
73
87
|
return { loadedEngines, warnings };
|
|
74
88
|
}
|
|
@@ -81,18 +95,19 @@ async function loadProcessor(script, options) {
|
|
|
81
95
|
script.config.processor
|
|
82
96
|
);
|
|
83
97
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
98
|
+
// Resolve with CJS semantics first (handles extensionless paths and
|
|
99
|
+
// directories); fall back to the path as-is
|
|
100
|
+
let resolvedPath = processorPath;
|
|
101
|
+
try {
|
|
102
|
+
resolvedPath = require.resolve(processorPath);
|
|
103
|
+
} catch (_err) {}
|
|
104
|
+
|
|
105
|
+
// import() loads both CJS and ESM (including ESM with top-level
|
|
106
|
+
// await). Normalize the result into a plain mutable object: module
|
|
107
|
+
// namespace objects are frozen, and engines/plugins may attach
|
|
108
|
+
// properties to the processor object later (e.g. $rewriteMetricName)
|
|
109
|
+
const ns = await import(pathToFileURL(resolvedPath).href);
|
|
110
|
+
script.config.processor = Object.assign({}, ns.default ?? {}, ns);
|
|
96
111
|
}
|
|
97
112
|
|
|
98
113
|
return script;
|
|
@@ -152,12 +167,12 @@ async function runner(script, payload, options, callback) {
|
|
|
152
167
|
|
|
153
168
|
const runnableScript = prepareScript(script, payload);
|
|
154
169
|
|
|
155
|
-
const ee = new EventEmitter();
|
|
170
|
+
const ee: any = new EventEmitter();
|
|
156
171
|
|
|
157
172
|
//
|
|
158
173
|
// load engines:
|
|
159
174
|
//
|
|
160
|
-
const { loadedEngines: runnerEngines } = loadEngines(
|
|
175
|
+
const { loadedEngines: runnerEngines } = await loadEngines(
|
|
161
176
|
runnableScript,
|
|
162
177
|
ee,
|
|
163
178
|
warnings
|
|
@@ -456,7 +471,7 @@ function createContext(script, contextVars, additionalProperties = {}) {
|
|
|
456
471
|
'funcs'
|
|
457
472
|
]);
|
|
458
473
|
|
|
459
|
-
const INITIAL_CONTEXT = {
|
|
474
|
+
const INITIAL_CONTEXT: any = {
|
|
460
475
|
vars: Object.assign(
|
|
461
476
|
{
|
|
462
477
|
target: script.config.target,
|
|
@@ -521,7 +536,7 @@ async function handleScriptHook(hook, script, hookEvents, contextVars = {}) {
|
|
|
521
536
|
return {};
|
|
522
537
|
}
|
|
523
538
|
|
|
524
|
-
const { loadedEngines: engines } = loadEngines(script, hookEvents);
|
|
539
|
+
const { loadedEngines: engines } = await loadEngines(script, hookEvents);
|
|
525
540
|
|
|
526
541
|
for (const e of engines) {
|
|
527
542
|
if (
|
package/lib/{ssms.js → ssms.ts}
RENAMED
|
@@ -6,16 +6,20 @@
|
|
|
6
6
|
|
|
7
7
|
// Use our own fork of DDSketch until this PR is merged into main:
|
|
8
8
|
// https://github.com/DataDog/sketches-js/pull/13
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
import { EventEmitter } from 'node:events';
|
|
10
|
+
import { DDSketch } from '@artilleryio/sketches-js';
|
|
11
|
+
import createDebug from 'debug';
|
|
12
|
+
import { clearDriftless, setDriftlessInterval } from 'driftless';
|
|
13
|
+
|
|
14
|
+
const debug = createDebug('ssms');
|
|
14
15
|
|
|
15
16
|
const MAX_METRIC_NAME_LENGTH = 1024;
|
|
16
17
|
|
|
17
18
|
class SSMS extends EventEmitter {
|
|
18
|
-
|
|
19
|
+
// Untyped JS class - properties assigned dynamically
|
|
20
|
+
[key: string]: any;
|
|
21
|
+
|
|
22
|
+
constructor(_options?) {
|
|
19
23
|
super();
|
|
20
24
|
|
|
21
25
|
this.opts = _options || {};
|
|
@@ -270,7 +274,7 @@ class SSMS extends EventEmitter {
|
|
|
270
274
|
// Aggregate at lower resolution, i.e. combine three distinct periods of 10s into one of 30s
|
|
271
275
|
// Note: does not check that periods are contiguous, everything is simply merged together
|
|
272
276
|
static pack(periods) {
|
|
273
|
-
const result = {
|
|
277
|
+
const result: any = {
|
|
274
278
|
counters: {},
|
|
275
279
|
histograms: {},
|
|
276
280
|
rates: {}
|
|
@@ -356,7 +360,7 @@ class SSMS extends EventEmitter {
|
|
|
356
360
|
static deserializeMetrics(pd) {
|
|
357
361
|
const object = parse(pd);
|
|
358
362
|
for (const [name, buf] of Object.entries(object.histograms)) {
|
|
359
|
-
const h = DDSketch.fromProto(buf);
|
|
363
|
+
const h = DDSketch.fromProto(buf as any);
|
|
360
364
|
object.histograms[name] = h;
|
|
361
365
|
}
|
|
362
366
|
|
|
@@ -378,7 +382,7 @@ class SSMS extends EventEmitter {
|
|
|
378
382
|
this.incr(name.slice(0, MAX_METRIC_NAME_LENGTH), value);
|
|
379
383
|
}
|
|
380
384
|
|
|
381
|
-
incr(name, value, t) {
|
|
385
|
+
incr(name, value, t?) {
|
|
382
386
|
this._counters.push(
|
|
383
387
|
t || Date.now(),
|
|
384
388
|
name.slice(0, MAX_METRIC_NAME_LENGTH),
|
|
@@ -391,7 +395,7 @@ class SSMS extends EventEmitter {
|
|
|
391
395
|
this.histogram(name.slice(0, MAX_METRIC_NAME_LENGTH), value);
|
|
392
396
|
}
|
|
393
397
|
|
|
394
|
-
histogram(name, value, t) {
|
|
398
|
+
histogram(name, value, t?) {
|
|
395
399
|
this._histograms.push(
|
|
396
400
|
t || Date.now(),
|
|
397
401
|
name.slice(0, MAX_METRIC_NAME_LENGTH),
|
|
@@ -399,12 +403,12 @@ class SSMS extends EventEmitter {
|
|
|
399
403
|
);
|
|
400
404
|
}
|
|
401
405
|
|
|
402
|
-
rate(name, t) {
|
|
406
|
+
rate(name, t?) {
|
|
403
407
|
this._rates.push(t || Date.now(), name.slice(0, MAX_METRIC_NAME_LENGTH));
|
|
404
408
|
}
|
|
405
409
|
|
|
406
410
|
getMetrics(period) {
|
|
407
|
-
const result = {};
|
|
411
|
+
const result: any = {};
|
|
408
412
|
|
|
409
413
|
const counters = this._aggregatedCounters[period];
|
|
410
414
|
const histograms = this._aggregatedHistograms[period];
|
|
@@ -644,7 +648,7 @@ function summarizeHistogram(h) {
|
|
|
644
648
|
}
|
|
645
649
|
|
|
646
650
|
/// ///////////////////////////////////////////
|
|
647
|
-
function stringify(value, space) {
|
|
651
|
+
function stringify(value, space?) {
|
|
648
652
|
return JSON.stringify(value, replacer, space);
|
|
649
653
|
}
|
|
650
654
|
|
|
@@ -715,8 +719,4 @@ function max(values) {
|
|
|
715
719
|
return m === Number.NEGATIVE_INFINITY ? undefined : m;
|
|
716
720
|
}
|
|
717
721
|
|
|
718
|
-
|
|
719
|
-
SSMS,
|
|
720
|
-
summarizeHistogram,
|
|
721
|
-
normalizeTs
|
|
722
|
-
};
|
|
722
|
+
export { SSMS, summarizeHistogram, normalizeTs };
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { EventEmitter } from 'node:events';
|
|
2
|
+
import { engine_util } from '@artilleryio/int-commons';
|
|
3
|
+
import chalk from 'chalk';
|
|
4
|
+
import { SSMS } from './ssms.ts';
|
|
3
5
|
|
|
4
6
|
// NOTE: This may be called more than once, and so should be non-destructive
|
|
5
|
-
async function updateGlobalObject(opts = {}) {
|
|
7
|
+
async function updateGlobalObject(opts: any = {}) {
|
|
6
8
|
global.artillery = global.artillery || {};
|
|
7
9
|
|
|
8
10
|
global.artillery.runtimeOptions = global.artillery.runtimeOptions || {};
|
|
@@ -12,7 +14,7 @@ async function updateGlobalObject(opts = {}) {
|
|
|
12
14
|
global.artillery.metrics = global.artillery.metrics || {};
|
|
13
15
|
global.artillery.metrics.event = async (msg, opts) => {
|
|
14
16
|
if (opts.level === 'error') {
|
|
15
|
-
console.log(chalk.red(msg));
|
|
17
|
+
console.log((chalk as any).red(msg));
|
|
16
18
|
} else {
|
|
17
19
|
console.log(msg);
|
|
18
20
|
}
|
|
@@ -20,8 +22,7 @@ async function updateGlobalObject(opts = {}) {
|
|
|
20
22
|
|
|
21
23
|
global.artillery.util = global.artillery.util || {};
|
|
22
24
|
|
|
23
|
-
global.artillery.util.template =
|
|
24
|
-
require('@artilleryio/int-commons').engine_util.template;
|
|
25
|
+
global.artillery.util.template = engine_util.template;
|
|
25
26
|
|
|
26
27
|
global.artillery.plugins = global.artillery.plugins || [];
|
|
27
28
|
|
|
@@ -40,7 +41,7 @@ async function updateGlobalObject(opts = {}) {
|
|
|
40
41
|
});
|
|
41
42
|
}
|
|
42
43
|
|
|
43
|
-
global.artillery.__SSMS =
|
|
44
|
+
global.artillery.__SSMS = SSMS;
|
|
44
45
|
|
|
45
46
|
if (!Object.hasOwn(global.artillery, 'suggestedExitCode')) {
|
|
46
47
|
Object.defineProperty(global.artillery, 'suggestedExitCode', {
|
|
@@ -87,10 +88,4 @@ async function main() {
|
|
|
87
88
|
|
|
88
89
|
main();
|
|
89
90
|
|
|
90
|
-
|
|
91
|
-
runner: require('./lib/runner'),
|
|
92
|
-
engine_http: require('./lib/engine_http'),
|
|
93
|
-
ssms: require('./lib/ssms'),
|
|
94
|
-
isIdlePhase: require('./lib/is-idle-phase'),
|
|
95
|
-
updateGlobalObject
|
|
96
|
-
};
|
|
91
|
+
export { updateGlobalObject };
|
|
@@ -2,9 +2,10 @@
|
|
|
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 { pathToFileURL } from 'node:url';
|
|
6
|
+
import l from 'lodash';
|
|
6
7
|
|
|
7
|
-
|
|
8
|
+
export default create;
|
|
8
9
|
|
|
9
10
|
// naive implementation of selection with replacement
|
|
10
11
|
function create(list) {
|
|
@@ -75,6 +76,9 @@ function bench() {
|
|
|
75
76
|
});
|
|
76
77
|
}
|
|
77
78
|
|
|
78
|
-
if (
|
|
79
|
+
if (
|
|
80
|
+
process.argv[1] &&
|
|
81
|
+
import.meta.url === pathToFileURL(process.argv[1]).href
|
|
82
|
+
) {
|
|
79
83
|
bench();
|
|
80
84
|
}
|