From bf42938aa84060971d6c150b5a4196102e0a8ebb Mon Sep 17 00:00:00 2001 From: Joe Talerico Date: Mon, 11 Sep 2023 14:01:36 -0400 Subject: [PATCH] Adding simple retry for empty value We are seeing `NaN` in some CI runs. This is due to no output from netperf. This change makes a second attempt in the event the parsing fails to succeed. Signed-off-by: Joe Talerico --- cmd/k8s-netperf/k8s-netperf.go | 8 +++++++- pkg/netperf/netperf.go | 4 ++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/cmd/k8s-netperf/k8s-netperf.go b/cmd/k8s-netperf/k8s-netperf.go index 4e2ec9b6..2964fa26 100644 --- a/cmd/k8s-netperf/k8s-netperf.go +++ b/cmd/k8s-netperf/k8s-netperf.go @@ -385,7 +385,13 @@ func executeWorkload(nc config.Config, s config.PerfScenarios, hostNet bool, ipe nr, err = netperf.ParseResults(&r) if err != nil { log.Error(err) - os.Exit(1) + log.Info("Rerunning test due to NaN") + r, err := netperf.Run(s.ClientSet, s.RestConfig, nc, Client, serverIP) + nr, err = netperf.ParseResults(&r) + if err != nil { + log.Error(err) + os.Exit(1) + } } } npr.LossSummary = append(npr.LossSummary, float64(nr.LossPercent)) diff --git a/pkg/netperf/netperf.go b/pkg/netperf/netperf.go index de8e6269..21a1c3e9 100644 --- a/pkg/netperf/netperf.go +++ b/pkg/netperf/netperf.go @@ -4,6 +4,7 @@ import ( "bytes" "context" "fmt" + "math" "strconv" "strings" @@ -114,6 +115,9 @@ func ParseResults(stdout *bytes.Buffer) (sample.Sample, error) { sample.Retransmits, _ = strconv.ParseFloat(strings.Trim(l[1], "\r"), 64) } } + if math.IsNaN(sample.Throughput) { + return sample, fmt.Errorf("Throughput value is NaN") + } sample.LossPercent = 100 - (recv / send * 100) return sample, nil }