Skip to content

Commit

Permalink
Merge branch 'master' into apiclient
Browse files Browse the repository at this point in the history
  • Loading branch information
ccfish2 authored Feb 22, 2022
2 parents 184a86a + 7ad77da commit cf503ce
Show file tree
Hide file tree
Showing 19 changed files with 44 additions and 781 deletions.
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ go 1.17

require (
github.com/Masterminds/semver/v3 v3.1.1
github.com/alessio/shellescape v1.4.1
github.com/argoproj/argo-workflows/v3 v3.2.6
github.com/go-logr/logr v0.4.0
github.com/onsi/ginkgo v1.16.4
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,6 @@ github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuy
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d/go.mod h1:rBZYJk541a8SKzHPHnH3zbiI+7dagKZ0cgpgrD7Fyho=
github.com/alessio/shellescape v1.4.1 h1:V7yhSDDn8LP4lc4jS8pFkt0zCnzVJlG5JXy9BVKJUX0=
github.com/alessio/shellescape v1.4.1/go.mod h1:PZAiSCk0LJaZkiCSkPv8qIobYglO3FPpyFjDCtHLS30=
github.com/aliyun/aliyun-oss-go-sdk v2.1.8+incompatible/go.mod h1:T/Aws4fEfogEE9v+HPhhw+CntffsBHJ8nXQCwKr0/g8=
github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883/go.mod h1:rCTlJbsFo29Kk6CurOXKm700vrz8f0KW0JNfpkRJY/8=
github.com/andybalholm/brotli v1.0.1/go.mod h1:loMXtMfwqflxFJPmdbJO0a3KNoPuLBgiu3qAvBg8x/Y=
Expand Down
33 changes: 0 additions & 33 deletions test-load/dolphin/app/main.go

This file was deleted.

9 changes: 0 additions & 9 deletions test-load/dolphin/main.go

This file was deleted.

104 changes: 44 additions & 60 deletions test-load/pkg/cmd/dolphin/tests/load.go → test-load/main.go
Original file line number Diff line number Diff line change
@@ -1,85 +1,74 @@
package tests
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package main

import (
"bufio"
"bytes"
"context"
"fmt"
"io"

"os"
"os/exec"
"strconv"
"strings"
"sync"
"time"

"github.com/keikoproj/addon-manager/pkg/common"
"github.com/keikoproj/addon-manager/test-bdd/testutil"
"github.com/keikoproj/addon-manager/test-load/pkg/cmd"
"github.com/keikoproj/addon-manager/test-load/pkg/log"
"github.com/spf13/cobra"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/dynamic"
"sigs.k8s.io/controller-runtime/pkg/client/config"
)

type flagpole struct {
managerPID string // passed in kubeconfig
wfcontrollerPID string
numberOfGoRoutines int
}
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

const (
NumberOfWFPerRoutine = 200
eventNameBase = 100
numberOfRoutines = 10
)

// NewCommand ...
func NewCommand(logger log.Logger, streams cmd.IOStreams) *cobra.Command {
flags := &flagpole{}
cmd := &cobra.Command{
Args: cobra.NoArgs,
Use: "tests",
Short: "tests load",
Long: "tests addon-manager loads",
RunE: func(cmd *cobra.Command, args []string) error {
return RunLoads(logger, flags)
},
}
cmd.Flags().StringVar(&flags.managerPID, "managerPID", "", " addon manager pid")
cmd.Flags().StringVar(&flags.wfcontrollerPID, "wfcontrollerPID", "", " workflow controller pid")
cmd.Flags().IntVar(&flags.numberOfGoRoutines, "numberOfGoRoutines", 10, " number of goroutines to be created. Each deploy 200 workflows.")
return cmd
}

func RunLoads(logger log.Logger, flags *flagpole) error {
func main() {
s, e := os.Getenv("LOADTEST_START_NUMBER"), os.Getenv("LOADTEST_END_NUMBER")
x, _ := strconv.Atoi(s)
y, _ := strconv.Atoi(e)
fmt.Printf("start = %d end = %d", x, y)

if flags.numberOfGoRoutines == 0 {
fmt.Printf("please specify at least one goroutine.")
flags.numberOfGoRoutines = 2
}
perfsummary, err := os.Create("summary.txt")
costsummary, err := os.Create("summary.txt")
if err != nil {
return fmt.Errorf("failed creating summary file. %v", err)
return
}
dataWriter := bufio.NewWriter(perfsummary)
dataWriter := bufio.NewWriter(costsummary)

stop := make(chan bool)
mgrPid := os.Getenv("MANAGER_PID")
ctrlPid := os.Getenv("WFCTRL_PID")
go func(mgrPid, ctrlPid string, writer *bufio.Writer) {
for {
select {
case <-stop:
return
default:
fmt.Printf("\n every 2 minutes collecting mgr %s wfctrl %s %%cpu/%%mem ", mgrPid, ctrlPid)
fmt.Printf("\n every 2 minutes collecting data for mgr %s wfctrl %s", mgrPid, ctrlPid)
Summary(mgrPid, ctrlPid, writer)
time.Sleep(2 * time.Minute)
}
}
}(flags.managerPID, flags.wfcontrollerPID, dataWriter)
}(mgrPid, ctrlPid, dataWriter)

var wg sync.WaitGroup
wg.Add(flags.numberOfGoRoutines)
wg.Add(numberOfRoutines)
lock := &sync.Mutex{}

cfg := config.GetConfigOrDie()
Expand All @@ -90,30 +79,23 @@ func RunLoads(logger log.Logger, flags *flagpole) error {
var relativeAddonPath = "docs/examples/eventrouter.yaml"
var addonGroupSchema = common.AddonGVR()

for i := 1; i <= flags.numberOfGoRoutines; i++ {
for i := 1; i <= numberOfRoutines; i++ {
go func(i int, lock *sync.Mutex) {
defer wg.Done()
for j := i * eventNameBase; j < i*eventNameBase+int(NumberOfWFPerRoutine); j++ {
for j := i * 100; j < i*100+200; j++ {
addon, err := testutil.CreateLoadTestsAddon(lock, dynClient, relativeAddonPath, fmt.Sprintf("-%d", j))
if err != nil {
fmt.Printf("\n create addon failure for %v. retry 10 times after every 1 second. \n", err)
fmt.Printf("\n\n create addon failure err %v", err)
time.Sleep(1 * time.Second)
for i := 0; i < 10; i++ {
addon, err = testutil.CreateLoadTestsAddon(lock, dynClient, relativeAddonPath, fmt.Sprintf("-%d", j))
if err != nil || addon == nil {
time.Sleep(1 * time.Second)
continue
}
break
}
continue
}

addonName = addon.GetName()
addonNamespace = addon.GetNamespace()
for x := 0; x <= 500; x++ {
a, err := dynClient.Resource(addonGroupSchema).Namespace(addonNamespace).Get(ctx, addonName, metav1.GetOptions{})
if a == nil || err != nil || a.UnstructuredContent()["status"] == nil {
fmt.Printf("\n\n addon is not readdy err <%v> retry after 1 second ", err)
fmt.Printf("\n\n retry get addon status %v get ", err)
time.Sleep(1 * time.Second)
continue
}
Expand All @@ -124,11 +106,11 @@ func RunLoads(logger log.Logger, flags *flagpole) error {
}
wg.Wait()
stop <- true
perfsummary.Close()
return nil
costsummary.Close()

}

// capture cpu/memory/addons number periodically
// capture cpu/memory/addons number every 3 mintues
func Summary(managerPID, wfctrlPID string, datawriter *bufio.Writer) error {

kubectlCmd := exec.Command("kubectl", "-n", "addon-manager-system", "get", "addons")
Expand Down Expand Up @@ -162,23 +144,25 @@ func Summary(managerPID, wfctrlPID string, datawriter *bufio.Writer) error {
reader.Close()

AddonsNum := buf.String()
fmt.Printf("\n atm total addons number %s\n", AddonsNum)
fmt.Printf("\n addons number %s\n", AddonsNum)

//cmd = fmt.Sprintf("ps -p %s -o %%cpu,%%mem", managerPID)
cmd := exec.Command("ps", "-p", managerPID, "-o", "%cpu,%mem")
fmt.Printf("manager cpu cmd %v", *cmd)
managerUsage, err := cmd.Output()
if err != nil {
fmt.Printf("failed to collect addonmanager cpu/mem usage. %v", err)
return err
}
//fmt.Printf("\n addonmanager cpu/mem usage %s ", managerUsage)

cmd = exec.Command("ps", "-p", wfctrlPID, "-o", "%cpu,%mem")
wfControllerUsage, err := cmd.Output()
if err != nil {
fmt.Printf("failed to collect addonmanager cpu/mem usage. %v", err)
return err
}

//fmt.Printf("workflow controller cpu/mem usage %s ", wfControllerUsage)
fmt.Printf("addons number %s addonmanager cpu/mem usage %s controller cpu/mem usage %s", AddonsNum, managerUsage, wfControllerUsage)
oneline := fmt.Sprintf("<addons-num:%s \n addon-mgr:%s \nwf-controller:%s>", strings.TrimSpace(AddonsNum), strings.TrimSuffix(string(managerUsage), "\n"), strings.TrimSuffix(string(wfControllerUsage), "\n"))
datawriter.WriteString(oneline + "\n#############\n")
Expand Down
1 change: 0 additions & 1 deletion test-load/pkg/cmd/doc.go

This file was deleted.

98 changes: 0 additions & 98 deletions test-load/pkg/cmd/dolphin/root.go

This file was deleted.

20 changes: 0 additions & 20 deletions test-load/pkg/cmd/iostreams.go

This file was deleted.

14 changes: 0 additions & 14 deletions test-load/pkg/cmd/log.go

This file was deleted.

1 change: 0 additions & 1 deletion test-load/pkg/exec/doc.go

This file was deleted.

Loading

0 comments on commit cf503ce

Please sign in to comment.