A common requested case is to track the iteration_duration metric without including time spent for setup and teardown functions. This feature is not yet available but a threshold on iteration_duration or any pre-existing metrics can be used as a workaround.
It's based on the concept of creating thresholds for sub-metrics created by tags for the required scope and setting the criteria that always pass. It works with any enabled tags that already works with threshold, for example:
- iteration_duration{scenario:default} generates a sub-metric collecting samples only for the default scenario's iteration. scenario:default is used because that's the internal k6 scenario name when we haven't specified options. scenarios` explicitly and are just using the execution shortcuts instead.
- iteration_duration{group:::setup} or iteration_duration{group:::teardown} create sub-metrics collecting the duration only for setup and teardown. k6 implicitly creates groups for setup and teardown, and :: is the group separator.
- http_req_duration{scenario:default} can be useful as well for isolating executed long-running requests.
Dedicated sub-metrics have been generated collecting samples only for the scope defined by thresholds: