From 02f7c4e340435bb4be9f10c5582531e957c67ad8 Mon Sep 17 00:00:00 2001 From: Tom J Nowell Date: Fri, 20 Sep 2024 10:14:46 +0100 Subject: [PATCH 1/4] refactor how provisioner and hook timing are measured so that milliseconds are included --- provision/provision-helpers.sh | 17 +++++++++++------ provision/provisioners.sh | 16 ++++++++++------ 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/provision/provision-helpers.sh b/provision/provision-helpers.sh index 7bf1458a9..d186747ca 100755 --- a/provision/provision-helpers.sh +++ b/provision/provision-helpers.sh @@ -393,9 +393,13 @@ vvv_hook() { return 1 fi - local hook_var_prios="VVV_HOOKS_${1}" - local start - start=$(date +%s) + local hook_var_prios + local hook_elapsed + local hook_end_timestamp + local hook_start_timestamp + + hook_var_prios="VVV_HOOKS_${1}" + hook_start_timestamp="$(date -u +"%s.%2N")" vvv_info " ▷ Running ${1} hook" eval "if [ -z \"\${${hook_var_prios}}\" ]; then return 0; fi" local sorted @@ -408,9 +412,10 @@ vvv_hook() { $f done done - local end - end=$(date +%s) - vvv_success " ✔ Finished ${1} hook in $((end - start))s" + hook_end_timestamp="$(date -u +"%s.%2N")" + hook_elapsed=$(date -u -d "0 ${hook_end_timestamp} seconds - ${hook_start_timestamp} seconds" +"%-Mm %-Ss %-3Nms") + + vvv_success " ✔ Finished ${1} hook in ${hook_elapsed}" } export -f vvv_hook diff --git a/provision/provisioners.sh b/provision/provisioners.sh index 657f8762d..abb82ef67 100755 --- a/provision/provisioners.sh +++ b/provision/provisioners.sh @@ -13,6 +13,7 @@ exec 7>&2 source /srv/provision/provision-helpers.sh VVV_PROVISIONER_RUNNING="" +VVV_PROVISIONER_START_TIMESTAMP=0 # @description Signal that a provisioner has begun, and setup timings, failed provisioner flags, etc # @arg $1 string Name of the provisioner @@ -21,7 +22,7 @@ function provisioner_begin() { touch "/vagrant/failed_provisioners/provisioner-${VVV_PROVISIONER_RUNNING}" log_to_file "provisioner-${VVV_PROVISIONER_RUNNING}" vvv_success " ▷ Running the '${VVV_PROVISIONER_RUNNING}' provisioner..." - start_seconds="$(date +%s)" + VVV_PROVISIONER_START_TIMESTAMP="$(date -u +"%s.%2N")" trap "provisioner_end" EXIT } @@ -29,10 +30,13 @@ function provisioner_begin() { # @arg $1 string Name of the provisioner function provisioner_end() { local PROVISION_SUCCESS="${1:-"1"}" - local end_seconds="$(date +%s)" - local elapsed="$(( end_seconds - start_seconds ))" + local end_timestamp + local elapsed + + end_timestamp="$(date -u +"%s.%2N")" + elapsed=$(date -u -d "0 ${end_timestamp} seconds - ${VVV_PROVISIONER_START_TIMESTAMP} seconds" +"%-Mm %-Ss %-3Nms") if [[ $PROVISION_SUCCESS -eq "0" ]]; then - vvv_success " ✔ The '${VVV_PROVISIONER_RUNNING}' provisioner completed in ${elapsed} seconds." + vvv_success " ✔ The '${VVV_PROVISIONER_RUNNING}' provisioner completed in ${elapsed}." rm -f "/vagrant/failed_provisioners/provisioner-${VVV_PROVISIONER_RUNNING}" else vvv_error " ! The '${VVV_PROVISIONER_RUNNING}' provisioner ran into problems, the full log is available at '${VVV_CURRENT_LOG_FILE}'. It completed in ${elapsed} seconds." @@ -41,13 +45,13 @@ function provisioner_end() { trap - EXIT } -if [[ ! -z $VVV_LOG ]]; then +if [[ -n $VVV_LOG ]]; then provisioner_begin "${VVV_LOG}" fi # @description Signal that a provisioner has finished with success function provisioner_success() { - if [[ ! -z $VVV_LOG ]]; then + if [[ -n $VVV_LOG ]]; then provisioner_end 0 fi } From d96e01d3bf3aef9e54e4dd084b580f550e59bfbc Mon Sep 17 00:00:00 2001 From: Tom J Nowell Date: Fri, 20 Sep 2024 10:18:06 +0100 Subject: [PATCH 2/4] document timing improvements in the changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 67549fc49..ef30eeb62 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ permalink: /docs/en-US/changelog/ ### Enhancements * Upgraded MariaDB from 10.5 to 10.11 ( #2728 ) +* Provisioner/Hook timings now show milliseconds ( #2735 ) ### Bug Fixes From dfe0a26595dfeccec28352613b2f7a00d7f29668 Mon Sep 17 00:00:00 2001 From: Tom J Nowell Date: Fri, 20 Sep 2024 12:52:38 +0100 Subject: [PATCH 3/4] If a network check fails, try it again without the quiet flag so that we can see the issue, also fix the listing of failed checks to show just the failed ones --- provision/provision-helpers.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/provision/provision-helpers.sh b/provision/provision-helpers.sh index 966d1c682..68c11424b 100755 --- a/provision/provision-helpers.sh +++ b/provision/provision-helpers.sh @@ -78,6 +78,7 @@ function check_network_connection_to_host() { return 0 fi vvv_error " ! Network connection issues found. Unable to reach ${url}" + wget --spider --timeout=5 --tries=3 "${url}" return 1 } export -f check_network_connection_to_host @@ -119,7 +120,7 @@ function network_check() { vvv_error " " vvv_error "VVV tried to check several domains it needs for provisioning but ${#failed_hosts[@]} of ${#hosts_to_test[@]} failed:" vvv_error " " - for url in "${hosts_to_test[@]}"; do + for url in "${failed_hosts[@]}"; do echo -e "${CRESET} [${RED}x${CRESET}] ${url}${RED}|" done vvv_error " " From b747b6a3ba5439a3136e4ba03f51faf36747c9dc Mon Sep 17 00:00:00 2001 From: Tom J Nowell Date: Fri, 20 Sep 2024 12:57:14 +0100 Subject: [PATCH 4/4] additional error checking on mariadb restart --- provision/core/mariadb/provision.sh | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/provision/core/mariadb/provision.sh b/provision/core/mariadb/provision.sh index 1077c5a3b..bb6a83ef1 100644 --- a/provision/core/mariadb/provision.sh +++ b/provision/core/mariadb/provision.sh @@ -136,11 +136,20 @@ function mysql_setup() { # happens after a `vagrant halt`. Check to see if it's running before # deciding whether to start or restart. if service mariadb status > /dev/null; then - vvv_info " * Starting the mariadb service" - service mariadb restart + vvv_info " * Restarting the mariadb service" + if ! service mariadb restart; then + vvv_error " * Restarting the MariaDB failed! Fetching service status." + service mariadb status + exit 1 + fi else vvv_info " * Restarting mariadb service" service mariadb start + if ! service mariadb start; then + vvv_error " * Starting MariaDB failed! Fetching service status." + service mariadb status + exit 1 + fi fi # IMPORT SQL