Skip to content

Commit

Permalink
update rhdh-setup and add search-catalog scenario
Browse files Browse the repository at this point in the history
Signed-off-by: Pavel Macík <[email protected]>
  • Loading branch information
pmacik committed Nov 23, 2023
1 parent baf5ef2 commit e8d9803
Show file tree
Hide file tree
Showing 9 changed files with 185 additions and 91 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
.venv
.vscode
.rhdh-setup.git*
benchmark-scenario
benchmark-before
benchmark-after
Expand Down
19 changes: 14 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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 ===

Expand Down Expand Up @@ -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 ===

Expand Down
2 changes: 2 additions & 0 deletions ci-scripts/rhdh-setup/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
.tmp/*
nohup.out
app-config.yaml
config.yaml
134 changes: 77 additions & 57 deletions ci-scripts/rhdh-setup/create_resource.sh
Original file line number Diff line number Diff line change
@@ -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
}
40 changes: 22 additions & 18 deletions ci-scripts/rhdh-setup/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down Expand Up @@ -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
}

Expand All @@ -172,28 +172,32 @@ 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
;;
d)
delete
exit 0
;;
i)
install
;;
*)
echo "Invalid option: ${flag}"
echo "WARNING: Invalid option: ${flag} - defaulting to -i (install)"
install
;;
esac
done

install
create_objs
4 changes: 2 additions & 2 deletions ci-scripts/rhdh-setup/template/backstage/chart-values.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
global:
clusterRouterBase: ${OPENSHIFT_APP_DOMAIN}
imagePullSecrets:
- rhdh-pull-secret
route:
enabled: true
host: "{{ .Values.global.host }}"
Expand Down Expand Up @@ -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}
Expand Down
16 changes: 9 additions & 7 deletions ci-scripts/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion ci-scripts/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit e8d9803

Please sign in to comment.