From 73c14b449b4aefd5949409539a8ea84448197fe9 Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Thu, 25 Jan 2024 23:12:02 -0800 Subject: [PATCH] add "warp-client-file" hosts file --- cli/benchmark.go | 4 ++++ cli/benchserver.go | 24 +++++++++++++++++++++--- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/cli/benchmark.go b/cli/benchmark.go index e44ab15a..cf23beb4 100644 --- a/cli/benchmark.go +++ b/cli/benchmark.go @@ -89,6 +89,10 @@ var benchFlags = []cli.Flag{ EnvVar: "", Value: "", }, + cli.StringFlag{ + Name: "warp-client-file", + Usage: "Connect to warp clients from a file", + }, } // runBench will run the supplied benchmark and save/print the analysis. diff --git a/cli/benchserver.go b/cli/benchserver.go index 066fe67c..9918cd12 100644 --- a/cli/benchserver.go +++ b/cli/benchserver.go @@ -18,6 +18,7 @@ package cli import ( + "bufio" "context" "errors" "fmt" @@ -88,11 +89,27 @@ type serverRequest struct { // runServerBenchmark will run a benchmark server if requested. // Returns a bool whether clients were specified. func runServerBenchmark(ctx *cli.Context, b bench.Benchmark) (bool, error) { - if ctx.String("warp-client") == "" { - return false, nil + warpClient := ctx.String("warp-client") + var hosts []string + if warpClient == "" { + file := ctx.String("warp-client-file") + if file == "" { + return false, nil + } + f, err := os.Open(file) + if err != nil { + return false, err + } + scn := bufio.NewScanner(f) + for scn.Scan() { + hosts = append(hosts, scn.Text()) + } + f.Close() + } else { + hosts = parseHosts(warpClient, false) } - conns := newConnections(parseHosts(ctx.String("warp-client"), false)) + conns := newConnections(hosts) if len(conns.hosts) == 0 { return true, errors.New("no hosts") } @@ -110,6 +127,7 @@ func runServerBenchmark(ctx *cli.Context, b bench.Benchmark) (bool, error) { // Serialize parameters excludeFlags := map[string]struct{}{ "warp-client": {}, + "warp-client-file": {}, "warp-client-server": {}, "serverprof": {}, "autocompletion": {},