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

Populate __ENV.K6_CLOUDRUN_TEST_RUN_ID on local executions of k6 cloud run #4092

Merged
merged 13 commits into from
Dec 24, 2024

Conversation

joanlopez
Copy link
Contributor

@joanlopez joanlopez commented Dec 5, 2024

What?

It populates the __ENV.K6_CLOUDRUN_TEST_RUN_ID, which is the environment variable that contains the test run id on Cloud executions, with the corresponding value for local executions streaming results to the Cloud: k6 cloud run --local-execution.

Why?

Because this unlocks different projects we have ongoing, currently blocked by the lack of a mechanism to read that variable on local executions streaming results to the Cloud.

Checklist

  • I have performed a self-review of my code.
  • I have added tests for my changes.
  • I have run linter locally (make lint) and all checks pass.
  • I have run tests locally (make tests) and all tests pass.
  • I have commented on my code, particularly in hard-to-understand areas.

Related PR(s)/Issue(s)

Contributes to #4041

@joanlopez joanlopez added the cloud label Dec 5, 2024
@joanlopez joanlopez requested a review from mstoykov December 5, 2024 13:54
@joanlopez joanlopez self-assigned this Dec 5, 2024
@joanlopez joanlopez requested a review from a team as a code owner December 5, 2024 13:54
@joanlopez joanlopez requested review from oleiade and removed request for a team December 5, 2024 13:54
@joanlopez
Copy link
Contributor Author

Note that the approach followed here won't make testRunId available for those executions still using the deprecated command to run a local execution: k6 run -o cloud, mainly because I cannot think of any feasible way to do that other than one that looks along the lines of what I did in k6/cloud-v2, and for which I know @mstoykov have objections to.

But I'd be very happy to see any suggestions or ideas for possible workarounds.
Although, I'm also happy with using that as mechanism to push those still using the deprecated command.

@joanlopez joanlopez added this to the v0.56.0 milestone Dec 5, 2024
oleiade
oleiade previously approved these changes Dec 9, 2024
Copy link
Member

@oleiade oleiade left a comment

Choose a reason for hiding this comment

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

I left a couple of nit comments behind, but none of them blocking, I'd be happy with this merged as-is. Great work!

js/modules/k6/cloud/cloud.go Outdated Show resolved Hide resolved
js/modules/k6/cloud/cloud.go Outdated Show resolved Hide resolved
js/modules/k6/cloud/cloud.go Outdated Show resolved Hide resolved
cloudapi/config.go Outdated Show resolved Hide resolved
cmd/cloud_run.go Outdated Show resolved Hide resolved
Comment on lines 134 to 141
raw, err := cloudConfToRawMessage(conf)
if err != nil {
return fmt.Errorf("could not serialize cloud configuration: %w", err)
}

test.derivedConfig.Collectors[builtinOutputCloud.String()] = raw

return nil
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this actually needed ? I guess maybe if we save it to disk, but not otherwise?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm lacking historical context here (about when and how those overrides are used), but in case there's overrides from Cloud, I guess we might want those to be applied and "sent" to the Cloud output 🤔

If not, I'm happy with removing the entire if block and just ignore overrides from Cloud here.

cmd/outputs_cloud.go Show resolved Hide resolved
@mstoykov
Copy link
Contributor

@joanlopez maybe first rebase though as there have been a few changes including to the CI that mean theat you will have more lint failures.

cmd/outputs_cloud.go Outdated Show resolved Hide resolved
cmd/outputs_cloud.go Outdated Show resolved Hide resolved
@joanlopez joanlopez changed the title k6/cloud module with the testRunId Populate __ENV.K6_CLOUDRUN_TEST_RUN_ID on local executions of k6 cloud run Dec 19, 2024
@joanlopez
Copy link
Contributor Author

Please @andrewslotin, @mstoykov, @oleiade, @olegbespalov, note that these changes will make __ENV.K6_CLOUDRUN_TEST_RUN_ID to be available when using the new k6 cloud run --local-execution, and NOT when using the legacy (deprecated) k6 run -o cloud.

That's mainly because that would require a larger refactor, to completely move the creation of the test run outside of the Cloud output, as I did in master...k6/cloud, but that would mean "making the Cloud output even a more special output", and @mstoykov discouraged that.

Otherwise, I don't think there's any way we can modify the environment from within the Cloud output particularly, and reflect that to the test's environment. But I'm open for suggestions/ideas, if any.

PS: @olegbespalov adding you as a reviewer, cause I think @oleiade won't be able to follow up on this PR for now.

@andrewslotin
Copy link
Contributor

@joanlopez, since k6 run -o cloud has been deprecated, I believe it's fair to not add new functionality there 👍

@joanlopez
Copy link
Contributor Author

@joanlopez, since k6 run -o cloud has been deprecated, I believe it's fair to not add new functionality there 👍

I agree, I just wanted to make it clear so w'all set proper expectations.

cmd/cloud_run.go Outdated
Comment on lines 140 to 147
// If the "K6_CLOUDRUN_TEST_RUN_ID" is set, then it means that this code is being executed in the k6 Cloud.
// Therefore, we don't need to continue with the test run creation, as we don't need to create any test run.
// This should technically never happen, as k6, when executed in the Cloud, it uses the standard "run"
// command "locally", but we add this early return just in case, for safety.
//
// If not, we know this execution requires a test run to be created in the Cloud.
// So, we create it as part of the process of loading and configuring the test.
if _, isSet := c.runCmd.gs.Env[testRunIDKey]; !isSet {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should just drop this part for now and maybe add it later.

Copy link
Contributor

Choose a reason for hiding this comment

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

I do agree

Copy link
Contributor

@mstoykov mstoykov left a comment

Choose a reason for hiding this comment

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

LGTM, just lets remoe the one if

cloudapi/config.go Outdated Show resolved Hide resolved
cmd/cloud_run.go Outdated
Comment on lines 140 to 147
// If the "K6_CLOUDRUN_TEST_RUN_ID" is set, then it means that this code is being executed in the k6 Cloud.
// Therefore, we don't need to continue with the test run creation, as we don't need to create any test run.
// This should technically never happen, as k6, when executed in the Cloud, it uses the standard "run"
// command "locally", but we add this early return just in case, for safety.
//
// If not, we know this execution requires a test run to be created in the Cloud.
// So, we create it as part of the process of loading and configuring the test.
if _, isSet := c.runCmd.gs.Env[testRunIDKey]; !isSet {
Copy link
Contributor

Choose a reason for hiding this comment

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

I do agree

output/cloud/output.go Show resolved Hide resolved
mstoykov
mstoykov previously approved these changes Dec 20, 2024
@joanlopez joanlopez merged commit 3b15ea0 into master Dec 24, 2024
27 of 28 checks passed
@joanlopez joanlopez deleted the k6/cloud-v3 branch December 24, 2024 08:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants