From 5356eb6a2c876e6ffed083f6982720e93ebf399b Mon Sep 17 00:00:00 2001 From: Joe Talerico aka rook Date: Mon, 9 Sep 2024 13:51:12 -0400 Subject: [PATCH] Addressing Vishnu's feedback Signed-off-by: Joe Talerico aka rook --- pkg/drivers/iperf.go | 16 ++++++---------- pkg/drivers/netperf.go | 16 ++++++---------- pkg/drivers/uperf.go | 27 ++++++++++----------------- 3 files changed, 22 insertions(+), 37 deletions(-) diff --git a/pkg/drivers/iperf.go b/pkg/drivers/iperf.go index f0a19983..0ae7fe52 100644 --- a/pkg/drivers/iperf.go +++ b/pkg/drivers/iperf.go @@ -128,13 +128,11 @@ func (i *iperf3) Run(c *kubernetes.Clientset, for i := 0; i <= retry; i++ { log.Debug("⏰ Waiting for iperf3 to be present on VM") _, err = sshclient.Run("until iperf3 -h; do sleep 30; done") - if err != nil { - time.Sleep(10 * time.Second) - continue - } else { + if err == nil { present = true break } + time.Sleep(10 * time.Second) } if !present { sshclient.Close() @@ -144,15 +142,13 @@ func (i *iperf3) Run(c *kubernetes.Clientset, ran := false for i := 0; i <= retry; i++ { stdout, err = sshclient.Run(strings.Join(cmd[:], " ")) - if err != nil { - log.Debugf("Failed running command %s", err) - log.Debugf("⏰ Retrying iperf3 command -- cloud-init still finishing up") - time.Sleep(60 * time.Second) - continue - } else { + if err == nil { ran = true break } + log.Debugf("Failed running command %s", err) + log.Debugf("⏰ Retrying iperf3 command -- cloud-init still finishing up") + time.Sleep(60 * time.Second) } sshclient.Close() if !ran { diff --git a/pkg/drivers/netperf.go b/pkg/drivers/netperf.go index 453b37ad..63dba7d8 100644 --- a/pkg/drivers/netperf.go +++ b/pkg/drivers/netperf.go @@ -107,13 +107,11 @@ func (n *netperf) Run(c *kubernetes.Clientset, rc rest.Config, nc config.Config, for i := 0; i <= retry; i++ { log.Debug("⏰ Waiting for netperf to be present on VM") _, err = sshclient.Run("until which netperf; do sleep 30; done") - if err != nil { - time.Sleep(10 * time.Second) - continue - } else { + if err == nil { present = true break } + time.Sleep(10 * time.Second) } if !present { sshclient.Close() @@ -123,15 +121,13 @@ func (n *netperf) Run(c *kubernetes.Clientset, rc rest.Config, nc config.Config, ran := false for i := 0; i <= retry; i++ { _, err = sshclient.Run(fmt.Sprintf("netperf -H %s -l 1 -- %s", serverIP, strconv.Itoa(k8s.NetperfServerDataPort))) - if err != nil { - log.Debugf("Failed running command %s", err) - log.Debugf("⏰ Retrying netperf command -- cloud-init still finishing up") - time.Sleep(60 * time.Second) - continue - } else { + if err == nil { ran = true break } + log.Debugf("Failed running command %s", err) + log.Debugf("⏰ Retrying netperf command -- cloud-init still finishing up") + time.Sleep(60 * time.Second) } stdout, err = sshclient.Run(strings.Join(cmd[:], " ")) if err != nil { diff --git a/pkg/drivers/uperf.go b/pkg/drivers/uperf.go index 264d579e..14c0fd40 100644 --- a/pkg/drivers/uperf.go +++ b/pkg/drivers/uperf.go @@ -215,13 +215,11 @@ func (u *uperf) Run(c *kubernetes.Clientset, rc rest.Config, nc config.Config, c for i := 0; i <= retry; i++ { log.Debug("⏰ Waiting for uperf to be present on VM") _, err = sshclient.Run("until uperf -h; do sleep 30; done") - if err != nil { - time.Sleep(10 * time.Second) - continue - } else { + if err == nil { present = true break } + time.Sleep(10 * time.Second) } if !present { sshclient.Close() @@ -231,15 +229,13 @@ func (u *uperf) Run(c *kubernetes.Clientset, rc rest.Config, nc config.Config, c ran := false for i := 0; i <= retry; i++ { stdout, err = sshclient.Run(strings.Join(cmd[:], " ")) - if err != nil { - log.Debugf("Failed running command %s", err) - log.Debugf("⏰ Retrying uperf command -- cloud-init still finishing up") - time.Sleep(60 * time.Second) - continue - } else { + if err == nil { ran = true break } + log.Debugf("Failed running command %s", err) + log.Debugf("⏰ Retrying uperf command -- cloud-init still finishing up") + time.Sleep(60 * time.Second) } sshclient.Close() if !ran { @@ -252,7 +248,7 @@ func (u *uperf) Run(c *kubernetes.Clientset, rc rest.Config, nc config.Config, c // ParseResults accepts the stdout from the execution of the benchmark. // It will return a Sample struct or error -func (u *uperf) ParseResults(stdout *bytes.Buffer, nc config.Config) (sample.Sample, error) { +func (u *uperf) ParseResults(stdout *bytes.Buffer, _ config.Config) (sample.Sample, error) { sample := sample.Sample{} sample.Driver = u.driverName sample.Metric = "Mb/s" @@ -285,13 +281,10 @@ func (u *uperf) ParseResults(stdout *bytes.Buffer, nc config.Config) (sample.Sam } averageByte, _ := stats.Mean(byteSummary) - if strings.Contains(nc.Profile, "STREAM") { - sample.Throughput = float64(averageByte*8) / 1000000 - } else { - sample.Throughput, _ = stats.Mean(opSummary) - } + averageOps, _ := stats.Mean(opSummary) + sample.Throughput = float64(averageByte*8) / 1000000 sample.Latency99ptile, _ = stats.Percentile(latSummary, 99) - log.Debugf("Storing uperf sample Average bytes: %f , P99 Latency %f, Throughput: %f ", averageByte, sample.Latency99ptile, sample.Throughput) + log.Debugf("Storing uperf sample throughput: %f Mbps, P99 Latency %f, Average ops: %f ", sample.Throughput, sample.Latency99ptile, averageOps) return sample, nil