GithubHelp home page GithubHelp logo

vs4vijay / newman-reporter-influxdb Goto Github PK

View Code? Open in Web Editor NEW
18.0 4.0 3.0 234 KB

Newman Reporter for InfluxDB

License: MIT License

JavaScript 86.31% Makefile 13.69%
newman newman-reporter newman-reporters api api-testing postman postman-test influxdb

newman-reporter-influxdb's Introduction

newman-reporter-influxdb

InfluxDB reporter for Newman that sends the test results information to InfluxDB (1.x, 2.x) which can be used from Grafana to build dashboard.

npm version npm downloads code license npm publish

Getting Started

  1. Install newman
  2. Install newman-reporter-influxdb
  3. Install InfluxDB (Get the server address, port, database name, etc)

Prerequisites

  1. node and npm
  2. newman - npm install -g newman
  3. InfluxDB

Installation

npm install -g newman-reporter-influxdb

Installation should be done globally if newman is installed globally, otherwise install without -g option


Usage

Specify -r influxdb option while running the collection

newman run <collection-url> -r influxdb \
  --reporter-influxdb-server <server-ip> \
  --reporter-influxdb-port <server-port> \
  --reporter-influxdb-name <database-name> \
  --reporter-influxdb-measurement <measurement-name>
  • By default, reporter consider influxdb version 1.x (i.e 1.7, 1.8)
  • In case of InfluxDB version 2, specify version, org and bucket name as well
    • --reporter-influxdb-version 2
    • --reporter-influxdb-org <org-name>
    • --reporter-influxdb-name <bucket-name>

Example:

# For InfluxDB version 1.x

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-name newman_reports \
--reporter-influxdb-measurement api_results

# For InfluxDB version 2.x

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

Options:

Option Remarks
--reporter-influxdb-server IP Address or Host of InfluxDB
--reporter-influxdb-port Port no. (Usually 8086)
--reporter-influxdb-version InfluxDB Version 1, 2 (default 1)
--reporter-influxdb-org InfluxDB Org (For InfluxDB version 2.x)
--reporter-influxdb-port Port no. (Usually 8086)
--reporter-influxdb-name Database name (or Bucket name for InfluxDB version 2.x)
--reporter-influxdb-measurement Measurement Point name (If not provided, then reporter will create measurement with prefix newman_results-<timestamp>)
--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-identifier (Optional) An identifier to be passed to InfluxDB (default: run-${Date.now()})
--reporter-influxdb-mode Transmission Mode http, https, udp (default: http)
--reporter-debug Enable debug mode (default: false)

Compatibility

newman-reporter-influxdb InfluxDB
v1.0.0+ v1.7
v2.0.0+ v1.8, v2.x

Notes:

  • This reporter currently uses InfluxDB HTTP APIs / TCP Protocol to send data

To Do

  • Convert to ES6 based version
  • Folder Structure
  • Username and Password support
  • Include UDP Reporter as well
  • HTTPS Support
  • Add batch operation
  • ESLint / StandardJS
  • CI/CD with Github Actions
  • HealthCheck to InfluxDB
  • Remove axios to make it lightweight
  • Compatibility with InfluxDB 2.x
  • Tests

Development

  • Install Dependencies: npm install
  • To Install Local Package:
    • npm pack
    • npm i -g newman-reporter-<name>.<version>.tgz
    • OR
    • make local-install
  • Run Unit Tests:
  • Run Smoke Tests:
    • make test-v1
    • make test-v2

Development Notes


npm publish --access public

- name: npm publish
        run: |
          LATEST=`npm view . version`
          CURRENT=`cat package.json | jq -r .version`
          if [ "$LATEST" != "$CURRENT" ]
          then
            npm ci
            npm publish
          fi

{
    "scripts": {
        "postpublish" : "PACKAGE_VERSION=$(cat package.json | grep version | head -1 | awk -F: '{ print $2 }' | sed 's/[\",]//g' | tr -d '[[:space:]]') && git tag $PACKAGE_VERSION && git push --tags"
    }
}

PACKAGE_VERSION=$(cat package.json \
  | grep version \
  | head -1 \
  | awk -F: '{ print $2 }' \
  | sed 's/[",]//g' \
  | tr -d '[[:space:]]')

