Skip to content

Commit

Permalink
Add scale num
Browse files Browse the repository at this point in the history
Signed-off-by: Wenqi Qiu <[email protected]>
  • Loading branch information
wenqiq committed Feb 1, 2024
1 parent f62c828 commit a8dbb16
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 9 deletions.
5 changes: 4 additions & 1 deletion test/performance/framework/case.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ func (c *ScaleTestCase) Name() string {
type ScaleResult struct {
err error
actualCheckNum int
scaleNum int
}

func (c *ScaleTestCase) Run(ctx context.Context, testData *ScaleData) error {
Expand All @@ -72,6 +73,7 @@ func (c *ScaleTestCase) Run(ctx context.Context, testData *ScaleData) error {
ress := make(chan time.Duration, testData.maxCheckNum)
res := "failed"
actualCheckNum := 0
scaleNum := 0
defer func() {
close(ress)
close(done)
Expand All @@ -90,6 +92,7 @@ func (c *ScaleTestCase) Run(ctx context.Context, testData *ScaleData) error {
return err.(error)
}
actualCheckNum = scaleRes.actualCheckNum
scaleNum = scaleRes.scaleNum
res = "success"
}

Expand All @@ -115,7 +118,7 @@ func (c *ScaleTestCase) Run(ctx context.Context, testData *ScaleData) error {
}

rows = append(rows, table.GenerateRow(caseName, res, time.Since(startTime).String(),
avg.String(), maxRes.String(), minRes.String(), strconv.Itoa(actualCheckNum)))
avg.String(), maxRes.String(), minRes.String(), strconv.Itoa(actualCheckNum), strconv.Itoa(scaleNum)))
table.ShowResult(os.Stdout, rows)
return nil
}
Expand Down
3 changes: 2 additions & 1 deletion test/performance/framework/networkpolicy.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,13 @@ func init() {
}

