metrics: move the metric start/stop around the install/upgrade/restore command, because we want to avoid being polluted by snapshot create/restore ...

This commit is contained in:
Alexandre Aubin 2023-02-21 17:01:21 +01:00
parent fe56eb2de7
commit f514824235
2 changed files with 14 additions and 10 deletions

View file

@ -94,7 +94,7 @@ _INSTALL_APP () {
# because this also applies to upgrades ... ie older version may have different args and default values # because this also applies to upgrades ... ie older version may have different args and default values
# Fetch and loop over all manifest arg # Fetch and loop over all manifest arg
if [[ -e $package_path/manifest.json ]] if [[ -e $package_path/manifest.json ]]
then then
local manifest_args="$(jq -r '.arguments.install[].name' $package_path/manifest.json)" local manifest_args="$(jq -r '.arguments.install[].name' $package_path/manifest.json)"
else else
@ -106,7 +106,7 @@ _INSTALL_APP () {
# If the argument is not yet in install args, add its default value # If the argument is not yet in install args, add its default value
if ! echo "$install_args" | grep -q -E "\<$ARG=" if ! echo "$install_args" | grep -q -E "\<$ARG="
then then
if [[ -e $package_path/manifest.json ]] if [[ -e $package_path/manifest.json ]]
then then
local default_value=$(jq -e -r --arg ARG $ARG '.arguments.install[] | select(.name==$ARG) | .default' $package_path/manifest.json) local default_value=$(jq -e -r --arg ARG $ARG '.arguments.install[] | select(.name==$ARG) | .default' $package_path/manifest.json)
else else
@ -197,7 +197,7 @@ _VALIDATE_THAT_APP_CAN_BE_ACCESSED () {
else else
local has_public_arg=$(grep -q '\[install.init_main_permission\]' $package_path/manifest.toml && echo true || echo false) local has_public_arg=$(grep -q '\[install.init_main_permission\]' $package_path/manifest.toml && echo true || echo false)
fi fi
if [ "$install_type" != 'private' ] && [[ $has_public_arg == "false" ]] if [ "$install_type" != 'private' ] && [[ $has_public_arg == "false" ]]
then then
log_debug "Forcing public access using a skipped_uris setting" log_debug "Forcing public access using a skipped_uris setting"
@ -243,7 +243,7 @@ _VALIDATE_THAT_APP_CAN_BE_ACCESSED () {
--output './curl_output' \ --output './curl_output' \
$check_domain$curl_check_path" \ $check_domain$curl_check_path" \
> "$TEST_CONTEXT/curl_print" > "$TEST_CONTEXT/curl_print"
LXC_EXEC "cat ./curl_output" > $curl_output LXC_EXEC "cat ./curl_output" > $curl_output
# Analyze the result of curl command # Analyze the result of curl command
@ -382,10 +382,14 @@ TEST_INSTALL () {
_PREINSTALL _PREINSTALL
metrics_start
# Install the application in a LXC container # Install the application in a LXC container
_INSTALL_APP "path=$check_path" "is_public=$is_public" "init_main_permission=$init_main_permission" \ _INSTALL_APP "path=$check_path" "is_public=$is_public" "init_main_permission=$init_main_permission" \
&& _VALIDATE_THAT_APP_CAN_BE_ACCESSED "$SUBDOMAIN" "$check_path" "$install_type" \ && _VALIDATE_THAT_APP_CAN_BE_ACCESSED "$SUBDOMAIN" "$check_path" "$install_type" \
metrics_stop
local install=$? local install=$?
[ $install -eq 0 ] || return 1 [ $install -eq 0 ] || return 1
@ -488,10 +492,14 @@ TEST_UPGRADE () {
ret=$? ret=$?
[ $ret -eq 0 ] || { log_error "Pre-upgrade instruction failed"; return 1; } [ $ret -eq 0 ] || { log_error "Pre-upgrade instruction failed"; return 1; }
metrics_start
# Upgrade the application in a LXC container # Upgrade the application in a LXC container
_RUN_YUNOHOST_CMD "app upgrade $app_id --file /app_folder --force" \ _RUN_YUNOHOST_CMD "app upgrade $app_id --file /app_folder --force" \
&& _VALIDATE_THAT_APP_CAN_BE_ACCESSED "$SUBDOMAIN" "$check_path" "upgrade" && _VALIDATE_THAT_APP_CAN_BE_ACCESSED "$SUBDOMAIN" "$check_path" "upgrade"
metrics_stop
return $? return $?
} }
@ -608,8 +616,10 @@ TEST_BACKUP_RESTORE () {
fi fi
# Restore the application from the previous backup # Restore the application from the previous backup
metrics_start
_RUN_YUNOHOST_CMD "backup restore Backup_test --force --apps $app_id" \ _RUN_YUNOHOST_CMD "backup restore Backup_test --force --apps $app_id" \
&& _VALIDATE_THAT_APP_CAN_BE_ACCESSED "$SUBDOMAIN" "$check_path" && _VALIDATE_THAT_APP_CAN_BE_ACCESSED "$SUBDOMAIN" "$check_path"
metrics_stop
ret=$? ret=$?
[ $ret -eq 0 ] || main_result=1 [ $ret -eq 0 ] || main_result=1

View file

@ -111,9 +111,6 @@ TEST_LAUNCHER () {
# And keep this value separately # And keep this value separately
local global_start_timer=$starttime local global_start_timer=$starttime
# Start metrics measurement
metrics_start
current_test_id=$(basename $testfile | cut -d. -f1) current_test_id=$(basename $testfile | cut -d. -f1)
current_test_infos="$TEST_CONTEXT/tests/$current_test_id.json" current_test_infos="$TEST_CONTEXT/tests/$current_test_id.json"
current_test_results="$TEST_CONTEXT/results/$current_test_id.json" current_test_results="$TEST_CONTEXT/results/$current_test_id.json"
@ -171,9 +168,6 @@ TEST_LAUNCHER () {
# End the timer for the test # End the timer for the test
stop_timer one_test stop_timer one_test
# Stop metrics and show results
metrics_stop
LXC_STOP $LXC_NAME LXC_STOP $LXC_NAME
# Update the lock file with the date of the last finished test. # Update the lock file with the date of the last finished test.