Hello there!
I have a k6 performance test script that I would like to use in a scheduled run. However, it seems that all script need to be run at least once before it is available for a scheduled test. This script is not something that we want to execute during the day, so I tried to build in a default scenario that executes the test a single time, and a breaking test that we want to run at night. I then want to select the scenario to execute based on an environment variable that I set in the Grafana k6 settings. Some example code snippets of how I am trying to achieve this:
Preparing the scenarios:
let scenarios = {
default: {
executor: "per-vu-iterations",
vus: 1,
iterations: 1,
},
breaking: {
executor: "ramping-vus",
stages: [
{ duration: "3m", target: 1 },
{ duration: "3m", target: 10 },
{ duration: "3m", target: 20 },
{ duration: "3m", target: 30 },
{ duration: "3m", target: 40 },
{ duration: "3m", target: 50 },
{ duration: "3m", target: 60 },
{ duration: "3m", target: 70 },
{ duration: "3m", target: 80 },
{ duration: "3m", target: 90 },
{ duration: "3m", target: 100 },
],
}
}
Setting up the options:
export const options = {
scenarios: {},
// other options here
thresholds: {
'http_req_failed{type:vacancy}': [{ threshold: 'rate<0.01', abortOnFail: true }], // http errors should be less than 1%, otherwise, abort
'http_req_duration{type:vacancy}': ['p(95)<5000'], // 95% of requests should be below 5000ms
}
}
And selecting the scenario:
if (__ENV.PRODUCTNAME_SCENARIO) {
options.scenarios[__ENV.PRODUCTNAME_SCENARIO] = scenarios[__ENV.PRODUCTNAME_SCENARIO];
}
else {
options.scenarios["default"] = scenarios["default"];
}
I run the k6 script in the cloud without any environment variable, and the default scenario is performed. Then, when I add the environment variable to the Grafana k6 settings, it seems to recognize the variable when I look at the script. However, in the overview of the executed test, it tells me no scenario was configured, with or without the environment variable.
What could be the reason that the scenario is not being used correctly, using this setup? Any help would be greatly appreciated.