grafana / k6

A modern load testing tool, using Go and JavaScript - https://k6.io
GNU Affero General Public License v3.0
26.12k stars 1.27k forks source link

Expose GCk6 test run ID via a JS API to the test script #4041

Open andrewslotin opened 2 weeks ago

andrewslotin commented 2 weeks ago

Whenever a k6 test is executed in Grafana Cloud using k6 cloud run or if Grafana Cloud is set as an output with k6 cloud run --local-execution, a test run ID is generated for that execution. This identifier is helpful for distinguishing between local runs, such as debugging a load test script, and cloud executions. It also aids in correlating requests made during the test run.

Currently, there is no reliable way to retrieve this value from within the test script code. To address this, I propose modifying the options.cloud object returned by k6/execution, adding a field that will be populated with the test run ID for the current execution.

joanlopez commented 2 weeks ago

Side-note; I'm not sure if now there's "a reliable way to retrieve this value from within the" (paraphrasing the sentence above) Go code (e.g. an extension or output), but I'd really love if we make that possible as well as part of this task, as that will unlock/make possible other ideas we have on the backlog.

In essence, being able to now the Test Run Id from Go code, either a normal "JavaScript" extension or from an "output" extension.

cc/ @Blinkuu this might be of your relevance, as this would be a blocker/requirement for the "Insights output" idea we discussed, as you need the Test Run ID to fetch the insights from the API.

cc/ @oleiade I see you assigned here, so ping me if you need further context.

mstoykov commented 2 weeks ago

@joanlopez the original proposal is about putting it in options.cloud and practically every part of k6 has access to the options. Which is why I proposed it like that internally, instead of coming up with another specific API.