Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add NullSystemTagSet to correctly read K6_SYSTEM_TAGS from env #3660

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 11 additions & 5 deletions cmd/config_consolidation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
},
},
Expand Down
2 changes: 1 addition & 1 deletion cmd/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
4 changes: 2 additions & 2 deletions execution/scheduler_ext_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion js/http_bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 4 additions & 5 deletions js/modules/k6/execution/execution_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
})
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion js/modules/k6/experimental/tracing/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion js/modules/k6/grpc/params_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
),
Expand Down
2 changes: 1 addition & 1 deletion js/modules/k6/grpc/teststate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
),
Expand Down
2 changes: 1 addition & 1 deletion js/modules/k6/http/request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
2 changes: 1 addition & 1 deletion js/modules/k6/http/response_callback_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
2 changes: 1 addition & 1 deletion js/modules/k6/k6_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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})),
Expand Down
4 changes: 2 additions & 2 deletions js/modules/k6/ws/ws_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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() {
Expand Down
4 changes: 2 additions & 2 deletions js/runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
})))

Expand Down Expand Up @@ -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())
Expand Down
8 changes: 4 additions & 4 deletions lib/archive_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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`),
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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`),
Expand Down
10 changes: 5 additions & 5 deletions lib/netext/httpext/request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion lib/netext/httpext/transport_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions lib/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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 {
Expand Down
10 changes: 5 additions & 5 deletions lib/options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -516,24 +516,24 @@ 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) {
t.Parallel()
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)
})
})
})
Expand Down
Loading
Loading