From 787e2cd897231def513578e281690f6374dba2f2 Mon Sep 17 00:00:00 2001 From: Ammar Bandukwala Date: Fri, 17 Feb 2023 20:37:06 +0000 Subject: [PATCH 1/4] feat(cli): make minor improvements to speedtest - Remove mostly redundant "Transferred" column - Rename "Bandwidth" to "Throughput" - Replace "--reverse" (which has an ambiguous starting state) with "--direction=(up|down)" - Tolerate AgentStartErrors which may be caused by failing startup script --- cli/speedtest.go | 31 +++++++++++++--------- cli/testdata/coder_speedtest_--help.golden | 10 +++---- 2 files changed, 23 insertions(+), 18 deletions(-) diff --git a/cli/speedtest.go b/cli/speedtest.go index 6dd0f10c4ea28..3ab9822b2a71e 100644 --- a/cli/speedtest.go +++ b/cli/speedtest.go @@ -19,9 +19,9 @@ import ( func speedtest() *cobra.Command { var ( - direct bool - duration time.Duration - reverse bool + direct bool + duration time.Duration + direction string ) cmd := &cobra.Command{ Annotations: workspaceCommand, @@ -48,7 +48,7 @@ func speedtest() *cobra.Command { return client.WorkspaceAgent(ctx, workspaceAgent.ID) }, }) - if err != nil { + if err != nil && !xerrors.Is(err, cliui.AgentStartError) { return xerrors.Errorf("await agent: %w", err) } logger := slog.Make(sloghuman.Sink(cmd.ErrOrStderr())) @@ -94,17 +94,22 @@ func speedtest() *cobra.Command { } else { conn.AwaitReachable(ctx) } - dir := tsspeedtest.Download - if reverse { - dir = tsspeedtest.Upload + var tsDir tsspeedtest.Direction + switch direction { + case "up": + tsDir = tsspeedtest.Upload + case "down": + tsDir = tsspeedtest.Download + default: + return xerrors.Errorf("invalid direction: %q", direction) } - cmd.Printf("Starting a %ds %s test...\n", int(duration.Seconds()), dir) - results, err := conn.Speedtest(ctx, dir, duration) + cmd.Printf("Starting a %ds %s test...\n", int(duration.Seconds()), tsDir) + results, err := conn.Speedtest(ctx, tsDir, duration) if err != nil { return err } tableWriter := cliui.Table() - tableWriter.AppendHeader(table.Row{"Interval", "Transfer", "Bandwidth"}) + tableWriter.AppendHeader(table.Row{"Interval", "Throughput"}) startTime := results[0].IntervalStart for _, r := range results { if r.Total { @@ -112,7 +117,6 @@ func speedtest() *cobra.Command { } tableWriter.AppendRow(table.Row{ fmt.Sprintf("%.2f-%.2f sec", r.IntervalStart.Sub(startTime).Seconds(), r.IntervalEnd.Sub(startTime).Seconds()), - fmt.Sprintf("%.4f MBits", r.MegaBits()), fmt.Sprintf("%.4f Mbits/sec", r.MBitsPerSecond()), }) } @@ -122,8 +126,9 @@ func speedtest() *cobra.Command { } cliflag.BoolVarP(cmd.Flags(), &direct, "direct", "d", "", false, "Specifies whether to wait for a direct connection before testing speed.") - cliflag.BoolVarP(cmd.Flags(), &reverse, "reverse", "r", "", false, - "Specifies whether to run in reverse mode where the client receives and the server sends.") + cliflag.StringVarP(cmd.Flags(), &direction, "direction", "", "", "down", + "Specifies whether to run in reverse mode where the client receives and the server sends. (up|down)", + ) cmd.Flags().DurationVarP(&duration, "time", "t", tsspeedtest.DefaultDuration, "Specifies the duration to monitor traffic.") return cmd diff --git a/cli/testdata/coder_speedtest_--help.golden b/cli/testdata/coder_speedtest_--help.golden index fa8cb952a866c..f3ba1eac6ae13 100644 --- a/cli/testdata/coder_speedtest_--help.golden +++ b/cli/testdata/coder_speedtest_--help.golden @@ -4,11 +4,11 @@ Usage: coder speedtest [flags] Flags: - -d, --direct Specifies whether to wait for a direct connection before testing speed. - -h, --help help for speedtest - -r, --reverse Specifies whether to run in reverse mode where the client receives and - the server sends. - -t, --time duration Specifies the duration to monitor traffic. (default 5s) + -d, --direct Specifies whether to wait for a direct connection before testing speed. + --direction string Specifies whether to run in reverse mode where the client receives + and the server sends. (up|down) (default "down") + -h, --help help for speedtest + -t, --time duration Specifies the duration to monitor traffic. (default 5s) Global Flags: --global-config coder Path to the global coder config directory. From 4b91702139f8d1865ae435f543a74a4fc50bb6e5 Mon Sep 17 00:00:00 2001 From: Ammar Bandukwala Date: Fri, 17 Feb 2023 14:49:25 -0600 Subject: [PATCH 2/4] Update cli/testdata/coder_speedtest_--help.golden Co-authored-by: Muhammad Atif Ali --- cli/testdata/coder_speedtest_--help.golden | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/testdata/coder_speedtest_--help.golden b/cli/testdata/coder_speedtest_--help.golden index f3ba1eac6ae13..dfa828d6db6c3 100644 --- a/cli/testdata/coder_speedtest_--help.golden +++ b/cli/testdata/coder_speedtest_--help.golden @@ -5,7 +5,7 @@ Usage: Flags: -d, --direct Specifies whether to wait for a direct connection before testing speed. - --direction string Specifies whether to run in reverse mode where the client receives + --direction string Specifies whether to test downlink or uplink throughput (up|down) (default "down") and the server sends. (up|down) (default "down") -h, --help help for speedtest -t, --time duration Specifies the duration to monitor traffic. (default 5s) From d442e9df6e518fbef17d076343e3eabd120c5aaa Mon Sep 17 00:00:00 2001 From: Ammar Bandukwala Date: Fri, 17 Feb 2023 20:50:29 +0000 Subject: [PATCH 3/4] Revert "Update cli/testdata/coder_speedtest_--help.golden" This reverts commit 4b91702139f8d1865ae435f543a74a4fc50bb6e5. --- cli/testdata/coder_speedtest_--help.golden | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/testdata/coder_speedtest_--help.golden b/cli/testdata/coder_speedtest_--help.golden index dfa828d6db6c3..f3ba1eac6ae13 100644 --- a/cli/testdata/coder_speedtest_--help.golden +++ b/cli/testdata/coder_speedtest_--help.golden @@ -5,7 +5,7 @@ Usage: Flags: -d, --direct Specifies whether to wait for a direct connection before testing speed. - --direction string Specifies whether to test downlink or uplink throughput (up|down) (default "down") + --direction string Specifies whether to run in reverse mode where the client receives and the server sends. (up|down) (default "down") -h, --help help for speedtest -t, --time duration Specifies the duration to monitor traffic. (default 5s) From 47ab9fb6bc2f167c38b3eb3b2975dc57100dc633 Mon Sep 17 00:00:00 2001 From: Ammar Bandukwala Date: Sun, 19 Feb 2023 03:19:24 +0000 Subject: [PATCH 4/4] make gen --- docs/cli/coder_speedtest.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/cli/coder_speedtest.md b/docs/cli/coder_speedtest.md index 084389ade9270..b1fadf60ec82e 100644 --- a/docs/cli/coder_speedtest.md +++ b/docs/cli/coder_speedtest.md @@ -9,10 +9,10 @@ coder speedtest [flags] ### Options ``` - -d, --direct Specifies whether to wait for a direct connection before testing speed. - -h, --help help for speedtest - -r, --reverse Specifies whether to run in reverse mode where the client receives and the server sends. - -t, --time duration Specifies the duration to monitor traffic. (default 5s) + -d, --direct Specifies whether to wait for a direct connection before testing speed. + --direction string Specifies whether to run in reverse mode where the client receives and the server sends. (up|down) (default "down") + -h, --help help for speedtest + -t, --time duration Specifies the duration to monitor traffic. (default 5s) ``` ### Options inherited from parent commands