@wdio/sumologic-reporter 9.32.0-alpha.6 → 9.32.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/README.md CHANGED
@@ -38,6 +38,9 @@ module.exports = {
38
38
  ['sumologic', {
39
39
  // define sync interval how often logs get pushed to Sumologic
40
40
  syncInterval: 100,
41
+ maxRetries: 5,
42
+ requestTimeout: 30000,
43
+ shutdownTimeout: 4000,
41
44
  // endpoint of collector source
42
45
  sourceAddress: process.env.SUMO_SOURCE_ADDRESS
43
46
  }]
@@ -46,6 +49,14 @@ module.exports = {
46
49
  };
47
50
  ```
48
51
 
52
+ ### Delivery behaviour
53
+
54
+ Each collector request is limited to a positive `requestTimeout` in milliseconds (default: `30000`); non-positive or invalid values use the default. Transient failures — network errors, `408`, `429`, and `5xx` responses — are retried with backoff. `maxRetries` counts retries after the initial delivery attempt and defaults to `5`. A successful batch resets the retry counter.
55
+
56
+ Other unsuccessful HTTP responses disable the reporter immediately. When its retry limit is reached, the reporter stops its timer and discards its remaining queued logs. Delivery is best effort: logs may be lost, and retries can produce duplicates if the collector accepts a request before it times out.
57
+
58
+ After `runner:end`, `shutdownTimeout` limits the total time for remaining delivery attempts (default: `4000` milliseconds). Successful batches do not reset this deadline. When it expires, the reporter aborts the active request, stops its timers, discards pending logs, and logs their count. Non-positive or invalid values use the default; positive finite values are rounded up and capped at `2147483647`. Keep `shutdownTimeout` below WebdriverIO's `reporterSyncTimeout` (default: `5000`), with enough margin for `reporterSyncInterval` polling. A longer shutdown budget may require increasing both options. The shutdown deadline may expire before all configured retries are used.
59
+
49
60
  After running the first tests with the reporter you should be able to check out the tests logs with the following query:
50
61
 
51
62
  ```
package/build/index.d.ts CHANGED
@@ -6,10 +6,16 @@ import type { Options } from './types.js';
6
6
  */
7
7
  export default class SumoLogicReporter extends WDIOReporter {
8
8
  private _options;
9
- private _interval;
9
+ private _interval?;
10
+ private _shutdownTimer?;
11
+ private _requestController?;
10
12
  private _unsynced;
11
13
  private _isSynchronising;
14
+ private _isDisabled;
12
15
  private _hasRunnerEnd;
16
+ private _retryAttempts;
17
+ private _retryDelay;
18
+ private _nextRetryAt;
13
19
  constructor(options: Options);
14
20
  get isSynchronised(): boolean;
15
21
  onRunnerStart(runner: RunnerStats): void;
@@ -22,6 +28,13 @@ export default class SumoLogicReporter extends WDIOReporter {
22
28
  onSuiteEnd(suite: SuiteStats): void;
23
29
  onRunnerEnd(runner: RunnerStats): void;
24
30
  sync(): Promise<void>;
31
+ private _isRetryableStatus;
32
+ private _retry;
33
+ private _getMaxRetries;
34
+ private _getRequestTimeout;
35
+ private _disable;
36
+ private _getShutdownTimeout;
37
+ private _stopInterval;
25
38
  }
26
39
  export * from './types.js';
27
40
  declare global {
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AACxE,OAAO,YAAY,MAAM,gBAAgB,CAAA;AAGzC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;AA4BzC;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,iBAAkB,SAAQ,YAAY;IACvD,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,SAAS,CAAgB;IAEjC,OAAO,CAAC,SAAS,CAAe;IAChC,OAAO,CAAC,gBAAgB,CAAQ;IAChC,OAAO,CAAC,aAAa,CAAQ;gBAEjB,OAAO,EAAE,OAAO;IAmB5B,IAAI,cAAc,YAEjB;IAED,aAAa,CAAC,MAAM,EAAE,WAAW;IAQjC,YAAY,CAAC,KAAK,EAAE,UAAU;IAQ9B,WAAW,CAAC,IAAI,EAAE,SAAS;IAQ3B,UAAU,CAAC,IAAI,EAAE,SAAS;IAQ1B,UAAU,CAAC,IAAI,EAAE,SAAS;IAQ1B,UAAU,CAAC,IAAI,EAAE,SA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AC,IAAI,EAAE,SAAS;IAYzB,UAAU,CAAC,KAAK,EAAE,UAAU;IAY5B,WAAW,CAAC,MAAM,EAAE,WAAW;IAkBzB,IAAI;IA0FV,OAAO,CAAC,kBAAkB;IAI1B,OAAO,CAAC,MAAM;IAkBd,OAAO,CAAC,cAAc;IAOtB,OAAO,CAAC,kBAAkB;IAO1B,OAAO,CAAC,QAAQ;IAShB,OAAO,CAAC,mBAAmB;IAO3B,OAAO,CAAC,aAAa;CAUxB;AAED,cAAc,YAAY,CAAA;AAE1B,OAAO,CAAC,MAAM,CAAC;IACX,UAAU,WAAW,CAAC;QAClB,UAAU,cAAe,SAAQ,OAAO;SAAG;KAC9C;CACJ"}
package/build/index.js CHANGED
@@ -4,6 +4,11 @@ import WDIOReporter from "@wdio/reporter";
4
4
  import logger from "@wdio/logger";
5
5
  var log = logger("@wdio/sumologic-reporter");
6
6
  var MAX_LINES = 100;
7
+ var MAX_RETRY_DELAY = 1e3;
8
+ var DEFAULT_MAX_RETRIES = 5;
9
+ var DEFAULT_REQUEST_TIMEOUT = 3e4;
10
+ var DEFAULT_SHUTDOWN_TIMEOUT = 4e3;
11
+ var MAX_REQUEST_TIMEOUT = 2147483647;
7
12
  function formatDate(date) {
8
13
  const year = date.getFullYear();
9
14
  const month = String(date.getMonth() + 1).padStart(2, "0");
@@ -22,9 +27,15 @@ function formatDate(date) {
22
27
  var SumoLogicReporter = class extends WDIOReporter {
23
28
  _options;
24
29
  _interval;
30
+ _shutdownTimer;
31
+ _requestController;
25
32
  _unsynced = [];
26
33
  _isSynchronising = false;
34
+ _isDisabled = false;
27
35
  _hasRunnerEnd = false;
36
+ _retryAttempts = 0;
37
+ _retryDelay = 0;
38
+ _nextRetryAt = 0;
28
39
  constructor(options) {
29
40
  super(options);
30
41
  this._options = Object.assign({
@@ -35,16 +46,20 @@ var SumoLogicReporter = class extends WDIOReporter {
35
46
  // endpoint of collector source
36
47
  sourceAddress: process.env.SUMO_SOURCE_ADDRESS
37
48
  }, options);
38
- if (typeof this._options.sourceAddress !== "string") {
39
- log.error('Sumo Logic requires "sourceAddress" paramater');
49
+ if (typeof this._options.sourceAddress !== "string" || this._options.sourceAddress.trim() === "") {
50
+ this._disable('Sumo Logic reporter disabled: a non-empty "sourceAddress" is required');
51
+ return;
40
52
  }
41
53
  this._interval = global.setInterval(this.sync.bind(this), this._options.syncInterval);
42
54
  }
43
55
  // @ts-ignore
44
56
  get isSynchronised() {
45
- return this._unsynced.length === 0;
57
+ return this._isDisabled || this._unsynced.length === 0;
46
58
  }
47
59
  onRunnerStart(runner) {
60
+ if (this._isDisabled) {
61
+ return;
62
+ }
48
63
  this._unsynced.push(stringify({
49
64
  time: formatDate(/* @__PURE__ */ new Date()),
50
65
  event: "runner:start",
@@ -52,6 +67,9 @@ var SumoLogicReporter = class extends WDIOReporter {
52
67
  }));
53
68
  }
54
69
  onSuiteStart(suite) {
70
+ if (this._isDisabled) {
71
+ return;
72
+ }
55
73
  this._unsynced.push(stringify({
56
74
  time: formatDate(/* @__PURE__ */ new Date()),
57
75
  event: "suite:start",
@@ -59,6 +77,9 @@ var SumoLogicReporter = class extends WDIOReporter {
59
77
  }));
60
78
  }
61
79
  onTestStart(test) {
80
+ if (this._isDisabled) {
81
+ return;
82
+ }
62
83
  this._unsynced.push(stringify({
63
84
  time: formatDate(/* @__PURE__ */ new Date()),
64
85
  event: "test:start",
@@ -66,6 +87,9 @@ var SumoLogicReporter = class extends WDIOReporter {
66
87
  }));
67
88
  }
68
89
  onTestSkip(test) {
90
+ if (this._isDisabled) {
91
+ return;
92
+ }
69
93
  this._unsynced.push(stringify({
70
94
  time: formatDate(/* @__PURE__ */ new Date()),
71
95
  event: "test:skip",
@@ -73,6 +97,9 @@ var SumoLogicReporter = class extends WDIOReporter {
73
97
  }));
74
98
  }
75
99
  onTestPass(test) {
100
+ if (this._isDisabled) {
101
+ return;
102
+ }
76
103
  this._unsynced.push(stringify({
77
104
  time: formatDate(/* @__PURE__ */ new Date()),
78
105
  event: "test:pass",
@@ -80,6 +107,9 @@ var SumoLogicReporter = class extends WDIOReporter {
80
107
  }));
81
108
  }
82
109
  onTestFail(test) {
110
+ if (this._isDisabled) {
111
+ return;
112
+ }
83
113
  this._unsynced.push(stringify({
84
114
  time: formatDate(/* @__PURE__ */ new Date()),
85
115
  event: "test:fail",
@@ -87,6 +117,9 @@ var SumoLogicReporter = class extends WDIOReporter {
87
117
  }));
88
118
  }
89
119
  onTestEnd(test) {
120
+ if (this._isDisabled) {
121
+ return;
122
+ }
90
123
  this._unsynced.push(stringify({
91
124
  time: formatDate(/* @__PURE__ */ new Date()),
92
125
  event: "test:end",
@@ -94,6 +127,9 @@ var SumoLogicReporter = class extends WDIOReporter {
94
127
  }));
95
128
  }
96
129
  onSuiteEnd(suite) {
130
+ if (this._isDisabled) {
131
+ return;
132
+ }
97
133
  this._unsynced.push(stringify({
98
134
  time: formatDate(/* @__PURE__ */ new Date()),
99
135
  event: "suite:end",
@@ -102,32 +138,125 @@ var SumoLogicReporter = class extends WDIOReporter {
102
138
  }
103
139
  onRunnerEnd(runner) {
104
140
  this._hasRunnerEnd = true;
141
+ if (this._isDisabled) {
142
+ return;
143
+ }
105
144
  this._unsynced.push(stringify({
106
145
  time: formatDate(/* @__PURE__ */ new Date()),
107
146
  event: "runner:end",
108
147
  data: runner
109
148
  }));
149
+ if (!this._shutdownTimer) {
150
+ this._shutdownTimer = setTimeout(() => {
151
+ this._disable(`Sumo Logic reporter shutdown timeout reached; discarding ${this._unsynced.length} queued events`);
152
+ }, this._getShutdownTimeout());
153
+ }
110
154
  }
111
155
  async sync() {
156
+ if (this._isDisabled) {
157
+ return;
158
+ }
112
159
  if (this._hasRunnerEnd && this._unsynced.length === 0) {
113
- clearInterval(this._interval);
160
+ this._stopInterval();
161
+ return;
162
+ }
163
+ if (this._isSynchronising || this._unsynced.length === 0 || Date.now() < this._nextRetryAt) {
164
+ return;
114
165
  }
115
- if (this._isSynchronising || this._unsynced.length === 0 || typeof this._options.sourceAddress !== "string") {
166
+ const sourceAddress = this._options.sourceAddress;
167
+ if (typeof sourceAddress !== "string" || sourceAddress.trim() === "") {
168
+ this._disable('Sumo Logic reporter disabled: a non-empty "sourceAddress" is required');
116
169
  return;
117
170
  }
118
171
  const logLines = this._unsynced.slice(0, MAX_LINES).join("\n");
119
172
  this._isSynchronising = true;
120
173
  log.debug("start synchronization");
174
+ const controller = new AbortController();
175
+ this._requestController = controller;
176
+ const requestTimer = setTimeout(() => controller.abort(), this._getRequestTimeout());
121
177
  try {
122
- const resp = await fetch(this._options.sourceAddress, {
178
+ const resp = await fetch(sourceAddress, {
123
179
  method: "POST",
124
- body: JSON.stringify(logLines)
180
+ body: JSON.stringify(logLines),
181
+ signal: controller.signal
125
182
  });
183
+ if (this._isDisabled) {
184
+ return;
185
+ }
186
+ if (!resp.ok) {
187
+ if (!this._isRetryableStatus(resp.status)) {
188
+ this._disable(`failed to send data to Sumo Logic (HTTP ${resp.status}); disabling reporter`);
189
+ return;
190
+ }
191
+ this._retry(resp.status);
192
+ return;
193
+ }
194
+ this._retryAttempts = 0;
195
+ this._retryDelay = 0;
196
+ this._nextRetryAt = 0;
126
197
  this._unsynced.splice(0, MAX_LINES);
127
- this._isSynchronising = false;
198
+ if (this._hasRunnerEnd && this._unsynced.length === 0) {
199
+ this._stopInterval();
200
+ }
128
201
  return log.debug(`synchronised collector data, server status: ${resp.status}`);
129
- } catch (err) {
130
- return log.error("failed send data to Sumo Logic:\n", err.stack);
202
+ } catch {
203
+ if (!this._isDisabled) {
204
+ this._retry();
205
+ }
206
+ } finally {
207
+ clearTimeout(requestTimer);
208
+ controller.abort();
209
+ this._requestController = void 0;
210
+ this._isSynchronising = false;
211
+ }
212
+ }
213
+ _isRetryableStatus(status) {
214
+ return status === 408 || status === 429 || status >= 500 && status <= 599;
215
+ }
216
+ _retry(status) {
217
+ const maxRetries = this._getMaxRetries();
218
+ if (this._retryAttempts >= maxRetries) {
219
+ const statusMessage2 = status === void 0 ? "" : ` (HTTP ${status})`;
220
+ this._disable(`failed to send data to Sumo Logic${statusMessage2}; retry limit of ${maxRetries} reached, disabling reporter`);
221
+ return;
222
+ }
223
+ this._retryAttempts++;
224
+ this._retryDelay = Math.min(
225
+ Math.max(this._options.syncInterval ?? 100, this._retryDelay * 2),
226
+ MAX_RETRY_DELAY
227
+ );
228
+ this._nextRetryAt = Date.now() + this._retryDelay;
229
+ const statusMessage = status === void 0 ? "" : ` (HTTP ${status})`;
230
+ log.error(`failed to send data to Sumo Logic${statusMessage}; retrying (${this._retryAttempts}/${maxRetries})`);
231
+ }
232
+ _getMaxRetries() {
233
+ const { maxRetries } = this._options;
234
+ return typeof maxRetries === "number" && Number.isFinite(maxRetries) && maxRetries >= 0 ? Math.floor(maxRetries) : DEFAULT_MAX_RETRIES;
235
+ }
236
+ _getRequestTimeout() {
237
+ const { requestTimeout } = this._options;
238
+ return typeof requestTimeout === "number" && Number.isFinite(requestTimeout) && requestTimeout > 0 ? Math.min(Math.ceil(requestTimeout), MAX_REQUEST_TIMEOUT) : DEFAULT_REQUEST_TIMEOUT;
239
+ }
240
+ _disable(message) {
241
+ this._isDisabled = true;
242
+ this._unsynced = [];
243
+ this._nextRetryAt = 0;
244
+ this._stopInterval();
245
+ this._requestController?.abort();
246
+ log.error(message);
247
+ }
248
+ _getShutdownTimeout() {
249
+ const { shutdownTimeout } = this._options;
250
+ return typeof shutdownTimeout === "number" && Number.isFinite(shutdownTimeout) && shutdownTimeout > 0 ? Math.min(Math.ceil(shutdownTimeout), MAX_REQUEST_TIMEOUT) : DEFAULT_SHUTDOWN_TIMEOUT;
251
+ }
252
+ _stopInterval() {
253
+ if (this._shutdownTimer) {
254
+ clearTimeout(this._shutdownTimer);
255
+ this._shutdownTimer = void 0;
256
+ }
257
+ if (this._interval) {
258
+ clearInterval(this._interval);
259
+ this._interval = void 0;
131
260
  }
132
261
  }
133
262
  };
package/build/types.d.ts CHANGED
@@ -5,6 +5,25 @@ export interface Options extends Partial<Reporters.Options> {
5
5
  * @default 100
6
6
  */
7
7
  syncInterval?: number;
8
+ /**
9
+ * maximum number of retries after the initial delivery attempt
10
+ * non-negative finite values are rounded down; all other values use the default
11
+ * @default 5
12
+ */
13
+ maxRetries?: number;
14
+ /**
15
+ * maximum time in milliseconds to wait for a collector response
16
+ * positive finite values are rounded up and capped at 2147483647; all other values use the default
17
+ * @default 30000
18
+ */
19
+ requestTimeout?: number;
20
+ /**
21
+ * total time in milliseconds to flush queued events after runner:end, including requests and retries
22
+ * keep below WebdriverIO's reporterSyncTimeout, allowing time for its polling interval
23
+ * positive finite values are rounded up and capped at 2147483647; all other values use the default
24
+ * @default 4000
25
+ */
26
+ shutdownTimeout?: number;
8
27
  /**
9
28
  * endpoint of collector source
10
29
  * @default
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAE5C,MAAM,WAAW,OAAQ,SAAQ,OAAO,CAAC,SAAS,CAAC,OAAO,CAAC;IACvD;;;OAGG;IACH,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB;;;;;;OAMG;IACH,aAAa,CAAC,EAAE,MAAM,CAAA;CACzB"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAE5C,MAAM,WAAW,OAAQ,SAAQ,OAAO,CAAC,SAAS,CAAC,OAAO,CAAC;IACvD;;;OAGG;IACH,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB;;;;OAIG;IACH,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB;;;;OAIG;IACH,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB;;;;;OAKG;IACH,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB;;;;;;OAMG;IACH,aAAa,CAAC,EAAE,MAAM,CAAA;CACzB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wdio/sumologic-reporter",
3
- "version": "9.32.0-alpha.6+3d8818a67",
3
+ "version": "9.32.0",
4
4
  "description": "A WebdriverIO reporter that sends test results to Sumologic for data analyses",
5
5
  "author": "Christian Bromann <mail@bromann.dev>",
6
6
  "homepage": "https://github.com/webdriverio/webdriverio/tree/main/packages/wdio-sumologic-reporter",
@@ -32,9 +32,9 @@
32
32
  },
33
33
  "typeScriptVersion": "3.8.3",
34
34
  "dependencies": {
35
- "@wdio/logger": "9.32.0-alpha.6+3d8818a67",
36
- "@wdio/reporter": "9.32.0-alpha.6+3d8818a67",
37
- "@wdio/types": "9.32.0-alpha.6+3d8818a67",
35
+ "@wdio/logger": "9.29.1",
36
+ "@wdio/reporter": "9.32.0",
37
+ "@wdio/types": "9.32.0",
38
38
  "json-stringify-safe": "^5.0.1"
39
39
  },
40
40
  "devDependencies": {
@@ -43,5 +43,5 @@
43
43
  "publishConfig": {
44
44
  "access": "public"
45
45
  },
46
- "gitHead": "3d8818a67404f0b5d4b81eda877ffad1f4d317c0"
46
+ "gitHead": "5c2a318d9a5e8424a2f2de95df9374b89bda7936"
47
47
  }