From eb677897529a1d7c22ea2ded84bafb69d7d4fd45 Mon Sep 17 00:00:00 2001 From: ankur22 Date: Mon, 4 Mar 2024 11:37:31 +0000 Subject: [PATCH 1/3] Add new env var K6_CLOUD_PUSH_REF_ID This will help us keep track of the current test run id and allow components in the browser module to work with it. --- env/env.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/env/env.go b/env/env.go index 5f523fa41..1573e2380 100644 --- a/env/env.go +++ b/env/env.go @@ -81,6 +81,12 @@ const ( ScreenshotsOutput = "K6_BROWSER_SCREENSHOTS_OUTPUT" ) +const ( + // K6TestRunID represents the test run id. Note: this was taken from + // k6. + K6TestRunID = "K6_CLOUD_PUSH_REF_ID" +) + // LookupFunc defines a function to look up a key from the environment. type LookupFunc func(key string) (string, bool) From d85ce6b3077e877c282d053fab1890ac9fa1c1a2 Mon Sep 17 00:00:00 2001 From: ankur22 Date: Mon, 4 Mar 2024 11:38:37 +0000 Subject: [PATCH 2/3] Add parse of K6_CLOUD_PUSH_REF_ID This will read and record the value of K6_CLOUD_PUSH_REF_ID when it is available and not an empty string. The test run id will be available to any component that requires it. --- browser/module.go | 5 +++++ browser/modulevu.go | 2 ++ 2 files changed, 7 insertions(+) diff --git a/browser/module.go b/browser/module.go index 8ab1cfe8f..821fa06ac 100644 --- a/browser/module.go +++ b/browser/module.go @@ -38,6 +38,7 @@ type ( initOnce *sync.Once tracesMetadata map[string]string filePersister filePersister + testRunID string } // JSModule exposes the properties available to the JS script. @@ -91,6 +92,7 @@ func (m *RootModule) NewModuleInstance(vu k6modules.VU) k6modules.Instance { ), taskQueueRegistry: newTaskQueueRegistry(vu), filePersister: m.filePersister, + testRunID: m.testRunID, }), Devices: common.GetDevices(), NetworkProfiles: common.GetNetworkProfiles(), @@ -126,6 +128,9 @@ func (m *RootModule) initialize(vu k6modules.VU) { if err != nil { k6ext.Abort(vu.Context(), "failed to create file persister: %v", err) } + if e, ok := initEnv.LookupEnv(env.K6TestRunID); ok && e != "" { + m.testRunID = e + } } func startDebugServer() { diff --git a/browser/modulevu.go b/browser/modulevu.go index 64ae87324..ea6597985 100644 --- a/browser/modulevu.go +++ b/browser/modulevu.go @@ -22,6 +22,8 @@ type moduleVU struct { *taskQueueRegistry filePersister + + testRunID string } // browser returns the VU browser instance for the current iteration. From e8987b56d662397bce3d0c4be7be5f991cf075c1 Mon Sep 17 00:00:00 2001 From: ankur22 Date: Mon, 4 Mar 2024 13:37:14 +0000 Subject: [PATCH 3/3] Add comment on new env var block --- env/env.go | 1 + 1 file changed, 1 insertion(+) diff --git a/env/env.go b/env/env.go index 1573e2380..401673dfb 100644 --- a/env/env.go +++ b/env/env.go @@ -81,6 +81,7 @@ const ( ScreenshotsOutput = "K6_BROWSER_SCREENSHOTS_OUTPUT" ) +// Infrastructural. const ( // K6TestRunID represents the test run id. Note: this was taken from // k6.