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/02/17 07:53:35 UTC

[GitHub] [apisix] xianshun163 opened a new issue #6352: How to forward to the original uri in the balancer.lua, when it have change in the plugin?

xianshun163 opened a new issue #6352:
URL: https://github.com/apache/apisix/issues/6352


   ### Issue description
   
   Dear all,   I   use the proxy-rewrite  to change the uri,   then  in the balancer.lua,  if  all the  backupend server is avalable,  I want to  forwards the request to other cluster ,  so  I want to set the uri to the original,  but  I can not do it. 
   I try it like this : ctx.var.upstream_uri = ctx.old_upstream_uri
   but it not work now,  It still forwards the modified URI, not the original.
   
   ### Environment
   
   - apisix version (cmd: `apisix version`):1.11.0
   - OS (cmd: `uname -a`):center os 7
   - OpenResty / Nginx version (cmd: `nginx -V` or `openresty -V`):
   - etcd version, if have (cmd: run `curl http://127.0.0.1:9090/v1/server_info` to get the info from server-info API):
   - apisix-dashboard version, if have:
   - the plugin runner version, if the issue is about a plugin runner (cmd: depended on the kind of runner):
   - luarocks version, if the issue is about installation (cmd: `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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix] tzssangglass commented on issue #6352: How to forward to the original uri in the balancer.lua, when it have change in the plugin?

Posted by GitBox <gi...@apache.org>.
tzssangglass commented on issue #6352:
URL: https://github.com/apache/apisix/issues/6352#issuecomment-1046233015


   > if (run or header_changed or ctx.donot_change_uri ) and balancer.recreate_request then
   > core.log.warn("do recreate_request")
   > balancer.recreate_request()
   > end
   
   This code will only be executed during the balancer retry phase.
   
   I've thought about it for a while, and your needs are a bit specific and a bit tricky to implement.
   
   I'm turning this issue into a discussion because it's not related to the project.
   


-- 
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 #6352: How to forward to the original uri in the balancer.lua, when it have change in the plugin?

Posted by GitBox <gi...@apache.org>.
tzssangglass commented on issue #6352:
URL: https://github.com/apache/apisix/issues/6352#issuecomment-1043906285


   I just remind you that you need `balancer.recreate_request()` after you modify the uri in the balancer phase.
   
   Can you give more specific examples?


-- 
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] xianshun163 commented on issue #6352: How to forward to the original uri in the balancer.lua, when it have change in the plugin?

Posted by GitBox <gi...@apache.org>.
xianshun163 commented on issue #6352:
URL: https://github.com/apache/apisix/issues/6352#issuecomment-1043831310


   @tzssangglass , 
   
   > 2\. balancer.recreate_request()
   
   Thank you for your reply. I don't fully understand your content. 
   I   let the balancer.recreate_ Request () at balancer.Lua code 345 line , is called or not, and the URI is still  the same as proxy_ rewrite. Lua has been modified,   without restoring the original URI. Is my  test wrong?
   
   In addition, my purpose is to work in balancer.Lua, when  all the upstream unavailable, the request is transferred to another backup  gateway ,  so the URI should be restored to its original appearance.
   
   


-- 
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] xianshun163 commented on issue #6352: How to forward to the original uri in the balancer.lua, when it have change in the plugin?

Posted by GitBox <gi...@apache.org>.
xianshun163 commented on issue #6352:
URL: https://github.com/apache/apisix/issues/6352#issuecomment-1043941209


   I  modify it like this:  
   1、in balancer.lua     local function pick_server(route, ctx)
              -- when all node is fail  
               ctx.balancer_server = my_backup_gateway_server
               ctx.var.upstream_uri =  ctx.var._cache.real_request_uri
               ctx.donot_change_uri = true
   2、in balancer.lua     function _M.run(route, ctx, plugin_funcs)
            if (run or header_changed  or ctx.donot_change_uri ) and balancer.recreate_request  then
               core.log.warn("do recreate_request")
               balancer.recreate_request()
           end
   


-- 
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 edited a comment on issue #6352: How to forward to the original uri in the balancer.lua, when it have change in the plugin?

Posted by GitBox <gi...@apache.org>.
tzssangglass edited a comment on issue #6352:
URL: https://github.com/apache/apisix/issues/6352#issuecomment-1043906285


   I just remind you that you need `balancer.recreate_request()` after you modify the uri in the balancer phase.
   
   Can you show how you modified it?


-- 
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] xianshun163 commented on issue #6352: How to forward to the original uri in the balancer.lua, when it have change in the plugin?

Posted by GitBox <gi...@apache.org>.
xianshun163 commented on issue #6352:
URL: https://github.com/apache/apisix/issues/6352#issuecomment-1042804532


   In other words, in the balancer phase, can I still modify  the URI?


-- 
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 #6352: How to forward to the original uri in the balancer.lua, when it have change in the plugin?

Posted by GitBox <gi...@apache.org>.
tzssangglass commented on issue #6352:
URL: https://github.com/apache/apisix/issues/6352#issuecomment-1043743742


   1. you need rto use `balancer.recreate_request` after you changed the uri;
   2. you can hook `before_proxy` in plugins to do this, see: https://github.com/apache/apisix/blob/b52f95b53c689cfd2fd0f4cbf0fefedd4cce9b5e/apisix/balancer.lua#L342-L346, then you don't need to call  `balancer.recreate_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