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 ee122cd  feat: log when request is blocked by a plugin (#3214)
ee122cd is described below

commit ee122cd048ffc15693941e507f677310a43eb8c6
Author: 罗泽轩 <[email protected]>
AuthorDate: Thu Jan 7 05:45:08 2021 -0600

    feat: log when request is blocked by a plugin (#3214)
    
    Signed-off-by: spacewander <[email protected]>
---
 apisix/init.lua                  | 4 ++++
 doc/architecture-design.md       | 2 ++
 doc/zh-cn/architecture-design.md | 2 ++
 t/plugin/ip-restriction.t        | 2 ++
 4 files changed, 10 insertions(+)

diff --git a/apisix/init.lua b/apisix/init.lua
index 8c79c08..1c85bd7 100644
--- a/apisix/init.lua
+++ b/apisix/init.lua
@@ -151,6 +151,10 @@ local function run_plugin(phase, plugins, api_ctx)
             if phase_func then
                 local code, body = phase_func(plugins[i + 1], api_ctx)
                 if code or body then
+                    if code >= 400 then
+                        core.log.warn(plugins[i].name, " exits with http 
status code ", code)
+                    end
+
                     core.response.exit(code, body)
                 end
             end
diff --git a/doc/architecture-design.md b/doc/architecture-design.md
index a434d97..e8b1f22 100644
--- a/doc/architecture-design.md
+++ b/doc/architecture-design.md
@@ -225,6 +225,8 @@ The plugin configuration is submitted as part of Route or 
Service and placed und
 
 Not all plugins have specific configuration items. For example, there is no 
specific configuration item under `prometheus`. In this case, an empty object 
identifier can be used.
 
+If a request is rejected by a plugin, there will be warn level log like 
`ip-restriction exits with http status code 403`.
+
 [APISIX supported plugin list](README.md#plugins)
 
 [Back to top](#Table-of-contents)
diff --git a/doc/zh-cn/architecture-design.md b/doc/zh-cn/architecture-design.md
index cedfe90..7527e09 100644
--- a/doc/zh-cn/architecture-design.md
+++ b/doc/zh-cn/architecture-design.md
@@ -233,6 +233,8 @@ local _M = {
 并不是所有插件都有具体配置项,比如 `prometheus` 下是没有任何具体配置项,这时候用一个空的对象
 标识即可。
 
+如果一个请求因为某个插件而被拒绝,会有类似这样的 warn 日志:`ip-restriction exits with http status code 
403`。
+
 [查看 APISIX 已支持插件列表](plugins.md)
 
 [返回目录](#目录)
diff --git a/t/plugin/ip-restriction.t b/t/plugin/ip-restriction.t
index cf9a9a5..03653ed 100644
--- a/t/plugin/ip-restriction.t
+++ b/t/plugin/ip-restriction.t
@@ -269,6 +269,8 @@ GET /hello
 --- error_code: 403
 --- response_body
 {"message":"Your IP address is not allowed"}
+--- error_log
+ip-restriction exits with http status code 403
 --- no_error_log
 [error]
 

Reply via email to