Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add config to control write all status to x-upsream-apisix-status #6392

Merged
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
8ac287c
feat: add config to control write all status to x-upsream-apisix-status
Feb 21, 2022
e41138e
doc: add doc
Feb 21, 2022
fa58fdc
Merge branch 'master' into feature/resp-all-upstream-status
Feb 21, 2022
6b9dd1c
fix: modify config.json
Feb 21, 2022
f696391
fix: modify doc
Feb 21, 2022
b2bf96c
fix: remove datadog config.json
Feb 21, 2022
15dcb93
fix: modify test case & fix some error
Feb 21, 2022
d285758
fix: modify test case. remove duplicate code
Feb 21, 2022
5b24a19
merge:maser
Feb 21, 2022
f1e280a
fix: remove ;
Feb 21, 2022
2b82f96
fix: rename config name
Feb 21, 2022
363f4ad
fix:remove datalog from config.json
Feb 21, 2022
627cacf
fix: modify test case
Feb 22, 2022
b236178
fix: test case
Feb 22, 2022
737bbbf
Merge branch 'master' into feature/resp-all-upstream-status
Feb 22, 2022
b57f265
fix: test case
Feb 22, 2022
af58a93
fix: test case
Feb 22, 2022
f033c0a
fix: test case
Feb 22, 2022
12dc467
fix: test case
Feb 22, 2022
a102aa6
fix: fix test case
Feb 22, 2022
6e0c097
fix: when return 200 do not log
Feb 23, 2022
840daa5
fix: test case
Feb 23, 2022
2691ab3
feat: add log
Feb 23, 2022
d86e765
fix: add log
Feb 23, 2022
babb0d2
fix: add log
Feb 23, 2022
922cc84
fix: add test
Feb 23, 2022
5b3c2c0
fix: modify
Feb 23, 2022
6009c2b
fix: test case
Feb 23, 2022
6b9e435
fix: add log
Feb 23, 2022
bcd4112
fix: add test case
Feb 23, 2022
cb07135
fix: remove log
Feb 23, 2022
07db3ac
fix: format code
Feb 23, 2022
8a07c89
fix: modify test case
Feb 23, 2022
f0b7400
fix: modify test case
Feb 23, 2022
6264b2b
fix: modify
Feb 23, 2022
0f06ba1
fix: modify resp status
Feb 23, 2022
aec91c8
docs: modify docs
Feb 23, 2022
f8aabe1
Merge branch 'master' into feature/resp-all-upstream-status
Feb 24, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 21 additions & 14 deletions apisix/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -589,22 +589,29 @@ function _M.http_header_filter_phase()
core.response.set_header("Server", ver_header)

local up_status = get_var("upstream_status")
if up_status and #up_status == 3
and tonumber(up_status) >= 500
and tonumber(up_status) <= 599
then
set_resp_upstream_status(up_status)
elseif up_status and #up_status > 3 then
-- the up_status can be "502, 502" or "502, 502 : "
local last_status
if str_byte(up_status, -1) == str_byte(" ") then
last_status = str_sub(up_status, -6, -3)
if up_status then
local_conf = core.config.local_conf()
if local_conf.apisix and local_conf.apisix.show_upstream_status_in_response_header then
set_resp_upstream_status(up_status)
else
last_status = str_sub(up_status, -3)
end
if #up_status == 3
and tonumber(up_status) >= 500
and tonumber(up_status) <= 599
then
set_resp_upstream_status(up_status)
elseif #up_status > 3 then
-- the up_status can be "502, 502" or "502, 502 : "
local last_status
if str_byte(up_status, -1) == str_byte(" ") then
last_status = str_sub(up_status, -6, -3)
else
last_status = str_sub(up_status, -3)
end

if tonumber(last_status) >= 500 and tonumber(last_status) <= 599 then
set_resp_upstream_status(up_status)
if tonumber(last_status) >= 500 and tonumber(last_status) <= 599 then
set_resp_upstream_status(up_status)
end
end
end
end

Expand Down
1 change: 1 addition & 0 deletions conf/config-default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ apisix:
enable_admin_cors: true # Admin API support CORS response headers.
enable_dev_mode: false # Sets nginx worker_processes to 1 if set to true
enable_reuseport: true # Enable nginx SO_REUSEPORT switch if set to true.
show_upstream_status_in_response_header: false # when true all upstream status write to `X-APISIX-Upstream-Status` otherwise only 5xx code
enable_ipv6: true
config_center: etcd # etcd: use etcd to store the config value
# yaml: fetch the config value from local yaml file `/your_path/conf/apisix.yaml`
Expand Down
2 changes: 1 addition & 1 deletion docs/zh/latest/debug-function.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ title: 调试功能

## `5xx` 响应状态码

500、502、503 等类似的 `5xx` 状态码,是由于服务器错误而响应的状态码,当一个请求出现 `5xx` 状态码时;它可能来源于 `APISIX` 或 `Upstream` 。如何识别这些响应状态码的来源,是一件很有意义的事,它能够快速的帮助我们确定问题的所在。
500、502、503 等类似的 `5xx` 状态码,是由于服务器错误而响应的状态码,当一个请求出现 `5xx` 状态码时;它可能来源于 `APISIX` 或 `Upstream` 。如何识别这些响应状态码的来源,是一件很有意义的事,它能够快速的帮助我们确定问题的所在。(当修改 `conf/nginx.conf` 的配置 `show_upstream_status_in_response_header` 为 true 时,会返回所有上游状态码,不仅仅是 `5xx` 状态。)

## 如何识别 `5xx` 响应状态码的来源

Expand Down
Loading