Browse Source

Add url groups to k6 script

DarthSim 3 years ago
parent
commit
9adf06fb04
2 changed files with 16 additions and 4 deletions
  1. 10 1
      k6/index.js
  2. 6 3
      k6/urls.json.example

+ 10 - 1
k6/index.js

@@ -16,7 +16,12 @@ export let options = {
 randomSeed(42)
 randomSeed(42)
 
 
 const urls = new SharedArray('urls', function () {
 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 = [];
   let unshuffled = [];
   data.forEach((e) => {
   data.forEach((e) => {
@@ -36,6 +41,10 @@ const urls = new SharedArray('urls', function () {
   return shuffled;
   return shuffled;
 });
 });
 
 
+if (urls.length == 0) {
+  throw "URLs list is empty"
+}
+
 export default function() {
 export default function() {
   http.get(urls[exec.scenario.iterationInTest % urls.length])
   http.get(urls[exec.scenario.iterationInTest % urls.length])
 }
 }

+ 6 - 3
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",
     "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",
     "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"
   }
   }
 ]
 ]