diff --git a/cmd/loadTests.go b/cmd/loadTests.go index be71152dc6..e5948bb24c 100644 --- a/cmd/loadTests.go +++ b/cmd/loadTests.go @@ -17,10 +17,12 @@ import ( metricsConstants "github.com/redhat-appstudio-qe/perf-monitoring/api/pkg/constants" "github.com/redhat-appstudio-qe/perf-monitoring/api/pkg/metrics" appstudioApi "github.com/redhat-appstudio/application-api/api/v1alpha1" + buildservice "github.com/redhat-appstudio/build-service/api/v1alpha1" "github.com/redhat-appstudio/e2e-tests/pkg/constants" "github.com/redhat-appstudio/e2e-tests/pkg/framework" "github.com/redhat-appstudio/e2e-tests/pkg/utils" loadtestUtils "github.com/redhat-appstudio/e2e-tests/pkg/utils/loadtests" + "github.com/redhat-appstudio/e2e-tests/pkg/utils/tekton" integrationv1beta1 "github.com/redhat-appstudio/integration-service/api/v1beta1" "github.com/spf13/cobra" pipeline "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1" @@ -31,6 +33,7 @@ import ( k8swait "k8s.io/apimachinery/pkg/util/wait" "k8s.io/klog/v2" "knative.dev/pkg/apis" + rclient "sigs.k8s.io/controller-runtime/pkg/client" ) var ( @@ -55,6 +58,7 @@ var ( enableProgressBars bool pushGatewayURI string = "" jobName string = "" + buildPipelineSelectorBundle string = "" ) var ( @@ -297,6 +301,7 @@ func init() { rootCmd.Flags().BoolVar(&enableProgressBars, "enable-progress-bars", false, "if you want to enable progress bars") rootCmd.Flags().StringVar(&pushGatewayURI, "pushgateway-url", pushGatewayURI, "PushGateway url (needs to be set if metrics are enabled)") rootCmd.Flags().StringVar(&jobName, "job-name", jobName, "Job Name to track Metrics (needs to be set if metrics are enabled)") + rootCmd.Flags().StringVar(&buildPipelineSelectorBundle, "build-pipeline-selector-bundle", buildPipelineSelectorBundle, "BuildPipelineSelector bundle to use when testing with build-definition PR") } func logError(errCode int, message string) { @@ -794,6 +799,11 @@ func StageCleanup(users []loadtestUtils.User) { if err != nil { klog.Errorf("while deleting component detection queries for user: %s, got error: %v\n", user.Username, err) } + + err = deleteAllBuildPipelineSelectors(framework, time.Minute) + if err != nil { + klog.Errorf("while deleting build pipeline selectors for user: %s, got error: %v\n", user.Username, err) + } } } @@ -850,11 +860,81 @@ func componentForUser(username string) string { return "" } +func listAllBuildPipelineSelectors(f *framework.Framework) (*buildservice.BuildPipelineSelectorList, error) { + list := &buildservice.BuildPipelineSelectorList{} + err := f.AsKubeDeveloper.HasController.KubeRest().List(context.Background(), list, &rclient.ListOptions{Namespace: f.UserNamespace}) + klog.V(5).Infof("listAllBuildPipelineSelectors namespace: %s, len: %d, err: %v", f.UserNamespace, len(list.Items), err) + return list, err +} + +func deleteAllBuildPipelineSelectors(f *framework.Framework, timeout time.Duration) error { + klog.V(5).Infof("deleteAllBuildPipelineSelectors start namespace: %s", f.UserNamespace) + defer klog.V(5).Infof("deleteAllBuildPipelineSelectors end") + + list, err := listAllBuildPipelineSelectors(f) + if err != nil { + return fmt.Errorf("error listing build pipeline selectors from %s: %v", f.UserNamespace, err) + } + + for _, bps := range list.Items { + toDelete := bps + err = f.AsKubeDeveloper.HasController.KubeRest().Delete(context.Background(), &toDelete) + if err != nil { + return fmt.Errorf("error deleting build pipeline selector %s from %s: %v", bps.Name, f.UserNamespace, err) + } + } + + return utils.WaitUntil(func() (done bool, err error) { + list, err := listAllBuildPipelineSelectors(f) + if err != nil { + return false, nil + } + return len(list.Items) == 0, nil + }, timeout) +} + +func createBuildPipelineSelector(f *framework.Framework, bundle *string) error { + klog.V(5).Infof("createBuildPipelineSelector start bundle: %s, namespace: %s", *bundle, f.UserNamespace) + defer klog.V(5).Infof("createBuildPipelineSelector end") + + var err error + + err = deleteAllBuildPipelineSelectors(f, time.Minute) + if err != nil { + klog.Errorf("error deleting build pipeline selectors from %s: %v\n", f.UserNamespace, err) + } + + bps := &buildservice.BuildPipelineSelector{ + ObjectMeta: metav1.ObjectMeta{ + Name: "build-pipeline-selector", + Namespace: f.UserNamespace, + }, + Spec: buildservice.BuildPipelineSelectorSpec{Selectors: []buildservice.PipelineSelector{ + { + Name: "all-pipelines", + PipelineRef: *tekton.NewBundleResolverPipelineRef("docker-build", *bundle), + }, + }}, + } + err = f.AsKubeAdmin.CommonController.KubeRest().Create(context.TODO(), bps) + if err != nil { + return fmt.Errorf("error creating build pipeline selector in %s with bundle %s: %v", f.UserNamespace, *bundle, err) + } + + return nil +} + func frameworkForUser(username string) *framework.Framework { val, ok := frameworkMap.Load(username) if ok { framework, ok2 := val.(*framework.Framework) if ok2 { + if buildPipelineSelectorBundle != "" { + err := createBuildPipelineSelector(framework, &buildPipelineSelectorBundle) + if err != nil { + klog.Errorf("Error creating build pipeline selector: %v", err) + } + } return framework } else { klog.Errorf("Invalid type of map value: %+v", val) diff --git a/tests/load-tests/ci-scripts/collect-results.sh b/tests/load-tests/ci-scripts/collect-results.sh index f335389521..8070cfc041 100755 --- a/tests/load-tests/ci-scripts/collect-results.sh +++ b/tests/load-tests/ci-scripts/collect-results.sh @@ -23,6 +23,7 @@ find "$output_dir" -type f -name '*.pprof' -exec cp -vf {} "${ARTIFACT_DIR}" \; pipelineruns_json=$ARTIFACT_DIR/pipelineruns.json taskruns_json=$ARTIFACT_DIR/taskruns.json pods_json=$ARTIFACT_DIR/pods.json +buildpipelineselectors_json=$ARTIFACT_DIR/buildpipelineselectors.json application_timestamps=$ARTIFACT_DIR/applications.appstudio.redhat.com_timestamps application_timestamps_csv=${application_timestamps}.csv @@ -182,6 +183,9 @@ jq -r ".items[] | .spec.nodeName" "$pods_json" | sort | uniq -c | sed -e 's,\s\+ echo "Node;Pods" >"$task_pods_distribution_csv" jq -r '.items[] | select(.metadata.labels."appstudio.openshift.io/application" != null).spec.nodeName' "$pods_json" | sort | uniq -c | sed -e 's,\s\+\([0-9]\+\)\s\+\(.*\),\2;\1,g' >>"$task_pods_distribution_csv" +## Record BuildPipelineSelectors +oc get BuildPipelineSelectors -A -o json >"$buildpipelineselectors_json" + ## Tekton Artifact Performance Analysis tapa_dir=./tapa.git diff --git a/tests/load-tests/run-stage.sh b/tests/load-tests/run-stage.sh index 04775de59b..f2575fad80 100755 --- a/tests/load-tests/run-stage.sh +++ b/tests/load-tests/run-stage.sh @@ -1,5 +1,6 @@ go run loadtest.go \ --component-repo "${COMPONENT_REPO:-https://github.com/devfile-samples/devfile-sample-code-with-quarkus}" \ + --build-pipeline-selector-bundle "${BUILD_PIPELINE_SELECTOR_BUNDLE:-}" \ --username "$USER_PREFIX" \ --users "${USERS_PER_THREAD:-2}" \ --test-scenario-git-url "${TEST_SCENARIO_GIT_URL:-https://github.com/redhat-appstudio/integration-examples.git}" \ diff --git a/tests/load-tests/run.sh b/tests/load-tests/run.sh index e52217df88..c6e074242e 100755 --- a/tests/load-tests/run.sh +++ b/tests/load-tests/run.sh @@ -82,6 +82,7 @@ else ## To enable progress bar , add `--enable-progress-bars` in [OPTIONS] go run loadtest.go \ --component-repo "${COMPONENT_REPO:-https://github.com/devfile-samples/devfile-sample-code-with-quarkus}" \ + --build-pipeline-selector-bundle "${BUILD_PIPELINE_SELECTOR_BUNDLE:-}" \ --username "$USER_PREFIX" \ --users "${USERS_PER_THREAD:-50}" \ --test-scenario-git-url "${TEST_SCENARIO_GIT_URL:-https://github.com/redhat-appstudio/integration-examples.git}" \