-
Notifications
You must be signed in to change notification settings - Fork 41
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
Parse the scenarios json from the K6_INSTANCE_SCENARIOS
env var
#906
Conversation
cf90f3a
to
6893d12
Compare
K6_INSTANCE_SCENARIOS
env var
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍 Thanks!
We're panicking in New() *RootModule
. And, it might not align with the expectations of the k6-core about how a module should behave when constructing it.
One suggestion to improve the situation is to handle initializations in NewModuleInstance
where we have a VU
. This way, we can handle any unexpected issues properly—with a k6 panic. To implement this, we can make use of sync.Once
for these global variables.
It might be unnecessary now. We can address this concern later on.
Squashing this PR might help. For example, "Add Some" 😄
Yeah, that's something I wasn't sure of, so I just used
🤦 thanks! |
This new method parses K6_BROWSER_WS_URL differently. Instead of a list of ws urls, it is a scenarios object, which needs to be unmarshalled and all ws urls extracted. The end result is the same -- a list of ws urls. This is a step closer to being able to work with a set of chrome browsers each with different characteristics that are set in the scenario. This commit contains the addition of this new method. Eventually this method will be used instead of the existing newRemoteRegistry method. Closes: #888
The scenarios will be set on the K6_INSTANCE_SCENARIOS env var instead of the K6_BROWSER_WS_URL. We feel that K6_BROWSER_WS_URL might still be useful for debugging in the short term, but it's worth noting that it doesn't provide the flexibility and granularity of the new env var.
This refactor will enable us to read from K6_BROWSER_WS_URL from the new method in a future commit. This will eventually allow us to retrieve both the values from K6_BROWSER_WS_URL and K6_INSTANCE_SCENARIOS from the new method.
This commit now works with the newly created checkForBrowserWSURLs in newRemoteRegistry.
This change the signature of the method to return the raw values. This will eventually allow the newRemoteRegistry method to pick from this set of raw values and the ones from checkForBrowserWSURLs.
We need to accommodate two reads from the environment (so two env vars) . This changes the test to set and read from the env.
Add the checkForScenarios before checkForBrowserWSURLs in newRemoteRegistry. The scenarios take precedence over the browser ws urls.
We're now implicitly testing checkForScenarios through the newRemoteRegistry tests.
If scenarios cannot be parsed an error is returned. It needs to be returned to the caller to handle. At the moment we should panic and stop the test for running if we're unable to parse the scenarios.
This test just ensures that K6_INSTANCE_SCENARIOS values are used instead of K6_BROWSER_WS_URL, if both are defined in the env.
Co-authored-by: İnanç Gümüş <inanc.gumus@grafana.com>
00da9ca
to
78d971a
Compare
Since creating a remoteRegistry now errors, we need to be able to send a signal back to k6 to let it know to shut down cleanly. At the moment there is no way to do this through New. We can achieve this with a workaround in NewModuleInstance though. Since NewModuleInstance is called once per vu and remoteRegistry only needs to be created once, we have to use sync.Once to init a new remoteRegistry once which is then used by all vus.
b7c2f59
to
1221193
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
Description of changes
newRemoteRegistry
now needs to parse two env vars. The first is the one that we have already defined,K6_BROWSER_WS_URL
, the new one isK6_INSTANCE_SCENARIOS
.K6_INSTANCE_SCENARIOS
defines a JSON object of the form:Each scenario will generally point to a unique ws url, which is from a unique instance of chrome. Currently we are only working with chrome, and all chrome instances are setup in the same way. In the future we will want to be able to launch different chrome instances each with their own unique characteristics as well as other web browsers.
K6_INSTANCE_SCENARIOS
takes precedence overK6_BROWSER_WS_URL
.K6_BROWSER_WS_URL
could still be useful for debugging purposes.Closes: #888
Checklist
Tasks