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

change: change the default router from radixtree uri to radixtree hos… #9047

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 6 additions & 1 deletion apisix/http/router/radixtree_host_uri.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
local require = require
local router = require("apisix.utils.router")
local core = require("apisix.core")
local event = require("apisix.core.event")
local get_services = require("apisix.http.service").services
local service_fetch = require("apisix.http.service").get
local ipairs = ipairs
Expand Down Expand Up @@ -104,8 +105,9 @@ local function create_radixtree_router(routes)
local host_routes = {}
local only_uri_routes = {}
host_router = nil
routes = routes or {}

for _, route in ipairs(routes or {}) do
for _, route in ipairs(routes) do
local status = core.table.try_read_attr(route, "value", "status")
-- check the status
if not status or status == 1 then
Expand All @@ -128,6 +130,9 @@ local function create_radixtree_router(routes)
end
})
end

event.push(event.CONST.BUILD_ROUTER, routes)

if #host_router_routes > 0 then
host_router = router.new(host_router_routes)
end
Expand Down
1 change: 1 addition & 0 deletions apisix/plugins/ai.lua
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ local function routes_analyze(routes)

local route_flags = core.table.new(0, 16)
local route_up_flags = core.table.new(0, 12)

for _, route in ipairs(routes) do
if type(route) == "table" then
for key, value in pairs(route.value) do
Expand Down
2 changes: 1 addition & 1 deletion conf/config-default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ apisix:
# Turn this option on if you want to be compatible with servlet when matching URI path.
normalize_uri_like_servlet: false
router:
http: radixtree_uri # radixtree_uri: match route by uri(base on radixtree)
http: radixtree_host_uri # radixtree_uri: match route by uri(base on radixtree)
# radixtree_host_uri: match route by host + uri(base on radixtree)
# radixtree_uri_with_parameter: like radixtree_uri but match uri with parameters,
# see https://github.com/api7/lua-resty-radixtree/#parameters-in-path for
Expand Down
10 changes: 8 additions & 2 deletions docs/en/latest/terminology/router.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,19 @@ A Router can have the following configurations:

- `apisix.router.http`: The HTTP request route. It can take the following values:

- `radixtree_uri`: (Default) Only use the `uri` as the primary index. To learn more about the support for full and deep prefix matching, check [How to use router-radixtree](../router-radixtree.md).
- `radixtree_uri`: Only use the `uri` as the primary index. To learn more about the support for full and deep prefix matching, check [How to use router-radixtree](../router-radixtree.md).
- `Absolute match`: Match completely with the given `uri` (`/foo/bar`, `/foo/glo`).
- `Prefix match`: Match with the given prefix. Use `*` to represent the given `uri` for prefix matching. For example, `/foo*` can match with `/foo/`, `/foo/a` and `/foo/b`.
- `match priority`: First try an absolute match, if it didn't match, try prefix matching.
- `Any filter attribute`: This allows you to specify any Nginx built-in variable as a filter, such as URL request parameters, request headers, and cookies.
- `radixtree_uri_with_parameter`: Like `radixtree_uri` but also supports parameter match.
- `radixtree_host_uri`: Matches both host and URI of the request. Use `host + uri` as the primary index (based on the `radixtree` engine).
- `radixtree_host_uri`: (Default) Matches both host and URI of the request. Use `host + uri` as the primary index (based on the `radixtree` engine).

:::note

In version 3.2 and earlier, APISIX used `radixtree_uri` as the default Router. `radixtree_uri` has better performance than `radixtree_host_uri`, so if you have higher performance requirements and can live with the fact that `radixtree_uri` only use the `uri` as the primary index, consider continuing to use `radixtree_uri` as the default Router.

:::

- `apisix.router.ssl`: SSL loads the matching route.
- `radixtree_sni`: (Default) Use `SNI` (Server Name Indication) as the primary index (based on the radixtree engine).
11 changes: 9 additions & 2 deletions docs/zh/latest/terminology/router.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,20 @@ Router 具有以下配置:

- `apisix.router.http`: HTTP 请求路由。

