-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: enable etcd health-check (#4191)
- Loading branch information
Showing
8 changed files
with
217 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
# | ||
# Licensed to the Apache Software Foundation (ASF) under one or more | ||
# contributor license agreements. See the NOTICE file distributed with | ||
# this work for additional information regarding copyright ownership. | ||
# The ASF licenses this file to You under the Apache License, Version 2.0 | ||
# (the "License"); you may not use this file except in compliance with | ||
# the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
version: "3.7" | ||
|
||
services: | ||
etcd0: | ||
image: "gcr.io/etcd-development/etcd:v3.4.15" | ||
container_name: etcd0 | ||
ports: | ||
- "23800:2380" | ||
- "23790:2379" | ||
environment: | ||
- ALLOW_NONE_AUTHENTICATION=yes | ||
- ETCD_NAME=etcd0 | ||
- ETCD_LISTEN_PEER_URLS=http://0.0.0.0:2380 | ||
- ETCD_LISTEN_CLIENT_URLS=http://0.0.0.0:2379 | ||
- ETCD_ADVERTISE_CLIENT_URLS=http://127.0.0.1:23790 | ||
- ETCD_INITIAL_ADVERTISE_PEER_URLS=http://etcd0:2380 | ||
- ETCD_INITIAL_CLUSTER_TOKEN=etcd-cluster | ||
- ETCD_INITIAL_CLUSTER=etcd0=http://etcd0:2380,etcd1=http://etcd1:2380,etcd2=http://etcd2:2380 | ||
- ETCD_INITIAL_CLUSTER_STATE=new | ||
|
||
etcd1: | ||
image: "gcr.io/etcd-development/etcd:v3.4.15" | ||
container_name: etcd1 | ||
ports: | ||
- "23801:2380" | ||
- "23791:2379" | ||
environment: | ||
- ALLOW_NONE_AUTHENTICATION=yes | ||
- ETCD_NAME=etcd1 | ||
- ETCD_LISTEN_PEER_URLS=http://0.0.0.0:2380 | ||
- ETCD_LISTEN_CLIENT_URLS=http://0.0.0.0:2379 | ||
- ETCD_ADVERTISE_CLIENT_URLS=http://127.0.0.1:23791 | ||
- ETCD_INITIAL_ADVERTISE_PEER_URLS=http://etcd1:2380 | ||
- ETCD_INITIAL_CLUSTER_TOKEN=etcd-cluster | ||
- ETCD_INITIAL_CLUSTER=etcd0=http://etcd0:2380,etcd1=http://etcd1:2380,etcd2=http://etcd2:2380 | ||
- ETCD_INITIAL_CLUSTER_STATE=new | ||
|
||
etcd2: | ||
image: "gcr.io/etcd-development/etcd:v3.4.15" | ||
container_name: etcd2 | ||
ports: | ||
- "23802:2380" | ||
- "23792:2379" | ||
environment: | ||
- ALLOW_NONE_AUTHENTICATION=yes | ||
- ETCD_NAME=etcd2 | ||
- ETCD_LISTEN_PEER_URLS=http://0.0.0.0:2380 | ||
- ETCD_LISTEN_CLIENT_URLS=http://0.0.0.0:2379 | ||
- ETCD_ADVERTISE_CLIENT_URLS=http://127.0.0.1:23792 | ||
- ETCD_INITIAL_ADVERTISE_PEER_URLS=http://etcd2:2380 | ||
- ETCD_INITIAL_CLUSTER_TOKEN=etcd-cluster | ||
- ETCD_INITIAL_CLUSTER=etcd0=http://etcd0:2380,etcd1=http://etcd1:2380,etcd2=http://etcd2:2380 | ||
- ETCD_INITIAL_CLUSTER_STATE=new |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
#!/usr/bin/env bash | ||
|
||
# | ||
# Licensed to the Apache Software Foundation (ASF) under one or more | ||
# contributor license agreements. See the NOTICE file distributed with | ||
# this work for additional information regarding copyright ownership. | ||
# The ASF licenses this file to You under the Apache License, Version 2.0 | ||
# (the "License"); you may not use this file except in compliance with | ||
# the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
. ./t/cli/common.sh | ||
|
||
# create 3 node etcd cluster in docker | ||
ETCD_NAME_0=etcd0 | ||
ETCD_NAME_1=etcd1 | ||
ETCD_NAME_2=etcd2 | ||
HEALTH_CHECK_RETRY_TIMEOUT=10 | ||
|
||
echo ' | ||
etcd: | ||
host: | ||
- "http://127.0.0.1:23790" | ||
- "http://127.0.0.1:23791" | ||
- "http://127.0.0.1:23792" | ||
health_check_timeout: '"$HEALTH_CHECK_RETRY_TIMEOUT"' | ||
' > conf/config.yaml | ||
|
||
docker-compose -f ./t/cli/docker-compose-etcd-cluster.yaml up -d | ||
|
||
# Check apisix not got effected when one etcd node disconnected | ||
make init && make run | ||
|
||
docker stop ${ETCD_NAME_0} | ||
code=$(curl -o /dev/null -s -w %{http_code} http://127.0.0.1:9080/apisix/admin/routes -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1') | ||
if [ ! $code -eq 200 ]; then | ||
echo "failed: apisix got effect when one etcd node out of a cluster disconnected" | ||
exit 1 | ||
fi | ||
docker start ${ETCD_NAME_0} | ||
|
||
docker stop ${ETCD_NAME_1} | ||
code=$(curl -o /dev/null -s -w %{http_code} http://127.0.0.1:9080/apisix/admin/routes -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1') | ||
if [ ! $code -eq 200 ]; then | ||
echo "failed: apisix got effect when one etcd node out of a cluster disconnected" | ||
exit 1 | ||
fi | ||
docker start ${ETCD_NAME_1} | ||
|
||
make stop | ||
|
||
echo "passed: apisix not got effected when one etcd node disconnected" | ||
|
||
# Check when all etcd nodes disconnected, apisix trying to reconnect with backoff, and could successfully recover when reconnected | ||
make init && make run | ||
|
||
docker stop ${ETCD_NAME_0} && docker stop ${ETCD_NAME_1} && docker stop ${ETCD_NAME_2} | ||
|
||
sleep_till=$(date +%s -d "$DATE + $HEALTH_CHECK_RETRY_TIMEOUT second") | ||
|
||
code=$(curl -o /dev/null -s -w %{http_code} http://127.0.0.1:9080/apisix/admin/routes -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1') | ||
if [ $code -eq 200 ]; then | ||
echo "failed: apisix not got effect when all etcd nodes disconnected" | ||
exit 1 | ||
fi | ||
|
||
docker start ${ETCD_NAME_0} && docker start ${ETCD_NAME_1} && docker start ${ETCD_NAME_2} | ||
|
||
# sleep till etcd health check try to check again | ||
current_time=$(date +%s) | ||
sleep_seconds=$(( $sleep_till - $current_time )) | ||
if [ "$sleep_seconds" -gt 0 ]; then | ||
sleep $sleep_seconds | ||
fi | ||
|
||
code=$(curl -o /dev/null -s -w %{http_code} http://127.0.0.1:9080/apisix/admin/routes -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1') | ||
if [ ! $code -eq 200 ]; then | ||
echo "failed: apisix could not recover when etcd node recover" | ||
exit 1 | ||
fi | ||
|
||
make stop | ||
|
||
echo "passed: when all etcd nodes disconnected, apisix trying to reconnect with backoff, and could successfully recover when reconnected" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters