Threshold on a group duration does nothing

Thresholds, Threshold on a group duration section

I have run exactly the same script as described in the documentation and noticed that test never fails even when group duration exceeds the threshold. It seems that group duration isn’t collected. Probably, some info is missed in documentation.

an example of the run
https://app.k6.io/runs/public/8d5061c6c344498e81f81e5d389ab3b5

Hi @MaksymCode

you are right. This example wasn’t working as expected in the cloud. Thank you for pointing it out. We have now removed it from the documentation.
I added the feature of creating thresholds on groups to the roadmap. We will try to implement this in the next few weeks.

It turns out that it’s very simple to create a custom metric for tracking group duration that works locally and in the cloud. Please see the script below.

import http from "k6/http";
import { group } from "k6";
import { sleep } from 'k6';
import { Trend } from 'k6/metrics';

let groupDuration = Trend("groupDuration");

export let options = {
  thresholds: {
    'groupDuration{groupName:individualRequests}': ['avg < 200'],
    'groupDuration{groupName:batchRequests}': ['avg < 200'],
  },
  vus: 1,
  duration: '10s'
};

function groupWithDurationMetric(name, group_function) {
  let start = new Date();
  group(name, group_function);
  let end = new Date();
  groupDuration.add(end - start, {groupName: name})
}

export default function () {

  groupWithDurationMetric("individualRequests", function () {
    http.get('https://test-api.k6.io/public/crocodiles/1/');
    http.get('https://test-api.k6.io/public/crocodiles/2/');
    http.get('https://test-api.k6.io/public/crocodiles/3/');
  });

  groupWithDurationMetric("batchRequests", function () {
    http.batch([
      ['GET', `https://test-api.k6.io/public/crocodiles/1/`],
      ['GET', `https://test-api.k6.io/public/crocodiles/2/`],
      ['GET', `https://test-api.k6.io/public/crocodiles/3/`],
    ]);
  });

  sleep(1);
}

Here’s how it looks for local execution:

And here’s a sample cloud run: app.k6.io - Performance testing for developers, like unit-testing, for performance

Hope this helps!

Hi @pawel,
thank you for a working example