From 92c53db6d2505a17a679215ae7ad8761d3d0f8fb Mon Sep 17 00:00:00 2001 From: Mihail Stoykov Date: Fri, 30 Aug 2024 14:02:05 +0300 Subject: [PATCH] Drop String, leave only Strings --- cmd/report.go | 14 ++++++++------ output/cloud/output.go | 2 +- usage/usage.go | 31 +------------------------------ 3 files changed, 10 insertions(+), 37 deletions(-) diff --git a/cmd/report.go b/cmd/report.go index f9c334e1cf9..74a6e9d2e31 100644 --- a/cmd/report.go +++ b/cmd/report.go @@ -56,15 +56,17 @@ func createReport( } u.Strings("outputs", o) } - - u.String("k6_version", consts.Version) execState := execScheduler.GetState() u.Uint64("vus_max", uint64(execState.GetInitializedVUsCount())) u.Uint64("iterations", execState.GetFullIterationCount()) - u.String("duration", execState.GetCurrentTestRunDuration().String()) - u.String("goos", runtime.GOOS) - u.String("goarch", runtime.GOARCH) - return u.Map() + m := u.Map() + + m["k6_version"] = consts.Version + m["duration"] = execState.GetCurrentTestRunDuration().String() + m["goos"] = runtime.GOOS + m["goarch"] = runtime.GOARCH + + return m } func reportUsage(ctx context.Context, execScheduler *execution.Scheduler, test *loadedAndConfiguredTest) error { diff --git a/output/cloud/output.go b/output/cloud/output.go index 025199ec511..01b367d56ba 100644 --- a/output/cloud/output.go +++ b/output/cloud/output.go @@ -345,7 +345,7 @@ func (out *Output) startVersionedOutput() error { } var err error - out.usage.String("output.cloud.test_run_id", out.testRunID) + out.usage.Strings("cloud/test_run_id", out.testRunID) // TODO: move here the creation of a new cloudapi.Client // so in the case the config has been overwritten the client uses the correct diff --git a/usage/usage.go b/usage/usage.go index 640822eca21..0850c3fe5d6 100644 --- a/usage/usage.go +++ b/usage/usage.go @@ -20,28 +20,8 @@ func New() *Usage { } } -// String appends the provided value to a slice of strings that is the value. -// If called only a single time, the value will be just a string not a slice -func (u *Usage) String(k, v string) { - u.l.Lock() - defer u.l.Unlock() - oldV, ok := u.m[k] - if !ok { - u.m[k] = v - return - } - switch oldV := oldV.(type) { - case string: - u.m[k] = []string{oldV, v} - case []string: - u.m[k] = append(oldV, v) - default: - // TODO: error, panic?, nothing, log? - } -} - // Strings appends the provided value to a slice of strings that is the value. -// Unlike String it +// Appending to the slice if the key is already there. func (u *Usage) Strings(k, v string) { u.l.Lock() defer u.l.Unlock() @@ -109,15 +89,6 @@ func (u *Usage) Map() map[string]any { default: // TODO:panic? error? } - case string: - switch i := keyLevel.(type) { - case string: - keyLevel = append([]string(nil), i, value) - case []string: - keyLevel = append(i, value) //nolint:gocritic // we assign to the final value - default: - // TODO:panic? error? - } case []string: switch i := keyLevel.(type) { case []string: