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 2021/01/14 11:38:12 UTC

[GitHub] [apisix] pengtaochang opened a new issue #3294: request help: I need to get the upstream setting in current router rule when develop a new plugin.

pengtaochang opened a new issue #3294:
URL: https://github.com/apache/apisix/issues/3294


   ### Issue description
    I need to get the upstream setting in current router rule when develop a new plugin like batch_request.
   ### Environment
    I need to get the upstream setting in current router rule when develop a new plugin like batch_request.
   * apisix version (cmd: `apisix version`):
   * OS: (cmd: `uname -a`)
   * OpenResty / Nginx version: (cmd: `nginx -V` or `openresty -V`)
   


----------------------------------------------------------------
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.

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



[GitHub] [apisix] Firstsawyou commented on issue #3294: request help: I need to get the upstream setting in current router rule when develop a new plugin.

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


   If your upstream is set on "route" then you can get the upstream through `ctx.matched_route` (upstream_id and service_id can also be obtained through `ctx.matched_route`). You can first view the data structure of "ctx.matched_route" through the log to determine to obtain the corresponding data.
   
   Example:
   
   ```lua
   core.log.warn("ctx.matched_route: ", core.json.encode(ctx.matched_route))
   ```
   
   print log:
   ```
   {"createdIndex":14,"modifiedIndex":6278,"has_domain":false,"clean_handlers":{},"value":{"plugins":{"traffic-split":{"rules":[{"weighted_upstreams":[{"upstream":{"hash_on":"vars","pass_host":"pass","type":"roundrobin","nodes":{"127.0.0.1:80":1},"name":"upstream_A"},"weight":1}],"match":[{"vars":[["http_release","==","new_release"]]}]}]}},"uris":["\/hello"],"create_time":1610288363,"status":1,"update_time":1610629287,"priority":0,"upstream":{"hash_on":"vars","type":"roundrobin","nodes":[{"weight":1,"host":"127.0.0.1","port":81}],"pass_host":"pass"},"id":"1"},"key":"\/apisix\/routes\/1"}
   ```
   
   If your upstream is set to "service" or "upstream" then you need to get it through the corresponding id.


----------------------------------------------------------------
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.

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



[GitHub] [apisix] pengtaochang commented on issue #3294: request help: I need to get the upstream setting in current router rule when develop a new plugin.

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


   @Firstsawyou  Thankyou very much, again, I write plugin code  in function _M.access(conf, ctx),  could you pointer me how to get the route object or upstream_id ,  I'd appreciate 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.

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



[GitHub] [apisix] Firstsawyou commented on issue #3294: request help: I need to get the upstream setting in current router rule when develop a new plugin.

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


   It can be obtained through the upstream id bound on the route, please refer to here: [https://github.com/apache/apisix/blob/master/apisix/init.lua#L436-L444 ](https://github.com/apache/apisix/blob/master/apisix/init.lua#L436-L444)


----------------------------------------------------------------
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.

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



[GitHub] [apisix] pengtaochang commented on issue #3294: request help: I need to get the upstream setting in current router rule when develop a new plugin.

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


   Thank you very much, you solved my problem perfectly.


----------------------------------------------------------------
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.

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



[GitHub] [apisix] pengtaochang closed issue #3294: request help: I need to get the upstream setting in current router rule when develop a new plugin.

Posted by GitBox <gi...@apache.org>.
pengtaochang closed issue #3294:
URL: https://github.com/apache/apisix/issues/3294


   


----------------------------------------------------------------
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.

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