@artilleryio/int-core 1.0.0 → 2.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 CHANGED
@@ -1,10 +1,8 @@
1
1
  const EventEmitter = require('events');
2
2
  const chalk = require('chalk');
3
3
 
4
- const { createGlobalObject } = require('../artillery/lib/artillery-global');
5
-
6
4
  // NOTE: This may be called more than once, and so should be non-destructive
7
- async function updateGlobalObject(opts) {
5
+ async function updateGlobalObject(opts = {}) {
8
6
  global.artillery = global.artillery || {};
9
7
 
10
8
  global.artillery.runtimeOptions = global.artillery.runtimeOptions || {};
@@ -57,10 +55,28 @@ async function updateGlobalObject(opts) {
57
55
  }
58
56
  });
59
57
  }
58
+
59
+ global.artillery.logger = global.artillery.logger || function (opts) {
60
+ return {
61
+ log: (...args) => {
62
+ global.artillery.globalEvents.emit('log', opts, ...args);
63
+ }
64
+ };
65
+ };
66
+
67
+ global.artillery.log = global.artillery.log || function (...args) {
68
+ global.artillery.globalEvents.emit('log', {}, ...args);
69
+ };
70
+
71
+ if (opts.version) {
72
+ global.artillery.version = opts.version;
73
+ }
74
+ if (opts.telemetry) {
75
+ global.artillery.telemetry = opts.telemetry;
76
+ }
60
77
  }
61
78
 
62
79
  async function main() {
63
- await createGlobalObject();
64
80
  await updateGlobalObject();
65
81
  }
66
82
 
@@ -26,6 +26,8 @@ const decompressResponse = require('decompress-response');
26
26
 
27
27
  const { promisify } = require('node:util');
28
28
 
29
+ const crypto = require('node:crypto');
30
+
29
31
  module.exports = HttpEngine;
30
32
 
31
33
  const DEFAULT_AGENT_OPTIONS = {
@@ -534,6 +536,7 @@ HttpEngine.prototype.step = function step(requestSpec, ee, opts) {
534
536
  let haveFailedCaptures = false;
535
537
 
536
538
  if (result !== null) {
539
+ ee.emit('trace:http:capture', result, uuid);
537
540
  if (
538
541
  Object.keys(result.matches).length > 0 ||
539
542
  Object.keys(result.captures).length > 0
@@ -651,13 +654,16 @@ HttpEngine.prototype.step = function step(requestSpec, ee, opts) {
651
654
 
652
655
  requestParams.retry = 0; // disable retries - ignored when using streams
653
656
 
657
+ const uuid = crypto.randomUUID();
654
658
  request(requestParams)
655
659
  .on('request', function (req) {
660
+ ee.emit('trace:http:request', requestParams, uuid);
661
+
656
662
  debugRequests('request start: %s', req.path);
657
663
  ee.emit('counter', 'http.requests', 1);
658
664
  ee.emit('rate', 'http.request_rate');
659
665
  req.on('response', function (res) {
660
-
666
+ ee.emit('trace:http:response', res, uuid);
661
667
  self._handleResponse(
662
668
  requestParams,
663
669
  res,
@@ -670,6 +676,7 @@ HttpEngine.prototype.step = function step(requestSpec, ee, opts) {
670
676
 
671
677
  })
672
678
  .on('error', function (err, body, res) {
679
+ ee.emit('trace:http:error', err, uuid);
673
680
  if (err.name === 'HTTPError') {
674
681
  return;
675
682
  }
package/lib/phases.js CHANGED
@@ -97,7 +97,10 @@ function createRamp(spec, ee) {
97
97
  const arrivalRate = spec.arrivalRate;
98
98
  const rampTo = spec.rampTo;
99
99
 
100
- const tick = 1000 / Math.max(arrivalRate, rampTo); // smallest tick
100
+ // smallest tick we can get away with. Both arrivalRate and rampTo
101
+ // can be zero. So in that case we use 1s ticks even tho no
102
+ // arrivals will be generated
103
+ let tick = 1000 / Math.max(Math.max(arrivalRate, rampTo), 1);
101
104
  const difference = rampTo - arrivalRate;
102
105
  const periods = duration * 1000 / tick;
103
106
 
@@ -107,7 +110,7 @@ function createRamp(spec, ee) {
107
110
  // Anything under function value should be an arrival
108
111
 
109
112
  let t = currentStep * tick / 1000;
110
- return ((difference / duration) * t + arrivalRate) / Math.max(rampTo, arrivalRate);
113
+ return ((difference / duration) * t + arrivalRate) / Math.max(rampTo, arrivalRate) || 0;
111
114
  };
112
115
 
113
116
  let probabilities = Array.from({length: periods}, () => Math.random());
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@artilleryio/int-core",
3
- "version": "1.0.0",
3
+ "version": "2.0.0",
4
4
  "main": "./index.js",
5
5
  "dependencies": {
6
6
  "@artilleryio/sketches-js": "^1.0.4",