Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/env for executor type OR the entire options object #2556

Closed
kkriegkxs opened this issue Jun 2, 2022 · 2 comments
Closed

cmd/env for executor type OR the entire options object #2556

kkriegkxs opened this issue Jun 2, 2022 · 2 comments
Labels
evaluation needed proposal needs to be validated or tested before fully implementing it in k6 feature

Comments

@kkriegkxs
Copy link

Feature Description

Add ability to specify the executor type via cmd or env var and a set of corresponding configs (which the i/u counts and stages are already implemented).
OR optionally (no pun intended) provide the entire options object either as an external file path or json string.

The intent is to enable specifying different options for multiple scripts executing in parallel (for the ease of automation)

Suggested Solution (optional)

No response

Already existing or connected issues / PRs (optional)

No response

@mstoykov mstoykov added the evaluation needed proposal needs to be validated or tested before fully implementing it in k6 label Jun 6, 2022
@mstoykov
Copy link
Contributor

mstoykov commented Jun 6, 2022

Hi @kkriegkxs,

OR optionally (no pun intended) provide the entire options object either as an external file path or json string.

This is possible even now.

SOME_VAR="{all the json you want}" k6 run script,js

script.js:

export let option = JSON.stringify(__ENV.SOME_VAR);
... 

As for the rest, given the above "workaround" and the fact that configuration in k6 already is really complex to work with and write and this will make it even more so - I very much doubt the k6 team will:

  1. introduce such a change before Configuration issues #883
  2. Even after the above issue is fixed - prioritize this, given the workaround that does 90% of what a real fix will do.

Will keep this open to let others give their opinion and so that there is an open issue about it ;)

@na--
Copy link
Member

na-- commented Jun 8, 2022

There are already multiple ways to achieve this. You can pass the whole options encoded as a JSON in an environment variable, as @mstoykov showed above. You can also pass just certain elements of it and inject those in the exported options object, like this:

export const options = {
  scenarios: {
    demo: {
      executor: 'constant-arrival-rate',
      duration: '30s',
      rate: __ENV.rate,
      preAllocatedVUs: __ENV.VUs,
    },
  },
};

and then run the test with k6 run --env rate=10 --env VUs=5 script.js.

You can also specify an external JSON config file with the --config CLI flag or, for even more flexibility, specify a config file path with an environment variable and then open() that file, parse it and re-export its contents as the script options, like this:

export let options = JSON.parse(open(__ENV.config_path)));

Then you can run the test with k6 run --env config_path=./config.json script.js.

And you can mix and match all of these strategies - for example, merge options from different config files with some defaults and some singular env-var options, or whatever you want... 🤷‍♂️ But yeah, k6 configuration is already flexible enough that, unless there is a specific use case that isn't covered, I wouldn't want to add to its complexity further until we've refactored its internals (#883) and reduced their complexity.

I'll close this for now, but if you think your use case isn't covered by these approaches, please comment and we may reopen the issue.

@na-- na-- closed this as completed Jun 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
evaluation needed proposal needs to be validated or tested before fully implementing it in k6 feature
Projects
None yet
Development

No branches or pull requests

3 participants