Skip to content

Commit

Permalink
Add more error checking
Browse files Browse the repository at this point in the history
Adding more error checking of values.

Signed-off-by: Joe Talerico <[email protected]>
  • Loading branch information
Joe Talerico committed Nov 1, 2023
1 parent 4e93887 commit 138d26a
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 12 deletions.
29 changes: 21 additions & 8 deletions cmd/k8s-netperf/k8s-netperf.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (

const namespace = "netperf"
const index = "k8s-netperf"
const retry = 3

var (
cfgfile string
Expand Down Expand Up @@ -389,15 +390,27 @@ func executeWorkload(nc config.Config, s config.PerfScenarios, hostNet bool, ipe
nr, err = netperf.ParseResults(&r)
if err != nil {
log.Error(err)
log.Warn("Rerunning test.")
r, err := netperf.Run(s.ClientSet, s.RestConfig, nc, Client, serverIP)
if err != nil {
log.Error(err)
os.Exit(1)
try := 0
success := false
// Retry the current test.
for try < retry {
log.Warn("Rerunning test.")
r, err := netperf.Run(s.ClientSet, s.RestConfig, nc, Client, serverIP)
if err != nil {
log.Error(err)
continue
}
nr, err = netperf.ParseResults(&r)
if err != nil {
log.Error(err)
try++
} else {
success = true
break
}
}
nr, err = netperf.ParseResults(&r)
if err != nil {
log.Error(err)
if !success {
fmt.Errorf("test was unsuccessful after retry.")

Check failure on line 413 in cmd/k8s-netperf/k8s-netperf.go

View workflow job for this annotation

GitHub Actions / build

unusedresult: result of fmt.Errorf call not used (govet)
os.Exit(1)
}
}
Expand Down
32 changes: 28 additions & 4 deletions pkg/archive/archive.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,34 @@ func BuildDocs(sr result.ScenarioResults, uuid string) ([]interface{}, error) {
ClientNodeLabels: r.ClientNodeLabels,
AcrossAZ: r.AcrossAZ,
}
d.UDPLossPercent, _ = result.Average(r.LossSummary)
d.TCPRetransmit, _ = result.Average(r.RetransmitSummary)
d.Throughput, _ = result.Average(r.ThroughputSummary)
d.Latency, _ = result.Average(r.LatencySummary)
UDPLossPercent, e := result.Average(r.LossSummary)
if e != nil {
logging.Warn("Unable to process udp loss, setting value to zero")
d.UDPLossPercent = 0
} else {
d.UDPLossPercent = UDPLossPercent
}
TCPRetransmit, e := result.Average(r.RetransmitSummary)
if e != nil {
logging.Warn("Unable to process tcp retransmits, setting value to zero")
d.TCPRetransmit = 0
} else {
d.TCPRetransmit = TCPRetransmit
}
Throughput, e := result.Average(r.ThroughputSummary)
if e != nil {
logging.Warn("Unable to process throughput, setting value to zero")
d.Throughput = 0
} else {
d.Throughput = Throughput
}
Latency, e := result.Average(r.LatencySummary)
if e != nil {
logging.Warn("Unable to process latency, setting value to zero")
d.Latency = 0
} else {
d.Latency = Latency
}
docs = append(docs, d)
}
return docs, nil
Expand Down
6 changes: 6 additions & 0 deletions pkg/netperf/netperf.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ func ParseResults(stdout *bytes.Buffer) (sample.Sample, error) {
if strings.Contains(l[0], "THROUGHPUT_UNITS") {
sample.Metric = l[1]
} else if strings.Contains(l[0], "THROUGHPUT") {
if len(strings.TrimSpace(l[1])) < 1 {
return sample, fmt.Errorf("Throughput was empty.")
}
sample.Throughput, _ = strconv.ParseFloat(strings.Trim(l[1], "\r"), 64)
} else if strings.Contains(l[0], "P99_LATENCY") {
sample.Latency99ptile, _ = strconv.ParseFloat(strings.Trim(l[1], "\r"), 64)
Expand All @@ -121,6 +124,9 @@ func ParseResults(stdout *bytes.Buffer) (sample.Sample, error) {
if math.IsNaN(sample.Throughput) {
return sample, fmt.Errorf("Throughput value is NaN")
}
if math.IsNaN(sample.Latency99ptile) {
return sample, fmt.Errorf("Latency value is NaN")
}
sample.LossPercent = 100 - (recv / send * 100)
return sample, nil
}

0 comments on commit 138d26a

Please sign in to comment.