From a302966ebb9f1817a31edbb3246a09ab5405a221 Mon Sep 17 00:00:00 2001 From: "Joe Talerico (rook)" Date: Fri, 15 Sep 2023 09:11:39 -0400 Subject: [PATCH] Adding simple retry for empty value (#104) 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 Co-authored-by: Joe Talerico --- cmd/k8s-netperf/k8s-netperf.go | 12 +++++++++++- pkg/netperf/netperf.go | 4 ++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/cmd/k8s-netperf/k8s-netperf.go b/cmd/k8s-netperf/k8s-netperf.go index 4e2ec9b6..6e32bcd2 100644 --- a/cmd/k8s-netperf/k8s-netperf.go +++ b/cmd/k8s-netperf/k8s-netperf.go @@ -385,7 +385,17 @@ 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.Warn("Rerunning test.") + r, err := netperf.Run(s.ClientSet, s.RestConfig, nc, Client, serverIP) + if err != nil { + log.Error(err) + os.Exit(1) + } + 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 }