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 03:19:07 UTC

[GitHub] [apisix] hmthoo opened a new issue, #8117: router can't support location @xxx ?

hmthoo opened a new issue, #8117:
URL: https://github.com/apache/apisix/issues/8117

   ### Description
   
   forward route through my custom plugin like this "/saas" --> "@apps_stable"
   
   ** router config
   ![image](https://user-images.githubusercontent.com/42607426/196588024-feb784a7-cd95-44d1-96b0-e6f464823a37.png)
   
   ** error.log 
   ```
   [error] 511#511: *5615935 could not find named location "@apps_stable"
   ```
   ** question
   apisix router can't support location @xxx ? Or I should do other configurations ?
   
   
   


-- 
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 #8117: router can't support location @xxx ?

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

   Considered as solved, feel free to reopen this if you needed.


-- 
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] hmthoo commented on issue #8117: router can't support location @xxx ?

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

   I have sovled this problem. If you want to add more than one nodes in `up_conf.nodes`,  you should add `prority` in it
   ```
       local up_conf = {
           type = "roundrobin",
           nodes = {
               {host = "192.168.100.92" , port = 8088 , weight = 10, prority = 0},
               {host = "192.168.100.91" , port = 8088 , weight = 10, prority = 0},
           }
       }
       core.log.warn(core.json.delay_encode(up_conf.nodes, true))
   
       local upstream_key = up_conf.type .. "#route_" .. matched_route.value.id
       upstream.set(ctx, upstream_key, ctx.conf_version, up_conf)
   ```
   @tzssangglass thanks


-- 
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 #8117: router can't support location @xxx ?

Posted by GitBox <gi...@apache.org>.
tzssangglass closed issue #8117: router can't support location @xxx ?
URL: https://github.com/apache/apisix/issues/8117


-- 
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 #8117: router can't support location @xxx ?

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

   > How to get the node information of an existing upstream to add to up_conf?For example, get the nodes information in my test upstream "upstream-test-a" and add it to the variable up_conf.
   
   `ctx.matched_upstream`, you can dump ctx by `ngx.log(ngx.WARN, "ctx : ", require("inspect")(ctx, {depth = 2}))`, and search info in 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 #8117: router can't support location @xxx ?

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

   > I have created upstream "upstream-test1" and "upstream-test2" via the admin api. how do forward to it in the access phase?
   
   search:
   
   ```
    upstream.set(ctx, up_conf.type .. "#route_" .. matched_route.value.id, 
                     ctx.conf_version, up_conf) 
   ```


-- 
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] hmthoo commented on issue #8117: router can't support location @xxx ?

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

   > Considered as solved, feel free to reopen this if you needed.
   Multiple nodes should be a common requirement.
   I suggest adding `priority` to the `example-plugin.lua`, don't let others encounter this problem because of missing fields.
   ```
       local up_conf = {
           type = "roundrobin",
           nodes = {
               {host = conf.ip, port = conf.port, weight = 1, priority = 0},
           }
       }
   ```


-- 
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] hmthoo commented on issue #8117: router can't support location @xxx ?

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

   > > I can't think of anything else too good at the moment, It judge whether the user id is in redis and forward it to the corresponding route.
   > 
   > forward it to the corresponding route is hard to do, but forwarding it to the corresponding upstream can be achieved
   
   You are right. If I want to forward to the corresponding upstream in the plugin how should I do 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] hmthoo commented on issue #8117: router can't support location @xxx ?

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

   > you can learn how to use redis in APISIX from:
   > 
   > https://github.com/apache/apisix/blob/23356d6c4a58379f5cf33be92e0d88cc6399a853/apisix/plugins/limit-count/limit-count-redis.lua#L54-L109
   > 
   > and how to set upstream from:
   > 
   > https://github.com/apache/apisix/blob/23356d6c4a58379f5cf33be92e0d88cc6399a853/apisix/plugins/example-plugin.lua#L84-L108
   
   > 
   
   thanks.   
   
   I'm having problems using this plugin in router.
   
   code
   ```
   ...
   
   function _M.rewrite(conf, ctx)
       core.log.warn("plugin rewrite phase, conf: ", core.json.encode(conf))
       core.log.warn("conf_type: ", ctx.conf_type)
       core.log.warn("conf_id: ", ctx.conf_id)
       core.log.warn("conf_version: ", ctx.conf_version)
   end
   
   function _M.access(conf, ctx)
       core.log.warn("plugin access phase, conf: ", core.json.encode(conf))
       if not conf.ip then
           core.log.warn("1111111111111")
           return
       end
       return
   end
   
   return _M
   ```
   
   error.log
   ```
   ... phase_func(): plugin rewrite phase, conf: {"disable":true}
   ... phase_func(): conf_type: route
   ... phase_func(): conf_id: 430412984771150526
   ... phase_func(): conf_version: 248
   ... phase_func(): plugin access phase, conf: {"disable":true}
   ... phase_func(): 1111111111111
   ```
   
   It seems impossible to get conf.ip
   
   I have created upstream "upstream-test1" and "upstream-test2" via the admin api. how do forward to it in the access phase?


