Skip to content

Commit

Permalink
fix fleetsize & clusternames
Browse files Browse the repository at this point in the history
  • Loading branch information
britaniar committed Dec 8, 2023
1 parent 02703c9 commit 61d5950
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 15 deletions.
2 changes: 1 addition & 1 deletion hack/loadtest/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ var (
placementDeadline = flag.Int("placement-deadline-second", 300, "The deadline for a placement to be applied (in seconds)")
pollInterval = flag.Int("poll-interval-millisecond", 250, "The poll interval for verification (in milli-second)")
maxCurrentPlacement = flag.Int("max-current-placement", 10, "The number of current placement load.")
loadTestLength = flag.Int("load-test-length-minute", 3, "The length of the load test in minutes.")
loadTestLength = flag.Int("load-test-length-minute", 20, "The length of the load test in minutes.")
clusterNames util.ClusterNames //will be used for PickFixed scenario, otherwise will apply to all clusters
)

Expand Down
24 changes: 10 additions & 14 deletions hack/loadtest/util/placement.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ func MeasureOnePlacement(ctx context.Context, hubClient client.Client, deadline,

klog.Infof("create the cluster resource placement `%s` in the hub cluster", crpName)
crp := &v1beta1.ClusterResourcePlacement{}

if err := createCRP(crp, crpFile, crpName, nsName); err != nil {
klog.ErrorS(err, "failed to create crp", "namespace", nsName, "crp", crpName)
return err
Expand All @@ -108,7 +107,7 @@ func MeasureOnePlacement(ctx context.Context, hubClient client.Client, deadline,
crpCount.Inc()

klog.Infof("verify that the cluster resource placement `%s` is applied", crpName)
fleetSize = collectApplyMetrics(ctx, hubClient, deadline, interval, crpName, currency, fleetSize, clusterNames)
fleetSize, clusterNames = collectApplyMetrics(ctx, hubClient, deadline, interval, crpName, currency, fleetSize, clusterNames)

klog.Infof("remove the namespaced resources applied by the placement `%s`", crpName)
deletionStartTime := time.Now()
Expand All @@ -120,13 +119,12 @@ func MeasureOnePlacement(ctx context.Context, hubClient client.Client, deadline,

// wait for the status of the CRP and make sure all conditions are all true
klog.Infof("verify cluster resource placement `%s` is updated", crpName)
waitForCrpToComplete(ctx, hubClient, deadline, interval, deletionStartTime, crpName, currency, fleetSize)

waitForCrpToComplete(ctx, hubClient, deadline, interval, deletionStartTime, clusterNames, crpName, currency, fleetSize)
return hubClient.Delete(ctx, crp)
}

// collect the crp apply metrics
func collectApplyMetrics(ctx context.Context, hubClient client.Client, deadline, pollInterval time.Duration, crpName string, currency string, fleetSize string, clusterNames ClusterNames) string {
func collectApplyMetrics(ctx context.Context, hubClient client.Client, deadline, pollInterval time.Duration, crpName string, currency string, fleetSize string, clusterNames ClusterNames) (string, ClusterNames) {
startTime := time.Now()
applyDeadline := startTime.Add(deadline)
var crp v1beta1.ClusterResourcePlacement
Expand All @@ -136,7 +134,7 @@ func collectApplyMetrics(ctx context.Context, hubClient client.Client, deadline,
for {
select {
case <-ctx.Done():
return "0"
return fleetSize, clusterNames
case <-ticker.C:
if err = hubClient.Get(ctx, types.NamespacedName{Name: crpName, Namespace: ""}, &crp); err != nil {
klog.ErrorS(err, "failed to get crp", "crp", crpName)
Expand All @@ -145,7 +143,7 @@ func collectApplyMetrics(ctx context.Context, hubClient client.Client, deadline,
klog.V(2).Infof("the cluster resource placement `%s` timeout", crpName)
LoadTestApplyCountMetric.WithLabelValues(currency, fleetSize, "timeout").Inc()
applyTimeoutCount.Inc()
return "0"
return fleetSize, clusterNames
}
continue
}
Expand All @@ -157,16 +155,14 @@ func collectApplyMetrics(ctx context.Context, hubClient client.Client, deadline,
// succeeded
klog.V(3).Infof("the cluster resource placement `%s` succeeded", crpName)
endTime := time.Since(startTime)
var newClusterNames []string
if fleetSize, newClusterNames, err = getFleetSize(crp, clusterNames); err != nil {
if fleetSize, clusterNames, err = getFleetSize(crp, clusterNames); err != nil {
klog.ErrorS(err, "Failed to get fleet size.")
return "0"
return fleetSize, nil
}
clusterNames = newClusterNames
LoadTestApplyCountMetric.WithLabelValues(currency, fleetSize, "succeed").Inc()
applySuccessCount.Inc()
LoadTestApplyLatencyMetric.WithLabelValues(currency, fleetSize).Observe(endTime.Seconds())
return fleetSize
return fleetSize, clusterNames
}
if time.Now().After(applyDeadline) {
if cond != nil && cond.Status == metav1.ConditionFalse {
Expand All @@ -180,7 +176,7 @@ func collectApplyMetrics(ctx context.Context, hubClient client.Client, deadline,
LoadTestApplyCountMetric.WithLabelValues(currency, fleetSize, "timeout").Inc()
applyTimeoutCount.Inc()
}
return "0"
return fleetSize, clusterNames
}
}
}
Expand Down Expand Up @@ -249,7 +245,7 @@ func collectDeleteMetrics(ctx context.Context, hubClient client.Client, deadline
}

// check crp updated/completed before deletion
func waitForCrpToComplete(ctx context.Context, hubClient client.Client, deadline, pollInterval time.Duration, deletionStartTime time.Time, crpName string, currency string, fleetSize string) {
func waitForCrpToComplete(ctx context.Context, hubClient client.Client, deadline, pollInterval time.Duration, deletionStartTime time.Time, clusterNames ClusterNames, crpName string, currency string, fleetSize string) {

Check failure on line 248 in hack/loadtest/util/placement.go

View workflow job for this annotation

GitHub Actions / Lint

unused-parameter: parameter 'clusterNames' seems to be unused, consider removing or renaming it as _ (revive)
startTime := time.Now()
applyDeadline := startTime.Add(deadline)
var crp v1beta1.ClusterResourcePlacement
Expand Down

0 comments on commit 61d5950

Please sign in to comment.