Separate metrics summary for each request in default function

The summary aggregates all of the results it shows. The only current way to get around that, before we implement Add explicit tracking and ignoring of metrics and sub-metrics · Issue #1321 · grafana/k6 · GitHub, is to define a threshold on a sub-metric. I gave an example for that in Ignore http calls made in Setup or Teardown in results? - #2 by nedyalko, but if I understand your use case correctly, it would be something like this:

import http from 'k6/http'

export let options = {
    vus: 5,
    duration: "10s",
    thresholds: {
        // Some dummy thresholds that are always going to pass. You don't even
        // need to have something here, I tried it and just this
        // `'http_req_duration{scenario:default}': []` is enough to trick
        // k6, but that's undefined behavior I can't promise we won't break
        // in the future...
        'http_req_duration{my_tag:create}': ['max>=0'],
        'http_req_duration{my_tag:read}': ['max>=0'],
        // You don't have to define custom tags, you can use any of the already defined
        // system tags: https://k6.io/docs/using-k6/tags-and-groups#system-tags
        'http_req_duration{method:POST}': ['max>=0'],
        'http_req_duration{url:https://httpbin.test.k6.io/anything}': ['max>=0'],
        'http_req_duration{status:200}': ['max>=0'],
    },
}

export default function () {
    http.post('https://httpbin.test.k6.io/delay/2', null, { tags: { my_tag: 'create' } });
    http.get('https://httpbin.test.k6.io/delay/1', { tags: { my_tag: 'read' } });

    http.post('https://httpbin.test.k6.io/anything', 'some body');
}

Alternatively, it might be better if you work with the raw metrics data directly by exporting it to JSON/CSV or sending it to InfluxDB or some other external service. You can see more details about that in Results output

1 Like