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 2019/12/22 15:32:05 UTC

[GitHub] [incubator-apisix] codjust opened a new issue #992: discuss: chash key support more flexible ways

codjust opened a new issue #992: discuss: chash key support more flexible ways
URL: https://github.com/apache/incubator-apisix/issues/992
 
 
   ### Issue description
   Now chash key only support fetch from nginx variable. We need to be more flexible approach,<br>eg: cookie, custom header and so on.
   Here is an example to achieve:
   upstream schema
   ```lua
   hash_on = {
               type = "string",
               default = "vars",
               enum = {
                 "vars",
                 "header",
                 "cookie",
                 "consumer"
               },
           },
           key = {
               description = "the key of chash for dynamic load balancing",
               type = "string"
           },
   ```
   eg:
   ```lua
   local function create_chash_hash_key(ctx, upstream)
       local key = upstream.key 
       local hash_on = upstream.hash_on
       local chash_key
       -- from nginx variable
       if hash_on == "vars" then 
           chash_key = ctx.var[key]
       elseif hash_on == "header" then 
           chash_key = ngx.req.get_headers()[key]
       elseif hash_on == "cookie" then 
           chash_key = ctx.var["cookie_" .. key]
           -- TODO chash_key doesn't exist, set-cookie
       end
       if not chash_key then 
           chash_key = ctx.var["remote_addr"]
       end
       return chash_key
   end
   ```
   
   hash_on type desc:
   1. vars: fetchs nginx variable
   2. header: custom headers or standard http headers
   3. cookie: fetch chash key from cookie. It can be used to sticky session
   4. consumer: hash by consumer_id
   
   If the specified chash key is not present, use default key: remote_addr(it can also provide default settings).
   
   everybody have a better idea?
   

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


With regards,
Apache Git Services

[GitHub] [incubator-apisix] codjust commented on issue #992: discuss: chash key support more flexible ways

Posted by GitBox <gi...@apache.org>.
codjust commented on issue #992: discuss: chash key support more flexible ways
URL: https://github.com/apache/incubator-apisix/issues/992#issuecomment-568468830
 
 
   > @codjust I prefer your design than the exist: https://github.com/apache/incubator-apisix/blob/master/lua/apisix/schema_def.lua#L261
   > And please send this discussion to the mailing list too, thx.
   
   ok,, done.

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


With regards,
Apache Git Services

[GitHub] [incubator-apisix] codjust closed issue #992: discuss: chash key support more flexible ways

Posted by GitBox <gi...@apache.org>.
codjust closed issue #992: discuss: chash key support more flexible ways
URL: https://github.com/apache/incubator-apisix/issues/992
 
 
   

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


With regards,
Apache Git Services

[GitHub] [incubator-apisix] moonming commented on issue #992: discuss: chash key support more flexible ways

Posted by GitBox <gi...@apache.org>.
moonming commented on issue #992: discuss: chash key support more flexible ways
URL: https://github.com/apache/incubator-apisix/issues/992#issuecomment-568396709
 
 
   @codjust I prefer your design  than the exist: https://github.com/apache/incubator-apisix/blob/master/lua/apisix/schema_def.lua#L261
   And please send this discussion to the mailing list too, thx.

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


With regards,
Apache Git Services