I would like to make a dropped_iterations_percentage metric. This metric should be a Rate, and it should be a percentage of dropped iterations over the total number of iterations.

The reasoning for this is we run a suite of k6 tests in a pipeline, and very occasionally tests will drop some iterations for tests. The tests have a wide variety of VU counts, total iterations, etc. Therefore, we want to define a threshold for all tests so that if only a small percentage of iterations is dropped the test will not fail.

The only way I could think of doing this is in the handleSummary method since it is only there that the iterations and dropped_iterations metrics are available in code. I could manually calculate the percentage and manually add the metric to the summary output, however if the threshold is exceeded the test still exits with a 0 code. I wasn’t able to find a way to make it exit without a 0.

Is there any way to go about making this metric? Thank you in advance.