echo $PACKAGE_VERSION

https://img.shields.io/npm/v/newman-reporter-influxdb.svg

<a href="https://www.npmjs.com/package/newman-reporter-influxdb"><img src="https://img.shields.io/npm/v/newman-reporter-influxdb.svg" alt="npm version"></a>
<a href="https://www.npmjs.com/package/newman-reporter-influxdb"><img src="https://img.shields.io/npm/dm/newman-reporter-influxdb.svg" alt="npm downloads"></a>

<img alt="GitHub All Releases" src="https://img.shields.io/github/downloads/vs4vijay/newman-reporter-influxdb/total">


https://nodejs.org/api/http.html#http_http_request_url_options_callback
https://nodejs.dev/making-http-requests-with-nodejs



https://github.com/influxdata/influxdb/blob/1.7/services/udp/README.md
https://docs.influxdata.com/influxdb/v1.7/supported_protocols/udp/


[udp]
  enabled = true
  bind-address = ":8086"
  database = "newman_reports_udp"
  batch-size = 1000
  batch-timeout = “1s”


To write, just send newline separated line protocol over UDP.  Can send one point at a time (not very performant) or send batches.

$ echo "newman_results value=1" > /dev/udp/localhost/8086
$ echo "select * from newman_results" | influx -database newman_reports_udp
Connected to http://localhost:8086 version 1.7
InfluxDB shell 0.9
name: newman_results
---------
time                value
2020-26-06T11:25:15.321527811Z    1

curl -G http://localhost:8086/query --data-urlencode "q=CREATE DATABASE newman_reports"

docker run --name influxdb-1.7 -p 8086:8086 influxdb:1.7
docker run --name influxdb-1.8 -p 8086:8086 influxdb:1.8
docker run --name influxdb-2 -p 8086:8086 quay.io/influxdb/influxdb:v2.0.3

newman-reporter-influxdb's People

Contributors

rbenhaddou avatar renovate-bot avatar renovate[bot] avatar snyk-bot avatar sweep-ai[bot] avatar tomaszsluszniak avatar vs4vijay avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

newman-reporter-influxdb's Issues

Allowing influxdb to called in https

Hey @vs4vijay

I would like to suggest you adding those following features :

  • Allow influx to be called through https protocol

I have actually forked with your repository to add this feature but it would be nice if we can have it directly from yours :

Here's a proposal :

in http.service.js

const axiosOptions = {
      baseURL: `${this.context.mode === "https" ? "https" : "http"}://${this.context.server}:${this.context.port}`
    };

-> It could be done in a different service js file like https.service.js but it would lot of duplicates only to change the protocol

Sweep: Connection with InfluxDB needs Authorization API key, not user/password authentification

Details

Hello
As it is said in the official doc :
"All requests to the InfluxDB v2 API must include an InfluxDB API token."
Therefore, i'm unable to connect with this reporter to my DB.

Is there a workaround?

Thx

Checklist
  • Modify src/http.service.jseaf726b Edit
  • Running GitHub Actions for src/http.service.jsEdit
  • Modify src/http.service.js4fa97d4 Edit
  • Running GitHub Actions for src/http.service.jsEdit
  • Modify src/http.service.jsa3dc928 Edit
  • Running GitHub Actions for src/http.service.jsEdit

400 returned following steps provided

Influx 1.8.4
newman 5.2.2

Follow steps provided in repo, is not successful returned status code 400

newman run .\collection.json -r influxdb --reporter-influxdb-server localhost --reporter-influxdb-port 8086 --reporter-influxdb-name postman --reporter-influxdb-measurement testing  --reporter-influxdb-username admin --reporter-influxdb-password admin

[+] Starting collection: test 1618250141484-0.08094263785491762
[1] Running httpbin post
[+] Finished collection: test (1618250141484-0.08094263785491762)
[-] ERROR: while sending data to InfluxDB Request failed with status code 400

Can query influx from command line
curl -G 'http://localhost:8086/query?pretty=true' --data-urlencode "db=postman" --data-urlencode "q=show measurements" { "results": [ { "statement_id": 0 } ] }

Allow passing an identifier to influxdb to search for specific report afterwards

Hey @vs4vijay

I would like to suggest you adding this following feature :

  • Allow passing an identifier to influxdb to search for specific report afterwards

