Skip to content

Commit

Permalink
fix(RHIXP-3670): Improve framework to be more reliable at high scalab…
Browse files Browse the repository at this point in the history
…ility values (#90)

Signed-off-by: Pavel Macík <[email protected]>
  • Loading branch information
pmacik authored Sep 30, 2024
1 parent a3bf22d commit 232ad28
Show file tree
Hide file tree
Showing 8 changed files with 228 additions and 107 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,8 @@ clean:
test: $(TMP_DIR) $(ARTIFACT_DIR)
echo $(SCENARIO)>$(TMP_DIR)/benchmark-scenario
ifneq ($(shell test '$(AUTH_PROVIDER)' == 'keycloak' && echo 1 || echo 0),0)
$(eval key_pass := $(shell oc -n rhdh-performance get secret perf-test-secrets -o template --template='{{.data.keycloak_user_pass}}' | base64 -d))
$(eval key_host := $(shell oc -n rhdh-performance get routes/keycloak -o template --template='{{.spec.host}}' ))
$(eval key_pass := $(shell oc -n $(RHDH_NAMESPACE) get secret perf-test-secrets -o template --template='{{.data.keycloak_user_pass}}' | base64 -d))
$(eval key_host := $(shell oc -n $(RHDH_NAMESPACE) get routes/keycloak -o template --template='{{.spec.host}}' ))
$(eval LOCUST_EXTRA_CMD := $(LOCUST_EXTRA_CMD) --keycloak-host $(key_host) --keycloak-password $(key_pass) )
ifneq ($(shell test $(USERS) -gt $(WORKERS) && echo 1 || echo 0),0)
@echo "users greater than workers "
Expand Down
60 changes: 49 additions & 11 deletions ci-scripts/collect-results.sh
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ try_gather_file "${TMP_DIR}/deploy-before"
try_gather_file "${TMP_DIR}/deploy-after"
try_gather_file "${TMP_DIR}/populate-before"
try_gather_file "${TMP_DIR}/populate-after"
try_gather_file "${TMP_DIR}/populate-users-groups-before"
try_gather_file "${TMP_DIR}/populate-users-groups-after"
try_gather_file "${TMP_DIR}/populate-catalog-before"
try_gather_file "${TMP_DIR}/populate-catalog-after"
try_gather_file "${TMP_DIR}/benchmark-before"
try_gather_file "${TMP_DIR}/benchmark-after"
try_gather_file "${TMP_DIR}/benchmark-scenario"
Expand Down Expand Up @@ -93,11 +97,42 @@ set +u
# shellcheck disable=SC1090,SC1091
source $PYTHON_VENV_DIR/bin/activate
set -u

timestamp_diff() {
started="$1"
ended="$2"
echo "$(date -d "$ended" +"%s.%N") - $(date -d "$started" +"%s.%N")" | bc
}

# populate phase
if [ "$PRE_LOAD_DB" == "true" ]; then
mstart=$(date --utc --date "$(cat "${TMP_DIR}/populate-before")" --iso-8601=seconds)
mend=$(date --utc --date "$(cat "${TMP_DIR}/populate-after")" --iso-8601=seconds)
mstart=$(date --utc --date "$(cat "${ARTIFACT_DIR}/populate-before")" --iso-8601=seconds)
mend=$(date --utc --date "$(cat "${ARTIFACT_DIR}/populate-after")" --iso-8601=seconds)
mhost=$(kubectl -n openshift-monitoring get route -l app.kubernetes.io/name=thanos-query -o json | jq --raw-output '.items[0].spec.host')
deploy_started=$(cat "${ARTIFACT_DIR}/deploy-before")
deploy_ended=$(cat "${ARTIFACT_DIR}/deploy-after")
populate_started=$(cat "${ARTIFACT_DIR}/populate-before")
populate_ended=$(cat "${ARTIFACT_DIR}/populate-after")
populate_users_groups_started=$(cat "${ARTIFACT_DIR}/populate-users-groups-before")
populate_users_groups_ended=$(cat "${ARTIFACT_DIR}/populate-users-groups-after")
populate_catalog_started=$(cat "${ARTIFACT_DIR}/populate-catalog-before")
populate_catalog_ended=$(cat "${ARTIFACT_DIR}/populate-catalog-after")
status_data.py \
--status-data-file "$monitoring_collection_data" \
--set \
measurements.timings.deploy.started="$deploy_started" \
measurements.timings.deploy.ended="$deploy_ended" \
measurements.timings.deploy.duration="$(timestamp_diff "$deploy_started" "$deploy_ended")" \
measurements.timings.populate.started="$populate_started" \
measurements.timings.populate.ended="$populate_ended" \
measurements.timings.populate.duration="$(timestamp_diff "$populate_started" "$populate_ended")" \
measurements.timings.populate_users_groups.started="$populate_users_groups_started" \
measurements.timings.populate_users_groups.ended="$populate_users_groups_ended" \
measurements.timings.populate_users_groups.duration="$(timestamp_diff "$populate_users_groups_started" "$populate_users_groups_ended")" \
measurements.timings.populate_catalog.started="$populate_catalog_started" \
measurements.timings.populate_catalog.ended="$populate_catalog_ended" \
measurements.timings.populate_catalog.duration="$(timestamp_diff "$populate_catalog_started" "$populate_catalog_ended")" \
-d &>"$monitoring_collection_log"
status_data.py \
--status-data-file "$monitoring_collection_data" \
--additional config/cluster_read_config.populate.yaml \
Expand All @@ -110,17 +145,20 @@ if [ "$PRE_LOAD_DB" == "true" ]; then
-d &>>"$monitoring_collection_log"
fi
# test phase
mstart=$(date --utc --date "$(cat "${TMP_DIR}/benchmark-before")" --iso-8601=seconds)
mend=$(date --utc --date "$(cat "${TMP_DIR}/benchmark-after")" --iso-8601=seconds)
mstart=$(date --utc --date "$(cat "${ARTIFACT_DIR}/benchmark-before")" --iso-8601=seconds)
mend=$(date --utc --date "$(cat "${ARTIFACT_DIR}/benchmark-after")" --iso-8601=seconds)
mhost=$(kubectl -n openshift-monitoring get route -l app.kubernetes.io/name=thanos-query -o json | jq --raw-output '.items[0].spec.host')
mversion=$(sed -n 's/^__version__ = "\(.*\)"/\1/p' "scenarios/$(cat "${TMP_DIR}/benchmark-scenario").py")
mversion=$(sed -n 's/^__version__ = "\(.*\)"/\1/p' "scenarios/$(cat "${ARTIFACT_DIR}/benchmark-scenario").py")
benchmark_started=$(cat "${ARTIFACT_DIR}/benchmark-before")
benchmark_ended=$(cat "${ARTIFACT_DIR}/benchmark-after")
status_data.py \
--status-data-file "$monitoring_collection_data" \
--set \
results.started="$(cat "${TMP_DIR}/benchmark-before")" \
results.ended="$(cat "${TMP_DIR}/benchmark-after")" \
name="RHDH load test $(cat "${TMP_DIR}/benchmark-scenario")" \
metadata.scenario.name="$(cat "${TMP_DIR}/benchmark-scenario")" \
measurements.timings.benchmark.started="$benchmark_started" \
measurements.timings.benchmark.ended="$benchmark_ended" \
measurements.timings.benchmark.duration="$(timestamp_diff "$benchmark_started" "$benchmark_ended")" \
name="RHDH load test $(cat "${ARTIFACT_DIR}/benchmark-scenario")" \
metadata.scenario.name="$(cat "${ARTIFACT_DIR}/benchmark-scenario")" \
metadata.scenario.version="$mversion" \
-d &>"$monitoring_collection_log"
status_data.py \
Expand All @@ -134,10 +172,10 @@ status_data.py \
--prometheus-token "$($cli whoami -t)" \
-d &>>"$monitoring_collection_log"
#Scenario specific metrics
if [ -f "scenarios/$(cat "${TMP_DIR}/benchmark-scenario").metrics.yaml" ]; then
if [ -f "scenarios/$(cat "${ARTIFACT_DIR}/benchmark-scenario").metrics.yaml" ]; then
status_data.py \
--status-data-file "$monitoring_collection_data" \
--additional "scenarios/$(cat "${TMP_DIR}/benchmark-scenario").metrics.yaml" \
--additional "scenarios/$(cat "${ARTIFACT_DIR}/benchmark-scenario").metrics.yaml" \
--monitoring-start "$mstart" \
--monitoring-end "$mend" \
--monitoring-raw-data-dir "$monitoring_collection_dir" \
Expand Down
30 changes: 15 additions & 15 deletions ci-scripts/prow-to-storage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ if [ -z "$HORREUM_JHUTAR_PASSWORD" ]; then
fi

function _log() {
echo "$( date -Ins --utc ) $1 $2" >&1
echo "$(date -Ins --utc) $1 $2" >&1
}

function debug() {
Expand Down Expand Up @@ -85,8 +85,8 @@ function check_json_string() {
function check_result() {
# Ensure benchmark.json have all the required fields => test finished
local f="$1"
if jq -e '.results.ended == null' "$f" >/dev/null; then
error "File is missing .results.ended, skipping"
if jq -e '.measurements.timings.benchmark.ended == null' "$f" >/dev/null; then
error "File is missing .measurements.timings.benchmark.ended, skipping"
return 1
fi
if jq -e '.results | length == 0' "$f" >/dev/null; then
Expand All @@ -101,7 +101,7 @@ function enritch_stuff() {
local key="$2"
local value="$3"
local current_in_file
current_in_file=$( jq --raw-output "$key" "$f" )
current_in_file=$(jq --raw-output "$key" "$f")
if [[ "$current_in_file" == "None" ]]; then
debug "Adding $key to JSON file"
jq "$key = \"$value\"" "$f" >"$$.json" && mv -f "$$.json" "$f"
Expand All @@ -120,9 +120,9 @@ function upload_es() {
debug "Considering file for upload to ES"

local current_doc_in_es current_count_in_es current_error_in_es
current_doc_in_es="$( curl --silent -X GET $ES_HOST/$ES_INDEX/_search -H 'Content-Type: application/json' -d '{"query":{"term":{"metadata.env.BUILD_ID.keyword":{"value":"'"$build_id"'"}}}}' )"
current_count_in_es="$( echo "$current_doc_in_es" | jq --raw-output .hits.total.value )"
current_error_in_es="$( echo "$current_doc_in_es" | jq --raw-output .error.type )"
current_doc_in_es="$(curl --silent -X GET $ES_HOST/$ES_INDEX/_search -H 'Content-Type: application/json' -d '{"query":{"term":{"metadata.env.BUILD_ID.keyword":{"value":"'"$build_id"'"}}}}')"
current_count_in_es="$(echo "$current_doc_in_es" | jq --raw-output .hits.total.value)"
current_error_in_es="$(echo "$current_doc_in_es" | jq --raw-output .error.type)"

if [[ "$current_error_in_es" == "index_not_found_exception" ]]; then
info "Index does not exist yet, going on"
Expand Down Expand Up @@ -154,8 +154,8 @@ function upload_horreum() {

local test_start test_end TOKEN test_id exists ids_list is_fail

test_start="$( format_date "$( jq --raw-output '.results.started | if . == "" then "-" else . end' "$f" )" )"
test_end="$( format_date "$( jq --raw-output '.results.ended | if . == "" then "-" else . end' "$f" )" )"
test_start="$(format_date "$(jq --raw-output '.measurements.timings.benchmark.started | if . == "" then "-" else . end' "$f")")"
test_end="$(format_date "$(jq --raw-output '.measurements.timings.benchmark.ended | if . == "" then "-" else . end' "$f")")"

if [ -z "$test_start" ] || [ -z "$test_end" ] || [ "$test_start" == "null" ] || [ "$test_end" == "null" ]; then
error "We need start ($test_start) and end ($test_end) time in the JSON we are supposed to upload"
Expand All @@ -164,11 +164,11 @@ function upload_horreum() {

debug "Considering file upload to Horreum: start: $test_start, end: $test_end, $test_matcher: $build_id"

TOKEN=$( curl -s $HORREUM_KEYCLOAK_HOST/realms/horreum/protocol/openid-connect/token -d "[email protected]" -d "password=$HORREUM_JHUTAR_PASSWORD" -d "grant_type=password" -d "client_id=horreum-ui" | jq --raw-output .access_token )
TOKEN=$(curl -s $HORREUM_KEYCLOAK_HOST/realms/horreum/protocol/openid-connect/token -d "[email protected]" -d "password=$HORREUM_JHUTAR_PASSWORD" -d "grant_type=password" -d "client_id=horreum-ui" | jq --raw-output .access_token)

test_id=$( curl --silent --get -H "Content-Type: application/json" -H "Authorization: Bearer $TOKEN" "$HORREUM_HOST/api/test/byName/$test_name" | jq --raw-output .id )
test_id=$(curl --silent --get -H "Content-Type: application/json" -H "Authorization: Bearer $TOKEN" "$HORREUM_HOST/api/test/byName/$test_name" | jq --raw-output .id)

exists=$( curl --silent --get -H "Content-Type: application/json" -H "Authorization: Bearer $TOKEN" "$HORREUM_HOST/api/dataset/list/$test_id" --data-urlencode "filter={\"$test_matcher\":\"$build_id\"}" | jq --raw-output '.datasets | length' )
exists=$(curl --silent --get -H "Content-Type: application/json" -H "Authorization: Bearer $TOKEN" "$HORREUM_HOST/api/dataset/list/$test_id" --data-urlencode "filter={\"$test_matcher\":\"$build_id\"}" | jq --raw-output '.datasets | length')

if [[ $exists -gt 0 ]]; then
info "Test result ($test_matcher=$build_id) found in Horreum ($exists), skipping upload"
Expand All @@ -184,7 +184,7 @@ function upload_horreum() {
echo

info "Getting pass/fail for file from Horreum"
ids_list=$( curl --silent "https://horreum.corp.redhat.com/api/alerting/variables?test=$test_id" | jq -r '.[] | .id' )
ids_list=$(curl --silent "https://horreum.corp.redhat.com/api/alerting/variables?test=$test_id" | jq -r '.[] | .id')
is_fail=0
for i in $ids_list; do
data='{
Expand All @@ -198,7 +198,7 @@ function upload_horreum() {
}
}'

count=$( curl --silent -H "Content-Type: application/json" "https://horreum.corp.redhat.com/api/changes/annotations" -d "$data" | jq -r '. | length' )
count=$(curl --silent -H "Content-Type: application/json" "https://horreum.corp.redhat.com/api/changes/annotations" -d "$data" | jq -r '. | length')
if [ "$count" -gt 0 ]; then
is_fail=1
enritch_stuff "$f" ".result" "FAIL"
Expand Down Expand Up @@ -226,7 +226,7 @@ for job in "mvp-cpt"; do
enritch_stuff "$out" ".\"\$schema\"" "$HORREUM_TEST_SCHEMA"
upload_horreum "$out" "$HORREUM_TEST_NAME" ".metadata.env.BUILD_ID" "$i"
upload_es "$out" "$i"
(( counter++ )) || true
((counter++)) || true
done
done

Expand Down
Loading

0 comments on commit 232ad28

Please sign in to comment.