diff --git a/k6/index.js b/k6/index.js index b45e1484..402a1599 100644 --- a/k6/index.js +++ b/k6/index.js @@ -16,7 +16,12 @@ export let options = { randomSeed(42) const urls = new SharedArray('urls', function () { - const data = JSON.parse(open('./urls.json')); + let data = JSON.parse(open('./urls.json')); + + const groups = (__ENV.URL_GROUPS || "").split(",").filter((g) => g != "") + if (groups.length > 0) { + data = data.filter((d) => groups.includes(d.group)) + } let unshuffled = []; data.forEach((e) => { @@ -36,6 +41,10 @@ const urls = new SharedArray('urls', function () { return shuffled; }); +if (urls.length == 0) { + throw "URLs list is empty" +} + export default function() { http.get(urls[exec.scenario.iterationInTest % urls.length]) } diff --git a/k6/urls.json.example b/k6/urls.json.example index 497d578f..7b8cf53c 100644 --- a/k6/urls.json.example +++ b/k6/urls.json.example @@ -1,13 +1,16 @@ [ { "url": "/rs:fit:500:500/crop:1000:1000/sh:2/rot:90/wm:1/pd:10/plain/local:///test.jpg", - "weight": 5 + "weight": 5, + "group": "jpg" }, { "url": "/rs:fit:500:0/plain/local:///test.png", - "weight": 2 + "weight": 2, + "group": "png" }, { - "url": "/rs:fill:300:0/wm:0.5:re:::0.2/plain/local:///test.gif" + "url": "/rs:fill:300:0/wm:0.5:re:::0.2/plain/local:///test.gif", + "group": "gif" } ]