From f6766e4c1dd67f38c14dd6b7ed5baef2b4a48f6f Mon Sep 17 00:00:00 2001 From: DarthSim Date: Wed, 5 Oct 2022 12:25:16 +0600 Subject: [PATCH] Update k6 script --- k6/index.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/k6/index.js b/k6/index.js index 8650cd6f..29d3e107 100644 --- a/k6/index.js +++ b/k6/index.js @@ -2,6 +2,7 @@ import { randomSeed, check } from 'k6'; import http from 'k6/http'; import { SharedArray } from 'k6/data'; import exec from 'k6/execution'; +import { Trend } from 'k6/metrics'; export let options = { discardResponseBodies: true, @@ -30,7 +31,7 @@ const urls = new SharedArray('urls', function () { let weight = e.weight || 1 for (var i = 0; i < weight; i++) { - unshuffled.push(url) + unshuffled.push({url, group: e.group}) } }) @@ -46,9 +47,17 @@ if (urls.length == 0) { throw "URLs list is empty" } +let group_durations = [...new Set(urls.map(url => url.group))] + .reduce((trends, group) => { + trends[group] = new Trend(`http_req_duration_${group}`, true); + return trends; + }, {}); + export default function() { - const res = http.get(urls[exec.scenario.iterationInTest % urls.length]); + const url = urls[exec.scenario.iterationInTest % urls.length] + const res = http.get(url.url); check(res, { 'is status 200': (r) => r.status === 200, }); + group_durations[url.group].add(res.timings.duration); }