You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by sp...@apache.org on 2022/11/04 05:52:40 UTC
[apisix] branch master updated: fix(ai): typo key name (#8232)
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 a62d33f2f fix(ai): typo key name (#8232)
a62d33f2f is described below
commit a62d33f2f1fcbd62fdd25ea2295b0d6c4675bd4c
Author: tzssangglass <tz...@gmail.com>
AuthorDate: Fri Nov 4 13:52:35 2022 +0800
fix(ai): typo key name (#8232)
---
apisix/plugins/ai.lua | 12 ++++++------
t/plugin/ai.t | 35 ++++++-----------------------------
t/plugin/ai2.t | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++
t/plugin/ai3.t | 41 +++++++++++++++++++++++++++++++++++++++++
4 files changed, 104 insertions(+), 35 deletions(-)
diff --git a/apisix/plugins/ai.lua b/apisix/plugins/ai.lua
index 46c90ef2e..afbda31d4 100644
--- a/apisix/plugins/ai.lua
+++ b/apisix/plugins/ai.lua
@@ -171,8 +171,8 @@ local function routes_analyze(routes)
route_flags["host"] = true
elseif key == "vars" then
route_flags["vars"] = true
- elseif key == "filter_fun"then
- route_flags["filter_fun"] = true
+ elseif key == "filter_func"then
+ route_flags["filter_func"] = true
elseif key == "remote_addr" or key == "remote_addrs" then
route_flags["remote_addr"] = true
elseif key == "service" then
@@ -212,8 +212,8 @@ local function routes_analyze(routes)
route_up_flags["timeout"] = true
elseif k == "tls" then
route_up_flags["tls"] = true
- elseif k == "keepalive" then
- route_up_flags["keepalive"] = true
+ elseif k == "keepalive_pool" then
+ route_up_flags["keepalive_pool"] = true
elseif k == "service_name" then
route_up_flags["service_name"] = true
end
@@ -229,7 +229,7 @@ local function routes_analyze(routes)
local global_rules_flag = router.global_rules and router.global_rules.values
and #router.global_rules.values ~= 0
- if route_flags["vars"] or route_flags["filter_fun"]
+ if route_flags["vars"] or route_flags["filter_func"]
or route_flags["remote_addr"]
or route_flags["service_id"]
or route_flags["plugin_config_id"]
@@ -266,7 +266,7 @@ local function routes_analyze(routes)
or route_up_flags["retries"]
or route_up_flags["timeout"]
or route_up_flags["tls"]
- or route_up_flags["keepalive"]
+ or route_up_flags["keepalive_pool"]
or route_up_flags["service_name"]
or route_up_flags["more_nodes"]
or global_rules_flag then
diff --git a/t/plugin/ai.t b/t/plugin/ai.t
index 6d04c1920..83eab86e8 100644
--- a/t/plugin/ai.t
+++ b/t/plugin/ai.t
@@ -119,39 +119,16 @@ use ai plane to match route
return
end
- local http = require "resty.http"
- local uri1 = "http://127.0.0.1:" .. ngx.var.server_port .. "/hello?k=a"
- local uri2 = "http://127.0.0.1:" .. ngx.var.server_port .. "/hello?k=v"
- local threads = {}
- for i = 1, 2 do
- local th = assert(ngx.thread.spawn(function(i)
- local httpc = http.new()
- local res, err
- if i == 1 then
- -- arg_k = a, match route
- res, err = httpc:request_uri(uri1)
- assert(res.status == 200)
- else
- -- arg_k = v, not match route
- res, err = httpc:request_uri(uri2)
- assert(res.status == 404)
- end
- if not res then
- ngx.log(ngx.ERR, err)
- return
- end
- end, i))
- table.insert(threads, th)
- end
- for i, th in ipairs(threads) do
- ngx.thread.wait(th)
- end
+ local code = t('/hello??k=a', ngx.HTTP_GET)
+ ngx.say(code)
- ngx.say("done")
+ local code = t('/hello??k=v', ngx.HTTP_GET)
+ ngx.say(code)
}
}
--- response_body
-done
+200
+404
--- no_error_log
use ai plane to match route
diff --git a/t/plugin/ai2.t b/t/plugin/ai2.t
index 2a54ae97f..9830f718b 100644
--- a/t/plugin/ai2.t
+++ b/t/plugin/ai2.t
@@ -375,3 +375,54 @@ do body filter
run before_proxy phase balancer_ip : 127.0.0.1
--- no_error_log
enable sample upstream
+
+
+
+=== TEST 6: upstream with keepalive_pool, disable sample upstream
+--- config
+ location /t {
+ content_by_lua_block {
+ local t = require("lib.test_admin").test
+
+ local code, body = t('/apisix/admin/routes/1',
+ ngx.HTTP_PUT,
+ [[{
+ "upstream": {
+ "nodes": {
+ "127.0.0.1:1980": 1
+ },
+ "keepalive_pool": {
+ "size": 1,
+ "idle_timeout": 8,
+ "requests": 2
+ },
+ "type": "roundrobin"
+ },
+ "uri": "/hello"
+ }]]
+ )
+ if code >= 300 then
+ ngx.status = code
+ ngx.say(body)
+ return
+ end
+ ngx.sleep(0.5)
+
+ local http = require "resty.http"
+ local uri = "http://127.0.0.1:" .. ngx.var.server_port .. "/hello"
+ local httpc = http.new()
+ local res, err = httpc:request_uri(uri)
+ assert(res.status == 200)
+ if not res then
+ ngx.log(ngx.ERR, err)
+ return
+ end
+ ngx.say(res.body)
+ }
+ }
+--- response_body
+do body filter
+--- error_log
+proxy request to 127.0.0.1:1980
+--- no_error_log
+enable sample upstream
diff --git a/t/plugin/ai3.t b/t/plugin/ai3.t
index c25d7765f..b56d10235 100644
--- a/t/plugin/ai3.t
+++ b/t/plugin/ai3.t
@@ -220,3 +220,44 @@ use ai plane to match route
--- response_body
apisix_bandwidth{type="ingress",route="foo"
apisix_bandwidth{type="ingress",route="bar"
+
+
+
+==== TEST 3: route has filter_func, disable route cache
+--- config
+ location /t {
+ content_by_lua_block {
+ local t = require("lib.test_admin").test
+ local code, body = t('/apisix/admin/routes/1',
+ ngx.HTTP_PUT,
+ [[{
+ "methods": ["GET"],
+ "filter_func": "function(vars) return vars.arg_k ~= 'v' end",
+ "upstream": {
+ "nodes": {
+ "127.0.0.1:1980": 1
+ },
+ "type": "roundrobin"
+ },
+ "uri": "/hello"
+ }]]
+ )
+
+ if code >= 300 then
+ ngx.status = code
+ ngx.say(body)
+ return
+ end
+
+ local code = t('/hello??k=a', ngx.HTTP_GET)
+ ngx.say(code)
+
+ local code = t('/hello??k=v', ngx.HTTP_GET)
+ ngx.say(code)
+ }
+ }
+--- response_body
+200
+404
+--- no_error_log
+use ai plane to match route