Knowledgebase

Tags


Background

Tags are a powerful tool that allow you to analyze your data from a few different perspectives. Some examples of this include:

  • Thresholds: specify thresholds on a subset of data points, based on things you ‘tag’
  • Result analysis: slice and dice the data in Insights by filtering metric data points based on tags

Tags with thresholds

Let’s have a look at a test script with a few different URLs:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import http from "k6/http";
import {sleep} from "k6";

export let options = {
    stages: [
        { target: 10, duration: "10s" }
    ]
};

const baseURL = "https://test.loadimpact.com";

export default function(data) {
    // Load page
    let res = http.get(baseURL);

    // Load static assets
    res = http.batch([
        ["GET", `${baseURL}/style.css`],
        ["GET", `${baseURL}/images/logo.png`]
    ]);

    sleep(3.0);
}

Now, imagine we want to set a threshold on the response time of the static assets separately from the page. The easiest way to accomplish that is by adding tags to the static asset requests and then setting up a threshold to only look at reponse times from requests tagged with that tag, something like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import http from "k6/http";
import {sleep} from "k6";

export let options = {
    stages: [
        { target: 10, duration: "10s" }
    ],
    thresholds: {
        // A threshold that only looks at requests with a tag "staticAsset" with a value of "yes"
        "http_req_duration{staticAsset:yes}": ["p(95)<500"]
    }
};

const baseURL = "https://test.loadimpact.com";

export default function(data) {
    // Load page
    let res = http.get(baseURL);

    // Load static assets (tagging them with "staticAsset"="yes")
    res = http.batch([
        ["GET", `${baseURL}/style.css`, null, { tags: { staticAsset: "yes" } }],
        ["GET", `${baseURL}/images/logo.png`, null, { tags: { staticAsset: "yes" } }]
    ]);

    sleep(3.0);
}

Tags for result analysis

In the “Filters” section of the result analysis page you can enter one or more tags to use as filters for the metrics data displayed under the “Breakdown tree”, “URL table” and “Analysis” tabs.

Any tag added will immediately filter the display metrics data in these tabs to only show data points that have been tagged with the selected tag name and value.

Results by load zone for Cloud Execution

With Cloud Execution all metrics data points are automatically tagged with the load zone from which they originated. This is very useful for slicing the results by load zone, just select the “load zone” tag and choose a load zone in the filter section to filter all the results in the breakdown, URL and Analysis tabs:

Insights results by load zone

See also:

  • k6 docs on tags for more information.