You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by GitBox <gi...@apache.org> on 2022/10/19 06:23:12 UTC
[GitHub] [apisix] Bigwen-1 opened a new issue, #8118: help request: The upstream route selection affects the next request
Bigwen-1 opened a new issue, #8118:
URL: https://github.com/apache/apisix/issues/8118
### Description
hi, 你好:
我们希望upstream支持多泳道部署功能,即根据请求标签选择可以自行匹配不同的上游 在upstream.lua set_by_route方法做了些调整。但是发现下次请求时init.lua 中api_ctx 的node (字段:matched_route value upstream node)仍为上次筛选过的node, 非etcd中存储的全量 请问是否存在数据污染问题? 跟踪发现是从init.lua _M.http_access_phase() router.router_http.match(api_ctx) -> radixtree_uri.lua _M.match(api_ctx)这步做的赋值
upstream.lua 修改内容如下:
function _M.set_by_route(route, api_ctx)
if api_ctx.upstream_conf then
-- upstream_conf has been set by traffic-split plugin
return
end
local up_conf = api_ctx.matched_upstream
if not up_conf then
return 503, "missing upstream configuration in Route or Service"
end
local scheme = up_conf.scheme
if up_conf.service_name then
local new_nodes = up_conf.nodes
if new_nodes == nil or next(new_nodes) == nil then
new_nodes = up_conf.parent.value.upstream.nodes
end
up_conf.nodes = new_nodes
end
local hxlabel = ngx.req.get_headers()["X-Label"]
local nodes_num = up_conf.nodes and #up_conf.nodes or 0
if nodes_num == 0 then
return HTTP_CODE_UPSTREAM_UNAVAILABLE, "no valid upstream node"
end
if ngx.req.get_headers()["X-Label"] then
local label_nodes = up_conf.nodes
local new_label_nodes = {}
for i, n in ipairs(label_nodes) do
if n.host == hxlabel then
local node = core.table.clone(n)
core.table.insert(new_label_nodes, node)
end
end
label_nodes = new_label_nodes
up_conf.nodes = label_nodes
end
set_directly(api_ctx, up_conf.type .. "#upstream_" .. tostring(up_conf),
tostring(up_conf), up_conf)
local nodes_count = up_conf.nodes and #up_conf.nodes or 0
if nodes_count == 0 then
return HTTP_CODE_UPSTREAM_UNAVAILABLE, "no valid upstream node"
end
.....
### Environment
- APISIX version (run `apisix version`): 2.14.1
- Operating system (run `uname -a`):
- OpenResty / Nginx version (run `openresty -V` or `nginx -V`):
- etcd version, if relevant (run `curl http://127.0.0.1:9090/v1/server_info`):
- APISIX Dashboard version, if relevant:
- Plugin runner version, for issues related to plugin runners:
- LuaRocks version, for installation issues (run `luarocks --version`):
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix] tzssangglass commented on issue #8118: help request: The upstream route selection affects the next request
Posted by GitBox <gi...@apache.org>.
tzssangglass commented on issue #8118:
URL: https://github.com/apache/apisix/issues/8118#issuecomment-1284022125
I think you can try the traffic-split plugin. After looking at your code, I think that traffic-split can do the job of splitting traffic based on headers
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix] tzssangglass commented on issue #8118: help request: The upstream route selection affects the next request
Posted by GitBox <gi...@apache.org>.
tzssangglass commented on issue #8118:
URL: https://github.com/apache/apisix/issues/8118#issuecomment-1284170951
ref: https://github.com/apache/apisix/blob/332928e0d2c519b68279273394687ac72e492c38/apisix/plugins/traffic-split.lua#L148-L192
you can learn from `traffic-split` code, `new_nodes` and `up_conf ` are new tables. don't change `up_conf.nodes`, deepcopy `up_conf.nodes` and use the copy object.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix] tzssangglass commented on issue #8118: help request: The upstream route selection affects the next request
Posted by GitBox <gi...@apache.org>.
tzssangglass commented on issue #8118:
URL: https://github.com/apache/apisix/issues/8118#issuecomment-1283979949
> 是的 目前定位到在经过init.lua _M.http_access_phase() router.router_http.match(api_ctx) —> radixtree_uri.lua _M.match(api_ctx)—> radixtree_uri.lua base_router.match_uri(uri_router, match_opts, api_ctx) —>route.lua _M.match_uri(uri_router, match_opts, api_ctx) 经过 local ok = uri_router:dispatch(api_ctx.var.uri, match_opts, api_ctx, match_opts) 一行获取到的match_opts中 matched_route upstream node为上次修改后的upstream api_ctx参数中也如此
I reproduced the problem you mentioned.
I found out first because `up_conf.nodes` came from `matched_route`, and `matched_route` came from the `route` when `creating create_radixtree_uri_router`, which is cross-requested.
In short, the `up_conf.nodes` you modified is cross-request, and we should not modify `up_conf.nodes` directly.
you can deepcopy `up_conf.nodes` and use the copy object.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix] Bigwen-1 commented on issue #8118: help request: The upstream route selection affects the next request
Posted by GitBox <gi...@apache.org>.
Bigwen-1 commented on issue #8118:
URL: https://github.com/apache/apisix/issues/8118#issuecomment-1283657895
是的 目前定位到在经过init.lua _M.http_access_phase() router.router_http.match(api_ctx) —> radixtree_uri.lua _M.match(api_ctx)—> radixtree_uri.lua base_router.match_uri(uri_router, match_opts, api_ctx) —>route.lua _M.match_uri(uri_router, match_opts, api_ctx) 经过match_opts.matched = core.tablepool.fetch("matched_route_record", 0, 4) 一行获取到的matched_route 中upstream node为上次修改后的upstream api_ctx参数中也如此
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix] tzssangglass commented on issue #8118: help request: The upstream route selection affects the next request
Posted by GitBox <gi...@apache.org>.
tzssangglass commented on issue #8118:
URL: https://github.com/apache/apisix/issues/8118#issuecomment-1283616691
> 但是发现下次请求时init.lua 中api_ctx 的node (字段:matched_route value upstream node)仍为上次筛选过的node,
The `api_ctx` stores per-request data, and the nodes are also the upstream nodes associated with the current matching route.
Modifying the nodes in the `api_ctx` of the current request does not affect the nodes in the `api_ctx` of the next request, by design.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix] tzssangglass closed issue #8118: help request: The upstream route selection affects the next request
Posted by GitBox <gi...@apache.org>.
tzssangglass closed issue #8118: help request: The upstream route selection affects the next request
URL: https://github.com/apache/apisix/issues/8118
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix] tzssangglass commented on issue #8118: help request: The upstream route selection affects the next request
Posted by GitBox <gi...@apache.org>.
tzssangglass commented on issue #8118:
URL: https://github.com/apache/apisix/issues/8118#issuecomment-1285508116
ok
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix] Bigwen-1 commented on issue #8118: help request: The upstream route selection affects the next request
Posted by GitBox <gi...@apache.org>.
Bigwen-1 commented on issue #8118:
URL: https://github.com/apache/apisix/issues/8118#issuecomment-1284062870
Thank you very much for your answer In practical applications, we need to use Zookeeper to register and discover, and the label may not be host, but may be other version fields, matching the IP registered by zk. At present, It seems that traffic-split does not support registration and discovery
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix] tzssangglass commented on issue #8118: help request: The upstream route selection affects the next request
Posted by GitBox <gi...@apache.org>.
tzssangglass commented on issue #8118:
URL: https://github.com/apache/apisix/issues/8118#issuecomment-1283903252
> In addition, please consult uri_router:dispatch(api_ctx. var.uri, match_opts, api_ctx, match_opts), where this method is defined, I can't point it here
https://github.com/api7/lua-resty-radixtree/blob/master/lib/resty/radixtree.lua#L687
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix] Bigwen-1 commented on issue #8118: help request: The upstream route selection affects the next request
Posted by GitBox <gi...@apache.org>.
Bigwen-1 commented on issue #8118:
URL: https://github.com/apache/apisix/issues/8118#issuecomment-1285402688
Hi, I have a good news to tell you that I solved this problem in the way you said today. Thank you again.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix] tzssangglass commented on issue #8118: help request: The upstream route selection affects the next request
Posted by GitBox <gi...@apache.org>.
tzssangglass commented on issue #8118:
URL: https://github.com/apache/apisix/issues/8118#issuecomment-1283629880
> 但是发现下次请求时init.lua 中api_ctx 的node (字段:matched_route value upstream node)仍为上次筛选过的node, 非etcd中存储的全量 请问是否存在数据污染问题?
Are you saying that if the nodes in the `matched_upstream` are modified in the first request, the nodes in the `matched_upstream` in the next request will be the ones modified by the previous request?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix] Bigwen-1 commented on issue #8118: help request: The upstream route selection affects the next request
Posted by GitBox <gi...@apache.org>.
Bigwen-1 commented on issue #8118:
URL: https://github.com/apache/apisix/issues/8118#issuecomment-1283743785
In addition, please consult uri_router:dispatch(api_ctx. var.uri, match_opts, api_ctx, match_opts), where this method is defined, I can't point it here
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org