Luis Serrano
Luis Serrano

Reputation: 87

Breaking down statistics at API level or Flow level in K6?

I was taking a quick look to K6 from loadimpact.

The graphs that I got so far show TPS, Response Time, Error rates at the global level and that is not too useful.

When I load test, I rather have those stats at the global level, but also at the flow level or at the APi level. This way if for example if I see some high latency I can tell right away if is caused by a single API or if all APIs are slow.

Or I can tell of a given API is giving say HTTP/500 or several different APIs are.

Can K6 show stats like TPS, Response Time, HTTP status at the API level, the flow level and global level?

Thanks

Upvotes: 1

Views: 1105

Answers (1)

Robin Gustafsson
Robin Gustafsson

Reputation: 241

Yes, it can, and you have 3 options here in terms of result presentation (all involve using custom metrics to some degree):

  1. End of test summary printed to stdout.
  2. You output the result data to InfluxDB+Grafana.
  3. You output the result data to Load Impact Insights.

Global stats you get with all three above, and per API endpoint stats you get out of the box with 2) and 3), but to get stats at the flow level you'd need to create custom metrics which works with all three options above. So something like this:

import http from "k6/http";
import { Trend, Rate } from "k6/metrics";
import { group, sleep } from "k6";

export let options = {
    stages: [
        { target: 10, duration: "30s" }
    ]
};

var flow1RespTime = new Trend("flow_1_resp_time");
var flow1TPS = new Rate("flow_1_tps");
var flow1FailureRate = new Rate("flow_1_failure_rate");

export default function() {
    group("Flow 1", function() {
        let res = http.get("https://test.loadimpact.com/");
        flow1RespTime.add(res.timings.duration);
        flow1TPS.add(1);
        flow1FailureRate.add(res.status == 0 || res.status > 399);
    });
    sleep(3);
};

This would expand the end of test summary stats printed to stdout to include the custom metrics:

enter image description here

Upvotes: 1

Related Questions