Elasticsearch: Improve logging in cluster wait

The cluster wait function can sometimes receive an invalid response,
and this would "pass" the status check condition. This change
prints the response to make it more clear what occured, and changes
the condition to explicitly wait for a "yellow" or "green" status.

Change-Id: Ifd1267a5fa19acbc6bc8bba65b1ba41409a584a3
This commit is contained in:
Steven Fitzpatrick 2020-07-13 16:24:36 -05:00
parent 84426374b6
commit 083c9498c6

View File

@ -14,13 +14,15 @@ limitations under the License.
*/}}
function check_cluster_health() {
STATUS=$(curl -s -K- <<< "--user ${ELASTICSEARCH_USERNAME}:${ELASTICSEARCH_PASSWORD}" \
"${ELASTICSEARCH_HOST}/_cat/health?format=json&pretty" | jq -r .[].status)
RESPONSE=$(curl -s -K- <<< "--user ${ELASTICSEARCH_USERNAME}:${ELASTICSEARCH_PASSWORD}" \
"${ELASTICSEARCH_HOST}/_cat/health?format=json&pretty" )
echo "Response: $RESPONSE"
STATUS=$(echo $RESPONSE | jq -r .[].status)
echo "Status: $STATUS"
}
check_cluster_health
while [[ $STATUS == "red" ]]; do
while [[ $STATUS != "yellow" ]] && [[ $STATUS != "green" ]]; do
echo "Waiting for cluster to become ready."
sleep 30
check_cluster_health