-- 
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 #8117: router can't support location @xxx ?

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

   > I can't think of anything else too good at the moment, It judge whether the user id is in redis and forward it to the corresponding route.
   
   forward it to the corresponding route is hard to do, but forwarding it to the corresponding upstream can be achieved


-- 
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 #8117: router can't support location @xxx ?

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

   you can learn how to use redis in APISIX from: https://github.com/apache/apisix/blob/23356d6c4a58379f5cf33be92e0d88cc6399a853/apisix/plugins/limit-count/limit-count-redis.lua#L54-L109
   
   and how to set upstream from: https://github.com/apache/apisix/blob/23356d6c4a58379f5cf33be92e0d88cc6399a853/apisix/plugins/example-plugin.lua#L84-L108
   
   


-- 
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] hmthoo commented on issue #8117: router can't support location @xxx ?

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

   > 
   
   thanks.   
   
   I'm having problems using this plugin in router.
   
   code
   ```
   ...
   
   function _M.rewrite(conf, ctx)
       core.log.warn("plugin rewrite phase, conf: ", core.json.encode(conf))
       core.log.warn("conf_type: ", ctx.conf_type)
       core.log.warn("conf_id: ", ctx.conf_id)
       core.log.warn("conf_version: ", ctx.conf_version)
   end
   
   function _M.access(conf, ctx)
       core.log.warn("plugin access phase, conf: ", core.json.encode(conf))
       if not conf.ip then
           core.log.warn("1111111111111")
           return
       end
       return
   end
   
   return _M
   ```
   
   error.log
   ```
   ... phase_func(): plugin rewrite phase, conf: {"disable":true}
   ... phase_func(): conf_type: route
   ... phase_func(): conf_id: 430412984771150526
   ... phase_func(): conf_version: 248
   ... phase_func(): plugin access phase, conf: {"disable":true}
   ... phase_func(): 1111111111111
   ```
   
   It seems impossible to get conf.ip
   
   I have created upstream "upstream-test1" and "upstream-test2" via the admin api. how do forward to it in the access phase?


-- 
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] hmthoo commented on issue #8117: router can't support location @xxx ?

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

   > > I have created upstream "upstream-test1" and "upstream-test2" via the admin api. how do forward to it in the access phase?
   > 
   > search:
   > 
   > ```
   >  upstream.set(ctx, up_conf.type .. "#route_" .. matched_route.value.id, 
   >                   ctx.conf_version, up_conf) 
   > ```
   
   Forwarding to upstrem via upstrem_set() is ok.   Thank you for giving me a general idea!
   
   How to get the node information of an existing upstream to add to up_conf?For example, get the nodes information in my test upstream "upstream-test-a" and add it to the variable up_conf.
   
   `  local up_conf = {
           type = "roundrobin",
           nodes = {
               {host = upstream-test-a.node-1.ip , port = upstream-test-a.node-1.port  , weight = 10},
               {host = upstream-test-a.node-2.ip , port = upstream-test-a.node-2.port  , weight = 10},
           }
       }`
   
   
   
   


-- 
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] soulbird commented on issue #8117: router can't support location @xxx ?

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

   It looks like you want to add an Nginx location configuration, and what you're adding here is a route. APISIX core does not use Nginx location for request matching, please check APISIX's definition of the route here https://github.com/apache/apisix/blob/master/docs/en/latest/admin-api.md# route.
   If you want to add Nginx configuration, please refer to here: https://github.com/apache/apisix/blob/master/conf/config-default.yaml#L170-L173.


