From af8baeb154c7113dff98d99c763b097acead61c3 Mon Sep 17 00:00:00 2001 From: Matt Lord Date: Tue, 21 Feb 2023 14:11:27 -0500 Subject: [PATCH 1/5] Examples: correct VTAdmin discovery file path and add check Signed-off-by: Matt Lord --- examples/common/scripts/vtadmin-up.sh | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/examples/common/scripts/vtadmin-up.sh b/examples/common/scripts/vtadmin-up.sh index 8f3caf39c15..ee680b57c30 100755 --- a/examples/common/scripts/vtadmin-up.sh +++ b/examples/common/scripts/vtadmin-up.sh @@ -3,6 +3,7 @@ script_dir="$(dirname "${BASH_SOURCE[0]:-$0}")" source "${script_dir}/../env.sh" +cluster_name="local" log_dir="${VTDATAROOT}/tmp" web_dir="${script_dir}/../../../web/vtadmin" @@ -20,7 +21,7 @@ vtadmin \ --alsologtostderr \ --rbac \ --rbac-config="${script_dir}/../vtadmin/rbac.yaml" \ - --cluster "id=local,name=local,discovery=staticfile,discovery-staticfile-path=./vtadmin/discovery.json,tablet-fqdn-tmpl={{ .Tablet.Hostname }}:15{{ .Tablet.Alias.Uid }}" \ + --cluster "id=${cluster_name},name=${cluster_name},discovery=staticfile,discovery-staticfile-path=${script_dir}/../vtadmin/discovery.json,tablet-fqdn-tmpl={{ .Tablet.Hostname }}:15{{ .Tablet.Alias.Uid }}" \ > "${log_dir}/vtadmin-api.out" 2>&1 & vtadmin_api_pid=$! @@ -33,14 +34,26 @@ vtadmin-api is running! - PID: ${vtadmin_api_pid} " +# Wait for vtadmin to successfully discover the cluster +for _ in {0..300}; do + id=$(curl -s "http://${hostname}:${vtadmin_api_port}/api/clusters" | jq -r '.result.clusters[0].name') + if [[ ${id} == "${cluster_name}" ]]; then + break + fi + sleep 0.1 +done + +# Check one last time +[[ $(curl -s "http://${hostname}:${vtadmin_api_port}/api/clusters" | jq -r '.result.clusters[0].name') == "${cluster_name}" ]] || fail "vtadmin failed to discover the running example Vitess cluster." + # As a TODO, it'd be nice to make the assumption that vtadmin-web is already # installed and built (since we assume that `make` has already been run for # other Vitess components.) -npm --prefix $web_dir --silent install +npm --prefix "$web_dir" --silent install REACT_APP_VTADMIN_API_ADDRESS="http://localhost:${vtadmin_api_port}" \ REACT_APP_ENABLE_EXPERIMENTAL_TABLET_DEBUG_VARS="true" \ - npm run --prefix $web_dir build + npm run --prefix "$web_dir" build "${web_dir}/node_modules/.bin/serve" --no-clipboard -l $vtadmin_web_port -s "${web_dir}/build" \ > "${log_dir}/vtadmin-web.out" 2>&1 & From 1ceb8c9020b787f929b16e2d86fe5fa1740dc7fe Mon Sep 17 00:00:00 2001 From: Matt Lord Date: Tue, 21 Feb 2023 16:19:56 -0500 Subject: [PATCH 2/5] Remove jq dependency Signed-off-by: Matt Lord --- examples/common/scripts/vtadmin-up.sh | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/examples/common/scripts/vtadmin-up.sh b/examples/common/scripts/vtadmin-up.sh index ee680b57c30..62c5189f41a 100755 --- a/examples/common/scripts/vtadmin-up.sh +++ b/examples/common/scripts/vtadmin-up.sh @@ -35,16 +35,17 @@ vtadmin-api is running! " # Wait for vtadmin to successfully discover the cluster +expected_cluster_result="{result\":{\"clusters\":[{\"id\":\"${cluster_name}\",\"name\":\"${cluster_name}\"}]},\"ok\":true}" for _ in {0..300}; do - id=$(curl -s "http://${hostname}:${vtadmin_api_port}/api/clusters" | jq -r '.result.clusters[0].name') - if [[ ${id} == "${cluster_name}" ]]; then + result=$(curl -s "http://${hostname}:${vtadmin_api_port}/api/clusters") + if [[ ${result} == "${expected_cluster_result}" ]]; then break fi sleep 0.1 done # Check one last time -[[ $(curl -s "http://${hostname}:${vtadmin_api_port}/api/clusters" | jq -r '.result.clusters[0].name') == "${cluster_name}" ]] || fail "vtadmin failed to discover the running example Vitess cluster." +[[ $(curl -s "http://${hostname}:${vtadmin_api_port}/api/clusters") == "${expected_cluster_result}" ]] || fail "vtadmin failed to discover the running example Vitess cluster." # As a TODO, it'd be nice to make the assumption that vtadmin-web is already # installed and built (since we assume that `make` has already been run for From f46cfbbbeaf073ce37651f9f9f287ae08813a388 Mon Sep 17 00:00:00 2001 From: Matt Lord Date: Tue, 21 Feb 2023 17:29:39 -0500 Subject: [PATCH 3/5] vtadmin examples scripts hardcode localhost Signed-off-by: Matt Lord --- examples/common/scripts/vtadmin-up.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/common/scripts/vtadmin-up.sh b/examples/common/scripts/vtadmin-up.sh index 62c5189f41a..162fb52042b 100755 --- a/examples/common/scripts/vtadmin-up.sh +++ b/examples/common/scripts/vtadmin-up.sh @@ -37,7 +37,7 @@ vtadmin-api is running! # Wait for vtadmin to successfully discover the cluster expected_cluster_result="{result\":{\"clusters\":[{\"id\":\"${cluster_name}\",\"name\":\"${cluster_name}\"}]},\"ok\":true}" for _ in {0..300}; do - result=$(curl -s "http://${hostname}:${vtadmin_api_port}/api/clusters") + result=$(curl -s "http://localhost:${vtadmin_api_port}/api/clusters") if [[ ${result} == "${expected_cluster_result}" ]]; then break fi @@ -45,7 +45,7 @@ for _ in {0..300}; do done # Check one last time -[[ $(curl -s "http://${hostname}:${vtadmin_api_port}/api/clusters") == "${expected_cluster_result}" ]] || fail "vtadmin failed to discover the running example Vitess cluster." +[[ $(curl -s "http://localhost:${vtadmin_api_port}/api/clusters") == "${expected_cluster_result}" ]] || fail "vtadmin failed to discover the running example Vitess cluster." # As a TODO, it'd be nice to make the assumption that vtadmin-web is already # installed and built (since we assume that `make` has already been run for From 349f2ef30e307d3f241f8a064f9120f92bfe9567 Mon Sep 17 00:00:00 2001 From: Matt Lord Date: Tue, 21 Feb 2023 18:45:09 -0500 Subject: [PATCH 4/5] Fix errant expectation Signed-off-by: Matt Lord --- examples/common/scripts/vtadmin-up.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/common/scripts/vtadmin-up.sh b/examples/common/scripts/vtadmin-up.sh index 162fb52042b..179e5089b90 100755 --- a/examples/common/scripts/vtadmin-up.sh +++ b/examples/common/scripts/vtadmin-up.sh @@ -35,7 +35,7 @@ vtadmin-api is running! " # Wait for vtadmin to successfully discover the cluster -expected_cluster_result="{result\":{\"clusters\":[{\"id\":\"${cluster_name}\",\"name\":\"${cluster_name}\"}]},\"ok\":true}" +expected_cluster_result="{\"result\":{\"clusters\":[{\"id\":\"${cluster_name}\",\"name\":\"${cluster_name}\"}]},\"ok\":true}" for _ in {0..300}; do result=$(curl -s "http://localhost:${vtadmin_api_port}/api/clusters") if [[ ${result} == "${expected_cluster_result}" ]]; then From 48ef9ca9cfb61c989e772a3aae914d22822b3a48 Mon Sep 17 00:00:00 2001 From: Matt Lord Date: Tue, 21 Feb 2023 21:51:05 -0500 Subject: [PATCH 5/5] Adjust healthy shard indicator Signed-off-by: Matt Lord --- examples/common/lib/utils.sh | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/examples/common/lib/utils.sh b/examples/common/lib/utils.sh index ab13e9bc6c4..f38568ccdad 100644 --- a/examples/common/lib/utils.sh +++ b/examples/common/lib/utils.sh @@ -52,18 +52,19 @@ function wait_for_healthy_shard_primary() { fi keyspace=${1} shard=${2} - healthy_indicator="PRIMARY: Serving" + unhealthy_indicator='"primary_alias": null' wait_secs=180 for _ in $(seq 1 ${wait_secs}); do - if curl -s "http://$(vtctldclient GetTablets --keyspace "${keyspace}" --shard "${shard}" | grep -i 'primary' | awk '{print $5}')/debug/status_details" | grep -qi "${healthy_indicator}"; then + if ! vtctldclient --server=localhost:15999 GetShard "${keyspace}/${shard}" | grep -qi "${unhealthy_indicator}"; then break fi sleep 1 done; - curl -s "http://$(vtctldclient GetTablets --keyspace "${keyspace}" --shard "${shard}" | grep -i 'primary' | awk '{print $5}')/debug/status_details" | grep -qi "${healthy_indicator}" \ - || fail "Timed out after ${wait_secs} seconds waiting for a primary tablet to be elected and become healthy in ${keyspace}/${shard}" + if vtctldclient --server=localhost:15999 GetShard "${keyspace}/${shard}" | grep -qi "${unhealthy_indicator}"; then + fail "Timed out after ${wait_secs} seconds waiting for a primary tablet to be elected and become healthy in ${keyspace}/${shard}" + fi } # Wait for a specified number of the keyspace/shard's tablets to show up