How to specify `rate` on CLI

Hi! I’ve checked that there is an order of precedence to specify options, where CLI Flags has the highest priority. However I cannot find a way to specify the rate option of constant-arrival-rate. Do I miss anything or is it not possible yet?

Hi @amosbird

Welcome to the community forum :wave:

This is not possible via CLI at this time, scenarios can only be configured via a code/config file.

Can add the feature request in the k6 repo for the team to consider in the future? What we would be looking at there is adding support for Scenarios in CLI, and you can also describe you particular case, you need to set rate in constant-arrival-rate. I can open it myself if you prefer, just let me know.

Cheers!

1 Like

Hi @eyeveebe , it would be perfect if you can help open the issue.

1 Like

Hi @amosbird

I created Support Scenarios in the CLI options · Issue #3054 · grafana/k6 · GitHub for you. Feel free to add any additional details to the discussion, and :+1: to help prioritize.

Cheers!

Hi @amosbird

Further discussing Support Scenarios in the CLI options · Issue #3054 · grafana/k6 · GitHub with the dev team, it will be a complex one to implement, especially if we go for handling multiple scenarios and not just adding --rate. The team is working on Configuration issues · Issue #883 · grafana/k6 · GitHub and they will most probably not attempt any other changes in the configuration until that is done.

As a workaround, have you attempted to pass an environment variable, and use it in your script __ENV.K6_RATE? Would that work for your case?

Cheers!

Hi @eyeveebe ! Could you share a concrete example of how to use __ENV.K6_RATE in a script?

Hi @amosbird

For sure. Based on the docs for how to pass environment variables to a k6 script you can create your script.js with rate: ${__ENV.K6_RATE}``:

import http from 'k6/http';
import { sleep } from 'k6';

export const options = {
    discardResponseBodies: true,
    scenarios: {
        contacts: {
            executor: 'constant-arrival-rate',
            // Our test should last 30 seconds in total
            duration: '30s',
            // It should start 30 iterations per `timeUnit`. Note that iterations starting points
            // will be evenly spread across the `timeUnit` period.
            rate: `${__ENV.K6_RATE}`,
            // It should start `rate` iterations per second
            timeUnit: '1s',
            // It should preallocate 2 VUs before starting the test
            preAllocatedVUs: 2,
            // It is allowed to spin up to 50 maximum VUs to sustain the defined
            // constant arrival rate.
            maxVUs: 50,
        },
    },
};

export default function () {
    http.get('https://test.k6.io/contacts.php');
    sleep(0.5);
}

And then run k6 run script.js -e K6_RATE=10, which will pass the value to the scenario.

I hope this helps.

Cheers!

1 Like