- `radixtree_uri`:(默认)只使用 `uri` 作为主索引。基于 `radixtree` 引擎,支持全量和深前缀匹配,更多信息请参考[如何使用 router-radixtree](../../../en/latest/router-radixtree.md)。
- `radixtree_uri`:只使用 `uri` 作为主索引。基于 `radixtree` 引擎,支持全量和深前缀匹配,更多信息请参考[如何使用 router-radixtree](../../../en/latest/router-radixtree.md)。
- `绝对匹配`:完整匹配给定的 `uri` ,比如 `/foo/bar`,`/foo/glo`。
- `前缀匹配`:末尾使用 `*` 代表给定的 `uri` 是前缀匹配。比如 `/foo*`,则允许匹配 `/foo/`、`/foo/a`和`/foo/b`等。
- `匹配优先级`:优先尝试绝对匹配,若无法命中绝对匹配,再尝试前缀匹配。
- `任意过滤属性`:允许指定任何 Nginx 内置变量作为过滤条件,比如 URL 请求参数、请求头、cookie 等。
- `radixtree_uri_with_parameter`:同 `radixtree_uri` 但额外有参数匹配的功能。
- `radixtree_host_uri`:使用 `host + uri` 作为主索引(基于 `radixtree` 引擎),对当前请求会同时匹配 `host` 和 `uri`,支持的匹配条件与 `radixtree_uri` 基本一致。
- `radixtree_host_uri`:(默认)使用 `host + uri` 作为主索引(基于 `radixtree` 引擎),对当前请求会同时匹配 `host` 和 `uri`,支持的匹配条件与 `radixtree_uri` 基本一致。

::: 注意

在3.2及之前版本,APISIX 使用 `radixtree_uri` 作为默认路由,`radixtree_uri` 比 `radixtree_host_uri` 拥有更好的性能,如果你对性能有更高的要求,并且能够接受 `radixtree_uri` 只使用 `uri` 作为主索引的特点,可以考虑继续使用 `radixtree_uri` 作为默认路由

:::


- `apisix.router.ssl`:SSL 加载匹配路由。
- `radixtree_sni`:(默认)使用 `SNI` (Server Name Indication) 作为主索引(基于 radixtree 引擎)。
12 changes: 0 additions & 12 deletions t/config-center-yaml/route.t
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,6 @@ hello world

=== TEST 6: route with bad plugin, radixtree_host_uri
--- yaml_config
apisix:
node_listen: 1984
router:
http: "radixtree_host_uri"
deployment:
role: data_plane
role_data_plane:
Expand Down Expand Up @@ -176,10 +172,6 @@ property "uri" validation failed

=== TEST 7: fix route with default value
--- yaml_config
apisix:
node_listen: 1984
router:
http: "radixtree_host_uri"
deployment:
role: data_plane
role_data_plane:
Expand All @@ -206,10 +198,6 @@ GET /hello

=== TEST 8: invalid route, bad vars operator
--- yaml_config
apisix:
node_listen: 1984
router:
http: "radixtree_host_uri"
deployment:
role: data_plane
role_data_plane:
Expand Down
11 changes: 0 additions & 11 deletions t/node/route-status.t
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,6 @@ worker_connections(256);
no_root_location();
no_shuffle();

our $yaml_config = <<_EOC_;
apisix:
node_listen: 1984
router:
http: 'radixtree_host_uri'
_EOC_

run_tests();

__DATA__
Expand Down Expand Up @@ -133,7 +126,6 @@ GET /hello
ngx.say(body)
}
}
--- yaml_config eval: $::yaml_config
--- request
GET /t
--- response_body
Expand All @@ -144,7 +136,6 @@ passed
=== TEST 6: hit route
--- request
GET /hello
--- yaml_config eval: $::yaml_config
--- more_headers
Host: foo.com
--- response_body
Expand Down Expand Up @@ -172,7 +163,6 @@ hello world
ngx.say(body)
}
}
--- yaml_config eval: $::yaml_config
--- request
GET /t
--- response_body
Expand All @@ -183,7 +173,6 @@ passed
=== TEST 8: route not found, failed by disable
--- request
GET /hello
--- yaml_config eval: $::yaml_config
--- more_headers
Host: foo.com
--- error_code: 404
Expand Down
16 changes: 8 additions & 8 deletions t/plugin/ai5.t
Original file line number Diff line number Diff line change
Expand Up @@ -171,11 +171,11 @@ done
qr/route match mode: \S[^,]+/
--- grep_error_log_out
route match mode: ai_match
route match mode: radixtree_uri
route match mode: radixtree_uri
route match mode: radixtree_uri
route match mode: radixtree_host_uri
route match mode: radixtree_host_uri
route match mode: radixtree_host_uri
route match mode: ai_match
route match mode: radixtree_uri
route match mode: radixtree_host_uri



Expand Down Expand Up @@ -263,8 +263,8 @@ done
--- grep_error_log eval
qr/route match mode: \S[^,]+/
--- grep_error_log_out
route match mode: radixtree_uri
route match mode: radixtree_uri
route match mode: radixtree_host_uri
route match mode: radixtree_host_uri
route match mode: ai_match
route match mode: radixtree_uri
route match mode: radixtree_uri
route match mode: radixtree_host_uri
route match mode: radixtree_host_uri
12 changes: 8 additions & 4 deletions t/router/radixtree-host-uri-priority.t
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,19 @@ deployment:
config_provider: yaml
_EOC_

