From e8d980338cffe4d48e96ec2583e1b551dde63005 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pavel=20Mac=C3=ADk?= Date: Wed, 22 Nov 2023 15:10:42 +0100 Subject: [PATCH] update rhdh-setup and add search-catalog scenario MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Pavel MacĂ­k --- .gitignore | 1 - Makefile | 19 ++- ci-scripts/rhdh-setup/.gitignore | 2 + ci-scripts/rhdh-setup/create_resource.sh | 134 ++++++++++-------- ci-scripts/rhdh-setup/deploy.sh | 40 +++--- .../template/backstage/chart-values.yaml | 4 +- ci-scripts/setup.sh | 16 ++- ci-scripts/test.sh | 2 +- scenarios/search-catalog.py | 58 ++++++++ 9 files changed, 185 insertions(+), 91 deletions(-) create mode 100644 scenarios/search-catalog.py diff --git a/.gitignore b/.gitignore index 0a3e568..4ff0568 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,5 @@ .venv .vscode -.rhdh-setup.git* benchmark-scenario benchmark-before benchmark-after diff --git a/Makefile b/Makefile index 394bcea..bdbfd6a 100644 --- a/Makefile +++ b/Makefile @@ -19,11 +19,11 @@ export SPAWN_RATE ?= 20 # RHDH image to deploy export RHDH_IMAGE_REGISTRY ?= quay.io export RHDH_IMAGE_REPO ?= rhdh/rhdh-hub-rhel9 -export RHDH_IMAGE_TAG ?= 1.0-162 +export RHDH_IMAGE_TAG ?= 1.0-190 # RHDH Helm chart to deploy export RHDH_NAMESPACE ?= rhdh-performance -export RHDH_HELM_REPO ?= https://gist.githubusercontent.com/nickboldt/a8483eb244f9c4286798e85accaa70af/raw/ +export RHDH_HELM_REPO ?= https://gist.githubusercontent.com/nickboldt/63cef5cb6285889527bd6a67c0e1c2a9/raw/ export RHDH_HELM_CHART ?= developer-hub export RHDH_HELM_RELEASE_NAME ?= rhdh @@ -64,12 +64,17 @@ namespace: ## Deploy RHDH .PHONY: deploy-rhdh deploy-rhdh: - ./ci-scripts/setup.sh + cd ./ci-scripts/rhdh-setup/; ./deploy.sh -i + +## Create users, groups and objects such as components and APIs in RHDH +.PHONY: populate-rhdh +populate-rhdh: + cd ./ci-scripts/rhdh-setup/; ./deploy.sh -c ## Undeploy RHDH .PHONY: undeploy-rhdh undeploy-rhdh: - ./ci-scripts/rhdh-setup/deploy.sh -d + cd ./ci-scripts/rhdh-setup/; ./deploy.sh -d ## === Locust Operator === @@ -127,7 +132,11 @@ test: ## Run the load test in CI end to end .PHONY: ci-run -ci-run: setup-venv deploy-locust add-dockerio test +ci-run: setup-venv deploy-locust test + +## Deploy and populate RHDH in CI end to end +.PHONY: ci-deploy +ci-deploy: namespace deploy-rhdh populate-rhdh ## === Maintanence === diff --git a/ci-scripts/rhdh-setup/.gitignore b/ci-scripts/rhdh-setup/.gitignore index abd9126..c5fad40 100644 --- a/ci-scripts/rhdh-setup/.gitignore +++ b/ci-scripts/rhdh-setup/.gitignore @@ -1,2 +1,4 @@ +.tmp/* +nohup.out app-config.yaml config.yaml diff --git a/ci-scripts/rhdh-setup/create_resource.sh b/ci-scripts/rhdh-setup/create_resource.sh index e24159a..0d77017 100755 --- a/ci-scripts/rhdh-setup/create_resource.sh +++ b/ci-scripts/rhdh-setup/create_resource.sh @@ -1,109 +1,129 @@ -#/bin/bash +#!/bin/bash -create_per_grp() { +export TMP_DIR=$(readlink -m .tmp) +mkdir -p $TMP_DIR +export WORKDIR=$(readlink -m .) + +function keycloak_url() { + f=$TMP_DIR/keycloak.url + if [ ! -f $f ]; then + echo -n "https://$(oc get routes keycloak -n ${RHDH_NAMESPACE} -o jsonpath='{.spec.host}')" >$f + fi + cat $f +} + +function backstage_url() { + f=$TMP_DIR/backstage.url + if [ ! -f $f ]; then + echo -n "https://$(oc get routes ${RHDH_HELM_RELEASE_NAME}-developer-hub -n ${RHDH_NAMESPACE} -o jsonpath='{.spec.host}')" >$f + fi + cat $f +} + +export -f keycloak_url backstage_url + +function create_per_grp() { varname=$2 obj_count=${!varname} - if [[ -z ${!varname} ]] ; then - echo "$varname is not set: Skipping $1 "; + if [[ -z ${!varname} ]]; then + echo "$varname is not set: Skipping $1 " exit 1 fi - local iter_count=`echo "(${obj_count}/${GROUP_COUNT})"|bc` - local mod=`echo "(${obj_count}%${GROUP_COUNT})"|bc` + local iter_count=$(echo "(${obj_count}/${GROUP_COUNT})" | bc) + local mod=$(echo "(${obj_count}%${GROUP_COUNT})" | bc) - if [[ ! ${mod} -eq 0 ]] ; then - iter_count=`echo "${iter_count}+1"|bc` + if [[ ! ${mod} -eq 0 ]]; then + iter_count=$(echo "${iter_count}+1" | bc) fi indx=0 - for i in `seq 1 $((${iter_count}))`; do - for j in `seq 1 $((${GROUP_COUNT}))`; do - indx=$((1+indx)) - [[ ${obj_count} -lt $indx ]] && break - local out=$(${1} ${j} ${indx}) + for i in $(seq 1 $((${iter_count}))); do + for j in $(seq 1 $((${GROUP_COUNT}))); do + indx=$((1 + indx)) + [[ ${obj_count} -lt $indx ]] && break + local out=$(${1} ${j} ${indx}) done done } -clone_and_upload() { - export backstage_url="https://$(oc get routes ${RHDH_HELM_RELEASE_NAME}-developer-hub -n ${RHDH_NAMESPACE} -o jsonpath='{.spec.host}')" +function clone_and_upload() { git_str="${GITHUB_USER}:${GITHUB_TOKEN}@github.com" - base_name=`basename $GITHUB_REPO` - git_dir=${base_name%%.*} - git_repo=`echo $GITHUB_REPO|sed -e "s/github.com/${git_str}/g"` + base_name=$(basename $GITHUB_REPO) + git_dir=$TMP_DIR/${base_name} + git_repo=$(echo $GITHUB_REPO | sed -e "s/github.com/${git_str}/g") [[ -d ${git_dir} ]] && rm -rf ${git_dir} - git clone $git_repo + git clone $git_repo $git_dir cd $git_dir - tmp_branch=`mktemp -u XXXXXXXXXX` + tmp_branch=$(mktemp -u XXXXXXXXXX) git checkout -b $tmp_branch - mv ../${1} . - git add ${1} + mv -vf ${1} . + filename=$(basename ${1}) + git add $filename git commit -a -m "commit objects" git push -f --set-upstream origin $tmp_branch cd .. sleep 5 - upload_url=${GITHUB_REPO%.*}/blob/${tmp_branch}/${1} - curl -k ${backstage_url}'/api/catalog/locations' -X POST -H 'Accept-Encoding: gzip, deflate, br' -H 'Content-Type: application/json' --data-raw '{"type":"url","target":"'"${upload_url}"'"}' + upload_url=${GITHUB_REPO%.*}/blob/${tmp_branch}/${filename} + curl -k "$(backstage_url)/api/catalog/locations" -X POST -H 'Accept-Encoding: gzip, deflate, br' -H 'Content-Type: application/json' --data-raw '{"type":"url","target":"'"${upload_url}"'"}' } -create_api() { - export grp_indx=$1 +function create_api() { + export grp_indx=$1 export api_indx=$2 - cat template/component/api.template | envsubst '${grp_indx} ${api_indx}'>> api.yaml + cat $WORKDIR/template/component/api.template | envsubst '${grp_indx} ${api_indx}' >>$TMP_DIR/api.yaml } -create_cmp() { - export grp_indx=$1 +function create_cmp() { + export grp_indx=$1 export cmp_indx=$2 - cat template/component/component.template | envsubst '${grp_indx} ${cmp_indx}'>> component.yaml + cat $WORKDIR/template/component/component.template | envsubst '${grp_indx} ${cmp_indx}' >>$TMP_DIR/component.yaml } -create_group() { - token=`cat /tmp/token` - curl -s -k --location --request POST ${keycloak_url}'/auth/admin/realms/backstage/groups' \ - -H 'Content-Type: application/json' \ - -H 'Authorization: Bearer '$token \ - --data-raw '{"name": "group'"${0}"'"}' +function create_group() { + token=$(cat $TMP_DIR/token) + curl -s -k --location --request POST "$(keycloak_url)/auth/admin/realms/backstage/groups" \ + -H 'Content-Type: application/json' \ + -H 'Authorization: Bearer '$token \ + --data-raw '{"name": "group'"${0}"'"}' } -create_groups() { +function create_groups() { echo "Creating Groups in Keycloak" - export keycloak_url="https://$(oc get routes keycloak -n ${RHDH_NAMESPACE} -o jsonpath='{.spec.host}')" - export keycloak_pass=$(oc -n ${RHDH_NAMESPACE} get secret credential-example-sso -o template --template='{{.data.ADMIN_PASSWORD}}'|base64 -d) export -f get_token - nohup bash -c 'get_token' & + nohup bash -c 'get_token' & refresh_pid=$! sleep 5 export -f create_group - seq 1 ${GROUP_COUNT}| xargs -n1 -P10 bash -c 'create_group' + seq 1 ${GROUP_COUNT} | xargs -n1 -P10 bash -c 'create_group' kill $refresh_pid } -create_user() { - token=`cat /tmp/token` - grp=`echo "${0}%${GROUP_COUNT}"|bc` - [[ $grp -eq 0 ]] && grp=${GROUP_COUNT} - curl -s -k --location --request POST ${keycloak_url}'/auth/admin/realms/backstage/users' \ - -H 'Content-Type: application/json' \ - -H 'Authorization: Bearer '$token \ - --data-raw '{"firstName":"test'"${0}"'","lastName":"tester", "email":"test'"${0}"'@test.com", "enabled":"true", "username":"test'"${0}"'","groups":["/group'"${grp}"'"]}' +function create_user() { + token=$(cat $TMP_DIR/token) + grp=$(echo "${0}%${GROUP_COUNT}" | bc) + [[ $grp -eq 0 ]] && grp=${GROUP_COUNT} + keycloak_url="https://$(oc get routes keycloak -n ${RHDH_NAMESPACE} -o jsonpath='{.spec.host}')" + curl -s -k --location --request POST "$(keycloak_url)/auth/admin/realms/backstage/users" \ + -H 'Content-Type: application/json' \ + -H 'Authorization: Bearer '$token \ + --data-raw '{"firstName":"test'"${0}"'","lastName":"tester", "email":"test'"${0}"'@test.com", "enabled":"true", "username":"test'"${0}"'","groups":["/group'"${grp}"'"]}' } -create_users() { +function create_users() { echo "Creating Users in Keycloak" - export keycloak_url="https://$(oc get routes keycloak -n ${RHDH_NAMESPACE} -o jsonpath='{.spec.host}')" - export keycloak_pass=$(oc -n ${RHDH_NAMESPACE} get secret credential-example-sso -o template --template='{{.data.ADMIN_PASSWORD}}'|base64 -d) export -f get_token export GROUP_COUNT - nohup bash -c 'get_token' & + nohup bash -c 'get_token' & refresh_pid=$! sleep 5 export -f create_user - seq 1 ${BACKSTAGE_USER_COUNT}| xargs -n1 -P10 bash -c 'create_user' + seq 1 ${BACKSTAGE_USER_COUNT} | xargs -n1 -P10 bash -c 'create_user' kill $refresh_pid } -get_token() { - while true; do - echo -n $(curl -s -k ${keycloak_url}/auth/realms/master/protocol/openid-connect/token -d "username=admin" -d "password="${keycloak_pass} -d 'grant_type=password' -d 'client_id=admin-cli' | jq -r .access_token)>/tmp/token +function get_token() { + keycloak_pass=$(oc -n ${RHDH_NAMESPACE} get secret credential-example-sso -o template --template='{{.data.ADMIN_PASSWORD}}' | base64 -d) + while true; do + curl -s -k "$(keycloak_url)/auth/realms/master/protocol/openid-connect/token" -d "username=admin" -d "password=${keycloak_pass}" -d 'grant_type=password' -d 'client_id=admin-cli' | jq -r .access_token >$TMP_DIR/token sleep 30 done } diff --git a/ci-scripts/rhdh-setup/deploy.sh b/ci-scripts/rhdh-setup/deploy.sh index b1bda6f..bd86b52 100755 --- a/ci-scripts/rhdh-setup/deploy.sh +++ b/ci-scripts/rhdh-setup/deploy.sh @@ -20,9 +20,9 @@ export RHDH_KEYCLOAK_REPLICAS=${RHDH_KEYCLOAK_REPLICAS:-1} export RHDH_IMAGE_REGISTRY=${RHDH_IMAGE_REGISTRY:-quay.io} export RHDH_IMAGE_REPO=${RHDH_IMAGE_REPO:-rhdh/rhdh-hub-rhel9} -export RHDH_IMAGE_TAG=${RHDH_IMAGE_TAG:-1.0-162} +export RHDH_IMAGE_TAG=${RHDH_IMAGE_TAG:-1.0-190} -export RHDH_HELM_REPO=${RHDH_HELM_REPO:-https://gist.githubusercontent.com/nickboldt/a8483eb244f9c4286798e85accaa70af/raw} #v1.0-162 +export RHDH_HELM_REPO=${RHDH_HELM_REPO:-https://gist.githubusercontent.com/nickboldt/63cef5cb6285889527bd6a67c0e1c2a9/raw} export RHDH_HELM_CHART=${RHDH_HELM_CHART:-developer-hub} export PRE_LOAD_DB="${PRE_LOAD_DB:-true}" @@ -150,19 +150,19 @@ EOF create_objs() { if ! $PRE_LOAD_DB; then - create_groups - create_users + create_groups + create_users fi - if [[ ${GITHUB_USER} ]] && [[ ${GITHUB_REPO} ]] ; then - create_per_grp create_cmp COMPONENT_COUNT - [[ $? -eq 0 ]] && clone_and_upload component.yaml + if [[ ${GITHUB_USER} ]] && [[ ${GITHUB_REPO} ]]; then + create_per_grp create_cmp COMPONENT_COUNT + [[ $? -eq 0 ]] && clone_and_upload $TMP_DIR/component.yaml - create_per_grp create_api API_COUNT - [[ $? -eq 0 ]] && clone_and_upload api.yaml + create_per_grp create_api API_COUNT + [[ $? -eq 0 ]] && clone_and_upload $TMP_DIR/api.yaml else - echo "skipping component creating. GITHUB_REPO and GITHUB_USER not set" - exit 1 + echo "skipping component creating. GITHUB_REPO and GITHUB_USER not set" + exit 1 fi } @@ -172,16 +172,19 @@ install() { keycloak_install if $PRE_LOAD_DB; then - create_groups - create_users + create_groups + create_users fi backstage_install setup_monitoring } -while getopts "rd" flag; do +while getopts "crdi" flag; do case "${flag}" in + c) + create_objs + ;; r) delete ;; @@ -189,11 +192,12 @@ while getopts "rd" flag; do delete exit 0 ;; + i) + install + ;; *) - echo "Invalid option: ${flag}" + echo "WARNING: Invalid option: ${flag} - defaulting to -i (install)" + install ;; esac done - -install -create_objs diff --git a/ci-scripts/rhdh-setup/template/backstage/chart-values.yaml b/ci-scripts/rhdh-setup/template/backstage/chart-values.yaml index 510efbd..b3f8a41 100644 --- a/ci-scripts/rhdh-setup/template/backstage/chart-values.yaml +++ b/ci-scripts/rhdh-setup/template/backstage/chart-values.yaml @@ -1,5 +1,7 @@ global: clusterRouterBase: ${OPENSHIFT_APP_DOMAIN} + imagePullSecrets: + - rhdh-pull-secret route: enabled: true host: "{{ .Values.global.host }}" @@ -68,8 +70,6 @@ upstream: image: debug: false pullPolicy: Always - pullSecrets: - - rhdh-pull-secret registry: ${RHDH_IMAGE_REGISTRY} repository: ${RHDH_IMAGE_REPO} tag: ${RHDH_IMAGE_TAG} diff --git a/ci-scripts/setup.sh b/ci-scripts/setup.sh index 687cb94..9866e3a 100755 --- a/ci-scripts/setup.sh +++ b/ci-scripts/setup.sh @@ -6,19 +6,21 @@ set -o pipefail echo "TODO: implement installation and setup of backstage to given openshift cluster" -export GITHUB_TOKEN QUAY_TOKEN KUBECONFIG +export GITHUB_TOKEN GITHUB_USER GITHUB_REPO QUAY_TOKEN KUBECONFIG GITHUB_TOKEN=$(cat /usr/local/ci-secrets/backstage-performance/github.token) +GITHUB_USER=$(cat /usr/local/ci-secrets/backstage-performance/github.user) +GITHUB_REPO=$(cat /usr/local/ci-secrets/backstage-performance/github.repo) QUAY_TOKEN=$(cat /usr/local/ci-secrets/backstage-performance/quay.token) -echo "$(date --utc -Ins) Creating namespace" -make namespace - -cd ./ci-scripts/rhdh-setup - export RHDH_DEPLOYMENT_REPLICAS=5 export RHDH_DB_REPLICAS=5 export RHDH_KEYCLOAK_REPLICAS=5 +export API_COUNT=1000 +export COMPONENT_COUNT=1000 +export BACKSTAGE_USER_COUNT=1000 +export GROUP_COUNT=50 + echo "$(date --utc -Ins) Running deployment script" -./deploy.sh +make ci-deploy diff --git a/ci-scripts/test.sh b/ci-scripts/test.sh index e65a25f..7cbdfe8 100755 --- a/ci-scripts/test.sh +++ b/ci-scripts/test.sh @@ -12,7 +12,7 @@ DOCKERIO_TOKEN=$(cat /usr/local/ci-secrets/backstage-performance/dockerio.token) #export USERS=1000 #export WORKERS=10 #export DURATION=10m -export SCENARIO="list-catalog" +export SCENARIO="search-catalog" export HOST="https://$(oc get routes rhdh-developer-hub -n rhdh-performance -o jsonpath='{.spec.host}')" # end-of testing env diff --git a/scenarios/search-catalog.py b/scenarios/search-catalog.py new file mode 100644 index 0000000..4cd1bd8 --- /dev/null +++ b/scenarios/search-catalog.py @@ -0,0 +1,58 @@ +from locust import HttpUser, task +from urllib3.exceptions import InsecureRequestWarning +import urllib3 + +urllib3.disable_warnings(InsecureRequestWarning) + +__version__ = "1" + +params = {} + +params["all"] = { + "types[0]": "software-catalog", +} + +params["all_components"] = { + "types[0]": "software-catalog", + "filters[kind]": "Component", +} + +params["not_found"] = { + "types[0]": "software-catalog", + "term": "n/a" +} + +params["components_by_lifecycle"] = { + "types[0]": "software-catalog", + "filters[kind]": "Component", + "filters[lifecycle][0]": "experimental", +} + +base_path = "/api/search/query" + + +class SearchCatalogTest(HttpUser): + + def on_start(self): + self.client.verify = False + + def search(self, query="all") -> None: + self.client.get(base_path, + verify=False, + params=params[query]) + + @task + def searchAll(self) -> None: + self.search("all") + + @task + def searchAllComponents(self) -> None: + self.search("all_components") + + @task + def searchNotFound(self) -> None: + self.search("not_found") + + @task + def searchComponentsByLifecycle(self) -> None: + self.search("components_by_lifecycle")