Skip to content

Commit 2a794a9

Browse files
authored
Improvements/experiment-2 (#6)
* Add network/nptest module and update dependencies * Merge branch 'kubernetes:master' into kubernetes-perf-tests-issues-kubernetes#2876 * Refactor the test details to tests.go * Use declarative syntax for parsing logics * Merge branch 'kubernetes:master' into kubernetes-perf-tests-issues-kubernetes#2876 * Export a lib function so that test can be run from another go program * Change the name of module * create an experimental package * Some more experiments * Removing replace directive * Add replace directive * Adding lib function be make the test reusable * Update go.mod * Merge Master * Merge branch 'master' into improvements/experiment-2 * Minor Bug Fix and Add return type to the test * Merge remote-tracking branch 'origin/master' into improvements/experiment-2
1 parent bea0c35 commit 2a794a9

File tree

5 files changed

+36
-24
lines changed

5 files changed

+36
-24
lines changed

network/benchmarks/netperf/lib/outputlib.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func getDataFromPod(c *kubernetes.Clientset, podName, startMarker, endMarker, te
3434
return &data, nil
3535
}
3636

37-
func processRawData(rawData *string, testNamespace, tag, fileExtension string) error {
37+
func processRawData(rawData *string, testNamespace, tag, fileExtension string) (string, error) {
3838
t := time.Now().UTC()
3939
outputFileDirectory := fmt.Sprintf("results_%s-%s", testNamespace, tag)
4040
outputFilePrefix := fmt.Sprintf("%s-%s_%s.", testNamespace, tag, t.Format("20060102150405"))
@@ -43,17 +43,17 @@ func processRawData(rawData *string, testNamespace, tag, fileExtension string) e
4343
if _, err := os.Stat(outputFileDirectory); os.IsNotExist(err) {
4444
err := os.Mkdir(outputFileDirectory, 0766)
4545
if err != nil {
46-
return err
46+
return "", err
4747
}
4848
}
4949
fd, err := os.OpenFile(outputFilePath, os.O_RDWR|os.O_CREATE, 0666)
5050
if err != nil {
51-
return fmt.Errorf("ERROR writing output datafile: %s", err)
51+
return "", fmt.Errorf("ERROR writing output datafile: %s", err)
5252
}
5353
defer fd.Close()
5454
_, err = fd.WriteString(*rawData)
5555
if err != nil {
56-
return fmt.Errorf("error writing string: %s", err)
56+
return "", fmt.Errorf("error writing string: %s", err)
5757
}
58-
return nil
58+
return outputFilePath, nil
5959
}

network/benchmarks/netperf/lib/testlib.go

+14-8
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,22 @@ type TestParams struct {
2929
KubeConfig string
3030
}
3131

32-
func PerformTests(testParams TestParams) error {
32+
type Result struct {
33+
JsonResultFile string
34+
CsvResultFile string
35+
}
36+
37+
func PerformTests(testParams TestParams) ([]Result, error) {
3338
c, err := setupClient(testParams.KubeConfig)
3439
if err != nil {
35-
return fmt.Errorf("failed to create clientset: %v", err)
40+
return nil, fmt.Errorf("failed to create clientset: %v", err)
3641
}
3742
nodes, err := getMinionNodes(c)
3843
if err != nil {
39-
return fmt.Errorf("failed to get nodes: %v", err)
44+
return nil, fmt.Errorf("failed to get nodes: %v", err)
4045
}
4146
if len(nodes.Items) < 2 {
42-
return fmt.Errorf("at least 2 nodes are required to run the tests")
47+
return nil, fmt.Errorf("at least 2 nodes are required to run the tests")
4348
}
4449
primaryNode := nodes.Items[0]
4550
secondaryNode := nodes.Items[1]
@@ -49,7 +54,7 @@ func PerformTests(testParams TestParams) error {
4954

5055
if testParams.CleanupOnly {
5156
cleanup(c, testParams.TestNamespace)
52-
return nil
57+
return nil, nil
5358
}
5459

5560
fmt.Println("Network Performance Test")
@@ -59,9 +64,10 @@ func PerformTests(testParams TestParams) error {
5964
fmt.Println("Docker image : ", testParams.Image)
6065
fmt.Println("------------------------------------------------------------")
6166

62-
if err := executeTests(c, testParams, primaryNode, secondaryNode); err != nil {
63-
return fmt.Errorf("failed to execute tests: %v", err)
67+
results, err := executeTests(c, testParams, primaryNode, secondaryNode)
68+
if err != nil {
69+
return nil, fmt.Errorf("failed to execute tests: %v", err)
6470
}
6571
cleanup(c, testParams.TestNamespace)
66-
return nil
72+
return results, nil
6773
}

network/benchmarks/netperf/lib/utilslib.go

+15-10
Original file line numberDiff line numberDiff line change
@@ -225,27 +225,31 @@ func createRCs(c *kubernetes.Clientset, testParams TestParams, primaryNode, seco
225225
return nil
226226
}
227227

228-
func executeTests(c *kubernetes.Clientset, testParams TestParams, primaryNode, secondaryNode api.Node) error {
228+
func executeTests(c *kubernetes.Clientset, testParams TestParams, primaryNode, secondaryNode api.Node) ([]Result, error) {
229+
results := make([]Result, testParams.Iterations)
229230
for i := 0; i < testParams.Iterations; i++ {
230231
cleanup(c, testParams.TestNamespace)
231232
if err := createServices(c, testParams.TestNamespace); err != nil {
232-
return fmt.Errorf("failed to create services: %v", err)
233+
return nil, fmt.Errorf("failed to create services: %v", err)
233234
}
234235
time.Sleep(3 * time.Second)
235236
if err := createRCs(c, testParams, primaryNode, secondaryNode); err != nil {
236-
return fmt.Errorf("failed to create replication controllers: %v", err)
237+
return nil, fmt.Errorf("failed to create replication controllers: %v", err)
237238
}
238239
fmt.Println("Waiting for netperf pods to start up")
239240

240241
orchestratorPodName := getOrchestratorPodName(c, testParams.TestNamespace)
241242
fmt.Println("Orchestrator Pod is", orchestratorPodName)
242243

244+
var jsonFilePath string
245+
var csvFilePath string
246+
243247
// The pods orchestrate themselves, we just wait for the results file to show up in the orchestrator container
244248
for {
245249
// Monitor the orchestrator pod for the CSV results file
246250
csvdata, err := getDataFromPod(c, orchestratorPodName, csvDataMarker, csvEndDataMarker, testParams.TestNamespace)
247251
if err != nil {
248-
return fmt.Errorf("error getting CSV data from orchestrator pod: %v", err)
252+
return nil, fmt.Errorf("error getting CSV data from orchestrator pod: %v", err)
249253
}
250254
if csvdata == nil {
251255
fmt.Println("Scanned orchestrator pod filesystem - no results file found yet...")
@@ -256,29 +260,30 @@ func executeTests(c *kubernetes.Clientset, testParams TestParams, primaryNode, s
256260
if testParams.JsonOutput {
257261
jsondata, err := getDataFromPod(c, orchestratorPodName, jsonDataMarker, jsonEndDataMarker, testParams.TestNamespace)
258262
if err != nil {
259-
return fmt.Errorf("error getting JSON data from orchestrator pod: %v", err)
263+
return nil, fmt.Errorf("error getting JSON data from orchestrator pod: %v", err)
260264
}
261265
if jsondata == nil {
262266
fmt.Println("Scanned orchestrator pod filesystem - no json data found yet...")
263267
time.Sleep(60 * time.Second)
264268
continue
265269
}
266-
err = processRawData(jsondata, testParams.TestNamespace, testParams.Tag, "json")
270+
jsonFilePath, err = processRawData(jsondata, testParams.TestNamespace, testParams.Tag, "json")
267271
if err != nil {
268-
return fmt.Errorf("error processing JSON data: %v", err)
272+
return nil, fmt.Errorf("error processing JSON data: %v", err)
269273
}
270274
}
271275

272-
err = processRawData(csvdata, testParams.TestNamespace, testParams.Tag, "csv")
276+
csvFilePath, err = processRawData(csvdata, testParams.TestNamespace, testParams.Tag, "csv")
273277
if err != nil {
274-
return fmt.Errorf("error processing CSV data: %v", err)
278+
return nil, fmt.Errorf("error processing CSV data: %v", err)
275279
}
276280

277281
break
278282
}
279283
fmt.Printf("TEST RUN (Iteration %d) FINISHED - cleaning up services and pods\n", i)
284+
results[i] = Result{JsonResultFile: jsonFilePath, CsvResultFile: csvFilePath}
280285
}
281-
return nil
286+
return results, nil
282287
}
283288

284289
func getOrchestratorPodName(c *kubernetes.Clientset, testNamespace string) string {

network/benchmarks/netperf/nptest/nptest.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ func main() {
172172

173173
}
174174
grabEnv()
175-
// testcases = testcases[testFrom:testTo]
175+
testcases = testcases[testFrom:testTo]
176176
fmt.Println("Running as", mode, "...")
177177
if mode == orchestratorMode {
178178
orchestrate()

network/benchmarks/netperf/nptest/parsers/json_parsers.go

+1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ func ParseIperfThrouputTCPTest(output string) string {
5353
outputResult.MeanRoundTripTime = iperfThroughput.End.Streams[0].Sender.MeanRoundTripTime
5454
outputResult.MinRoundTripTime = iperfThroughput.End.Streams[0].Sender.MinRoundTripTime
5555
outputResult.MaxRoundTripTime = iperfThroughput.End.Streams[0].Sender.MaxRoundTripTime
56+
outputResult.Retransmits = iperfThroughput.End.Streams[0].Sender.Retransmits
5657
outputResult.CPUUtilization.Host = iperfThroughput.End.CPUUtilizationPercent.HostTotal
5758
outputResult.CPUUtilization.Remote = iperfThroughput.End.CPUUtilizationPercent.RemoteTotal
5859

0 commit comments

Comments
 (0)