How to determine the average response time, p95 and other metrics statistics of some selected request only in a script

Hi, I am not sure where to get the average response time and the value of other metrics (p95, min, max,med,p90) of some selected endpoints/request only in a script (not all request are to be included)

I am using 3 methods:

1. I added tags for the selected requests so I can view their metric statistics values in the local summary results. See https://k6.io/docs/using-k6/thresholds/#thresholds-on-tags

Ex:

 **thresholds:** {
        'http_req_duration{type:API}': ['p(95)<=50000'], 
        //http_req_failed: ['rate<=0.01'], // http errors should be less than or equal to 1%
    },

export default function main() {
          response = http.get (https://google.com), {
                headers: {
                       Authorization: abcdeghi
                }
                       tags: { type: 'API' },
           });


           response = http.post(https://friends.com), {
               headers: {
                       Authorization: abcdeghi
               }
                       tags: { type: 'API' },
            });



Local Summary Result:

  1. I also placed those selected requests in a group so I can view their metric statistics values in the k6 cloud.

Ex:

 **thresholds:** {
        'http_req_duration{type:API}': ['p(95)<=some number here'], 
        //http_req_failed: ['rate<=0.01'], // http errors should be less than or equal to 1%
    },

export default function main() {

 group('Log In - View Home Page', function () {
          response = http.get (https://google.com), {
                headers: {
                       Authorization: abcdeghi
                }
                       tags: { type: 'API' },
           });


           response = http.post(https://friends.com), {
               headers: {
                       Authorization: abcdeghi
               }
                       tags: { type: 'API' },
            });
});



k6 Cloud Result:

  1. Since I placed them in groups, I also defined that group in the threshold so their metric statistics values will be displayed in the local summary results. See https://k6.io/docs/using-k6/thresholds/#threshold-on-group-duration

Ex:

 **thresholds:** {
        'http_req_duration{type:API}': ['p(95)<=some number here'], 
       'group_duration{group:::Log In - View Home Page}': ['avg <= some number here'],
    },

export default function main() {

 group('Log In - View Home Page', function () {
          response = http.get (https://google.com), {
                headers: {
                       Authorization: abcdeghi
                }
                       tags: { type: 'API' },
           });


           response = http.post(https://friends.com), {
               headers: {
                       Authorization: abcdeghi
               }
                       tags: { type: 'API' },
            });
});



Local Summary Result:

What should I use or to where should I refer to between these 3?

Thanks

Hi @mmm014 !

Let me try to help you!

Hi, I am not sure where to get the average response time and the value of other metrics (p95, min, max,med,p90) of some selected endpoints/request only in a script (not all request are to be included)

If you’re looking for metrics for some average of the requests then definitely method number 1 (using the tags) is something that you’re looking for.

The 2 and 3 is based on group_duration metric which contains the total time of execution the group function.

1 Like

Hi @olegbespalov ,

I see. Correct me if I am wrong. The tags (method 1) reads the metrics of those selected endpoints/request itself individually and displays the average p95, p99,min,max,etc. in totality,

And if I want to see the metric statistics of those selected endpoints or request as a whole or as a complete set of iteration… I should be using methods 2 or 3. Correct?

Tags is being processed via endpoint to endpoint while group_duration (method 2 or 3) are processed as complete set or iteration having those endpoints

Hi @mmm014

Sorry for the delay.

The tags (method 1) reads the metrics of those selected endpoints/request itself individually and displays the average p95, p99,min,max,etc. in totality,

I’m not going to correct you since it seems like you got it right. Maybe only re-phrase a bit. A method with tags (1) allows you to do different aggregations (p95, p99, min, max, etc.) for the metrics marked with tags. And the unit here is an individual request.

In the 2 and 3, a unit is a group of operations (everything inside the group function), and we do aggregations (p95, p99, min, max, etc) for the group.

Let me know if that helps,
Cheers

Thank you @olegbespalov

LAST follow up question about this topic.

My script has 6 GROUPS wherein each groups are the different scenarios (6 scenarios. Ex. Log in (1st) > Load Profile Tab (2nd) > Update Profile Info (3rd) … > Log Out (6th). I need to load test only the 3rd GROUP (which is Updating Profile Info). The requirement is that the p95 and average response time shall be less than 3 seconds.

Basically, all the covered API requests for the Updating Profile Info scenario are inside that 3rd Group. My question is when we load test that specific scenario or group only, knowing we can apply both method 1 or 2/3…which one is more appropriate to use for getting the average and p95 response time? I am still battling between the two given my current test set up.

Apologies for this follow up question. I appreciate your support for this one. Thank you!

Hi @mmm014

No worries at all, I’ll try to do my best :smiley:

the answer for that fully depends on the requirement

If that requirement (p95, 3 seconds) applies to the set of operations (group)? For example, p95 of customers should spend on the Updating profile info no more than 3 seconds on this XXX load.

If that requirement applies to the API’s endpoints then I believe it’s method 1.

Let me know if that answers!