Using tags and threshold on checks in scenarios

Dear all,

I have a testscript with three scenarios, where in total three test scripts are being run after each other. My goal is to put a threshold of 95% on each of the test checks independently. I have tried putting tags on them, but I have yet to figure out how to use these in the thresholds.

I have been staring at the k6 documentation on various pages for quite a while now, feeling a bit lost in the thought process of how to get this done. I would really appreciate any help at all. Thanks in advance!

My code:

    export const options = {
      thresholds: {

      },
      scenarios: {
        login_test: {
          executor: 'ramping-vus',
          startVUs: 0,
          stages: [
            { duration: '10s', target: 10 },
            { duration: '1m', target: 50 },
            { duration: '1m', target: 100 },
            { duration: '2m', target: 100 },
            { duration: '1m', target: 0 },
          ],
          exec: 'loginTest',
          tags: { test_name: 'login' },
        },
        get_customization_test: {
          executor: 'ramping-vus',
          startVUs: 0,
          stages: [
            { duration: '1m', target: 5 },
            { duration: '1m', target: 10 },
            { duration: '2m', target: 10 },
            { duration: '1m', target: 0 },
          ],
          exec: 'getCustomizationTest',
          startTime: '5m',
          tags: { test_name: 'get-customization' },
        },
        get_customizations_test: {
          executor: 'ramping-vus',
          startVUs: 0,
          stages: [
            { duration: '1m', target: 5 },
            { duration: '1m', target: 10 },
            { duration: '2m', target: 10 },
            { duration: '1m', target: 0 },
          ],
          exec: 'getCustomizationsTest',
          startTime: '10m',
          tags: { test_name: 'get-customizations' },
        },
      },
    }

See this example in the docs: https://k6.io/docs/using-k6/scenarios/advanced-examples#multiple-exec-functions-tags-environment-variables-and-thresholds

In your case, you don’t even need to add tags manually to the scenarios, since the metrics from each scenario are automatically tagged with scenario: <the-scenario-id>. So, the thresholds should look somewhat like this:

export const options = {
    thresholds: {
        'checks{scenario:login_test}': ['rate>0.95'], // <5% errors
        'checks{scenario:get_customization_test}': ['rate>0.95'],
        'checks{scenario:get_customizations_test}': ['rate>0.95'],
    },
    // ...
}
3 Likes

Thanks a lot, it works!