0

I am working on developing load testing for one workflow using HTTP request calls. In the workflow, the response of one API call is used in the next API's call either as a parameter or as a request body. So, the sequence in which API is called is very important.

My question is about the result. Is there any mechanism in K6 by which I get a breakup of how much time it took to execute each API call?

Jay
  • 339
  • 1
  • 7
  • 23

1 Answers1

2

Yes, you can filter metrics by their (default or custom) tags. Here is an example:

import { check } from 'k6';
import 'http' from 'k6/http';

export const options = {
  thresholds: {
    'http_req_duration{name:${}/endpoint1}': [ 'avg>0' ], // arbitrary threshold
    'http_req_duration{name:${}/endpoint2}': [ 'avg>0' ],
  },
};

export default function() {
  const server = 'http://example.com';
  const token = http.get(http.url`${server}/endpoint1`).json('token');
  check(
    http.post(http.url`${server}/endpoint2`, 'token=' + token),
    {
      'token accepted': r => r.status === 200,
    });
}

String templates tagged with http.url will automatically set the name tag for your requests, allowing you to easily filter a subset of requests.

knittl
  • 246,190
  • 53
  • 318
  • 364
  • I tried the same way. I get only name on results it's not replaced with url. Please suggest – Meiyappan Kannappa Nov 16 '22 at 17:36
  • @MeiyappanKannappa you have to be more specific than that to expect an answer. (Feel free to ask a new question with all the relevant detail, i.e. a minimal, reproducible example) – knittl Nov 16 '22 at 20:31
  • I tried the above example, in the results for API Breakup statistics, I dont get the 'name' attribute replaced with http.url (server url). My results are like below ✓ { name:${}/ }................: avg=287.29ms min=287.29ms med=287.29ms max=287.29ms p(90)=287.29ms p(95)=287.29ms ✓ { name:${}/contacts.php }....: avg=252.94ms min=252.94ms med=252.94ms max=252.94ms p(90)=252.94ms p(95)=252.94ms – Meiyappan Kannappa Nov 17 '22 at 02:18
  • @MeiyappanKannappa the name attribute will not be replaced in the summary. The tagged strings will be used to group URLs. Your summary looks like how I would expect it to look. – knittl Nov 17 '22 at 06:53