diff --git a/k6/tests/config.js b/k6/tests/config.js new file mode 100644 index 0000000..fb82265 --- /dev/null +++ b/k6/tests/config.js @@ -0,0 +1,29 @@ +// config.js +export function getConfig() { + return { + smoke: { + rate: parseFloat(__ENV.SMOKE_RATE || "0.99"), + duration: parseInt(__ENV.SMOKE_DURATION || "600"), + }, + average: { + rate: parseFloat(__ENV.AVERAGE_RATE || "0.99"), + duration: parseInt(__ENV.AVERAGE_DURATION || "800"), + }, + stress: { + rate: parseFloat(__ENV.STRESS_RATE || "0.99"), + duration: parseInt(__ENV.STRESS_DURATION || "1600"), + }, + soak: { + rate: parseFloat(__ENV.SOAK_RATE || "0.99"), + duration: parseInt(__ENV.SOAK_DURATION || "800"), + }, + spike: { + rate: parseFloat(__ENV.SPIKE_RATE || "0.99"), + duration: parseInt(__ENV.SPIKE_DURATION || "3200"), + }, + breakpoint: { + rate: parseFloat(__ENV.BREAKPOINT_RATE || "0.99"), + }, + }; + } + \ No newline at end of file diff --git a/k6/tests/kyverno-pss.js b/k6/tests/kyverno-pss.js index 1fe7163..a211720 100644 --- a/k6/tests/kyverno-pss.js +++ b/k6/tests/kyverno-pss.js @@ -9,6 +9,9 @@ import { randomString, } from "./util.js"; +import { getConfig } from "./config.js"; + + let scenarios = { smoke: { executor: "constant-vus", @@ -63,34 +66,49 @@ let scenarios = { }, }; + +const config = getConfig(); export let options = { scenarios: {}, thresholds: { - "checks{type:smoke}": [{ threshold: "rate>0.99", abortOnFail: true }], // checks should pass for 99% of requests - "http_req_duration{type:smoke}": [ - { threshold: "p(95)<600", abortOnFail: true }, - ], // 95% of requests should be below 600ms - "checks{type:average}": [{ threshold: "rate>0.99", abortOnFail: true }], + "checks{type:smoke}": [ // checks should pass for (config.smoke.rate*100)% of requests + { threshold: `rate>${config.smoke.rate}`, abortOnFail: true }, + ], + "http_req_duration{type:smoke}": [ // 95% of requests should be below (config.smoke.duration)ms + { threshold: `p(95)<${config.smoke.duration}`, abortOnFail: true }, + ], + "checks{type:average}": [ + { threshold: `rate>${config.average.rate}`, abortOnFail: true }, + ], "http_req_duration{type:average}": [ - { threshold: "p(95)<800", abortOnFail: true }, + { threshold: `p(95)<${config.average.duration}`, abortOnFail: true }, + ], + "checks{type:stress}": [ + { threshold: `rate>${config.stress.rate}`, abortOnFail: true }, ], - "checks{type:stress}": [{ threshold: "rate>0.99", abortOnFail: true }], "http_req_duration{type:stress}": [ - { threshold: "p(95)<1600", abortOnFail: true }, + { threshold: `p(95)<${config.stress.duration}`, abortOnFail: true }, + ], + "checks{type:soak}": [ + { threshold: `rate>${config.soak.rate}`, abortOnFail: true }, ], - "checks{type:soak}": [{ threshold: "rate>0.99", abortOnFail: true }], "http_req_duration{type:soak}": [ - { threshold: "p(95)<800", abortOnFail: true }, + { threshold: `p(95)<${config.soak.duration}`, abortOnFail: true }, + ], + "checks{type:spike}": [ + { threshold: `rate>${config.spike.rate}`, abortOnFail: true }, ], - "checks{type:spike}": [{ threshold: "rate>0.99", abortOnFail: true }], "http_req_duration{type:spike}": [ - { threshold: "p(95)<3200", abortOnFail: true }, + { threshold: `p(95)<${config.spike.duration}`, abortOnFail: true }, + ], + "checks{type:breakpoint}": [ + { threshold: `rate>${config.breakpoint.rate}`, abortOnFail: true }, ], - "checks{type:breakpoint}": [{ threshold: "rate>0.99", abortOnFail: true }], }, teardownTimeout: "10m", }; + if (__ENV.SCENARIO) { // Use just a single scenario if `--env scenario=foo` is used. options.scenarios[__ENV.SCENARIO] = scenarios[__ENV.SCENARIO];