@artilleryio/int-core 2.21.0 → 2.22.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/lib/runner.js CHANGED
@@ -2,10 +2,8 @@
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
- 'use strict';
6
-
7
5
  const EventEmitter = require('eventemitter3');
8
- const path = require('path');
6
+ const path = require('node:path');
9
7
  const _ = require('lodash');
10
8
  const debug = require('debug')('runner');
11
9
  const debugPerf = require('debug')('perf');
@@ -15,7 +13,7 @@ const createPhaser = require('./phases');
15
13
  const createReader = require('./readers');
16
14
  const engineUtil = require('@artilleryio/int-commons').engine_util;
17
15
  const wl = require('./weighted-pick');
18
- const { pathToFileURL } = require('url');
16
+ const { pathToFileURL } = require('node:url');
19
17
 
20
18
  const Engines = {
21
19
  http: require('./engine_http'),
@@ -45,8 +43,8 @@ function loadEngines(
45
43
  ) {
46
44
  const loadedEngines = _.map(
47
45
  Object.assign({}, Engines, script.config.engines),
48
- function loadEngine(engineConfig, engineName) {
49
- let moduleName = 'artillery-engine-' + engineName;
46
+ function loadEngine(_engineConfig, engineName) {
47
+ const moduleName = `artillery-engine-${engineName}`;
50
48
  try {
51
49
  let Engine;
52
50
  if (typeof Engines[engineName] !== 'undefined') {
@@ -103,7 +101,7 @@ async function loadProcessor(script, options) {
103
101
  function prepareScript(script, payload) {
104
102
  const runnableScript = _.cloneDeep(script);
105
103
 
106
- _.each(runnableScript.config.phases, function (phaseSpec) {
104
+ _.each(runnableScript.config.phases, (phaseSpec) => {
107
105
  phaseSpec.mode = phaseSpec.mode || runnableScript.config.mode;
108
106
  });
109
107
 
@@ -121,7 +119,7 @@ function prepareScript(script, payload) {
121
119
  ];
122
120
  } else {
123
121
  runnableScript.config.payload = payload;
124
- _.each(runnableScript.config.payload, function (el) {
122
+ _.each(runnableScript.config.payload, (el) => {
125
123
  el.reader = createReader(el.order, el);
126
124
  });
127
125
  }
@@ -130,7 +128,7 @@ function prepareScript(script, payload) {
130
128
  }
131
129
 
132
130
  // Flatten flows (can have nested arrays of request specs with YAML references):
133
- _.each(runnableScript.scenarios, function (scenarioSpec) {
131
+ _.each(runnableScript.scenarios, (scenarioSpec) => {
134
132
  scenarioSpec.flow = _.flatten(scenarioSpec.flow);
135
133
  });
136
134
 
@@ -138,7 +136,7 @@ function prepareScript(script, payload) {
138
136
  }
139
137
 
140
138
  async function runner(script, payload, options, callback) {
141
- let opts = _.assign(
139
+ const opts = _.assign(
142
140
  {
143
141
  periodicStats: script.config.statsInterval || 30,
144
142
  mode: script.config.mode || 'uniform'
@@ -154,7 +152,7 @@ async function runner(script, payload, options, callback) {
154
152
 
155
153
  const runnableScript = prepareScript(script, payload);
156
154
 
157
- let ee = new EventEmitter();
155
+ const ee = new EventEmitter();
158
156
 
159
157
  //
160
158
  // load engines:
@@ -165,9 +163,9 @@ async function runner(script, payload, options, callback) {
165
163
  warnings
166
164
  );
167
165
 
168
- const promise = new Promise(function (resolve, reject) {
169
- ee.run = function (contextVars) {
170
- let runState = {
166
+ const promise = new Promise((resolve, _reject) => {
167
+ ee.run = (contextVars) => {
168
+ const runState = {
171
169
  pendingScenarios: 0,
172
170
  // pendingRequests: 0,
173
171
  compiledScenarios: null,
@@ -180,7 +178,7 @@ async function runner(script, payload, options, callback) {
180
178
  run(runnableScript, ee, opts, runState, contextVars);
181
179
  };
182
180
 
183
- ee.stop = async function (done) {
181
+ ee.stop = async (_done) => {
184
182
  metrics.stop();
185
183
  };
186
184
 
@@ -202,14 +200,14 @@ function run(script, ee, options, runState, contextVars) {
202
200
  const metrics = runState.metrics;
203
201
  const intermediates = [];
204
202
 
205
- let phaser = createPhaser(script.config.phases);
206
- let scenarioContext;
203
+ const phaser = createPhaser(script.config.phases);
204
+ let _scenarioContext;
207
205
 
208
- phaser.on('arrival', function (spec) {
206
+ phaser.on('arrival', (spec) => {
209
207
  if (runState.pendingScenarios >= spec.maxVusers) {
210
208
  metrics.counter('vusers.skipped', 1);
211
209
  } else {
212
- scenarioContext = runScenario(
210
+ _scenarioContext = runScenario(
213
211
  script,
214
212
  metrics,
215
213
  runState,
@@ -218,13 +216,13 @@ function run(script, ee, options, runState, contextVars) {
218
216
  );
219
217
  }
220
218
  });
221
- phaser.on('phaseStarted', function (spec) {
219
+ phaser.on('phaseStarted', (spec) => {
222
220
  ee.emit('phaseStarted', spec);
223
221
  });
224
- phaser.on('phaseCompleted', function (spec) {
222
+ phaser.on('phaseCompleted', (spec) => {
225
223
  ee.emit('phaseCompleted', spec);
226
224
  });
227
- phaser.on('done', function () {
225
+ phaser.on('done', () => {
228
226
  debug('All phases launched');
229
227
 
230
228
  const doneYet = setInterval(function checkIfDone() {
@@ -242,7 +240,7 @@ function run(script, ee, options, runState, contextVars) {
242
240
  }, 1000);
243
241
  });
244
242
 
245
- metrics.on('metricData', (ts, periodData) => {
243
+ metrics.on('metricData', (_ts, periodData) => {
246
244
  const cloned = SSMS.deserializeMetrics(SSMS.serializeMetrics(periodData));
247
245
  intermediates.push(periodData);
248
246
  ee.emit('stats', cloned);
@@ -258,7 +256,7 @@ function runScenario(script, metrics, runState, contextVars, options) {
258
256
  // Compile scenarios if needed
259
257
  //
260
258
  if (!runState.compiledScenarios) {
261
- _.each(script.scenarios, function (scenario) {
259
+ _.each(script.scenarios, (scenario) => {
262
260
  if (typeof scenario.weight === 'undefined') {
263
261
  scenario.weight = 1;
264
262
  } else {
@@ -272,7 +270,7 @@ function runScenario(script, metrics, runState, contextVars, options) {
272
270
  const w = engineUtil.template(scenario.weight, {
273
271
  vars: variableValues
274
272
  });
275
- scenario.weight = isNaN(parseInt(w)) ? 0 : parseInt(w); //eslint-disable-line radix
273
+ scenario.weight = Number.isNaN(parseInt(w, 10)) ? 0 : parseInt(w, 10);
276
274
  debug(
277
275
  `scenario ${scenario.name} weight has been set to ${scenario.weight}`
278
276
  );
@@ -282,33 +280,33 @@ function runScenario(script, metrics, runState, contextVars, options) {
282
280
  runState.picker = wl(script.scenarios);
283
281
 
284
282
  runState.scenarioEvents = new EventEmitter();
285
- runState.scenarioEvents.on('counter', function (name, value) {
283
+ runState.scenarioEvents.on('counter', (name, value) => {
286
284
  metrics.counter(name, value);
287
285
  });
288
286
  // TODO: Deprecate
289
- runState.scenarioEvents.on('customStat', function (stat) {
287
+ runState.scenarioEvents.on('customStat', (stat) => {
290
288
  metrics.summary(stat.stat, stat.value);
291
289
  });
292
- runState.scenarioEvents.on('summary', function (name, value) {
290
+ runState.scenarioEvents.on('summary', (name, value) => {
293
291
  metrics.summary(name, value);
294
292
  });
295
- runState.scenarioEvents.on('histogram', function (name, value) {
293
+ runState.scenarioEvents.on('histogram', (name, value) => {
296
294
  metrics.summary(name, value);
297
295
  });
298
- runState.scenarioEvents.on('rate', function (name) {
296
+ runState.scenarioEvents.on('rate', (name) => {
299
297
  metrics.rate(name);
300
298
  });
301
- runState.scenarioEvents.on('started', function () {
299
+ runState.scenarioEvents.on('started', () => {
302
300
  runState.pendingScenarios++;
303
301
  });
304
302
  // TODO: Take an object so that it can have code, description etc
305
- runState.scenarioEvents.on('error', function (errCode) {
303
+ runState.scenarioEvents.on('error', (errCode) => {
306
304
  metrics.counter(`errors.${errCode}`, 1);
307
305
  });
308
306
 
309
307
  runState.compiledScenarios = _.map(
310
308
  script.scenarios,
311
- function (scenarioSpec, scenarioIndex) {
309
+ (scenarioSpec, scenarioIndex) => {
312
310
  const name = scenarioSpec.engine || script.config.engine || 'http';
313
311
  const engine = runState.engines.find((e) => e.__name === name);
314
312
 
@@ -377,7 +375,7 @@ function runScenario(script, metrics, runState, contextVars, options) {
377
375
  'runScenarioDelta: %s',
378
376
  Math.round((runScenarioDelta / 1e6) * 100) / 100
379
377
  );
380
- runState.compiledScenarios[i](scenarioContext, function (err, context) {
378
+ runState.compiledScenarios[i](scenarioContext, (err, _context) => {
381
379
  runState.pendingScenarios--;
382
380
  if (err) {
383
381
  debug(err);
@@ -395,15 +393,15 @@ function runScenario(script, metrics, runState, contextVars, options) {
395
393
  }
396
394
 
397
395
  function datafileVariables(script) {
398
- let result = {};
396
+ const result = {};
399
397
  if (script.config.payload) {
400
- _.each(script.config.payload, function (el) {
398
+ _.each(script.config.payload, (el) => {
401
399
  if (!el.loadAll) {
402
400
  // Load individual fields from the CSV into VU context variables
403
401
  // If data = [] (i.e. the CSV file is empty, or only has headers and
404
402
  // skipHeaders = true), then row could = undefined
405
- let row = el.reader(el.data) || [];
406
- _.each(el.fields, function (fieldName, j) {
403
+ const row = el.reader(el.data) || [];
404
+ _.each(el.fields, (fieldName, j) => {
407
405
  result[fieldName] = row[j];
408
406
  });
409
407
  } else {
@@ -423,9 +421,9 @@ function datafileVariables(script) {
423
421
  }
424
422
 
425
423
  function inlineVariables(script) {
426
- let result = {};
424
+ const result = {};
427
425
  if (script.config.variables) {
428
- _.each(script.config.variables, function (v, k) {
426
+ _.each(script.config.variables, (v, k) => {
429
427
  let val;
430
428
  if (_.isArray(v)) {
431
429
  val = _.sample(v);
@@ -473,7 +471,7 @@ function createContext(script, contextVars, additionalProperties = {}) {
473
471
  if (script._scriptPath) {
474
472
  INITIAL_CONTEXT.vars.$scenarioFile = script._scriptPath;
475
473
  }
476
- let result = INITIAL_CONTEXT;
474
+ const result = INITIAL_CONTEXT;
477
475
 
478
476
  // variables from payloads:
479
477
  const variableValues1 = datafileVariables(script);
@@ -516,11 +514,11 @@ function handleScriptHook(hook, script, hookEvents, contextVars = {}) {
516
514
  const { loadedEngines: engines } = loadEngines(script, hookEvents);
517
515
  const ee = new EventEmitter();
518
516
 
519
- return new Promise(function (resolve, reject) {
520
- ee.on('request', function () {
517
+ return new Promise((resolve, reject) => {
518
+ ee.on('request', () => {
521
519
  hookEvents.emit(`${hook}TestRequest`);
522
520
  });
523
- ee.on('error', function (error) {
521
+ ee.on('error', (error) => {
524
522
  hookEvents.emit(`${hook}TestError`, error);
525
523
  });
526
524
 
@@ -537,7 +535,7 @@ function handleScriptHook(hook, script, hookEvents, contextVars = {}) {
537
535
  scenario: script[hook]
538
536
  });
539
537
 
540
- hookScenario(hookContext, function (err, context) {
538
+ hookScenario(hookContext, (err, context) => {
541
539
  if (err) {
542
540
  debug(err);
543
541
  return reject(err);
package/lib/ssms.js CHANGED
@@ -8,10 +8,12 @@
8
8
  // https://github.com/DataDog/sketches-js/pull/13
9
9
  const { DDSketch } = require('@artilleryio/sketches-js');
10
10
  // const {DDSketch} = require('@datadog/sketches-js');
11
- const EventEmitter = require('events');
11
+ const EventEmitter = require('node:events');
12
12
  const { setDriftlessInterval, clearDriftless } = require('driftless');
13
13
  const debug = require('debug')('ssms');
14
14
 
15
+ const MAX_METRIC_NAME_LENGTH = 1024;
16
+
15
17
  class SSMS extends EventEmitter {
16
18
  constructor(_options) {
17
19
  super();
@@ -153,7 +155,7 @@ class SSMS extends EventEmitter {
153
155
  k.match(/^(http|socketio)\.codes.*/)
154
156
  );
155
157
  for (const n of codeNames) {
156
- const code = parseInt(n.split('.codes.')[1]);
158
+ const code = parseInt(n.split('.codes.')[1], 10);
157
159
  result.codes[code] = pd.counters[n];
158
160
  }
159
161
 
@@ -167,9 +169,7 @@ class SSMS extends EventEmitter {
167
169
  }
168
170
 
169
171
  return {
170
- report: function () {
171
- return result;
172
- }
172
+ report: () => result
173
173
  };
174
174
  }
175
175
 
@@ -360,8 +360,6 @@ class SSMS extends EventEmitter {
360
360
  object.histograms[name] = h;
361
361
  }
362
362
 
363
- object.period = object.period;
364
-
365
363
  return object;
366
364
  }
367
365
 
@@ -377,24 +375,32 @@ class SSMS extends EventEmitter {
377
375
 
378
376
  // TODO: Deprecate
379
377
  counter(name, value) {
380
- this.incr(name, value);
378
+ this.incr(name.slice(0, MAX_METRIC_NAME_LENGTH), value);
381
379
  }
382
380
 
383
381
  incr(name, value, t) {
384
- this._counters.push(t || Date.now(), name, value);
382
+ this._counters.push(
383
+ t || Date.now(),
384
+ name.slice(0, MAX_METRIC_NAME_LENGTH),
385
+ value
386
+ );
385
387
  }
386
388
 
387
389
  // TODO: Deprecate
388
390
  summary(name, value) {
389
- this.histogram(name, value);
391
+ this.histogram(name.slice(0, MAX_METRIC_NAME_LENGTH), value);
390
392
  }
391
393
 
392
394
  histogram(name, value, t) {
393
- this._histograms.push(t || Date.now(), name, value);
395
+ this._histograms.push(
396
+ t || Date.now(),
397
+ name.slice(0, MAX_METRIC_NAME_LENGTH),
398
+ value
399
+ );
394
400
  }
395
401
 
396
402
  rate(name, t) {
397
- this._rates.push(t || Date.now(), name);
403
+ this._rates.push(t || Date.now(), name.slice(0, MAX_METRIC_NAME_LENGTH));
398
404
  }
399
405
 
400
406
  getMetrics(period) {
@@ -626,7 +632,7 @@ function summarizeHistogram(h) {
626
632
  min: round(h.min, 1),
627
633
  max: round(h.max, 1),
628
634
  count: h.count,
629
- mean: round(h.sum/h.count, 1),
635
+ mean: round(h.sum / h.count, 1),
630
636
  p50: round(h.getValueAtQuantile(0.5), 1),
631
637
  median: round(h.getValueAtQuantile(0.5), 1), // Here for compatibility
632
638
  p75: round(h.getValueAtQuantile(0.75), 1),
@@ -646,10 +652,10 @@ function parse(text) {
646
652
  return JSON.parse(text, reviver);
647
653
  }
648
654
 
649
- function replacer(key, value) {
655
+ function replacer(_key, value) {
650
656
  if (isBufferLike(value) && isArray(value.data)) {
651
657
  if (value.data.length > 0) {
652
- value.data = 'base64:' + Buffer.from(value.data).toString('base64');
658
+ value.data = `base64:${Buffer.from(value.data).toString('base64')}`;
653
659
  } else {
654
660
  value.data = '';
655
661
  }
@@ -658,7 +664,7 @@ function replacer(key, value) {
658
664
  return value;
659
665
  }
660
666
 
661
- function reviver(key, value) {
667
+ function reviver(_key, value) {
662
668
  if (isBufferLike(value)) {
663
669
  if (isArray(value.data)) {
664
670
  return Buffer.from(value.data);
@@ -2,17 +2,15 @@
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
- 'use strict';
6
-
7
5
  const l = require('lodash');
8
6
 
9
7
  module.exports = create;
10
8
 
11
9
  // naive implementation of selection with replacement
12
10
  function create(list) {
13
- let dist = l.reduce(
11
+ const dist = l.reduce(
14
12
  list,
15
- function (acc, el, i) {
13
+ (acc, el, i) => {
16
14
  for (let j = 0; j < el.weight * 100; j++) {
17
15
  acc.push(i);
18
16
  }
@@ -21,8 +19,8 @@ function create(list) {
21
19
  []
22
20
  );
23
21
 
24
- return function () {
25
- let i = dist[l.random(0, dist.length - 1)];
22
+ return () => {
23
+ const i = dist[l.random(0, dist.length - 1)];
26
24
  return [i, list[i]];
27
25
  };
28
26
  }
@@ -45,11 +43,11 @@ function bench() {
45
43
 
46
44
  const picker = create(items);
47
45
 
48
- const ITERS = Math.pow(10, 6);
46
+ const ITERS = 10 ** 6;
49
47
  const startedAt = Date.now();
50
48
 
51
- const picks = l.map(l.range(ITERS), function () {
52
- let x = picker()[1];
49
+ const picks = l.map(l.range(ITERS), () => {
50
+ const x = picker()[1];
53
51
  return x;
54
52
  });
55
53
 
@@ -61,18 +59,12 @@ function bench() {
61
59
  Math.round(ITERS / delta)
62
60
  );
63
61
 
64
- const sumWeights = l.reduce(
65
- items,
66
- function (acc, item) {
67
- return acc + item.weight;
68
- },
69
- 0
70
- );
62
+ const sumWeights = l.reduce(items, (acc, item) => acc + item.weight, 0);
71
63
 
72
64
  console.log('sumWeights = %s', sumWeights);
73
65
 
74
- l.each(items, function (p) {
75
- let count = l.filter(picks, { value: p.value }).length;
66
+ l.each(items, (p) => {
67
+ const count = l.filter(picks, { value: p.value }).length;
76
68
  console.log(
77
69
  'Count of %s = %s (should be: %s%, is: %s%)',
78
70
  p.value,
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@artilleryio/int-core",
3
- "version": "2.21.0",
3
+ "version": "2.22.0",
4
4
  "main": "./index.js",
5
5
  "license": "MPL-2.0",
6
6
  "dependencies": {
7
- "@artilleryio/int-commons": "2.17.0",
7
+ "@artilleryio/int-commons": "2.18.0",
8
8
  "@artilleryio/sketches-js": "^2.1.1",
9
9
  "agentkeepalive": "^4.1.0",
10
10
  "arrivals": "^2.1.2",
@@ -35,8 +35,8 @@
35
35
  "ws": "^7.5.7"
36
36
  },
37
37
  "scripts": {
38
- "lint": "eslint --ext \".js,.ts,.tsx\" .",
39
- "lint-fix": "npm run lint -- --fix",
38
+ "lint": "npx @biomejs/biome check .",
39
+ "lint-fix": "npx @biomejs/biome check --write .",
40
40
  "test": "npm run test:unit && npm run test:acceptance",
41
41
  "test:unit": "tap --timeout=300 test/unit/*.test.js",
42
42
  "test:acceptance": "tap --timeout 300 test/acceptance/*.test.js && tap --timeout=300 test/acceptance/**/*.test.js"
package/.eslintrc DELETED
@@ -1,46 +0,0 @@
1
- {
2
- "env": {
3
- "node": true,
4
- "es6": true
5
- },
6
- "globals": {
7
- "expect": true
8
- },
9
- "rules": {
10
- // Ignore Rules
11
- "strict": 0,
12
- "no-underscore-dangle": 0,
13
- "no-mixed-requires": 0,
14
- "no-use-before-define": 0,
15
- "no-process-exit": 0,
16
- "no-shadow": 0,
17
-
18
- // Warnings
19
- "no-debugger": 1,
20
- "no-empty": 1,
21
- "no-invalid-regexp": 1,
22
- "no-warning-comments": 1,
23
- "no-unused-expressions": 1,
24
- "no-native-reassign": 1,
25
- "no-fallthrough": 1,
26
- "camelcase": 1,
27
- "no-unused-vars": 1,
28
-
29
- // Errors
30
- "no-undef": 2,
31
- "no-dupe-keys": 2,
32
- "no-empty-character-class": 2,
33
- "no-self-compare": 2,
34
- "valid-typeof": 2,
35
- "handle-callback-err": 2,
36
- "radix": 2,
37
- "no-new-require": 2,
38
- "no-mixed-spaces-and-tabs": 2,
39
-
40
- // stylistic errors
41
- "new-cap": 2,
42
- "no-spaced-func": 2,
43
- "semi-spacing": 2,
44
- "quotes": [1, "single"]
45
- }
46
- }