From ce5bb7b9125356e4c77fb70900d54642a14553a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BD=97=E6=B3=BD=E8=BD=A9?= Date: Thu, 23 Dec 2021 14:57:16 +0800 Subject: [PATCH] change: enable HTTP when stream proxy is set and enable_admin is true (#5867) Co-authored-by: leslie <59061168+leslie-tsang@users.noreply.github.com> --- apisix/cli/ngx_tpl.lua | 2 +- docs/en/latest/stream-proxy.md | 5 ++++- docs/zh/latest/stream-proxy.md | 5 ++++- t/cli/test_core_config.sh | 4 ++-- t/cli/test_dns.sh | 4 ++-- t/cli/test_stream_config.sh | 18 ++++++++++++++++++ 6 files changed, 31 insertions(+), 7 deletions(-) diff --git a/apisix/cli/ngx_tpl.lua b/apisix/cli/ngx_tpl.lua index 66c18372..20ba36dd 100644 --- a/apisix/cli/ngx_tpl.lua +++ b/apisix/cli/ngx_tpl.lua @@ -155,7 +155,7 @@ stream { } {% end %} -{% if not (stream_proxy and stream_proxy.only ~= false) then %} +{% if enable_admin or not (stream_proxy and stream_proxy.only ~= false) then %} http { # put extra_lua_path in front of the builtin path # so user can override the source code diff --git a/docs/en/latest/stream-proxy.md b/docs/en/latest/stream-proxy.md index 4b32a001..078e3745 100644 --- a/docs/en/latest/stream-proxy.md +++ b/docs/en/latest/stream-proxy.md @@ -41,10 +41,13 @@ apisix: - "127.0.0.1:9211" ``` -If you need to enable both HTTP and stream proxy, set the `only` to false: +If `apisix.enable_admin` is true, both HTTP and stream proxy are enabled with the configuration above. + +If you have set the `enable_admin` to false, and need to enable both HTTP and stream proxy, set the `only` to false: ```yaml apisix: + enable_admin: false stream_proxy: # TCP/UDP proxy only: false tcp: # TCP proxy address list diff --git a/docs/zh/latest/stream-proxy.md b/docs/zh/latest/stream-proxy.md index 8039b1ce..9b0d8400 100644 --- a/docs/zh/latest/stream-proxy.md +++ b/docs/zh/latest/stream-proxy.md @@ -40,10 +40,13 @@ apisix: - "127.0.0.1:9211" ``` -如果你需要同时启用 HTTP 和 stream 代理,设置 `only` 为 false: +如果 `apisix.enable_admin` 为 true,上面的配置会同时启用 HTTP 和 stream 代理。 + +如果你设置 `enable_admin` 为 false,且需要同时启用 HTTP 和 stream 代理,设置 `only` 为 false: ```yaml apisix: + enable_admin: false stream_proxy: # TCP/UDP proxy only: false tcp: # TCP proxy address list diff --git a/t/cli/test_core_config.sh b/t/cli/test_core_config.sh index be193785..7b968205 100755 --- a/t/cli/test_core_config.sh +++ b/t/cli/test_core_config.sh @@ -56,7 +56,7 @@ nginx_config: make init count=$(grep -c "lua_max_pending_timers 10240;" conf/nginx.conf) -if [ "$count" -ne 1 ]; then +if [ "$count" -ne 2 ]; then echo "failed: failed to set lua_max_pending_timers in stream proxy" exit 1 fi @@ -64,7 +64,7 @@ fi echo "passed: set lua_max_pending_timers successfully in stream proxy" count=$(grep -c "lua_max_running_timers 2561;" conf/nginx.conf) -if [ "$count" -ne 1 ]; then +if [ "$count" -ne 2 ]; then echo "failed: failed to set lua_max_running_timers in stream proxy" exit 1 fi diff --git a/t/cli/test_dns.sh b/t/cli/test_dns.sh index 38c6d7a2..62985eac 100755 --- a/t/cli/test_dns.sh +++ b/t/cli/test_dns.sh @@ -53,7 +53,7 @@ apisix: make init count=$(grep -c "resolver 127.0.0.1 \[::1\]:5353 valid=30;" conf/nginx.conf) -if [ "$count" -ne 1 ]; then +if [ "$count" -ne 2 ]; then echo "failed: dns_resolver_valid doesn't take effect" exit 1 fi @@ -74,7 +74,7 @@ apisix: make init count=$(grep -c "resolver 127.0.0.1 \[::1\] \[::2\];" conf/nginx.conf) -if [ "$count" -ne 1 ]; then +if [ "$count" -ne 2 ]; then echo "failed: can't handle IPv6 resolver w/o bracket" exit 1 fi diff --git a/t/cli/test_stream_config.sh b/t/cli/test_stream_config.sh index 1e0cd2a3..71e2f336 100755 --- a/t/cli/test_stream_config.sh +++ b/t/cli/test_stream_config.sh @@ -21,6 +21,7 @@ echo " apisix: + enable_admin: false stream_proxy: tcp: - addr: 9100 @@ -38,6 +39,7 @@ echo "passed: enable stream proxy only by default" echo " apisix: + enable_admin: false stream_proxy: only: false tcp: @@ -52,6 +54,22 @@ if [ "$count" -ne 2 ]; then exit 1 fi +echo " +apisix: + enable_admin: true + stream_proxy: + tcp: + - addr: 9100 +" > conf/config.yaml + +make init + +count=$(grep -c "lua_package_path" conf/nginx.conf) +if [ "$count" -ne 2 ]; then + echo "failed: failed to enable stream proxy and http proxy when admin is enabled" + exit 1 +fi + echo "passed: enable stream proxy and http proxy" echo "