From 93f8f8eea546be83b8a7014cf73ab82f123a49f8 Mon Sep 17 00:00:00 2001 From: ubuntu Date: Wed, 13 Jan 2021 19:40:11 +0000 Subject: [PATCH 01/10] debug mode --- src/influxdb-reporter.js | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/src/influxdb-reporter.js b/src/influxdb-reporter.js index 6d37e45..b691304 100644 --- a/src/influxdb-reporter.js +++ b/src/influxdb-reporter.js @@ -25,7 +25,9 @@ class InfluxDBReporter { const events = 'start iteration beforeItem item script request test assertion console exception done'.split(' '); events.forEach((e) => { if (typeof this[e] == 'function') newmanEmitter.on(e, (err, args) => this[e](err, args)) }); - // console.log('[+] Reporter Options', reporterOptions); + if (this.reporterOptions.debug) { + console.log('[+] Reporter Options', reporterOptions); + } } start(error, args) { @@ -116,10 +118,15 @@ class InfluxDBReporter { if(error) { this.context.currentItem.data.test_status = 'FAIL'; - const failMessage = `${error.test} | ${error.name}: ${error.message}`; + var failMessage = `${error.test} | ${error.name}`; + if (this.reporterOptions.debug) { + failMessage += `: ${error.message}`; + } this.context.currentItem.data.failed.push(failMessage); this.context.currentItem.data.failed_count++; - this.context.assertions.failed.push(failMessage); // for debug only + if (this.reporterOptions.debug) { + this.context.assertions.failed.push(failMessage); + } } else if(args.skipped) { if(this.context.currentItem.data.test_status !== 'FAIL') { this.context.currentItem.data.test_status = 'SKIP'; @@ -128,31 +135,20 @@ class InfluxDBReporter { const skipMessage = args.assertion; this.context.currentItem.data.skipped.push(args.assertion); this.context.currentItem.data.skipped_count++; - this.context.assertions.skipped.push(skipMessage); // for debug only + if (this.reporterOptions.debug) { + this.context.assertions.skipped.push(skipMessage); + } } } item(error, args) { const binaryData = this.buildPayload(this.context.currentItem.data); - // console.log('binaryData', binaryData); - this.service.sendData(binaryData); } done() { this.service.disconnect(); console.log(`[+] Finished collection: ${this.options.collection.name} (${this.context.id})`); - - // console.log('this.context', this.context); - // console.log('this.options.collection', this.options.collection); - - // this.stream.write(payload); - // this.stream.done(); - - // this.exports.push({ - // name: 'newman-reporter-influxdb', - // options: reporterOptions - // }); } /// Private method starts here From d324d2e9027a66f97ca5f66a152d10fdddd495a6 Mon Sep 17 00:00:00 2001 From: ubuntu Date: Wed, 13 Jan 2021 20:06:28 +0000 Subject: [PATCH 02/10] show reporterOptions --- src/influxdb-reporter.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/influxdb-reporter.js b/src/influxdb-reporter.js index b691304..bb0e0b6 100644 --- a/src/influxdb-reporter.js +++ b/src/influxdb-reporter.js @@ -25,9 +25,7 @@ class InfluxDBReporter { const events = 'start iteration beforeItem item script request test assertion console exception done'.split(' '); events.forEach((e) => { if (typeof this[e] == 'function') newmanEmitter.on(e, (err, args) => this[e](err, args)) }); - if (this.reporterOptions.debug) { - console.log('[+] Reporter Options', reporterOptions); - } + console.log('[+] Reporter Options', reporterOptions); } start(error, args) { From 24f2dac881bd62777aa590b47ba7266f1bf863ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20S=C5=82uszniak?= Date: Wed, 13 Jan 2021 20:35:11 +0000 Subject: [PATCH 03/10] reporterOptions also in debug mode --- src/influxdb-reporter.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/influxdb-reporter.js b/src/influxdb-reporter.js index bb0e0b6..b691304 100644 --- a/src/influxdb-reporter.js +++ b/src/influxdb-reporter.js @@ -25,7 +25,9 @@ class InfluxDBReporter { const events = 'start iteration beforeItem item script request test assertion console exception done'.split(' '); events.forEach((e) => { if (typeof this[e] == 'function') newmanEmitter.on(e, (err, args) => this[e](err, args)) }); - console.log('[+] Reporter Options', reporterOptions); + if (this.reporterOptions.debug) { + console.log('[+] Reporter Options', reporterOptions); + } } start(error, args) { From e80e1a8c4b3704841db956bcc1293ce9f8aa0a0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20S=C5=82uszniak?= Date: Thu, 14 Jan 2021 06:12:27 +0000 Subject: [PATCH 04/10] more debug cases --- src/http.service.js | 11 +++++------ src/influxdb-reporter.js | 14 +++++++------- src/udp.service.js | 8 ++------ 3 files changed, 14 insertions(+), 19 deletions(-) diff --git a/src/http.service.js b/src/http.service.js index 58dfdfa..98bfc54 100644 --- a/src/http.service.js +++ b/src/http.service.js @@ -47,7 +47,7 @@ class HttpService { const res = await this.client.post('/api/v2/signin'); this.client.defaults.headers.common['cookie'] = res.headers['set-cookie']; } catch (error) { - console.log('[-] ERROR: while signing in to InfluxDB', error); + console.log('[-] ERROR: while signing in to InfluxDB', error ? this.context.debug : error.message); } } @@ -56,7 +56,7 @@ class HttpService { try { await this.client.post('/api/v2/signout'); } catch (error) { - console.log('[-] ERROR: while signing out to InfluxDB', error); + console.log('[-] ERROR: while signing out to InfluxDB', error ? this.context.debug : error.message); } } @@ -66,7 +66,7 @@ class HttpService { try { const data = await axios.get(connectionUrl); } catch (error) { - console.log('[-] ERROR: not able to connect to InfluxDB', error); + console.log('[-] ERROR: not able to connect to InfluxDB', error ? this.context.debug : error.message); } } @@ -94,7 +94,7 @@ class HttpService { try { await this.client.post(url, data); } catch (error) { - console.log('[-] ERROR: while sending data to InfluxDB', error); + console.log('[-] ERROR: while sending data to InfluxDB', error ? this.context.debug : error.message); } } @@ -103,7 +103,6 @@ class HttpService { this.signOut(); } } - }; -module.exports = HttpService; \ No newline at end of file +module.exports = HttpService; diff --git a/src/influxdb-reporter.js b/src/influxdb-reporter.js index b691304..7d9c4fd 100644 --- a/src/influxdb-reporter.js +++ b/src/influxdb-reporter.js @@ -20,12 +20,13 @@ class InfluxDBReporter { failed: [], skipped: [] }, - list: [] + list: [], + debug: this.reporterOptions.debug }; const events = 'start iteration beforeItem item script request test assertion console exception done'.split(' '); events.forEach((e) => { if (typeof this[e] == 'function') newmanEmitter.on(e, (err, args) => this[e](err, args)) }); - if (this.reporterOptions.debug) { + if (this.context.debug) { console.log('[+] Reporter Options', reporterOptions); } } @@ -119,12 +120,12 @@ class InfluxDBReporter { this.context.currentItem.data.test_status = 'FAIL'; var failMessage = `${error.test} | ${error.name}`; - if (this.reporterOptions.debug) { + if (this.context.debug) { failMessage += `: ${error.message}`; } this.context.currentItem.data.failed.push(failMessage); this.context.currentItem.data.failed_count++; - if (this.reporterOptions.debug) { + if (this.context.debug) { this.context.assertions.failed.push(failMessage); } } else if(args.skipped) { @@ -135,7 +136,7 @@ class InfluxDBReporter { const skipMessage = args.assertion; this.context.currentItem.data.skipped.push(args.assertion); this.context.currentItem.data.skipped_count++; - if (this.reporterOptions.debug) { + if (this.context.debug) { this.context.assertions.skipped.push(skipMessage); } } @@ -178,7 +179,6 @@ class InfluxDBReporter { .replace(/,/g, '\\,') .replace(/=/g, '\\='); } - }; -module.exports = InfluxDBReporter; \ No newline at end of file +module.exports = InfluxDBReporter; diff --git a/src/udp.service.js b/src/udp.service.js index ba61a08..7da4baa 100644 --- a/src/udp.service.js +++ b/src/udp.service.js @@ -12,9 +12,7 @@ class UdpService { async sendData(data) { try { - this.socket.send(data, this.context.port, this.context.address, (error, response) => { - if(error) { console.log('udp error', error); throw error; @@ -22,16 +20,14 @@ class UdpService { console.log('udp response', response); }); - } catch (error) { - console.log('[-] ERROR: while sending data to InfluxDB', error); + console.log('[-] ERROR: while sending data to InfluxDB', error ? this.context.debug : error.message); } } close() { this.socket.close(); } - }; -module.exports = UdpService; \ No newline at end of file +module.exports = UdpService; From 78c3a3984230183c97fa8207bf990f8e84ee630f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20S=C5=82uszniak?= Date: Thu, 14 Jan 2021 06:26:23 +0000 Subject: [PATCH 05/10] single line if-statement works a bit different --- src/http.service.js | 8 ++++---- src/udp.service.js | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/http.service.js b/src/http.service.js index 98bfc54..d9935d7 100644 --- a/src/http.service.js +++ b/src/http.service.js @@ -47,7 +47,7 @@ class HttpService { const res = await this.client.post('/api/v2/signin'); this.client.defaults.headers.common['cookie'] = res.headers['set-cookie']; } catch (error) { - console.log('[-] ERROR: while signing in to InfluxDB', error ? this.context.debug : error.message); + console.log('[-] ERROR: while signing in to InfluxDB', this.context.debug ? error : error.message); } } @@ -56,7 +56,7 @@ class HttpService { try { await this.client.post('/api/v2/signout'); } catch (error) { - console.log('[-] ERROR: while signing out to InfluxDB', error ? this.context.debug : error.message); + console.log('[-] ERROR: while signing out to InfluxDB', this.context.debug ? error : error.message); } } @@ -66,7 +66,7 @@ class HttpService { try { const data = await axios.get(connectionUrl); } catch (error) { - console.log('[-] ERROR: not able to connect to InfluxDB', error ? this.context.debug : error.message); + console.log('[-] ERROR: not able to connect to InfluxDB', this.context.debug ? error : error.message); } } @@ -94,7 +94,7 @@ class HttpService { try { await this.client.post(url, data); } catch (error) { - console.log('[-] ERROR: while sending data to InfluxDB', error ? this.context.debug : error.message); + console.log('[-] ERROR: while sending data to InfluxDB', this.context.debug ? error : error.message); } } diff --git a/src/udp.service.js b/src/udp.service.js index 7da4baa..d9e465d 100644 --- a/src/udp.service.js +++ b/src/udp.service.js @@ -21,7 +21,7 @@ class UdpService { console.log('udp response', response); }); } catch (error) { - console.log('[-] ERROR: while sending data to InfluxDB', error ? this.context.debug : error.message); + console.log('[-] ERROR: while sending data to InfluxDB', this.context.debug ? error : error.message); } } From e3bf8c5e542848b39a98db2cf71d1b977037becf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20S=C5=82uszniak?= Date: Thu, 14 Jan 2021 07:02:26 +0000 Subject: [PATCH 06/10] readme - debug mode --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index a3df333..a25a9de 100644 --- a/README.md +++ b/README.md @@ -89,6 +89,7 @@ newman run https://www.getpostman.com/collections/631643-f695cab7-6878-eb55-7943 `--reporter-influxdb-username` (*Optional*) | Username created for InfluxDB (e.g. `newman_user`) `--reporter-influxdb-password` (*Optional*) | Password of the user (e.g. `p@ssw0rd`) `--reporter-influxdb-mode` | Transmission Mode `http`, `udp` (default: `http`) +`--reporter-debug` | Reporter debug mode (default: `false`) --- From 4ef4537f594c2677fba813bf8a993f3e35e5b738 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20S=C5=82uszniak?= Date: Thu, 14 Jan 2021 07:40:21 +0000 Subject: [PATCH 07/10] use let instead of var. Fallback values --- src/influxdb-reporter.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/influxdb-reporter.js b/src/influxdb-reporter.js index 7d9c4fd..f6e3dc9 100644 --- a/src/influxdb-reporter.js +++ b/src/influxdb-reporter.js @@ -21,8 +21,9 @@ class InfluxDBReporter { skipped: [] }, list: [], - debug: this.reporterOptions.debug + debug = this.reporterOptions.influxdbDebug || this.reporterOptions.debug || false }; + const events = 'start iteration beforeItem item script request test assertion console exception done'.split(' '); events.forEach((e) => { if (typeof this[e] == 'function') newmanEmitter.on(e, (err, args) => this[e](err, args)) }); @@ -57,7 +58,6 @@ class InfluxDBReporter { throw new Error('[-] ERROR: InfluxDB Database/Bucket Name is missing! Add --reporter-influxdb-name .'); } if (!this.context.measurement) { - // this.context.measurement = `api_results_${new Date().getTime()}`; throw new Error('[-] ERROR: InfluxDB Measurement Name is missing! Add --reporter-influxdb-measurement .'); } if (!this.context.mode) { @@ -119,7 +119,7 @@ class InfluxDBReporter { if(error) { this.context.currentItem.data.test_status = 'FAIL'; - var failMessage = `${error.test} | ${error.name}`; + let failMessage = `${error.test} | ${error.name}`; if (this.context.debug) { failMessage += `: ${error.message}`; } From 33553bc77b2c0b362ffedcc14b90cd1195e31645 Mon Sep 17 00:00:00 2001 From: vs4vijay Date: Thu, 14 Jan 2021 23:12:50 +0530 Subject: [PATCH 08/10] Changes for debug flag --- Makefile | 12 ++++++++++++ src/influxdb-reporter.js | 4 +++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index c764d76..5557166 100644 --- a/Makefile +++ b/Makefile @@ -25,6 +25,18 @@ test-v2: --reporter-influxdb-name viz \ --reporter-influxdb-measurement api_results +test-debug: + newman run https://www.getpostman.com/collections/631643-f695cab7-6878-eb55-7943-ad88e1ccfd65-JsLv -r influxdb \ + --reporter-influxdb-server localhost \ + --reporter-influxdb-port 8086 \ + --reporter-influxdb-org viz \ + --reporter-influxdb-version 2 \ + --reporter-influxdb-username viz \ + --reporter-influxdb-password db123456 \ + --reporter-influxdb-name viz \ + --reporter-influxdb-measurement api_results \ + --reporter-influxdb-debug true + test-failed: newman run test/failed.json -r influxdb \ --reporter-influxdb-server localhost \ diff --git a/src/influxdb-reporter.js b/src/influxdb-reporter.js index f6e3dc9..ab1b060 100644 --- a/src/influxdb-reporter.js +++ b/src/influxdb-reporter.js @@ -21,7 +21,7 @@ class InfluxDBReporter { skipped: [] }, list: [], - debug = this.reporterOptions.influxdbDebug || this.reporterOptions.debug || false + debug: false }; const events = 'start iteration beforeItem item script request test assertion console exception done'.split(' '); @@ -42,6 +42,8 @@ class InfluxDBReporter { this.context.username = this.reporterOptions.influxdbUsername || this.reporterOptions.username; this.context.password = this.reporterOptions.influxdbPassword || this.reporterOptions.password; this.context.mode = this.reporterOptions.influxdbMode || this.reporterOptions.mode; + this.context.debug = this.reporterOptions.influxdbDebug || this.reporterOptions.debug || false; + this.context.debug = this.context.debug === 'true'; if (!this.context.server) { throw new Error('[-] ERROR: InfluxDB Server Address is missing! Add --reporter-influxdb-server .'); From 3c8bc1b47a1937a5db62ea8949d4548be228750b Mon Sep 17 00:00:00 2001 From: vs4vijay Date: Thu, 14 Jan 2021 23:13:03 +0530 Subject: [PATCH 09/10] Bumped to version 2.0.1 --- package-lock.json | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index 6d9c00a..5bae69b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "newman-reporter-influxdb", - "version": "2.0.0", + "version": "2.0.1", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index ff11c20..295a6dd 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "newman-reporter-influxdb", - "version": "2.0.0", + "version": "2.0.1", "description": "Newman Reporter for InfluxDB", "main": "index.js", "scripts": { From da88971266aeb12dc45d990e35afd645f8c235af Mon Sep 17 00:00:00 2001 From: vs4vijay Date: Thu, 14 Jan 2021 23:13:09 +0530 Subject: [PATCH 10/10] Bumped to version 2.0.2 --- package-lock.json | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index 5bae69b..ec2dd56 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "newman-reporter-influxdb", - "version": "2.0.1", + "version": "2.0.2", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 295a6dd..2ae599c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "newman-reporter-influxdb", - "version": "2.0.1", + "version": "2.0.2", "description": "Newman Reporter for InfluxDB", "main": "index.js", "scripts": {