I will submit a PR later, please review it together.
------------------ ???????? ------------------ ??????: "Ming Wen"<[email protected]>; ????????: 2019??12??24??(??????) ????8:10 ??????: "dev"<[email protected]>; ????: Re: [DISCUSS] chash key support more flexible ways > > I do think we can learn this part from OpenResty Edge, > This is the part of the dashboard display. I was wondering if the underlying code implementation needed a classification as codjust said? Or just sort on the dashboard? Thanks, Ming Wen, Apache APISIX Twitter: _WenMing ???? <[email protected]> ??2019??12??23?????? ????10:56?????? > I do think we can learn this part from OpenResty Edge, > also I like the idea that take a Chash key from Header ,which is pretty > meaningful for us. > > [image: image.png] > > > Ming Wen <[email protected]> ??2019??12??23?????? ????9:04?????? > >> yuansheng, what do you think? >> >> Thanks, >> Ming Wen, Apache APISIX >> Twitter: _WenMing >> >> >> Ming Wen <[email protected]> ??2019??12??23?????? ????9:03?????? >> >> > hi, codjust, >> > I prefer your design than the existing one[1]. >> > >> > These categories "vars", "header", "cookie", "consumer" are friendly for >> > developer. >> > >> > [1] >> > >> https://github.com/apache/incubator-apisix/blob/master/lua/apisix/schema_def.lua#L261 >> > >> > Thanks, >> > Ming Wen, Apache APISIX >> > Twitter: _WenMing >> > >> > >> > codjust <[email protected]> ??2019??12??23?????? ????8:58?????? >> > >> >> Now chash key only support fetch from nginx variable. We need to be >> more >> >> flexible approach?? >> >> eg: cookie, custom header and so on. >> >> Here is an example to achieve: >> >> upstream json schema?? >> >> hash_on = { >> >> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; type = "string", >> >> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; default = "vars", >> >> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; enum = { >> >> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "vars", >> >> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "header", >> >> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "cookie", >> >> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "consumer" >> >> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }, >> >> &nbsp; &nbsp; &nbsp; &nbsp; }, >> >> &nbsp; &nbsp; &nbsp; &nbsp; key = { >> >> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; description = "the key of >> chash >> >> for dynamic load balancing", >> >> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; type = "string" >> >> &nbsp; &nbsp; &nbsp; &nbsp; }, >> >> >> >> >> >> eg: >> >> local function create_chash_hash_key(ctx, upstream) >> >> &nbsp; &nbsp; local key = upstream.key&nbsp; >> >> &nbsp; &nbsp; local hash_on = upstream.hash_on >> >> &nbsp; &nbsp; local chash_key >> >> &nbsp; &nbsp; -- from nginx variable >> >> &nbsp; &nbsp; if hash_on == "vars" then&nbsp; >> >> &nbsp; &nbsp; &nbsp; &nbsp; chash_key = ctx.var[key] >> >> &nbsp; &nbsp; elseif hash_on == "header" then&nbsp; >> >> &nbsp; &nbsp; &nbsp; &nbsp; chash_key = ngx.req.get_headers()[key] >> >> &nbsp; &nbsp; elseif hash_on == "cookie" then&nbsp; >> >> &nbsp; &nbsp; &nbsp; &nbsp; chash_key = ctx.var["cookie_" .. key] >> >> &nbsp; &nbsp; &nbsp; &nbsp; -- TODO chash_key doesn't exist, set-cookie >> >> &nbsp; &nbsp; end >> >> &nbsp; &nbsp; if not chash_key then&nbsp; >> >> &nbsp; &nbsp; &nbsp; &nbsp; chash_key = ctx.var["remote_addr"] >> >> &nbsp; &nbsp; end >> >> &nbsp; &nbsp; 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? >> >> >> >> github issue: >> >> https://github.com/apache/incubator-apisix/issues/992 >> > >> > >> >
