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 diff --git a/examples/common/scripts/vtadmin-up.sh b/examples/common/scripts/vtadmin-up.sh index 8f3caf39c15..179e5089b90 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,27 @@ vtadmin-api is running! - PID: ${vtadmin_api_pid} " +# 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://localhost:${vtadmin_api_port}/api/clusters") + if [[ ${result} == "${expected_cluster_result}" ]]; then + break + fi + sleep 0.1 +done + +# Check one last time +[[ $(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 # 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 &