Skip to content

Commit

Permalink
Merge pull request #24 from jigar-joshi-nirmata/configurable-threshol…
Browse files Browse the repository at this point in the history
…d-value

Feature: Configurable Threshold Values via config.json
  • Loading branch information
jigar-joshi-nirmata authored Jan 15, 2025
1 parent 47eb558 commit 58c500f
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 13 deletions.
29 changes: 29 additions & 0 deletions k6/tests/config.js
Original file line number Diff line number Diff line change
@@ -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"),
},
};
}

44 changes: 31 additions & 13 deletions k6/tests/kyverno-pss.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ import {
randomString,
} from "./util.js";

import { getConfig } from "./config.js";


let scenarios = {
smoke: {
executor: "constant-vus",
Expand Down Expand Up @@ -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];
Expand Down

0 comments on commit 58c500f

Please sign in to comment.