This is an automated email from the ASF dual-hosted git repository.
spacewander pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/apisix.git
The following commit(s) were added to refs/heads/master by this push:
new 6ae923a12 perf: move the APISIX error page to apisix-base (#8062)
6ae923a12 is described below
commit 6ae923a12fc1b7f8414b66efc053b19c7b5ddd08
Author: 罗泽轩 <[email protected]>
AuthorDate: Wed Oct 12 19:31:19 2022 +0800
perf: move the APISIX error page to apisix-base (#8062)
---
apisix/cli/ngx_tpl.lua | 32 ---------------------------
apisix/init.lua | 51 ++++++++++++++++----------------------------
t/APISIX.pm | 32 ---------------------------
t/error_page/error_page.t | 30 +++++++++++---------------
t/node/upstream-status-5xx.t | 4 ++--
t/node/upstream-status-all.t | 4 ++--
6 files changed, 35 insertions(+), 118 deletions(-)
diff --git a/apisix/cli/ngx_tpl.lua b/apisix/cli/ngx_tpl.lua
index a655efcfc..fd45d7f84 100644
--- a/apisix/cli/ngx_tpl.lua
+++ b/apisix/cli/ngx_tpl.lua
@@ -354,9 +354,6 @@ http {
include mime.types;
charset {* http.charset *};
- # error_page
- error_page 500 @50x.html;
-
{% if http.real_ip_header then %}
real_ip_header {* http.real_ip_header *};
{% end %}
@@ -467,13 +464,6 @@ http {
apisix.http_control()
}
}
-
- location @50x.html {
- set $from_error_page 'true';
- content_by_lua_block {
- require("apisix.error_handling").handle_500()
- }
- }
}
{% end %}
@@ -549,13 +539,6 @@ http {
apisix.http_admin()
}
}
-
- location @50x.html {
- set $from_error_page 'true';
- content_by_lua_block {
- require("apisix.error_handling").handle_500()
- }
- }
}
{% end %}
@@ -655,7 +638,6 @@ http {
set $upstream_host $http_host;
set $upstream_uri '';
set $ctx_ref '';
- set $from_error_page '';
{% if wasm then %}
set $wasm_process_req_body '';
@@ -828,20 +810,6 @@ http {
proxy_pass $upstream_mirror_uri;
}
{% end %}
-
- location @50x.html {
- set $from_error_page 'true';
- content_by_lua_block {
- require("apisix.error_handling").handle_500()
- }
- header_filter_by_lua_block {
- apisix.http_header_filter_phase()
- }
-
- log_by_lua_block {
- apisix.http_log_phase()
- }
- }
}
{% end %}
diff --git a/apisix/init.lua b/apisix/init.lua
index 3eb68765b..04920196d 100644
--- a/apisix/init.lua
+++ b/apisix/init.lua
@@ -188,6 +188,22 @@ function _M.http_ssl_phase()
end
+local function stash_ngx_ctx()
+ local ref = ctxdump.stash_ngx_ctx()
+ core.log.info("stash ngx ctx: ", ref)
+ ngx_var.ctx_ref = ref
+end
+
+
+local function fetch_ctx()
+ local ref = ngx_var.ctx_ref
+ core.log.info("fetch ngx ctx: ", ref)
+ local ctx = ctxdump.apply_ngx_ctx(ref)
+ ngx_var.ctx_ref = ''
+ return ctx
+end
+
+
local function parse_domain_in_route(route)
local nodes = route.value.upstream.nodes
local new_nodes, err = upstream_util.parse_domain_for_nodes(nodes)
@@ -430,10 +446,6 @@ function _M.http_access_phase()
api_ctx.route_id = route.value.id
api_ctx.route_name = route.value.name
- local ref = ctxdump.stash_ngx_ctx()
- core.log.info("stash ngx ctx: ", ref)
- ngx_var.ctx_ref = ref
-
-- run global rule
plugin.run_global_rules(api_ctx, router.global_rules, nil)
@@ -577,24 +589,17 @@ function _M.http_access_phase()
local up_scheme = api_ctx.upstream_scheme
if up_scheme == "grpcs" or up_scheme == "grpc" then
+ stash_ngx_ctx()
return ngx.exec("@grpc_pass")
end
if api_ctx.dubbo_proxy_enabled then
+ stash_ngx_ctx()
return ngx.exec("@dubbo_pass")
end
end
-local function fetch_ctx()
- local ref = ngx_var.ctx_ref
- core.log.info("fetch ngx ctx: ", ref)
- local ctx = ctxdump.apply_ngx_ctx(ref)
- ngx_var.ctx_ref = ''
- return ctx
-end
-
-
function _M.dubbo_access_phase()
ngx.ctx = fetch_ctx()
end
@@ -642,16 +647,6 @@ end
function _M.http_header_filter_phase()
- if ngx_var.ctx_ref ~= '' then
- -- prevent for the table leak
- local stash_ctx = fetch_ctx()
-
- -- internal redirect, so we should apply the ctx
- if ngx_var.from_error_page == "true" then
- ngx.ctx = stash_ctx
- end
- end
-
core.response.set_header("Server", ver_header)
local up_status = get_var("upstream_status")
@@ -737,16 +732,6 @@ end
function _M.http_log_phase()
- if ngx_var.ctx_ref ~= '' then
- -- prevent for the table leak
- local stash_ctx = fetch_ctx()
-
- -- internal redirect, so we should apply the ctx
- if ngx_var.from_error_page == "true" then
- ngx.ctx = stash_ctx
- end
- end
-
local api_ctx = common_phase("log")
if not api_ctx then
return
diff --git a/t/APISIX.pm b/t/APISIX.pm
index 2af517abd..fc79d0eb9 100644
--- a/t/APISIX.pm
+++ b/t/APISIX.pm
@@ -565,8 +565,6 @@ _EOC_
lua_socket_log_errors off;
client_body_buffer_size 8k;
- error_page 500 \@50x.html;
-
variables_hash_bucket_size 128;
upstream apisix_backend {
@@ -643,21 +641,6 @@ _EOC_
more_clear_headers Date;
}
-
- # this configuration is needed as error_page is configured in http
block
- location \@50x.html {
- set \$from_error_page 'true';
- content_by_lua_block {
- require("apisix.error_handling").handle_500()
- }
- header_filter_by_lua_block {
- apisix.http_header_filter_phase()
- }
-
- log_by_lua_block {
- apisix.http_log_phase()
- }
- }
}
$a6_ngx_directives
@@ -733,20 +716,6 @@ _EOC_
}
}
- location \@50x.html {
- set \$from_error_page 'true';
- content_by_lua_block {
- require("apisix.error_handling").handle_500()
- }
- header_filter_by_lua_block {
- apisix.http_header_filter_phase()
- }
-
- log_by_lua_block {
- apisix.http_log_phase()
- }
- }
-
location /v1/ {
content_by_lua_block {
apisix.http_control()
@@ -762,7 +731,6 @@ _EOC_
set \$upstream_host \$http_host;
set \$upstream_uri '';
set \$ctx_ref '';
- set \$from_error_page '';
set \$upstream_cache_zone off;
set \$upstream_cache_key '';
diff --git a/t/error_page/error_page.t b/t/error_page/error_page.t
index d6ec79a00..a9091c302 100644
--- a/t/error_page/error_page.t
+++ b/t/error_page/error_page.t
@@ -14,7 +14,17 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
-use t::APISIX 'no_plan';
+use t::APISIX;
+
+my $nginx_binary = $ENV{'TEST_NGINX_BINARY'} || 'nginx';
+my $version = eval { `$nginx_binary -V 2>&1` };
+
+# We put the error page into apisix-base. It is fine since this installation
is the default.
+if ($version !~ m/\/apisix-nginx-module/) {
+ plan(skip_all => "apisix-nginx-module not installed");
+} else {
+ plan('no_plan');
+}
log_level('debug');
repeat_each(1);
@@ -183,21 +193,7 @@ passed
-=== TEST 10: client abort
---- request
-GET /mysleep?seconds=3
---- abort
---- timeout: 0.5
---- ignore_response
---- grep_error_log eval
-qr/(stash|fetch) ngx ctx/
---- grep_error_log_out
-stash ngx ctx
-fetch ngx ctx
-
-
-
-=== TEST 11: check if the phases after proxy are run when 500 happens before
proxy
+=== TEST 10: check if the phases after proxy are run when 500 happens before
proxy
--- config
location /t {
content_by_lua_block {
@@ -239,7 +235,7 @@ passed
-=== TEST 12: hit
+=== TEST 11: hit
--- request
GET /hello
--- more_headers
diff --git a/t/node/upstream-status-5xx.t b/t/node/upstream-status-5xx.t
index 990276b55..6dc998f8d 100644
--- a/t/node/upstream-status-5xx.t
+++ b/t/node/upstream-status-5xx.t
@@ -206,8 +206,8 @@ passed
--- request
GET /server_error
--- error_code: 500
---- response_body_like
-.*apisix.apache.org.*
+--- response_body eval
+qr/500 Internal Server Error/
--- response_headers
X-APISIX-Upstream-Status: 500
diff --git a/t/node/upstream-status-all.t b/t/node/upstream-status-all.t
index d4807e5cb..2daabdc2b 100644
--- a/t/node/upstream-status-all.t
+++ b/t/node/upstream-status-all.t
@@ -209,8 +209,8 @@ apisix:
--- request
GET /server_error
--- error_code: 500
---- response_body_like
-.*apisix.apache.org.*
+--- response_body eval
+qr/500 Internal Server Error/
--- response_headers
X-APISIX-Upstream-Status: 500