diff --git a/cmd/config.go b/cmd/config.go index b5f84a3291a..8a37a55d57e 100644 --- a/cmd/config.go +++ b/cmd/config.go @@ -203,8 +203,8 @@ func getConsolidatedConfig(gs *state.GlobalState, cliConf Config, runnerOpts lib // // Note that if you add option default value here, also add it in command line argument help text. func applyDefault(conf Config) Config { - if conf.SystemTags == nil { - conf.SystemTags = &metrics.DefaultSystemTagSet + if !conf.SystemTags.Valid { + conf.SystemTags = metrics.DefaultSystemTagSet } if conf.SummaryTrendStats == nil { conf.SummaryTrendStats = lib.DefaultSummaryTrendStats diff --git a/cmd/config_consolidation_test.go b/cmd/config_consolidation_test.go index a4211cfeef1..95bc066293c 100644 --- a/cmd/config_consolidation_test.go +++ b/cmd/config_consolidation_test.go @@ -330,23 +330,29 @@ func getConfigConsolidationTestCases() []configConsolidationTestCase { // Test system tags {opts{}, exp{}, func(t *testing.T, c Config) { - assert.Equal(t, &metrics.DefaultSystemTagSet, c.Options.SystemTags) + assert.Equal(t, metrics.DefaultSystemTagSet, c.Options.SystemTags) }}, {opts{cli: []string{"--system-tags", `""`}}, exp{}, func(t *testing.T, c Config) { - assert.Equal(t, metrics.SystemTagSet(0), *c.Options.SystemTags) + assert.Equal(t, metrics.NewNullSystemTagSet(metrics.SystemTag(0)), c.Options.SystemTags) + }}, + {opts{env: []string{"K6_SYSTEM_TAGS=proto,method"}}, exp{}, func(t *testing.T, c Config) { + assert.Equal(t, metrics.NewNullSystemTagSet(metrics.TagProto|metrics.TagMethod), c.Options.SystemTags) + }}, + {opts{env: []string{"K6_SYSTEM_TAGS=\"\""}}, exp{}, func(t *testing.T, c Config) { + assert.Equal(t, metrics.NewNullSystemTagSet(metrics.SystemTag(0)), c.Options.SystemTags) }}, { opts{ runner: &lib.Options{ - SystemTags: metrics.NewSystemTagSet(metrics.TagSubproto, metrics.TagURL), + SystemTags: metrics.NewNullSystemTagSet(metrics.TagSubproto, metrics.TagURL), }, }, exp{}, func(t *testing.T, c Config) { assert.Equal( t, - *metrics.NewSystemTagSet(metrics.TagSubproto, metrics.TagURL), - *c.Options.SystemTags, + metrics.NewNullSystemTagSet(metrics.TagSubproto, metrics.TagURL), + c.Options.SystemTags, ) }, }, diff --git a/cmd/options.go b/cmd/options.go index 13ec8aa4b0d..7485aac6d6d 100644 --- a/cmd/options.go +++ b/cmd/options.go @@ -151,7 +151,7 @@ func getOptions(flags *pflag.FlagSet) (lib.Options, error) { if err != nil { return opts, err } - opts.SystemTags = metrics.ToSystemTagSet(systemTagList) + opts.SystemTags = metrics.ToNullSystemTagSet(systemTagList) } blacklistIPStrings, err := flags.GetStringSlice("blacklist-ip") diff --git a/execution/scheduler_ext_test.go b/execution/scheduler_ext_test.go index 73796319403..018cf81134f 100644 --- a/execution/scheduler_ext_test.go +++ b/execution/scheduler_ext_test.go @@ -329,7 +329,7 @@ func TestSchedulerSystemTags(t *testing.T) { require.NoError(t, err) require.NoError(t, runner.SetOptions(runner.GetOptions().Apply(lib.Options{ - SystemTags: &metrics.DefaultSystemTagSet, + SystemTags: metrics.DefaultSystemTagSet, }))) testRunState := getTestRunState(t, piState, runner.GetOptions(), runner) @@ -1184,7 +1184,7 @@ func TestRealTimeAndSetupTeardownMetrics(t *testing.T) { options, err := executor.DeriveScenariosFromShortcuts(runner.GetOptions().Apply(lib.Options{ Iterations: null.IntFrom(2), VUs: null.IntFrom(1), - SystemTags: &metrics.DefaultSystemTagSet, + SystemTags: metrics.DefaultSystemTagSet, SetupTimeout: types.NullDurationFrom(4 * time.Second), TeardownTimeout: types.NullDurationFrom(4 * time.Second), }), nil) diff --git a/js/http_bench_test.go b/js/http_bench_test.go index f97f4f22bec..08ca7547694 100644 --- a/js/http_bench_test.go +++ b/js/http_bench_test.go @@ -34,7 +34,7 @@ func BenchmarkHTTPRequests(b *testing.B) { MaxRedirects: null.IntFrom(10), Hosts: types.NullHosts{Trie: tb.Dialer.Hosts}, NoCookiesReset: null.BoolFrom(true), - SystemTags: &metrics.DefaultSystemTagSet, + SystemTags: metrics.DefaultSystemTagSet, RunTags: map[string]string{"myapp": "myhttpbench"}, }) require.NoError(b, err) diff --git a/js/modules/k6/execution/execution_test.go b/js/modules/k6/execution/execution_test.go index 615d0f7f232..7324cb6a9f9 100644 --- a/js/modules/k6/execution/execution_test.go +++ b/js/modules/k6/execution/execution_test.go @@ -77,7 +77,7 @@ func TestVUTagsMetadatasJSONEncoding(t *testing.T) { tenv := setupTagsExecEnv(t) tenv.MoveToVUContext(&lib.State{ Options: lib.Options{ - SystemTags: metrics.NewSystemTagSet(metrics.TagVU), + SystemTags: metrics.NewNullSystemTagSet(metrics.TagVU), }, Tags: lib.NewVUStateTags(metrics.NewRegistry().RootTagSet()), }) @@ -170,7 +170,7 @@ func TestVUTagsMetadataErrorOutOnInvalidValues(t *testing.T) { tenv := setupTagsExecEnv(t) tenv.MoveToVUContext(&lib.State{ Options: lib.Options{ - SystemTags: metrics.NewSystemTagSet(metrics.TagVU), + SystemTags: metrics.NewNullSystemTagSet(metrics.TagVU), }, Tags: lib.NewVUStateTags(metrics.NewRegistry().RootTagSet().With("vu", "42")), Logger: testLog, @@ -345,9 +345,8 @@ func TestOptionsTestFull(t *testing.T) { }, SummaryTrendStats: []string{"avg", "min", "max"}, SummaryTimeUnit: null.StringFrom("ms"), - SystemTags: func() *metrics.SystemTagSet { - sysm := metrics.SystemTagSet(metrics.TagIter | metrics.TagVU) - return &sysm + SystemTags: func() metrics.NullSystemTagSet { + return metrics.NewNullSystemTagSet(metrics.TagIter | metrics.TagVU) }(), RunTags: map[string]string{"runtag-key": "runtag-value"}, MetricSamplesBufferSize: null.IntFrom(8), diff --git a/js/modules/k6/experimental/tracing/client_test.go b/js/modules/k6/experimental/tracing/client_test.go index 1932f787e63..f0889c32471 100644 --- a/js/modules/k6/experimental/tracing/client_test.go +++ b/js/modules/k6/experimental/tracing/client_test.go @@ -233,7 +233,7 @@ func TestCallingInstrumentedRequestEmitsTraceIdMetadata(t *testing.T) { Transport: httpBin.HTTPTransport, BufferPool: lib.NewBufferPool(), Samples: samples, - Options: lib.Options{SystemTags: &metrics.DefaultSystemTagSet}, + Options: lib.Options{SystemTags: metrics.DefaultSystemTagSet}, }) // Inject a function in the JS runtime to assert the trace_id key diff --git a/js/modules/k6/grpc/params_test.go b/js/modules/k6/grpc/params_test.go index c43c6d91fa2..15d666608fe 100644 --- a/js/modules/k6/grpc/params_test.go +++ b/js/modules/k6/grpc/params_test.go @@ -158,7 +158,7 @@ func newParamsTestRuntime(t *testing.T, paramsJSON string) (*modulestest.Runtime state := &lib.State{ Group: root, Options: lib.Options{ - SystemTags: metrics.NewSystemTagSet( + SystemTags: metrics.NewNullSystemTagSet( metrics.TagName, metrics.TagURL, ), diff --git a/js/modules/k6/grpc/teststate_test.go b/js/modules/k6/grpc/teststate_test.go index 0340e9391e8..72408ba6b27 100644 --- a/js/modules/k6/grpc/teststate_test.go +++ b/js/modules/k6/grpc/teststate_test.go @@ -153,7 +153,7 @@ func (ts *testState) ToVUContext() { TLSConfig: ts.httpBin.TLSClientConfig, Samples: ts.samples, Options: lib.Options{ - SystemTags: metrics.NewSystemTagSet( + SystemTags: metrics.NewNullSystemTagSet( metrics.TagName, metrics.TagURL, ), diff --git a/js/modules/k6/http/request_test.go b/js/modules/k6/http/request_test.go index f997da34b5e..7caf7a2f85c 100644 --- a/js/modules/k6/http/request_test.go +++ b/js/modules/k6/http/request_test.go @@ -142,7 +142,7 @@ func newTestCase(t testing.TB) *httpTestCase { MaxRedirects: null.IntFrom(10), UserAgent: null.StringFrom("TestUserAgent"), Throw: null.BoolFrom(true), - SystemTags: &metrics.DefaultSystemTagSet, + SystemTags: metrics.DefaultSystemTagSet, Batch: null.IntFrom(20), BatchPerHost: null.IntFrom(20), // HTTPDebug: null.StringFrom("full"), diff --git a/js/modules/k6/http/response_callback_test.go b/js/modules/k6/http/response_callback_test.go index 6bd1c303cb6..b8072844993 100644 --- a/js/modules/k6/http/response_callback_test.go +++ b/js/modules/k6/http/response_callback_test.go @@ -544,5 +544,5 @@ func deleteSystemTag(state *lib.State, tag string) { for k := range enabledTags { tagsList = append(tagsList, k) } - state.Options.SystemTags = metrics.ToSystemTagSet(tagsList) + state.Options.SystemTags = metrics.ToNullSystemTagSet(tagsList) } diff --git a/js/modules/k6/k6_test.go b/js/modules/k6/k6_test.go index 74432901088..81af44f0fe1 100644 --- a/js/modules/k6/k6_test.go +++ b/js/modules/k6/k6_test.go @@ -414,7 +414,7 @@ func testCaseRuntime(t testing.TB) *testCase { state := &lib.State{ Group: root, Options: lib.Options{ - SystemTags: &metrics.DefaultSystemTagSet, + SystemTags: metrics.DefaultSystemTagSet, }, Samples: samples, Tags: lib.NewVUStateTags(registry.RootTagSet().WithTagsFromMap(map[string]string{"group": root.Path})), diff --git a/js/modules/k6/ws/ws_test.go b/js/modules/k6/ws/ws_test.go index 7239b2ee17c..1cb1784758c 100644 --- a/js/modules/k6/ws/ws_test.go +++ b/js/modules/k6/ws/ws_test.go @@ -92,7 +92,7 @@ func newTestState(t testing.TB) testState { Group: root, Dialer: tb.Dialer, Options: lib.Options{ - SystemTags: metrics.NewSystemTagSet( + SystemTags: metrics.NewNullSystemTagSet( metrics.TagURL, metrics.TagProto, metrics.TagStatus, @@ -736,7 +736,7 @@ func TestSystemTags(t *testing.T) { expectedTag, err := metrics.SystemTagString(expectedTagStr) require.NoError(t, err) tb := httpmultibin.NewHTTPMultiBin(t) - test.VU.StateField.Options.SystemTags = metrics.ToSystemTagSet([]string{expectedTagStr}) + test.VU.StateField.Options.SystemTags = metrics.ToNullSystemTagSet([]string{expectedTagStr}) _, err = test.VU.Runtime().RunString(tb.Replacer.Replace(` var res = ws.connect("WSBIN_URL/ws-echo", function(socket){ socket.on("open", function() { diff --git a/js/runner_test.go b/js/runner_test.go index f8a0273f0a1..ec573201b57 100644 --- a/js/runner_test.go +++ b/js/runner_test.go @@ -2180,7 +2180,7 @@ func TestSystemTags(t *testing.T) { require.NoError(t, r.SetOptions(r.GetOptions().Apply(lib.Options{ Throw: null.BoolFrom(false), TLSVersion: &lib.TLSVersions{Max: tls.VersionTLS13}, - SystemTags: metrics.ToSystemTagSet([]string{tc.tag}), + SystemTags: metrics.ToNullSystemTagSet([]string{tc.tag}), InsecureSkipTLSVerify: null.BoolFrom(true), }))) @@ -2653,7 +2653,7 @@ func TestExecutionInfo(t *testing.T) { } require.NoError(t, err) - r.Bundle.Options.SystemTags = &metrics.DefaultSystemTagSet + r.Bundle.Options.SystemTags = metrics.DefaultSystemTagSet samples := make(chan metrics.SampleContainer, 100) ctx, cancel := context.WithCancel(context.Background()) diff --git a/lib/archive_test.go b/lib/archive_test.go index 96036de086c..304e3b50b4c 100644 --- a/lib/archive_test.go +++ b/lib/archive_test.go @@ -123,7 +123,7 @@ func TestArchiveReadWrite(t *testing.T) { K6Version: consts.Version, Options: Options{ VUs: null.IntFrom(12345), - SystemTags: &metrics.DefaultSystemTagSet, + SystemTags: metrics.DefaultSystemTagSet, }, FilenameURL: &url.URL{Scheme: "file", Path: "/path/to/a.js"}, Data: []byte(`// a contents`), @@ -174,7 +174,7 @@ func TestArchiveReadWrite(t *testing.T) { Type: "js", Options: Options{ VUs: null.IntFrom(12345), - SystemTags: &metrics.DefaultSystemTagSet, + SystemTags: metrics.DefaultSystemTagSet, }, FilenameURL: &url.URL{Scheme: "file", Path: fmt.Sprintf("%s/a.js", entry.Pwd)}, K6Version: consts.Version, @@ -197,7 +197,7 @@ func TestArchiveReadWrite(t *testing.T) { Type: "js", Options: Options{ VUs: null.IntFrom(12345), - SystemTags: &metrics.DefaultSystemTagSet, + SystemTags: metrics.DefaultSystemTagSet, }, FilenameURL: &url.URL{Scheme: "file", Path: fmt.Sprintf("%s/a.js", entry.PwdNormAnon)}, K6Version: consts.Version, @@ -329,7 +329,7 @@ func TestStrangePaths(t *testing.T) { K6Version: consts.Version, Options: Options{ VUs: null.IntFrom(12345), - SystemTags: &metrics.DefaultSystemTagSet, + SystemTags: metrics.DefaultSystemTagSet, }, FilenameURL: &url.URL{Scheme: "file", Path: pathToChange}, Data: []byte(`// ` + pathToChange + ` contents`), diff --git a/lib/netext/httpext/request_test.go b/lib/netext/httpext/request_test.go index 7bb6441acb9..17f9394d8bd 100644 --- a/lib/netext/httpext/request_test.go +++ b/lib/netext/httpext/request_test.go @@ -249,7 +249,7 @@ func TestMakeRequestTimeoutInTheMiddle(t *testing.T) { registry := metrics.NewRegistry() state := &lib.State{ Options: lib.Options{ - SystemTags: &metrics.DefaultSystemTagSet, + SystemTags: metrics.DefaultSystemTagSet, }, Transport: srv.Client().Transport, Samples: samples, @@ -327,7 +327,7 @@ func TestTrailFailed(t *testing.T) { registry := metrics.NewRegistry() state := &lib.State{ Options: lib.Options{ - SystemTags: &metrics.DefaultSystemTagSet, + SystemTags: metrics.DefaultSystemTagSet, }, Transport: srv.Client().Transport, Samples: samples, @@ -392,7 +392,7 @@ func TestMakeRequestDialTimeout(t *testing.T) { registry := metrics.NewRegistry() state := &lib.State{ Options: lib.Options{ - SystemTags: &metrics.DefaultSystemTagSet, + SystemTags: metrics.DefaultSystemTagSet, }, Transport: &http.Transport{ DialContext: (&net.Dialer{ @@ -452,7 +452,7 @@ func TestMakeRequestTimeoutInTheBegining(t *testing.T) { registry := metrics.NewRegistry() state := &lib.State{ Options: lib.Options{ - SystemTags: &metrics.DefaultSystemTagSet, + SystemTags: metrics.DefaultSystemTagSet, }, Transport: srv.Client().Transport, Samples: samples, @@ -521,7 +521,7 @@ func TestMakeRequestRPSLimit(t *testing.T) { registry := metrics.NewRegistry() state := &lib.State{ Options: lib.Options{ - SystemTags: &metrics.DefaultSystemTagSet, + SystemTags: metrics.DefaultSystemTagSet, }, RPSLimit: rate.NewLimiter(rate.Limit(1), 1), Transport: ts.Client().Transport, diff --git a/lib/netext/httpext/transport_test.go b/lib/netext/httpext/transport_test.go index 1a049702615..8f3ae9faa52 100644 --- a/lib/netext/httpext/transport_test.go +++ b/lib/netext/httpext/transport_test.go @@ -26,7 +26,7 @@ func BenchmarkMeasureAndEmitMetrics(b *testing.B) { registry := metrics.NewRegistry() state := &lib.State{ Options: lib.Options{ - SystemTags: &metrics.DefaultSystemTagSet, + SystemTags: metrics.DefaultSystemTagSet, }, BuiltinMetrics: metrics.RegisterBuiltinMetrics(registry), Samples: samples, diff --git a/lib/options.go b/lib/options.go index 9331028fec4..56d682651fd 100644 --- a/lib/options.go +++ b/lib/options.go @@ -323,7 +323,7 @@ type Options struct { // Which system tags to include with metrics ("method", "vu" etc.) // Use pointer for identifying whether user provide any tag or not. - SystemTags *metrics.SystemTagSet `json:"systemTags" envconfig:"K6_SYSTEM_TAGS"` + SystemTags metrics.NullSystemTagSet `json:"systemTags" envconfig:"K6_SYSTEM_TAGS"` // Tags are key-value pairs to be applied to all samples for the run. RunTags map[string]string `json:"tags" envconfig:"K6_TAGS"` @@ -484,7 +484,7 @@ func (o Options) Apply(opts Options) Options { if opts.SummaryTimeUnit.Valid { o.SummaryTimeUnit = opts.SummaryTimeUnit } - if opts.SystemTags != nil { + if opts.SystemTags.Valid { o.SystemTags = opts.SystemTags } if len(opts.RunTags) > 0 { diff --git a/lib/options_test.go b/lib/options_test.go index 351cf0a7e55..ed1220a00a2 100644 --- a/lib/options_test.go +++ b/lib/options_test.go @@ -504,7 +504,7 @@ func TestOptions(t *testing.T) { }) t.Run("SystemTags", func(t *testing.T) { t.Parallel() - opts := Options{}.Apply(Options{SystemTags: metrics.NewSystemTagSet(metrics.TagProto)}) + opts := Options{}.Apply(Options{SystemTags: metrics.NewNullSystemTagSet(metrics.TagProto)}) assert.NotNil(t, opts.SystemTags) assert.NotEmpty(t, opts.SystemTags) assert.True(t, opts.SystemTags.Has(metrics.TagProto)) @@ -516,16 +516,16 @@ func TestOptions(t *testing.T) { var opts Options jsonStr := `{"systemTags":["url"]}` assert.NoError(t, json.Unmarshal([]byte(jsonStr), &opts)) - assert.Equal(t, *metrics.NewSystemTagSet(metrics.TagURL), *opts.SystemTags) + assert.Equal(t, metrics.NewNullSystemTagSet(metrics.TagURL), opts.SystemTags) t.Run("Roundtrip", func(t *testing.T) { t.Parallel() data, err := json.Marshal(opts.SystemTags) assert.NoError(t, err) assert.Equal(t, `["url"]`, string(data)) - var vers2 metrics.SystemTagSet + var vers2 metrics.NullSystemTagSet assert.NoError(t, json.Unmarshal(data, &vers2)) - assert.Equal(t, vers2, *opts.SystemTags) + assert.Equal(t, vers2, opts.SystemTags) }) }) t.Run("Blank", func(t *testing.T) { @@ -533,7 +533,7 @@ func TestOptions(t *testing.T) { var opts Options jsonStr := `{"systemTags":[]}` assert.NoError(t, json.Unmarshal([]byte(jsonStr), &opts)) - assert.Equal(t, metrics.SystemTagSet(0), *opts.SystemTags) + assert.Equal(t, metrics.NewNullSystemTagSet(0), opts.SystemTags) }) }) }) diff --git a/metrics/system_tag.go b/metrics/system_tag.go index 15e70f7a10c..d86bbac7a57 100644 --- a/metrics/system_tag.go +++ b/metrics/system_tag.go @@ -44,14 +44,14 @@ const ( // Other tags that are not enabled by default include: iter, vu, ocsp_status, ip // //nolint:gochecknoglobals -var DefaultSystemTagSet = SystemTagSet( +var DefaultSystemTagSet = NewNullSystemTagSet( TagProto | TagSubproto | TagStatus | TagMethod | TagURL | TagName | TagGroup | TagCheck | TagError | TagErrorCode | TagTLSVersion | TagScenario | TagService | TagExpectedResponse) // NonIndexableSystemTags are high cardinality system tags (i.e. metadata). // //nolint:gochecknoglobals -var NonIndexableSystemTags = SystemTagSet(TagIter | TagVU) +var NonIndexableSystemTags = NewNullSystemTagSet(TagIter | TagVU) // Add adds a tag to tag set. func (i *SystemTagSet) Add(tag SystemTag) { @@ -153,3 +153,91 @@ func (i *SystemTagSet) UnmarshalText(data []byte) error { } return nil } + +// NullSystemTagSet is a wrapper around SystemTagSet like guregu/null +type NullSystemTagSet struct { + Set *SystemTagSet + Valid bool +} + +// ToNullSystemTagSet converts list of tags to NullSystemTagSet +func ToNullSystemTagSet(tags []string) NullSystemTagSet { + return NullSystemTagSet{ + Set: ToSystemTagSet(tags), + Valid: true, + } +} + +// NewNullSystemTagSet returns valid (Valid: true) SystemTagSet +func NewNullSystemTagSet(tags ...SystemTag) NullSystemTagSet { + return NullSystemTagSet{ + Set: NewSystemTagSet(tags...), + Valid: true, + } +} + +// Add adds a tag to tag set. +func (n *NullSystemTagSet) Add(tag SystemTag) { + if n.Set == nil { + n.Set = new(SystemTagSet) + n.Valid = true + } + n.Set.Add(tag) +} + +// Has checks a tag included in tag set. +func (n NullSystemTagSet) Has(tag SystemTag) bool { + if !n.Valid { + return false + } + return n.Set.Has(tag) +} + +// Map returns the EnabledTags with current value from SystemTagSet +func (n NullSystemTagSet) Map() EnabledTags { + return n.Set.Map() +} + +// SetString returns comma separated list of the string representation of all values in the set +func (n NullSystemTagSet) SetString() string { + return n.Set.SetString() +} + +// MarshalJSON converts NullSystemTagSet to valid JSON +func (n NullSystemTagSet) MarshalJSON() ([]byte, error) { + if !n.Valid { + return []byte(nullJSON), nil + } + + return n.Set.MarshalJSON() +} + +// UnmarshalJSON converts JSON to NullSystemTagSet +func (n *NullSystemTagSet) UnmarshalJSON(data []byte) error { + if bytes.Equal(data, []byte(nullJSON)) { + n.Set = nil + n.Valid = false + return nil + } + + var set SystemTagSet + if err := json.Unmarshal(data, &set); err != nil { + return err + } + n.Set = &set + n.Valid = true + return nil +} + +// UnmarshalText converts the tag list to SystemTagSet. +func (n *NullSystemTagSet) UnmarshalText(data []byte) error { + var set SystemTagSet + if err := set.UnmarshalText(data); err != nil { + return err + } + n.Set = &set + n.Valid = true + return nil +} + +const nullJSON = "null" diff --git a/metrics/tags.go b/metrics/tags.go index d94f4dc2c3b..3c1b118e9da 100644 --- a/metrics/tags.go +++ b/metrics/tags.go @@ -186,9 +186,9 @@ func (tm *TagsAndMeta) SetMetadata(key, value string) { } // SetSystemTagOrMetaIfEnabled checks if the supplied SystemTag is enabled in -// this test run (i.e. is in the SystemTagSet) and passes it to +// this test run (i.e. is in the NullSystemTagSet) and passes it to // SetSystemTagOrMeta() if it is. -func (tm *TagsAndMeta) SetSystemTagOrMetaIfEnabled(enabledSystemTags *SystemTagSet, tag SystemTag, value string) { +func (tm *TagsAndMeta) SetSystemTagOrMetaIfEnabled(enabledSystemTags NullSystemTagSet, tag SystemTag, value string) { if !enabledSystemTags.Has(tag) { return } diff --git a/metrics/tags_test.go b/metrics/tags_test.go index 1e4a7feb067..940b034f126 100644 --- a/metrics/tags_test.go +++ b/metrics/tags_test.go @@ -170,11 +170,11 @@ func TestTagsAndMetaSetSystemTagOrMetaIfEnabled(t *testing.T) { t.Parallel() tm := TagsAndMeta{} - tm.SetSystemTagOrMetaIfEnabled(&DefaultSystemTagSet, TagIter, "10") + tm.SetSystemTagOrMetaIfEnabled(DefaultSystemTagSet, TagIter, "10") _, ok := tm.Metadata["iter"] assert.False(t, ok) - tm.SetSystemTagOrMetaIfEnabled(&NonIndexableSystemTags, TagIter, "10") + tm.SetSystemTagOrMetaIfEnabled(NonIndexableSystemTags, TagIter, "10") _, ok = tm.Metadata["iter"] assert.True(t, ok) } diff --git a/output/cloud/output.go b/output/cloud/output.go index d981a897f56..b4be6c4e5d9 100644 --- a/output/cloud/output.go +++ b/output/cloud/output.go @@ -139,7 +139,7 @@ func newOutput(params output.Params) (*Output, error) { } // validateRequiredSystemTags checks if all required tags are present. -func validateRequiredSystemTags(scriptTags *metrics.SystemTagSet) error { +func validateRequiredSystemTags(scriptTags metrics.NullSystemTagSet) error { missingRequiredTags := []string{} requiredTags := metrics.SystemTagSet(metrics.TagName | metrics.TagMethod | diff --git a/output/cloud/output_test.go b/output/cloud/output_test.go index 7b2bdeb098b..75c8390f251 100644 --- a/output/cloud/output_test.go +++ b/output/cloud/output_test.go @@ -64,7 +64,7 @@ func TestNewOutputNameResolution(t *testing.T) { Logger: testutils.NewLogger(t), ScriptOptions: lib.Options{ Duration: types.NullDurationFrom(1 * time.Second), - SystemTags: &metrics.DefaultSystemTagSet, + SystemTags: metrics.DefaultSystemTagSet, }, ScriptPath: testCase.url, }) @@ -80,7 +80,7 @@ func TestCloudOutputRequireScriptName(t *testing.T) { Logger: testutils.NewLogger(t), ScriptOptions: lib.Options{ Duration: types.NullDurationFrom(1 * time.Second), - SystemTags: &metrics.DefaultSystemTagSet, + SystemTags: metrics.DefaultSystemTagSet, }, ScriptPath: &url.URL{Path: ""}, }) @@ -117,7 +117,7 @@ func TestOutputCreateTestWithConfigOverwrite(t *testing.T) { "K6_CLOUD_AGGREGATION_PERIOD": "30s", }, ScriptOptions: lib.Options{ - SystemTags: &metrics.DefaultSystemTagSet, + SystemTags: metrics.DefaultSystemTagSet, }, ScriptPath: &url.URL{Path: "/script.js"}, }) @@ -140,7 +140,7 @@ func TestOutputStartVersionError(t *testing.T) { Logger: testutils.NewLogger(t), ScriptOptions: lib.Options{ Duration: types.NullDurationFrom(1 * time.Second), - SystemTags: &metrics.DefaultSystemTagSet, + SystemTags: metrics.DefaultSystemTagSet, }, Environment: map[string]string{ "K6_CLOUD_API_VERSION": "99", @@ -213,7 +213,7 @@ func TestOutputStartWithTestRunID(t *testing.T) { "K6_CLOUD_PUSH_REF_ID": "12345", }, ScriptOptions: lib.Options{ - SystemTags: &metrics.DefaultSystemTagSet, + SystemTags: metrics.DefaultSystemTagSet, }, ScriptPath: &url.URL{Path: "/script.js"}, }) @@ -269,7 +269,7 @@ func TestOutputStopWithTestError(t *testing.T) { "K6_CLOUD_HOST": ts.URL, }, ScriptOptions: lib.Options{ - SystemTags: &metrics.DefaultSystemTagSet, + SystemTags: metrics.DefaultSystemTagSet, }, ScriptPath: &url.URL{Path: "/script.js"}, }) diff --git a/output/csv/output_test.go b/output/csv/output_test.go index ff7f4fffdff..4b98e3f56c6 100644 --- a/output/csv/output_test.go +++ b/output/csv/output_test.go @@ -496,7 +496,7 @@ func TestRun(t *testing.T) { Environment: env, ConfigArgument: data.fileName, ScriptOptions: lib.Options{ - SystemTags: metrics.NewSystemTagSet(metrics.TagError | metrics.TagCheck | metrics.TagVU), + SystemTags: metrics.NewNullSystemTagSet(metrics.TagError | metrics.TagCheck | metrics.TagVU), }, }) require.NoError(t, err)