-
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(gRPC): support more features (#8485)
- Loading branch information
1 parent
e66b694
commit 24d8e7c
Showing
11 changed files
with
793 additions
and
13 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
#!/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. | ||
# | ||
|
||
# 'make init' operates scripts and related configuration files in the current directory | ||
# The 'apisix' command is a command in the /usr/local/apisix, | ||
# and the configuration file for the operation is in the /usr/local/apisix/conf | ||
|
||
. ./t/cli/common.sh | ||
|
||
exit_if_not_customed_nginx | ||
|
||
# check etcd while enable auth | ||
git checkout conf/config.yaml | ||
|
||
export ETCDCTL_API=3 | ||
etcdctl version | ||
etcdctl --endpoints=127.0.0.1:2379 user add "root:apache-api6" | ||
etcdctl --endpoints=127.0.0.1:2379 role add root | ||
etcdctl --endpoints=127.0.0.1:2379 user grant-role root root | ||
etcdctl --endpoints=127.0.0.1:2379 user get root | ||
etcdctl --endpoints=127.0.0.1:2379 auth enable | ||
etcdctl --endpoints=127.0.0.1:2379 --user=root:apache-api6 del /apisix --prefix | ||
|
||
echo ' | ||
deployment: | ||
role: traditional | ||
role_traditional: | ||
config_provider: etcd | ||
etcd: | ||
host: | ||
- http://127.0.0.1:2379 | ||
prefix: /apisix | ||
timeout: 30 | ||
use_grpc: true | ||
user: root | ||
password: apache-api6 | ||
' > conf/config.yaml | ||
|
||
make run | ||
sleep 1 | ||
|
||
code=$(curl -o /dev/null -s -w %{http_code} http://127.0.0.1:9180/apisix/admin/routes -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1') | ||
make stop | ||
|
||
if [ ! $code -eq 200 ]; then | ||
echo "failed: could not work with etcd" | ||
exit 1 | ||
fi | ||
|
||
echo "passed: work well with etcd auth enabled" | ||
|
||
etcdctl --endpoints=127.0.0.1:2379 --user=root:apache-api6 auth disable | ||
etcdctl --endpoints=127.0.0.1:2379 role delete root | ||
etcdctl --endpoints=127.0.0.1:2379 user delete root |
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,153 @@ | ||
#!/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. | ||
# | ||
|
||
# 'make init' operates scripts and related configuration files in the current directory | ||
# The 'apisix' command is a command in the /usr/local/apisix, | ||
# and the configuration file for the operation is in the /usr/local/apisix/conf | ||
|
||
. ./t/cli/common.sh | ||
|
||
exit_if_not_customed_nginx | ||
|
||
custom_clean_up() { | ||
clean_up | ||
|
||
# stop etcd docker container | ||
docker-compose -f ./t/cli/docker-compose-etcd-cluster.yaml down | ||
} | ||
|
||
trap custom_clean_up EXIT | ||
|
||
# create 3 node etcd cluster in docker | ||
ETCD_NAME_0=etcd0 | ||
ETCD_NAME_1=etcd1 | ||
ETCD_NAME_2=etcd2 | ||
HEALTH_CHECK_RETRY_TIMEOUT=10 | ||
|
||
if [ -f "logs/error.log" ]; then | ||
rm logs/error.log | ||
fi | ||
touch logs/error.log | ||
|
||
echo ' | ||
deployment: | ||
role: traditional | ||
role_traditional: | ||
config_provider: etcd | ||
etcd: | ||
use_grpc: true | ||
host: | ||
- "http://0.0.0.0:23790" | ||
- "http://0.0.0.0:23791" | ||
- "http://0.0.0.0:23792" | ||
health_check_timeout: '"$HEALTH_CHECK_RETRY_TIMEOUT"' | ||
timeout: 2 | ||
' > conf/config.yaml | ||
|
||
docker-compose -f ./t/cli/docker-compose-etcd-cluster.yaml up -d | ||
|
||
# case 1: 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:9180/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:9180/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" | ||
|
||
# case 2: 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:9180/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} | ||
|
||
# case 3: sleep till etcd health check try to check again | ||
current_time=$(date +%s) | ||
sleep_seconds=$(( $sleep_till - $current_time + 3)) | ||
if [ "$sleep_seconds" -gt 0 ]; then | ||
sleep $sleep_seconds | ||
fi | ||
|
||
code=$(curl -o /dev/null -s -w %{http_code} http://127.0.0.1:9180/apisix/admin/routes -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1') | ||
if [ ! $code -eq 200 ]; then | ||
echo "failed: apisix could not recover when etcd node recover" | ||
docker ps | ||
cat logs/error.log | ||
exit 1 | ||
fi | ||
|
||
make stop | ||
|
||
echo "passed: when all etcd nodes disconnected, apisix trying to reconnect with backoff, and could successfully recover when reconnected" | ||
|
||
# case 4: stop one etcd node (result: start successful) | ||
docker stop ${ETCD_NAME_0} | ||
|
||
out=$(make init 2>&1) | ||
if echo "$out" | grep "23790" | grep "connection refused"; then | ||
echo "passed: APISIX successfully to start, stop only one etcd node" | ||
else | ||
echo "failed: stop only one etcd node APISIX should start normally" | ||
exit 1 | ||
fi | ||
|
||
# case 5: stop two etcd nodes (result: start failure) | ||
docker stop ${ETCD_NAME_1} | ||
|
||
out=$(make init 2>&1 || true) | ||
if echo "$out" | grep "23791" | grep "connection refused"; then | ||
echo "passed: APISIX failed to start, etcd cluster must have two or more healthy nodes" | ||
else | ||
echo "failed: two etcd nodes have been stopped, APISIX should fail to start" | ||
exit 1 | ||
fi | ||
|
||
# case 6: stop all etcd nodes (result: start failure) | ||
docker stop ${ETCD_NAME_2} | ||
|
||
out=$(make init 2>&1 || true) | ||
if echo "$out" | grep "23792" | grep "connection refused"; then | ||
echo "passed: APISIX failed to start, all etcd nodes have stopped" | ||
else | ||
echo "failed: all etcd nodes have stopped, APISIX should not be able to start" | ||
exit 1 | ||
fi |
Oops, something went wrong.