Skip to content

A package for generating automatic error reports from a k6 log file and displaying them in the console during performance testing.

Notifications You must be signed in to change notification settings

gpiechnik2/k6-errors-reporter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

37 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

k6-errors-reporter

A package for generating automatic error reports from a k6 log file and displaying them in the console during performance testing.

Installation

To install a package, use the command:

npm install -g k6-errors-reporter

Usage

The package can be used in two different ways.

1. Simple error display

For this way, just import and use the checkResponse function. It will display the most important information about the detected error during the test.

import { checkResponse } from 'https://raw.githubusercontent.com/gpiechnik2/k6-errors-reporter/main/dist/bundle.js';


export default function() {
    const res = http.get("https://k6.io")
    const status = check(
        res,
        {
          "response code is 201": (res) => res.status == 201
        }
    )
    checkResponse(res, status) // <----
}

Example log:

ERRO[0002]
  status.....: 412
  status_text: 412 Precondition Failed
  error_code.: Error code that correspond to the HTTP 4xx status codes for client errors
  body.......: {"isHttpError":true,"statusCode":400,"title":"Bad Request","message":"Unauthorized","type":"https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/400","body":{"error_text":"Unauthorized"}}
  request....: GET http://127.0.0.1:3001 |  source=console

2. Redirect the output to a file and generate reports based on it

The second way is a bit more complicated and assumes that we will redirect the displayed logs from the console to a file. This can be done using the command:

k6 run --log-output=file=output.json --log-format=json scenario.js

Next, inside the scenario.js script, let's import the auxiliary function checkResponse, which (compared to the previous usage) will take true as the third argument. This way the checkResponse function knows that we will redirect the logs to a file.

import { checkResponse } from 'https://raw.githubusercontent.com/gpiechnik2/k6-errors-reporter/main/dist/bundle.js';


export default function() {
    const res = http.get("https://k6.io")
    const status = check(
        res,
        {
          "response code is 201": (res) => res.status == 201
        }
    )
    checkResponse(res, status, true) // <----
}

This will create an output.json file. It allows us to generate several reports.

Reports

[IMPORTANT] Generating reports is possible only from the output.json file, which we can create only in the second way.

Html Report

Generate html report based on log file output.json.

k6-errors-reporter generate-html-report output.json report.html

HTML report

Markdown Report

Generate markdown report based on log file output.json.

k6-errors-reporter generate-markdown-report output.json report.md

Markdown report

Console Report

View all detected errors in the console.

k6-errors-reporter show-errors output.json

Report:

$ k6-errors-reporter show-errors output.json

> k6-errors-reporter@1.0.0 start
> node index.js "show-errors" "output.json"

[k6-errors-reporter] Displaying all errors:

[0] Error found
status.....: 507
status_text: 507 Insufficient Storage
error_code.: Error code that correspond to the HTTP 5xx status codes for server errors
body.......: {"isHttpError":true,"statusCode":400,"title":"Bad Request","message":"Web Server is Down","type":"https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/400","body":{"error_text":"Web Server is Down"}}
quantity...: 1
requests...: [{"url":"GET http://127.0.0.1:3001","time":"2022-10-11T22:33:23+02:00"}]

About

A package for generating automatic error reports from a k6 log file and displaying them in the console during performance testing.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published