From b32888d4c7129a1a51113206dcc07f0634f4471d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Miri=C4=87?= Date: Fri, 5 May 2023 14:36:01 +0200 Subject: [PATCH] Make scenario options JSON field optional Previously, the new scenario `options` field added in #3036 was being serialized to JSON by default, which made it an incompatible change with some of our internal Cloud services that validate the existing configuration structure. This change makes the object optional, and it will only be serialized if it's included in the data. --- cmd/tests/cmd_run_test.go | 2 +- js/modules/k6/execution/execution_test.go | 2 +- lib/executor/base_config.go | 18 +++++++++--------- lib/executor/executors_test.go | 2 +- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/cmd/tests/cmd_run_test.go b/cmd/tests/cmd_run_test.go index 5b1515d9ec5e..b218af734169 100644 --- a/cmd/tests/cmd_run_test.go +++ b/cmd/tests/cmd_run_test.go @@ -431,7 +431,7 @@ func TestExecutionTestOptionsDefaultValues(t *testing.T) { loglines := ts.LoggerHook.Drain() require.Len(t, loglines, 1) - expected := `{"paused":null,"executionSegment":null,"executionSegmentSequence":null,"noSetup":null,"setupTimeout":null,"noTeardown":null,"teardownTimeout":null,"rps":null,"dns":{"ttl":null,"select":null,"policy":null},"maxRedirects":null,"userAgent":null,"batch":null,"batchPerHost":null,"httpDebug":null,"insecureSkipTLSVerify":null,"tlsCipherSuites":null,"tlsVersion":null,"tlsAuth":null,"throw":null,"thresholds":null,"blacklistIPs":null,"blockHostnames":null,"hosts":null,"noConnectionReuse":null,"noVUConnectionReuse":null,"minIterationDuration":null,"ext":null,"summaryTrendStats":["avg", "min", "med", "max", "p(90)", "p(95)"],"summaryTimeUnit":null,"systemTags":["check","error","error_code","expected_response","group","method","name","proto","scenario","service","status","subproto","tls_version","url"],"tags":null,"metricSamplesBufferSize":null,"noCookiesReset":null,"discardResponseBodies":null,"consoleOutput":null,"scenarios":{"default":{"vus":null,"iterations":1,"executor":"shared-iterations","maxDuration":null,"options":{"browser":null},"startTime":null,"env":null,"tags":null,"gracefulStop":null,"exec":null}},"localIPs":null}` + expected := `{"paused":null,"executionSegment":null,"executionSegmentSequence":null,"noSetup":null,"setupTimeout":null,"noTeardown":null,"teardownTimeout":null,"rps":null,"dns":{"ttl":null,"select":null,"policy":null},"maxRedirects":null,"userAgent":null,"batch":null,"batchPerHost":null,"httpDebug":null,"insecureSkipTLSVerify":null,"tlsCipherSuites":null,"tlsVersion":null,"tlsAuth":null,"throw":null,"thresholds":null,"blacklistIPs":null,"blockHostnames":null,"hosts":null,"noConnectionReuse":null,"noVUConnectionReuse":null,"minIterationDuration":null,"ext":null,"summaryTrendStats":["avg", "min", "med", "max", "p(90)", "p(95)"],"summaryTimeUnit":null,"systemTags":["check","error","error_code","expected_response","group","method","name","proto","scenario","service","status","subproto","tls_version","url"],"tags":null,"metricSamplesBufferSize":null,"noCookiesReset":null,"discardResponseBodies":null,"consoleOutput":null,"scenarios":{"default":{"vus":null,"iterations":1,"executor":"shared-iterations","maxDuration":null,"startTime":null,"env":null,"tags":null,"gracefulStop":null,"exec":null}},"localIPs":null}` assert.JSONEq(t, expected, loglines[0].Message) } diff --git a/js/modules/k6/execution/execution_test.go b/js/modules/k6/execution/execution_test.go index f949be4344ce..c3255f2de518 100644 --- a/js/modules/k6/execution/execution_test.go +++ b/js/modules/k6/execution/execution_test.go @@ -211,7 +211,7 @@ func TestOptionsTestFull(t *testing.T) { Tags: map[string]string{ "tagkey": "tagvalue", }, - Options: lib.ScenarioOptions{ + Options: &lib.ScenarioOptions{ Browser: map[string]any{ "someOption": true, }, diff --git a/lib/executor/base_config.go b/lib/executor/base_config.go index bcb8c3ce5afa..dea8a7d9da17 100644 --- a/lib/executor/base_config.go +++ b/lib/executor/base_config.go @@ -23,14 +23,14 @@ const executorNameErr = "the executor name should contain only numbers, latin le // BaseConfig contains the common config fields for all executors type BaseConfig struct { - Name string `json:"-"` // set via the JS object key - Type string `json:"executor"` - StartTime types.NullDuration `json:"startTime"` - GracefulStop types.NullDuration `json:"gracefulStop"` - Env map[string]string `json:"env"` - Exec null.String `json:"exec"` // function name, externally validated - Tags map[string]string `json:"tags"` - Options lib.ScenarioOptions `json:"options"` + Name string `json:"-"` // set via the JS object key + Type string `json:"executor"` + StartTime types.NullDuration `json:"startTime"` + GracefulStop types.NullDuration `json:"gracefulStop"` + Env map[string]string `json:"env"` + Exec null.String `json:"exec"` // function name, externally validated + Tags map[string]string `json:"tags"` + Options *lib.ScenarioOptions `json:"options,omitempty"` // TODO: future extensions like distribution, others? } @@ -113,7 +113,7 @@ func (bc BaseConfig) GetExec() string { // GetScenarioOptions returns the options specific to a scenario. func (bc BaseConfig) GetScenarioOptions() *lib.ScenarioOptions { - return &bc.Options + return bc.Options } // GetTags returns any custom tags configured for the executor. diff --git a/lib/executor/executors_test.go b/lib/executor/executors_test.go index 5939e6ed8def..62801240feae 100644 --- a/lib/executor/executors_test.go +++ b/lib/executor/executors_test.go @@ -472,7 +472,7 @@ func TestArchiveRoundTripScenarioOptions(t *testing.T) { Tags: map[string]string{ "tagkey": "tagvalue", }, - Options: lib.ScenarioOptions{ + Options: &lib.ScenarioOptions{ Browser: map[string]any{ "someOption": "someValue", },