You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by me...@apache.org on 2020/03/25 01:48:19 UTC
[incubator-apisix] branch master updated: feature: run log plugins
in the global rule (#1333)
This is an automated email from the ASF dual-hosted git repository.
membphis pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-apisix.git
The following commit(s) were added to refs/heads/master by this push:
new be34880 feature: run log plugins in the global rule (#1333)
be34880 is described below
commit be348805eaea2b588004b13021b96be35205ff0e
Author: 罗泽轩 <sp...@gmail.com>
AuthorDate: Wed Mar 25 09:48:12 2020 +0800
feature: run log plugins in the global rule (#1333)
* feature: run log plugins in the global rule
Close #1202.
* register path as hello3 to avoid conflicts with other test case
---
lua/apisix.lua | 36 +++++++++++++++++++++-------
t/plugin/prometheus.t | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 92 insertions(+), 9 deletions(-)
diff --git a/lua/apisix.lua b/lua/apisix.lua
index 7517c46..45438e5 100644
--- a/lua/apisix.lua
+++ b/lua/apisix.lua
@@ -447,19 +447,37 @@ end
function _M.http_log_phase()
- local api_ctx = run_plugin("log")
- if api_ctx then
- if api_ctx.uri_parse_param then
- core.tablepool.release("uri_parse_param", api_ctx.uri_parse_param)
- end
+ local api_ctx = ngx.ctx.api_ctx
+ if not api_ctx then
+ return
+ end
- core.ctx.release_vars(api_ctx)
- if api_ctx.plugins then
- core.tablepool.release("plugins", api_ctx.plugins)
+ if router.global_rules and router.global_rules.values
+ and #router.global_rules.values > 0 then
+ local local_plugins = api_ctx.plugins
+ api_ctx.plugins = nil
+ local plugins = core.tablepool.fetch("plugins", 32, 0)
+ for _, global_rule in ipairs(router.global_rules.values) do
+ core.table.clear(plugins)
+ api_ctx.plugins = plugin.filter(global_rule, plugins)
+ run_plugin("log")
end
- core.tablepool.release("api_ctx", api_ctx)
+ api_ctx.plugins = local_plugins
+ core.tablepool.release("plugins", plugins)
end
+
+ run_plugin("log")
+ if api_ctx.uri_parse_param then
+ core.tablepool.release("uri_parse_param", api_ctx.uri_parse_param)
+ end
+
+ core.ctx.release_vars(api_ctx)
+ if api_ctx.plugins then
+ core.tablepool.release("plugins", api_ctx.plugins)
+ end
+
+ core.tablepool.release("api_ctx", api_ctx)
end
diff --git a/t/plugin/prometheus.t b/t/plugin/prometheus.t
index 52e55ee..078d479 100644
--- a/t/plugin/prometheus.t
+++ b/t/plugin/prometheus.t
@@ -459,3 +459,68 @@ passed
[200, 404, 200, 200]
--- no_error_log
[error]
+
+
+
+=== TEST 22: set it in global rule
+--- config
+ location /t {
+ content_by_lua_block {
+ local t = require("lib.test_admin").test
+ local code, body = t('/apisix/admin/global_rules/1',
+ ngx.HTTP_PUT,
+ [[{
+ "plugins": {
+ "prometheus": {}
+ }
+ }]]
+ )
+
+ if code >= 300 then
+ ngx.status = code
+ end
+ ngx.say(body)
+
+ local code, body = t('/apisix/admin/routes/3',
+ ngx.HTTP_PUT,
+ [[{
+ "methods": ["GET"],
+ "upstream": {
+ "nodes": {
+ "127.0.0.1:1980": 1
+ },
+ "type": "roundrobin"
+ },
+ "uri": "/hello3"
+ }]]
+ )
+ ngx.say(body)
+ }
+ }
+--- request
+GET /t
+--- response_body
+passed
+passed
+--- no_error_log
+[error]
+
+
+
+=== TEST 23: request from client
+--- pipelined_requests eval
+["GET /hello3", "GET /hello3"]
+--- error_code eval
+[404, 404]
+--- no_error_log
+[error]
+
+
+
+=== TEST 24: fetch the prometheus metric data
+--- request
+GET /apisix/prometheus/metrics
+--- response_body eval
+qr/apisix_http_status\{code="404",route="3",service="",node="127.0.0.1"\} 2/
+--- no_error_log
+[error]