add_block_preprocessor(sub {
my ($block) = @_;

if (!defined $block->yaml_config) {
$block->set_value("yaml_config", $yaml_config);
}
});

run_tests();

__DATA__

=== TEST 1: hit routes(priority: 1 + priority: 2)
--- yaml_config eval: $::yaml_config
--- apisix_yaml
routes:
-
Expand Down Expand Up @@ -72,7 +79,6 @@ use config_provider: yaml


=== TEST 2: hit routes(priority: 2 + priority: 1)
--- yaml_config eval: $::yaml_config
--- apisix_yaml
routes:
-
Expand Down Expand Up @@ -105,7 +111,6 @@ use config_provider: yaml


=== TEST 3: hit routes(priority: default_value + priority: 1)
--- yaml_config eval: $::yaml_config
--- apisix_yaml
routes:
-
Expand Down Expand Up @@ -137,7 +142,6 @@ use config_provider: yaml


=== TEST 4: hit routes(priority: 1 + priority: default_value)
--- yaml_config eval: $::yaml_config
--- apisix_yaml
routes:
-
Expand Down
23 changes: 8 additions & 15 deletions t/router/radixtree-host-uri.t
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ apisix:
http: 'radixtree_host_uri'
_EOC_

add_block_preprocessor(sub {
my ($block) = @_;

if (!defined $block->yaml_config) {
$block->set_value("yaml_config", $yaml_config);
}
});

run_tests();

__DATA__
Expand Down Expand Up @@ -58,7 +66,6 @@ __DATA__
ngx.say(body)
}
}
--- yaml_config eval: $::yaml_config
--- request
GET /t
--- response_body
Expand All @@ -69,7 +76,6 @@ passed
=== TEST 2: /not_found
--- request
GET /not_found
--- yaml_config eval: $::yaml_config
--- error_code: 404
--- response_body
{"error_msg":"404 Route Not Found"}
Expand All @@ -79,7 +85,6 @@ GET /not_found
=== TEST 3: /not_found
--- request
GET /hello
--- yaml_config eval: $::yaml_config
--- error_code: 404
--- response_body
{"error_msg":"404 Route Not Found"}
Expand All @@ -89,7 +94,6 @@ GET /hello
=== TEST 4: /not_found
--- request
GET /hello
--- yaml_config eval: $::yaml_config
--- more_headers
Host: not_found.com
--- error_code: 404
Expand All @@ -101,7 +105,6 @@ Host: not_found.com
=== TEST 5: hit routes
--- request
GET /hello
--- yaml_config eval: $::yaml_config
--- more_headers
Host: foo.com
--- response_body
Expand All @@ -112,7 +115,6 @@ hello world
=== TEST 6: hit routes
--- request
GET /hello
--- yaml_config eval: $::yaml_config
--- more_headers
Host: foo.com
--- response_body
Expand Down Expand Up @@ -144,7 +146,6 @@ hello world
ngx.say(body)
}
}
--- yaml_config eval: $::yaml_config
--- request
GET /t
--- response_body
Expand All @@ -155,7 +156,6 @@ passed
=== TEST 8: /not_found
--- request
GET /hello
--- yaml_config eval: $::yaml_config
--- error_code: 404
--- response_body
{"error_msg":"404 Route Not Found"}
Expand All @@ -165,7 +165,6 @@ GET /hello
=== TEST 9: hit routes
--- request
GET /server_port
--- yaml_config eval: $::yaml_config
--- more_headers
Host: anydomain.com
--- response_body_like eval
Expand Down Expand Up @@ -197,7 +196,6 @@ qr/1981/
ngx.say(body)
}
}
--- yaml_config eval: $::yaml_config
--- request
GET /t
--- response_body
Expand All @@ -208,7 +206,6 @@ passed
=== TEST 11: /not_found
--- request
GET /hello2
--- yaml_config eval: $::yaml_config
--- error_code: 404
--- response_body
{"error_msg":"404 Route Not Found"}
Expand All @@ -218,7 +215,6 @@ GET /hello2
=== TEST 12: hit routes
--- request
GET /hello
--- yaml_config eval: $::yaml_config
--- more_headers
Host: anydomain.com
--- response_body
Expand All @@ -241,7 +237,6 @@ hello world
ngx.say(body)
}
}
--- yaml_config eval: $::yaml_config
--- request
GET /t
--- response_body
Expand Down Expand Up @@ -274,7 +269,6 @@ passed
ngx.say(body)
}
}
--- yaml_config eval: $::yaml_config
--- request
GET /t
--- response_body
Expand All @@ -285,7 +279,6 @@ passed
=== TEST 15: hit routes
--- request
GET /hello
--- yaml_config eval: $::yaml_config
--- more_headers
Host: www.foo.com
--- response_body
Expand Down
Loading