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 65dda9f
Show file tree
Hide file tree
Showing 11 changed files with 226 additions and 104 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/rhdh-bot/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
31 changes: 25 additions & 6 deletions ci-scripts/collect-results.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,32 @@ set -o nounset
set -o errexit
set -o pipefail

echo "\n === Collecting test results and metrics ===\n"

ARTIFACT_DIR=${ARTIFACT_DIR:-artifacts}
monitoring_collection_data=$ARTIFACT_DIR/benchmark.json
monitoring_collection_log=$ARTIFACT_DIR/monitoring-collection.log
monitoring_collection_dir=$ARTIFACT_DIR/monitoring-collection-raw-data-dir
mkdir -p "$monitoring_collection_dir"

cp -vf load-test.log $ARTIFACT_DIR/load-test.log
try_gather_file() {
if [ -f $1 ]; then
cp -vf $1 ${2:-$ARTIFACT_DIR}
else
echo "WARNING: Tried to gather $1 but the file was not found!"
fi
}

try_gather_dir() {
if [ -d $1 ]; then
cp -vf $1 ${2:-$ARTIFACT_DIR}
else
echo "WARNING: Tried to gather $1 but the directory was not found!"
fi
}

try_gather_dir ./ci-scripts/rhdh-setup/.tmp
try_gather_file load-test.log

PYTHON_VENV_DIR=.venv

Expand All @@ -36,11 +55,11 @@ mversion=$(sed -n 's/^__version__ = "\(.*\)"/\1/p' scenarios/$(cat benchmark-sce
status_data.py \
--status-data-file "$monitoring_collection_data" \
--set \
results.started="$(cat benchmark-before)" \
results.ended="$(cat benchmark-after)" \
name="RHDH load test $(cat benchmark-scenario)" \
metadata.scenario.name="$(cat benchmark-scenario)" \
metadata.scenario.version="$mversion" \
results.started="$(cat benchmark-before)" \
results.ended="$(cat benchmark-after)" \
name="RHDH load test $(cat benchmark-scenario)" \
metadata.scenario.name="$(cat benchmark-scenario)" \
metadata.scenario.version="$mversion" \
-d &>"$monitoring_collection_log"
status_data.py \
--status-data-file "$monitoring_collection_data" \
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
11 changes: 9 additions & 2 deletions ci-scripts/rhdh-setup/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
# rhdh-setup
Run `./deploy.sh` to setup backstage with keycloak.
The script expects `QUAY_TOKEN` and `GITHUB_TOKEN` to be set.
Run `./deploy.sh -i` to install backstage with keycloak.

The script expects follwoing environmental variables to be set:
* `QUAY_TOKEN`
* `GITHUB_TOKEN`
* `GITHUB_USER`
* `GITHUB_REPO`

Run with `-r` to delete backstage and redeploy again `./deploy.sh -r`. This is used to syc up users and groups from keycloak.

Run with `-d` to delete backstage only.

Run with `-c` to create objects (Users, Groups, Components and APIs).
136 changes: 79 additions & 57 deletions ci-scripts/rhdh-setup/create_resource.sh
Original file line number Diff line number Diff line change
@@ -1,109 +1,131 @@
#/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`
git config user.name "rhdh-performance-bot"
git config user.email [email protected]
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
}
42 changes: 23 additions & 19 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/rhdh-bot/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
install
;;
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
Loading

0 comments on commit 65dda9f

Please sign in to comment.