Skip to content

Commit

Permalink
Improvements/experiment-2 (#6)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
ritwikranjan authored Sep 21, 2024
1 parent bea0c35 commit 2a794a9
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 24 deletions.
10 changes: 5 additions & 5 deletions network/benchmarks/netperf/lib/outputlib.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func getDataFromPod(c *kubernetes.Clientset, podName, startMarker, endMarker, te
return &data, nil
}

func processRawData(rawData *string, testNamespace, tag, fileExtension string) error {
func processRawData(rawData *string, testNamespace, tag, fileExtension string) (string, error) {
t := time.Now().UTC()
outputFileDirectory := fmt.Sprintf("results_%s-%s", testNamespace, tag)
outputFilePrefix := fmt.Sprintf("%s-%s_%s.", testNamespace, tag, t.Format("20060102150405"))
Expand All @@ -43,17 +43,17 @@ func processRawData(rawData *string, testNamespace, tag, fileExtension string) e
if _, err := os.Stat(outputFileDirectory); os.IsNotExist(err) {
err := os.Mkdir(outputFileDirectory, 0766)
if err != nil {
return err
return "", err
}
}
fd, err := os.OpenFile(outputFilePath, os.O_RDWR|os.O_CREATE, 0666)
if err != nil {
return fmt.Errorf("ERROR writing output datafile: %s", err)
return "", fmt.Errorf("ERROR writing output datafile: %s", err)
}
defer fd.Close()
_, err = fd.WriteString(*rawData)
if err != nil {
return fmt.Errorf("error writing string: %s", err)
return "", fmt.Errorf("error writing string: %s", err)
}
return nil
return outputFilePath, nil
}
22 changes: 14 additions & 8 deletions network/benchmarks/netperf/lib/testlib.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,22 @@ type TestParams struct {
KubeConfig string
}

func PerformTests(testParams TestParams) error {
type Result struct {
JsonResultFile string
CsvResultFile string
}

func PerformTests(testParams TestParams) ([]Result, error) {
c, err := setupClient(testParams.KubeConfig)
if err != nil {
return fmt.Errorf("failed to create clientset: %v", err)
return nil, fmt.Errorf("failed to create clientset: %v", err)
}
nodes, err := getMinionNodes(c)
if err != nil {
return fmt.Errorf("failed to get nodes: %v", err)
return nil, fmt.Errorf("failed to get nodes: %v", err)
}
if len(nodes.Items) < 2 {
return fmt.Errorf("at least 2 nodes are required to run the tests")
return nil, fmt.Errorf("at least 2 nodes are required to run the tests")
}
primaryNode := nodes.Items[0]
secondaryNode := nodes.Items[1]
Expand All @@ -49,7 +54,7 @@ func PerformTests(testParams TestParams) error {

if testParams.CleanupOnly {
cleanup(c, testParams.TestNamespace)
return nil
return nil, nil
}

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

if err := executeTests(c, testParams, primaryNode, secondaryNode); err != nil {
return fmt.Errorf("failed to execute tests: %v", err)
results, err := executeTests(c, testParams, primaryNode, secondaryNode)
if err != nil {
return nil, fmt.Errorf("failed to execute tests: %v", err)
}
cleanup(c, testParams.TestNamespace)
return nil
return results, nil
}
25 changes: 15 additions & 10 deletions network/benchmarks/netperf/lib/utilslib.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,27 +225,31 @@ func createRCs(c *kubernetes.Clientset, testParams TestParams, primaryNode, seco
return nil
}

func executeTests(c *kubernetes.Clientset, testParams TestParams, primaryNode, secondaryNode api.Node) error {
func executeTests(c *kubernetes.Clientset, testParams TestParams, primaryNode, secondaryNode api.Node) ([]Result, error) {
results := make([]Result, testParams.Iterations)
for i := 0; i < testParams.Iterations; i++ {
cleanup(c, testParams.TestNamespace)
if err := createServices(c, testParams.TestNamespace); err != nil {
return fmt.Errorf("failed to create services: %v", err)
return nil, fmt.Errorf("failed to create services: %v", err)
}
time.Sleep(3 * time.Second)
if err := createRCs(c, testParams, primaryNode, secondaryNode); err != nil {
return fmt.Errorf("failed to create replication controllers: %v", err)
return nil, fmt.Errorf("failed to create replication controllers: %v", err)
}
fmt.Println("Waiting for netperf pods to start up")

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

var jsonFilePath string
var csvFilePath string

// The pods orchestrate themselves, we just wait for the results file to show up in the orchestrator container
for {
// Monitor the orchestrator pod for the CSV results file
csvdata, err := getDataFromPod(c, orchestratorPodName, csvDataMarker, csvEndDataMarker, testParams.TestNamespace)
if err != nil {
return fmt.Errorf("error getting CSV data from orchestrator pod: %v", err)
return nil, fmt.Errorf("error getting CSV data from orchestrator pod: %v", err)
}
if csvdata == nil {
fmt.Println("Scanned orchestrator pod filesystem - no results file found yet...")
Expand All @@ -256,29 +260,30 @@ func executeTests(c *kubernetes.Clientset, testParams TestParams, primaryNode, s
if testParams.JsonOutput {
jsondata, err := getDataFromPod(c, orchestratorPodName, jsonDataMarker, jsonEndDataMarker, testParams.TestNamespace)
if err != nil {
return fmt.Errorf("error getting JSON data from orchestrator pod: %v", err)
return nil, fmt.Errorf("error getting JSON data from orchestrator pod: %v", err)
}
if jsondata == nil {
fmt.Println("Scanned orchestrator pod filesystem - no json data found yet...")
time.Sleep(60 * time.Second)
continue
}
err = processRawData(jsondata, testParams.TestNamespace, testParams.Tag, "json")
jsonFilePath, err = processRawData(jsondata, testParams.TestNamespace, testParams.Tag, "json")
if err != nil {
return fmt.Errorf("error processing JSON data: %v", err)
return nil, fmt.Errorf("error processing JSON data: %v", err)
}
}

err = processRawData(csvdata, testParams.TestNamespace, testParams.Tag, "csv")
csvFilePath, err = processRawData(csvdata, testParams.TestNamespace, testParams.Tag, "csv")
if err != nil {
return fmt.Errorf("error processing CSV data: %v", err)
return nil, fmt.Errorf("error processing CSV data: %v", err)
}

break
}
fmt.Printf("TEST RUN (Iteration %d) FINISHED - cleaning up services and pods\n", i)
results[i] = Result{JsonResultFile: jsonFilePath, CsvResultFile: csvFilePath}
}
return nil
return results, nil
}

func getOrchestratorPodName(c *kubernetes.Clientset, testNamespace string) string {
Expand Down
2 changes: 1 addition & 1 deletion network/benchmarks/netperf/nptest/nptest.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ func main() {

}
grabEnv()
// testcases = testcases[testFrom:testTo]
testcases = testcases[testFrom:testTo]
fmt.Println("Running as", mode, "...")
if mode == orchestratorMode {
orchestrate()
Expand Down
1 change: 1 addition & 0 deletions network/benchmarks/netperf/nptest/parsers/json_parsers.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ func ParseIperfThrouputTCPTest(output string) string {
outputResult.MeanRoundTripTime = iperfThroughput.End.Streams[0].Sender.MeanRoundTripTime
outputResult.MinRoundTripTime = iperfThroughput.End.Streams[0].Sender.MinRoundTripTime
outputResult.MaxRoundTripTime = iperfThroughput.End.Streams[0].Sender.MaxRoundTripTime
outputResult.Retransmits = iperfThroughput.End.Streams[0].Sender.Retransmits
outputResult.CPUUtilization.Host = iperfThroughput.End.CPUUtilizationPercent.HostTotal
outputResult.CPUUtilization.Remote = iperfThroughput.End.CPUUtilizationPercent.RemoteTotal

Expand Down

0 comments on commit 2a794a9

Please sign in to comment.