How to include HTTP status message in the output of --summary-export

I am using “–summary-export” to export the test results in JSON format. However, I cannot figure out how to include the status code (200,302,400 etc.) in the output.

Is there a way to achieve this? I tried adding “STATUS=true” at the beginning of “k6 run” command but had no luck.

Thanks,

Hi @ttrading,

I think what you want is for some metrics to be grouped by status code? This is currently not supported as … well it isn’t supported in the summary as well and the --summary-export is just the text summary at the end in a JSON format for easier parsing using by machines.

I would recommend using one of the result outputs and calculating it based on the metrics that are actually emitted. There is for example a JSON output which has all the metrics not just the aggregation that is in the summary export (which is also in JSON :wink: )

A hackish way that I do not recommend for reasons of it will make k6 heavier and is way too hackish is to define a threshold based on the status, which will lead to it both be in the text and exported(JSON) summary, example:

import http from "k6/http";

export let options = {
    thresholds: {
        "http_reqs{status:200}": ["count>1"],
        "http_reqs{status:201}": ["count>1"],
        "http_reqs{status:202}": ["count>1"],
        "http_reqs{status:203}": ["count>1"],
    },
};

// from https://jslib.k6.io/k6-utils/1.0.0/index.js
export function randomIntBetween(min, max) { // min and max included
      return Math.floor(Math.random() * (max - min + 1) + min);
}

export default function() {
    http.get("https://httpbin.test.k6.io/status/" + randomIntBetween(200,203));
}

will result in there being the following lines in the export:

        "http_reqs{status:200}": {
            "count": 21,
            "rate": 13.733594390128046,
            "thresholds": {
                "count>1": false
            }
        },
        "http_reqs{status:201}": {
            "count": 29,
            "rate": 18.965439872081586,
            "thresholds": {
                "count>1": false
            }
        },
        "http_reqs{status:202}": {
            "count": 24,
            "rate": 15.695536445860624,
            "thresholds": {
                "count>1": false
            }
        },
        "http_reqs{status:203}": {
            "count": 26,
            "rate": 17.003497816349007,
            "thresholds": {
                "count>1": false
            }
        },

And the following in the summary output

    http_reqs..................: 100   65.398069/s
    ✓ { status:200 }...........: 21    13.733594/s
    ✓ { status:201 }...........: 29    18.96544/s
    ✓ { status:202 }...........: 24    15.695536/s
    ✓ { status:203 }...........: 26    17.003498/s

But if you want this for each of the http_req_* metrics you will need to add one threshold per each per status code … which seems way too hackish and will probably slowdown k6 if there are enough thresholds and requests.