I have actually forked with your repository to add this feature but it would be nice if we can have it directly from yours :

Here's a proposal :

in influxdb.reporter.js

this.context.identifier = this.reporterOptions.influxdbIdentifier || this.reporterOptions.identifier;

Then used here in request event method :

const data = {
      collection_name: this.options.collection.name, 
      id: this.context.identifier,
      // ....
}

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

github-actions
.github/workflows/ci.yml
  • actions/checkout v2
  • actions/setup-node v2
  • actions/upload-artifact v4
  • actions/download-artifact v4
  • softprops/action-gh-release v2
  • actions/download-artifact v4
  • actions/setup-node v2
  • actions/download-artifact v4
  • actions/setup-node v2
.github/workflows/npm-publish.yml
  • actions/checkout v2
  • actions/setup-node v2
  • actions/checkout v2
  • actions/setup-node v2
  • actions/checkout v2
  • actions/setup-node v2
.github/workflows/pr-guardrails.yml
  • actions/checkout v2
  • actions/setup-node v2
npm
package.json
  • axios ^0.21.1
  • jest ^26.6.3

  • Check this box to trigger a request for Renovate to run again on this repository

Cannot read properties of undefined (reading 'status') at InfluxDBReporter.request \AppData\Roaming\npm\node_modules\newman-reporter-influxdb\src\influxdb-reporter.js:96:29

Details

Hi @vs4vijay, hope you are doing well. Currently i am facing an issue while running a postman collection using newman-influxdb-reporter.
I have used the below command:

newman run \Downloads\OrderServ\Basket\BasketCollection -e \Downloads\OrderServ\Basket\BasketEnvDesktopWeb -r influxdb --reporter-influxdb-server {server-ip-address}} --reporter-influxdb-mode http --reporter-influxdb-port 8086 --reporter-influxdb-org {org-name} --reporter-influxdb-version 2 --reporter-influxdb-username {user-name} --reporter-influxdb-password {password} --reporter-influxdb-name {bucket} --reporter-influxdb-measurement api_results

but i am getting the below error:

Starting collection: Orderserv Basket Management 1706014994995-0.031766501297362026
[+] Signing In to InfluxDB
\AppData\Roaming\npm\node_modules\newman-reporter-influxdb\src\influxdb-reporter.js:96
status: args.response.status,
^

TypeError: Cannot read properties of undefined (reading 'status')
at InfluxDBReporter.request \AppData\Roaming\npm\node_modules\newman-reporter-influxdb\src\influxdb-reporter.js:96:29)
at EventEmitter. (\AppData\Roaming\npm\node_modules\newman-reporter-influxdb\src\influxdb-reporter.js:28:105)
at EventEmitter.emit (node:events:525:35)
at Function.callbacks. [as request] (\AppData\Roaming\npm\node_modules\newman\lib\run\index.js:213:34)
at afterRequest (\AppData\Roaming\npm\node_modules\newman\node_modules\postman-runtime\lib\runner\extensions\http-request.command.js:86:35)
at \AppData\Roaming\npm\node_modules\newman\node_modules\postman-runtime\lib\runner\extensions\http-request.command.js:173:25
at onEnd (\AppData\Roaming\npm\node_modules\newman\node_modules\postman-runtime\lib\requester\requester.js:274:24)
at Request._callback (\AppData\Roaming\npm\node_modules\newman\node_modules\postman-runtime\lib\requester\requester.js:449:24)
at self.callback (\AppData\Roaming\npm\node_modules\newman\node_modules\postman-request\request.js:311:12)
at Request.emit (node:events:513:28)
at Request.onRequestError (\AppData\Roaming\npm\node_modules\newman\node_modules\postman-request\request.js:1199:8)
at ClientRequest.emit (node:events:513:28)
at Socket.socketErrorListener (node:_http_client:481:9)
at Socket.emit (node:events:513:28)
at emitErrorNT (node:internal/streams/destroy:157:8)
at emitErrorCloseNT (node:internal/streams/destroy:122:3)

Kindly assist in resolving the issue.

Checklist
  • Modify src/influxdb-reporter.jsdecd6d8 Edit
  • Running GitHub Actions for src/influxdb-reporter.jsEdit

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.