func ScaleNetworkPolicy(ctx context.Context, ch chan time.Duration, data *ScaleData) (res ScaleResult) {
checkCount, err := networkpolicy.ScaleUp(ctx, data.kubeconfig, data.kubernetesClientSet, data.namespaces,
checkCount, scaleNum, err := networkpolicy.ScaleUp(ctx, data.kubeconfig, data.kubernetesClientSet, data.namespaces,
data.Specification.NpNumPerNs, data.clientPods, data.Specification.IPv6, data.maxCheckNum, ch)
if err != nil {
res.err = fmt.Errorf("scale up NetworkPolicies error: %v", err)
return
}
res.scaleNum = scaleNum

defer func() {
for {
Expand Down
7 changes: 4 additions & 3 deletions test/performance/framework/networkpolicy/scale_up.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,14 @@ type NetworkPolicyInfo struct {
Spec netv1.NetworkPolicySpec
}

func ScaleUp(ctx context.Context, kubeConfig *rest.Config, cs kubernetes.Interface, nss []string, numPerNs int, clientPods []corev1.Pod, ipv6 bool, maxCheckNum int, ch chan time.Duration) (actualCheckNum int, err error) {
func ScaleUp(ctx context.Context, kubeConfig *rest.Config, cs kubernetes.Interface, nss []string, numPerNs int, clientPods []corev1.Pod, ipv6 bool, maxCheckNum int, ch chan time.Duration) (actualCheckNum, scale int, err error) {
// ScaleUp networkPolicies
start := time.Now()
scale = len(nss) * numPerNs
for _, ns := range nss {
npsData, err := generateNetworkPolicies(ns, numPerNs)
if err != nil {
return 0, fmt.Errorf("error when generating network policies: %w", err)
return 0, 0, fmt.Errorf("error when generating network policies: %w", err)
}
klog.InfoS("Scale up NetworkPolicies", "Num", len(npsData), "Namespace", ns)
for _, np := range npsData {
Expand All @@ -114,7 +115,7 @@ func ScaleUp(ctx context.Context, kubeConfig *rest.Config, cs kubernetes.Interfa
npInfo = NetworkPolicyInfo{Name: newNP.Name, Namespace: newNP.Namespace, Spec: newNP.Spec}
return nil
}); err != nil {
return 0, err
return 0, 0, err
}

if actualCheckNum < maxCheckNum && actualCheckNum < cap(ch) {
Expand Down
1 change: 1 addition & 0 deletions test/performance/framework/pods.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ func ScaleUpWorkloadPods(ctx context.Context, ch chan time.Duration, data *Scale
// Creating workload Pods
start := time.Now()
podNum := data.Specification.PodsNumPerNs
res.scaleNum = len(data.namespaces) * podNum
count := 0
for _, ns := range data.namespaces {
gErr, _ := errgroup.WithContext(context.Background())
Expand Down
3 changes: 3 additions & 0 deletions test/performance/framework/restart.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ func ScaleRestartAgent(ctx context.Context, ch chan time.Duration, data *ScaleDa
ch <- time.Since(start)
res.err = err
}()
res.scaleNum = data.nodesNum
err = data.kubernetesClientSet.CoreV1().Pods(metav1.NamespaceSystem).
DeleteCollection(ctx, metav1.DeleteOptions{}, metav1.ListOptions{LabelSelector: "app=antrea,component=antrea-agent"})
if err != nil {
Expand Down Expand Up @@ -68,10 +69,12 @@ func ScaleRestartAgent(ctx context.Context, ch chan time.Duration, data *ScaleDa
func RestartController(ctx context.Context, ch chan time.Duration, data *ScaleData) (res ScaleResult) {
var err error
start := time.Now()
res.scaleNum = 1
defer func() {
ch <- time.Since(start)
res.err = err
}()

err = data.kubernetesClientSet.CoreV1().Pods(metav1.NamespaceSystem).
DeleteCollection(ctx, metav1.DeleteOptions{}, metav1.ListOptions{LabelSelector: "app=antrea,component=antrea-controller"})
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion test/performance/framework/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ func init() {
func ScaleService(ctx context.Context, ch chan time.Duration, data *ScaleData) (res ScaleResult) {
var err error
maxSvcCheckedCount := data.nodesNum
// actualCheckNum := 0
svcs, actualCheckNum, err := service.ScaleUp(ctx, data.kubeconfig, data.kubernetesClientSet, data.namespaces, data.Specification.SvcNumPerNs, data.Specification.IPv6, maxSvcCheckedCount, ch, data.clientPods)
if err != nil {
err = fmt.Errorf("scale up services error: %v", err)
return
}
res.scaleNum = len(svcs)

defer func() {
res.err = err
Expand Down
7 changes: 4 additions & 3 deletions test/performance/framework/table/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,12 @@ const (
CtxMaxResponseTime = "MaxResponseTime"
CtxMinResponseTime = "MinResponseTime"
CtxSampleQuantity = "SampleQuantity"
CtxScaleNum = "Scale"
)

func GenerateRow(name, result string, duration, avgTime, maxTime, minTime, sampleQuantity string) []string {
func GenerateRow(name, result string, duration, avgTime, maxTime, minTime, sampleQuantity, scaleNum string) []string {
name = strings.ReplaceAll(name, " ", "-")
return []string{name, result, duration, avgTime, maxTime, minTime, sampleQuantity}
return []string{name, result, scaleNum, duration, avgTime, maxTime, minTime, sampleQuantity}
}

func ShowResult(w io.Writer, rows [][]string) {
Expand All @@ -40,7 +41,7 @@ func ShowResult(w io.Writer, rows [][]string) {
}
table.SetAutoFormatHeaders(false)
table.SetAlignment(tablewriter.ALIGN_CENTER)
headers := []string{"Name", "Result", "Duration", CtxAverageResponseTime, CtxMaxResponseTime, CtxMinResponseTime, CtxSampleQuantity}
headers := []string{"Name", "Result", CtxScaleNum, "Duration", CtxAverageResponseTime, CtxMaxResponseTime, CtxMinResponseTime, CtxSampleQuantity}
table.SetHeader(headers)
table.SetAutoMergeCells(true)
table.SetAutoWrapText(true)
Expand Down

0 comments on commit a8dbb16

Please sign in to comment.