Grafana K6 Plugin
Grafana K6 is an open-source load testing tool developed by Grafana.
K6 scripts can be executed in Step via the Grafana K6 Plugin, available to Step enterprise customers. This page describes how to install, configure and use the Grafana K6 plugin for Step.
Installation
Before using this plugin, Grafana K6 has to be installed on the machine running your agents.
By default, the k6 executable will be launched from your ${PATH}. You can define another installation folder by using the following property in the configuration file of your agent:
plugins.k6.folder: "C:\\Program Files\\k6\\"
Usage
Basic keyword configuration
When K6 is installed, you can easily run your script by creating a new keyword and uploading your js file:
![Grafana K& Keyword configuration screen](../../images/plugins/K6/Grafana_k6_keyword_screen_hu038eaa5ba0195ad678343e238d26fcb6_235645_500x400_fit_q75_h2_catmullrom_3.webp)
Alternatively you can also upload a zip file if your script is composed of modules.
Three basic options are visible by default:
- Iterations: defining the total number of iterations to run your script
- Duration: defining the total duration of your script. Note that the duration should include a suffix indicating the time unit (like ’10s’ or ‘5m’)
- Virtual Users (VUs): defining the number of VUs to run concurrently
Keyword Input
It is possible to pass input to your K6 keyword. These input parameters will be passed as environment variable to your script:
Example
- Let suppose you defined a K6 keyword using the following script:
import http from 'k6/http';
import { sleep } from 'k6';
import { check } from 'k6';
export const options = {
thresholds: {
checks: ['rate>0.9'],
},
};
export default function () {
const r = http.get(`https://${__ENV.MY_HOSTNAME}`, { tags: { name: "My Http request" } });
check(r, {
'response is status 200': (r) => r.status === 200,
});
sleep(1);
}
- And execute it with the following input:
![A Grafana K6 Keyword with a MY_HOSTNAME input](../../images/plugins/K6/Grafana_k6_keyword_with_input_hu8c4508d52d445d21fa4cad743db2e289_77929_500x400_fit_q75_h2_catmullrom_3.webp)
- You will get the following result, indicating that the script takes the value of the input given for constructing the URL:
![Execution of a Grafana K6 Keyword with a MY_HOSTNAME input](../../images/plugins/K6/Grafana_k6_keyword_with_input_execution_hu65c52850ea5d656185bf2fd9c50faeac_86360_500x400_fit_q75_h2_catmullrom_3.webp)
Keyword properties
Keyword properties are passed to K6 as environment variable.
- In order to avoid conflicts with keyword inputs and other environment variables, the name of each property is prefixed with ‘PROPERTIES_’
- As K6 doesn’t support special characters in environment variable names, all non alphanumeric characters are replaced by ‘_’
For example, a keyword property called “user.password”, it will be passed to K6 as environment variable as “PROPERTIES_user_password” and will be accessible within the K6 script as
__ENV.PROPERTIES_user_password
Keyword Output
When executing a K6 keyword, the following results will be available in Step
- In case of error, the stdOut and stdError will be attached to the execution
- If debug is activated, a debug.log file will be attached
- If your browser-based keyword generated screenshots, these files will also be attached to the execution
- Finally, the following metrics will be collected and available in the analytics dashboard
- trend
- gauge
- rate
- counter Note that the metrics are given by default as average or sum of the execution:
- counter measurements are given as the sum of all the value encontered for this counter
- rate and gauge are given as an average of the all the value
- trend is given as an average by default, but you can collect all the non-aggregated measurements by setting the measuresAsAvg parameter to “false” (“true” by default)
For example, below is the result of an successful execution with debug activated:
![Successful run of a Grafana K6 Keyword](../../images/plugins/K6/Grafana_k6_execution_simple_success_huebda82fca09d7925e3e9b170286d900e_271078_500x400_fit_q75_h2_catmullrom_3.webp)
Another example with a browser-based keyword, including a screenshot and an error:
![Failure of a Grafana K6 Keyword](../../images/plugins/K6/Grafana_k6_execution_browser_fail_hu33f1fa97056e4eb47265fdfcd5c9c108_71762_500x400_fit_q75_h2_catmullrom_3.webp)
Advanced options
It is also possible to controller the options passed to the k6 process via the Other Grafana K6 options dropdown:
![Grafana K6 Keyword configuration screen. Advanced options](../../images/plugins/K6/Grafana_k6_keyword_screen_advanced_hu038eaa5ba0195ad678343e238d26fcb6_259870_500x400_fit_q75_h2_catmullrom_3.webp)
This screen allows you to define options via:
- Command lines: in this example, we override the default user agent
- Environment variables: some options can only be passed as environment variables. In this case, we change the Headless option of the browser
Defining default values for your inputs
As input values are passed to the K6 script as environment variables, you can define default values to your inputs using the advanced options.
For example, defining the foillowing environment variable for the script of the previous example will force the script to use http://exense.ch/ as the default value for the input parameter MY_HOSTNAME
![Grafana K6 Keyword configuration screen. Defining a default value](../../images/plugins/K6/Grafana_k6_keyword_with_default_hu85ff1522477ac0bfae2c0a528caf22d5_76668_500x400_fit_q75_h2_catmullrom_3.webp)
Activating the debug mode
The debug mode can be activated by setting a parameter named debug to true or full:
![Activating debug for a Grafana K6 Keyword](../../images/plugins/K6/Grafana_k6_debug_plan_hu48ebe6db74bfdc98ee358f04a8621188_249093_500x400_fit_q75_h2_catmullrom_3.webp)
This will activate the debug for Http scripts and browser based scripts