Skip to content

Commit

Permalink
Make scenario options JSON field optional
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Ivan Mirić committed May 5, 2023
1 parent 07762a2 commit b32888d
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion cmd/tests/cmd_run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
2 changes: 1 addition & 1 deletion js/modules/k6/execution/execution_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down
18 changes: 9 additions & 9 deletions lib/executor/base_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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?
}
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion lib/executor/executors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
Expand Down

0 comments on commit b32888d

Please sign in to comment.