Getting separate summary for different scenarios in k6 script

Hi K6 team,
How can i configure k6 script so that i can get summary for each api calls we are making instead of summary for all iterations.
My scenario covers: 1. Users load the page which incurs parallel 6 batch api call and 2. post that user based on data loaded pass those data to make a result api call.

I want them to be in single iteration so that passing data from #1 scenario to #2 scenario would be easier, happy to take any suggestion though.

I am expeccting if i will be able to percentile summary for both scenario. I tried having it as different k6 scenarios and also with having both in single iteration/scenario function.

Any suggestion?

1 Like

Hi @rial :wave:

Unfortunately, I believe what you’re looking for is not possible at the moment in k6, and there are no trivial workarounds for it. At least none that I can think of right now :slightly_frowning_face:

However, considering that metrics and samples emitted in the context of a scenario are tagged accordingly, you should be able to access the insights you’re looking for by using a k6 output.
You could, for instance, produce a JSON file with the test results and filter what you’re looking for using jq for instance.
Or you could use a timeseries database output such as Prometheus or Influx, and build a Grafana dashboard that queries the stored data and displays panels with the information you’re looking for.

On another note, improving the k6 cli output to do better justice to groups and scenarios is one of the topics we plan to work on mid-term. No ETA yet, but it’s a topic we’re looking to improve in the future.

Let me know if I can be of further help! :bowing_man:


Hello All,
I did a Google search looking for how I might do exactly this.
I believe I have achieved what is needed.

Try the following

const testConfig = JSON.parse(open('./config/test.json'));
export const options = testConfig;

const myFirstApiCallTrend = new Trend('http_req_duration of first api call', true);
const mySecondApiCallTrend = new Trend('http_req_duration of second api call', true);

function bothMyApiCalls() {
    let response1 ='', body, params);
    let response2 ='', body, params);

The output should have a http_req_duration for each api call as below:

http_req_duration........... .............: avg=39.01ms    min=12.11ms med=26.9ms   max=354.61ms p(90)=78.71ms  p(95)=106.88ms p(99)=131.59ms
       { expected_response:true }.........: avg=39.01ms    min=12.11ms med=26.9ms   max=354.61ms p(90)=78.71ms  p(95)=106.88ms p(99)=131.59ms
http_req_duration of first api call.......: avg=42.43ms    min=20.2ms  med=28.08ms  max=138.91ms p(90)=103.05ms p(95)=109.63ms p(99)=127.86ms
http_req_duration of second api call......: avg=35.59ms    min=12.11ms med=23.15ms  max=354.61ms p(90)=65.96ms  p(95)=75.66ms  p(99)=174.72ms

My solution above is a simplified version of what I eventually implemented.
Hopefully this will put you on the right track. Comments and discussion are welcome.

This is similar, or if not the same as this request: How to track request duration for each endpoint? asked back in Nov 2020.