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

Parse the scenarios json from the K6_INSTANCE_SCENARIOS env var #906

Merged
merged 13 commits into from
May 30, 2023

Conversation

ankur22
Copy link
Collaborator

@ankur22 ankur22 commented May 24, 2023

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 is K6_INSTANCE_SCENARIOS. K6_INSTANCE_SCENARIOS defines a JSON object of the form:

[
    {
        "id": "one",
        "browsers": [
            { "handle": "ws://1..." }
        ]
    },
]

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 over K6_BROWSER_WS_URL. K6_BROWSER_WS_URL could still be useful for debugging purposes.

Closes: #888

Checklist

Tasks

@ankur22 ankur22 marked this pull request as draft May 24, 2023 15:47
@ankur22 ankur22 changed the title Add a method to parse and create remoteRegistry Parse the scenarios json from K6_BROWSER_WS_URL May 24, 2023
@ankur22 ankur22 changed the title Parse the scenarios json from K6_BROWSER_WS_URL Parse the scenarios json from the K6_BROWSER_WS_URL env var May 24, 2023
@ankur22 ankur22 force-pushed the add/scenario-json-parsing branch 2 times, most recently from cf90f3a to 6893d12 Compare May 25, 2023 13:47
@ankur22 ankur22 changed the title Parse the scenarios json from the K6_BROWSER_WS_URL env var Parse the scenarios json from the K6_INSTANCE_SCENARIOS env var May 26, 2023
@ankur22 ankur22 requested review from inancgumus and ka3de May 26, 2023 11:33
@ankur22 ankur22 marked this pull request as ready for review May 26, 2023 11:35
Copy link
Member

@inancgumus inancgumus left a 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" 😄

browser/registry.go Outdated Show resolved Hide resolved
@ankur22
Copy link
Collaborator Author

ankur22 commented May 26, 2023

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.

Yeah, that's something I wasn't sure of, so I just used panic. I'll double check that though 👍

Squashing this PR might help. For example, "Add Some" 😄

🤦 thanks!

ankur22 and others added 12 commits May 26, 2023 13:02
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>
@ankur22 ankur22 force-pushed the add/scenario-json-parsing branch from 00da9ca to 78d971a Compare May 26, 2023 12:02
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.
@ankur22 ankur22 force-pushed the add/scenario-json-parsing branch from b7c2f59 to 1221193 Compare May 26, 2023 16:12
Copy link
Collaborator

@ka3de ka3de left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@ankur22 ankur22 deleted the add/scenario-json-parsing branch May 30, 2023 10:40
inancgumus added a commit that referenced this pull request Jun 1, 2023
This is needed because we're receiving a sanitized (quoted) sceneario
JSON data from remote.

Related: #906 and #888.
inancgumus added a commit that referenced this pull request Jun 1, 2023
This is needed because we receive the remote's sanitized (quoted) scenario JSON data.

Related: #906 and #888.
inancgumus added a commit that referenced this pull request Jun 2, 2023
inancgumus added a commit that referenced this pull request Jun 2, 2023
@inancgumus inancgumus added remote remote browser related dependencies Pull requests that update a dependency file labels Oct 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dependencies Pull requests that update a dependency file remote remote browser related
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Parse instance scenarios into a flat WS URL list
3 participants