Skip to content

Commit

Permalink
Merge branch 'debug-changes' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
vs4vijay committed Jan 14, 2021
2 parents 354c305 + da88971 commit 4da272e
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 35 deletions.
12 changes: 12 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`)

---

Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "newman-reporter-influxdb",
"version": "2.0.0",
"version": "2.0.2",
"description": "Newman Reporter for InfluxDB",
"main": "index.js",
"scripts": {
Expand Down
11 changes: 5 additions & 6 deletions src/http.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', this.context.debug ? error : error.message);
}
}

Expand All @@ -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', this.context.debug ? error : error.message);
}
}

Expand All @@ -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', this.context.debug ? error : error.message);
}
}

Expand Down Expand Up @@ -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', this.context.debug ? error : error.message);
}
}

Expand All @@ -103,7 +103,6 @@ class HttpService {
this.signOut();
}
}

};

module.exports = HttpService;
module.exports = HttpService;
40 changes: 19 additions & 21 deletions src/influxdb-reporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,16 @@ class InfluxDBReporter {
failed: [],
skipped: []
},
list: []
list: [],
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)) });

// console.log('[+] Reporter Options', reporterOptions);
if (this.context.debug) {
console.log('[+] Reporter Options', reporterOptions);
}
}

start(error, args) {
Expand All @@ -38,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 <server-address>.');
Expand All @@ -54,7 +60,6 @@ class InfluxDBReporter {
throw new Error('[-] ERROR: InfluxDB Database/Bucket Name is missing! Add --reporter-influxdb-name <database-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 <measurement-name>.');
}
if (!this.context.mode) {
Expand Down Expand Up @@ -116,10 +121,15 @@ class InfluxDBReporter {
if(error) {
this.context.currentItem.data.test_status = 'FAIL';

const failMessage = `${error.test} | ${error.name}: ${error.message}`;
let failMessage = `${error.test} | ${error.name}`;
if (this.context.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.context.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';
Expand All @@ -128,31 +138,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.context.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
Expand Down Expand Up @@ -182,7 +181,6 @@ class InfluxDBReporter {
.replace(/,/g, '\\,')
.replace(/=/g, '\\=');
}

};

module.exports = InfluxDBReporter;
module.exports = InfluxDBReporter;
8 changes: 2 additions & 6 deletions src/udp.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,22 @@ 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;
}

console.log('udp response', response);
});

} catch (error) {
console.log('[-] ERROR: while sending data to InfluxDB', error);
console.log('[-] ERROR: while sending data to InfluxDB', this.context.debug ? error : error.message);
}
}

close() {
this.socket.close();
}

};

module.exports = UdpService;
module.exports = UdpService;

0 comments on commit 4da272e

Please sign in to comment.