-- 
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] hmthoo commented on issue #8117: router can't support location @xxx ?

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

   > > How to get the node information of an existing upstream to add to up_conf?For example, get the nodes information in my test upstream "upstream-test-a" and add it to the variable up_conf.
   > 
   > `ctx.matched_upstream`, you can dump ctx by `ngx.log(ngx.WARN, "ctx : ", require("inspect")(ctx, {depth = 2}))`, and search info in ctx.
   
   ### code 
   ```
       local up_conf = {
           type = "roundrobin",
           nodes = {
               {host = "192.168.100.92" , port = 8088 , weight = 10},
               {host = "192.168.100.91" , port = 8088 , weight = 10},
           }
       }
   
       core.log.warn(core.json.delay_encode(up_conf.nodes, true))
   
       local upstream_key = up_conf.type .. "#route_" .. matched_route.value.id
       upstream.set(ctx, upstream_key, ctx.conf_version, up_conf)
   ```
   
   ### error.log
   ```
   2022/10/24 09:51:57 [warn] 6666#6666: *35590445 [lua] saas-canary-dispatch.lua:63: phase_func(): [{"weight":10,"host":"192.168.100.91","port":8088},{"weight":10,"host":"192.168.100.92","port":8088}], client: 10.10.40.52, server: _, request: "GET /test/tologin HTTP/2.0", host: "test.com"
   2022/10/24 09:51:57 [error] 6666#6666: *35590445 lua entry thread aborted: runtime error: /usr/local/apisix/apisix/balancer.lua:55: table index is nil
   stack traceback:
   coroutine 0:
   	/usr/local/apisix/apisix/balancer.lua: in function 'transform_node'
   	/usr/local/apisix/apisix/balancer.lua:69: in function 'fetch_health_nodes'
   	/usr/local/apisix/apisix/balancer.lua:115: in function 'create_obj_fun'
   	/usr/local/apisix/apisix/core/lrucache.lua:95: in function 'lrucache_server_picker'
   	/usr/local/apisix/apisix/balancer.lua:247: in function 'pick_server'
   	/usr/local/apisix/apisix/init.lua:547: in function 'http_access_phase'
   	access_by_lua(nginx.conf:344):2: in main chunk, client: 10.10.40.52, server: _, request: "GET /test/tologin HTTP/2.0", host: "test.com"
   ```
   
   ### question
   when I try to add more than one nodes in "up_conf.nodes" , an error is reported 


-- 
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 #8117: router can't support location @xxx ?

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

   you can search `@grpc_pass` in source code to learn how to use `ngx.exec()` and `location` to do internal jumps, I think this is complex.
   
   I guess you can achieve your needs in a different way?


-- 
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] hmthoo commented on issue #8117: router can't support location @xxx ?

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

   > you can search `@grpc_pass` in source code to learn how to use `ngx.exec()` and `location` to do internal jumps, I think this is complex.
   > 
   > I guess you can achieve your needs in a different way?
   
   maybe...
   
   I can't think of anything else too good at the moment, It judge whether the user id is in redis and forward it to the corresponding route.
   
   @grpc_pass is a bit complicated, Internal jumps are not necessarily required. 
   
   I would like to know how to change my plugin code if I want to forward to a specific router.


-- 
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] hmthoo commented on issue #8117: router can't support location @xxx ?

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

   > It looks like you want to add an Nginx location configuration, and what you're adding here is a route. APISIX core does not use Nginx location for request matching, please check APISIX's definition of the route here https://github.com/apache/apisix/blob/master/docs/en/latest/admin-api.md# route. If you want to add Nginx configuration, please refer to here: https://github.com/apache/apisix/blob/master/conf/config-default.yaml#L170-L173.
   
   I didn't find the answer I was looking for in the documentation. 
   
   I want to disforward "/saas" to "@apps_stable" via a custom plugin.
   
   ## my code
   Forwarding to the location based on the cid in the cid list
   ```
   local core = require("apisix.core")
   local plugin_name = "cid-dispatch"
   local ngx_cache = ngx.shared.cid
   
   local schema = {
       type = "object",
       properties = {},
       additionalProperties = false,
   }
   
   local _M = {
       version = 1.0,
       priority = 3002,
       name = plugin_name,
       schema = schema,
   }
   
   function get_cookie(cname)
       local cookie_name = 'cookie_'..cname
       return ngx.var[cookie_name]
   end
   
   function get_upstream()
       local proxy = "@apps_stable"
       local cid_list = ngx_cache:get("cid_list")
   
       if  cid_cookie == nil then
           core.log.warn("can't get cid in cookie")
           return proxy
       end
   
       if cid_cookie then
           local patter_cid=','..cid_cookie..','
           local res = string.find(cid_list,patter_cid)
   
           if res == nil then
               return proxy
           end
   
           proxy = "@apps_canary"
           return proxy
       end
   
       return proxy
   end
   
   function _M.rewrite(conf, ctx)
       this_proxy = get_upstream()
       ngx.exec(this_proxy)
   end
   
   return _M
   ```
   


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