How to code iteration_duration as a Metric?

In my export default function I have a scenerio and working witk about 10 endpoint. I m using for loop for some endpoints. As a result, I want to calculate total duration time. When I add below code it gives me duration for last endpoint. But need the total duration like a iteration_duration. Because I use reporting so I should show iteration duration as a Metric.

completePickingTrend.add(completePickingCompleteProcessRes.timings.duration);

my options function;

export const options = {
    summaryTimeUnit: 'ms',
    scenarios: {
        CreatePicking: {
            exec: 'CreatePicking',
            executor: 'per-vu-iterations',
            vus: 2,
            iterations: 1
        },
    }
}

Hi @Yusuf,
if the completePickingCompleteProcessRes the Response of the last request? If yes, then the metric is expected to be representative only of the single endpoint.

If you want to aggregate them you need to compute a sum before in your code and then add the total.

You have also two k6 native alternatives:

  1. Use a group and get the implicit metric collected by k6:

For each group() function, k6 emits a group_duration metric that contains the total time to execute the group function.

  1. If the request can be processed in parallel then you can have a batch request and sum all the timings when the batch is completed.

Let me know if it helps you.