You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@apisix.apache.org by codjust <hc...@foxmail.com> on 2020/01/05 14:25:31 UTC
回复: [DISCUSS] chash key support more flexible ways
PR is here: https://github.com/apache/incubator-apisix/pull/1022
welcome to review it together.
thx.
regards,
codjust
------------------ 原始邮件 ------------------
发件人: "Ming Wen"<wenming@apache.org>;
发送时间: 2019年12月30日(星期一) 上午8:26
收件人: "dev"<dev@apisix.apache.org>;
主题: Re: [DISCUSS] chash key support more flexible ways
cool, look forward to it.
Thanks,
Ming Wen, Apache APISIX
Twitter: _WenMing
codjust <hcw1003@foxmail.com> 于2019年12月29日周日 下午10:51写道:
> I will submit a PR later, please review it together.
>
>
> ------------------&nbsp;原始邮件&nbsp;------------------
> 发件人:&nbsp;"Ming Wen"<wenming@apache.org&gt;;
> 发送时间:&nbsp;2019年12月24日(星期二) 上午8:10
> 收件人:&nbsp;"dev"<dev@apisix.apache.org&gt;;
>
> 主题:&nbsp;Re: [DISCUSS] chash key support more flexible ways
>
>
>
> &gt;
> &gt; I do think we can learn this part from OpenResty Edge,
> &gt;
> 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
>
>
> 李凌 <lilien1010@gmail.com&gt; 于2019年12月23日周一 下午10:56写道:
>
> &gt; I do think we can learn this part from OpenResty Edge,
> &gt; also I like the idea that take a Chash key from Header ,which is
> pretty
> &gt; meaningful for us.
> &gt;
> &gt; [image: image.png]
> &gt;
> &gt;
> &gt; Ming Wen <wenming@apache.org&gt; 于2019年12月23日周一 下午9:04写道:
> &gt;
> &gt;&gt; yuansheng, what do you think?
> &gt;&gt;
> &gt;&gt; Thanks,
> &gt;&gt; Ming Wen, Apache APISIX
> &gt;&gt; Twitter: _WenMing
> &gt;&gt;
> &gt;&gt;
> &gt;&gt; Ming Wen <wenming@apache.org&gt; 于2019年12月23日周一 下午9:03写道:
> &gt;&gt;
> &gt;&gt; &gt; hi, codjust,
> &gt;&gt; &gt; I prefer your design than the existing one[1].
> &gt;&gt; &gt;
> &gt;&gt; &gt; These categories "vars", "header", "cookie", "consumer" are
> friendly for
> &gt;&gt; &gt; developer.
> &gt;&gt; &gt;
> &gt;&gt; &gt; [1]
> &gt;&gt; &gt;
> &gt;&gt;
> https://github.com/apache/incubator-apisix/blob/master/lua/apisix/schema_def.lua#L261
> &gt;&gt
> <https://github.com/apache/incubator-apisix/blob/master/lua/apisix/schema_def.lua#L261&gt;&gt>;
> &gt;
> &gt;&gt; &gt; Thanks,
> &gt;&gt; &gt; Ming Wen, Apache APISIX
> &gt;&gt; &gt; Twitter: _WenMing
> &gt;&gt; &gt;
> &gt;&gt; &gt;
> &gt;&gt; &gt; codjust <hcw1003@foxmail.com&gt; 于2019年12月23日周一 下午8:58写道:
> &gt;&gt; &gt;
> &gt;&gt; &gt;&gt; Now chash key only support fetch from nginx variable. We
> need to be
> &gt;&gt; more
> &gt;&gt; &gt;&gt; flexible approach,
> &gt;&gt; &gt;&gt; eg: cookie, custom header and so on.
> &gt;&gt; &gt;&gt; Here is an example to achieve:
> &gt;&gt; &gt;&gt; upstream json schema:
> &gt;&gt; &gt;&gt; hash_on = {
> &gt;&gt; &gt;&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;
> &amp;nbsp; type = "string",
> &gt;&gt; &gt;&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;
> &amp;nbsp; default = "vars",
> &gt;&gt; &gt;&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;
> &amp;nbsp; enum = {
> &gt;&gt; &gt;&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;
> &amp;nbsp; &amp;nbsp; "vars",
> &gt;&gt; &gt;&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;
> &amp;nbsp; &amp;nbsp; "header",
> &gt;&gt; &gt;&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;
> &amp;nbsp; &amp;nbsp; "cookie",
> &gt;&gt; &gt;&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;
> &amp;nbsp; &amp;nbsp; "consumer"
> &gt;&gt; &gt;&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;
> &amp;nbsp; },
> &gt;&gt; &gt;&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; },
> &gt;&gt; &gt;&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; key = {
> &gt;&gt; &gt;&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;
> &amp;nbsp; description = "the key of
> &gt;&gt; chash
> &gt;&gt; &gt;&gt; for dynamic load balancing",
> &gt;&gt; &gt;&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;
> &amp;nbsp; type = "string"
> &gt;&gt; &gt;&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; },
> &gt;&gt; &gt;&gt;
> &gt;&gt; &gt;&gt;
> &gt;&gt; &gt;&gt; eg:
> &gt;&gt; &gt;&gt; local function create_chash_hash_key(ctx, upstream)
> &gt;&gt; &gt;&gt; &amp;nbsp; &amp;nbsp; local key = upstream.key&amp;nbsp;
> &gt;&gt; &gt;&gt; &amp;nbsp; &amp;nbsp; local hash_on = upstream.hash_on
> &gt;&gt; &gt;&gt; &amp;nbsp; &amp;nbsp; local chash_key
> &gt;&gt; &gt;&gt; &amp;nbsp; &amp;nbsp; -- from nginx variable
> &gt;&gt; &gt;&gt; &amp;nbsp; &amp;nbsp; if hash_on == "vars" then&amp;nbsp;
> &gt;&gt; &gt;&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; chash_key =
> ctx.var[key]
> &gt;&gt; &gt;&gt; &amp;nbsp; &amp;nbsp; elseif hash_on == "header"
> then&amp;nbsp;
> &gt;&gt; &gt;&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; chash_key =
> ngx.req.get_headers()[key]
> &gt;&gt; &gt;&gt; &amp;nbsp; &amp;nbsp; elseif hash_on == "cookie"
> then&amp;nbsp;
> &gt;&gt; &gt;&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; chash_key =
> ctx.var["cookie_" .. key]
> &gt;&gt; &gt;&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; -- TODO
> chash_key doesn't exist, set-cookie
> &gt;&gt; &gt;&gt; &amp;nbsp; &amp;nbsp; end
> &gt;&gt; &gt;&gt; &amp;nbsp; &amp;nbsp; if not chash_key then&amp;nbsp;
> &gt;&gt; &gt;&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; chash_key =
> ctx.var["remote_addr"]
> &gt;&gt; &gt;&gt; &amp;nbsp; &amp;nbsp; end
> &gt;&gt; &gt;&gt; &amp;nbsp; &amp;nbsp; return chash_key
> &gt;&gt; &gt;&gt; end
> &gt;&gt; &gt;&gt;
> &gt;&gt; &gt;&gt;
> &gt;&gt; &gt;&gt; hash_on type desc:
> &gt;&gt; &gt;&gt; 1 vars: fetchs nginx variable
> &gt;&gt; &gt;&gt; 2 header: custom headers or standard http headers
> &gt;&gt; &gt;&gt; 3 cookie: fetch chash key from cookie. It can be used to
> sticky session
> &gt;&gt; &gt;&gt; 4 consumer: hash by consumer_id
> &gt;&gt; &gt;&gt; If the specified chash key is not present, use default
> key:
> &gt;&gt; &gt;&gt; remote_addr(it can also provide default settings).
> &gt;&gt; &gt;&gt;
> &gt;&gt; &gt;&gt;
> &gt;&gt; &gt;&gt; everybody have a better idea?
> &gt;&gt; &gt;&gt;
> &gt;&gt; &gt;&gt; github issue:
> &gt;&gt; &gt;&gt; https://github.com/apache/incubator-apisix/issues/992
> &gt;&gt <https://github.com/apache/incubator-apisix/issues/992&gt;&gt>;
> &gt;
> &gt;&gt; &gt;
> &gt;&gt;
> &gt;
Re: [DISCUSS] chash key support more flexible ways
Posted by Ming Wen <we...@apache.org>.
Hi, codjust,
good job, I will review this PR :)
Thanks,
Ming Wen, Apache APISIX
Twitter: _WenMing
codjust <hc...@foxmail.com> 于2020年1月5日周日 下午10:25写道:
> PR is here: https://github.com/apache/incubator-apisix/pull/1022
> welcome to review it together.
> thx.
>
>
> regards,
> codjust
>
> ------------------ 原始邮件 ------------------
> 发件人: "Ming Wen"<wenming@apache.org>;
> 发送时间: 2019年12月30日(星期一) 上午8:26
> 收件人: "dev"<dev@apisix.apache.org>;
>
> 主题: Re: [DISCUSS] chash key support more flexible ways
>
>
>
> cool, look forward to it.
>
> Thanks,
> Ming Wen, Apache APISIX
> Twitter: _WenMing
>
>
> codjust <hcw1003@foxmail.com> 于2019年12月29日周日 下午10:51写道:
>
> > I will submit a PR later, please review it together.
> >
> >
> > ------------------&nbsp;原始邮件&nbsp;------------------
> > 发件人:&nbsp;"Ming Wen"<wenming@apache.org&gt;;
> > 发送时间:&nbsp;2019年12月24日(星期二) 上午8:10
> > 收件人:&nbsp;"dev"<dev@apisix.apache.org&gt;;
> >
> > 主题:&nbsp;Re: [DISCUSS] chash key support more flexible ways
> >
> >
> >
> > &gt;
> > &gt; I do think we can learn this part from OpenResty Edge,
> > &gt;
> > 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
> >
> >
> > 李凌 <lilien1010@gmail.com&gt; 于2019年12月23日周一 下午10:56写道:
> >
> > &gt; I do think we can learn this part from OpenResty Edge,
> > &gt; also I like the idea that take a Chash key from Header
> ,which is
> > pretty
> > &gt; meaningful for us.
> > &gt;
> > &gt; [image: image.png]
> > &gt;
> > &gt;
> > &gt; Ming Wen <wenming@apache.org&gt; 于2019年12月23日周一
> 下午9:04写道:
> > &gt;
> > &gt;&gt; yuansheng, what do you think?
> > &gt;&gt;
> > &gt;&gt; Thanks,
> > &gt;&gt; Ming Wen, Apache APISIX
> > &gt;&gt; Twitter: _WenMing
> > &gt;&gt;
> > &gt;&gt;
> > &gt;&gt; Ming Wen <wenming@apache.org&gt; 于2019年12月23日周一
> 下午9:03写道:
> > &gt;&gt;
> > &gt;&gt; &gt; hi, codjust,
> > &gt;&gt; &gt; I prefer your design than the existing
> one[1].
> > &gt;&gt; &gt;
> > &gt;&gt; &gt; These categories "vars", "header",
> "cookie", "consumer" are
> > friendly for
> > &gt;&gt; &gt; developer.
> > &gt;&gt; &gt;
> > &gt;&gt; &gt; [1]
> > &gt;&gt; &gt;
> > &gt;&gt;
> >
> https://github.com/apache/incubator-apisix/blob/master/lua/apisix/schema_def.lua#L261
> >
> <https://github.com/apache/incubator-apisix/blob/master/lua/apisix/schema_def.lua#L261>>;
> &gt;&gt
> > <
> https://github.com/apache/incubator-apisix/blob/master/lua/apisix/schema_def.lua#L261&gt;&gt>
> ;;
> > &gt;
> > &gt;&gt; &gt; Thanks,
> > &gt;&gt; &gt; Ming Wen, Apache APISIX
> > &gt;&gt; &gt; Twitter: _WenMing
> > &gt;&gt; &gt;
> > &gt;&gt; &gt;
> > &gt;&gt; &gt; codjust <hcw1003@foxmail.com&gt;
> 于2019年12月23日周一 下午8:58写道:
> > &gt;&gt; &gt;
> > &gt;&gt; &gt;&gt; Now chash key only support fetch
> from nginx variable. We
> > need to be
> > &gt;&gt; more
> > &gt;&gt; &gt;&gt; flexible approach,
> > &gt;&gt; &gt;&gt; eg: cookie, custom header and so on.
> > &gt;&gt; &gt;&gt; Here is an example to achieve:
> > &gt;&gt; &gt;&gt; upstream json schema:
> > &gt;&gt; &gt;&gt; hash_on = {
> > &gt;&gt; &gt;&gt; &amp;nbsp; &amp;nbsp;
> &amp;nbsp; &amp;nbsp; &amp;nbsp;
> > &amp;nbsp; type = "string",
> > &gt;&gt; &gt;&gt; &amp;nbsp; &amp;nbsp;
> &amp;nbsp; &amp;nbsp; &amp;nbsp;
> > &amp;nbsp; default = "vars",
> > &gt;&gt; &gt;&gt; &amp;nbsp; &amp;nbsp;
> &amp;nbsp; &amp;nbsp; &amp;nbsp;
> > &amp;nbsp; enum = {
> > &gt;&gt; &gt;&gt; &amp;nbsp; &amp;nbsp;
> &amp;nbsp; &amp;nbsp; &amp;nbsp;
> > &amp;nbsp; &amp;nbsp; "vars",
> > &gt;&gt; &gt;&gt; &amp;nbsp; &amp;nbsp;
> &amp;nbsp; &amp;nbsp; &amp;nbsp;
> > &amp;nbsp; &amp;nbsp; "header",
> > &gt;&gt; &gt;&gt; &amp;nbsp; &amp;nbsp;
> &amp;nbsp; &amp;nbsp; &amp;nbsp;
> > &amp;nbsp; &amp;nbsp; "cookie",
> > &gt;&gt; &gt;&gt; &amp;nbsp; &amp;nbsp;
> &amp;nbsp; &amp;nbsp; &amp;nbsp;
> > &amp;nbsp; &amp;nbsp; "consumer"
> > &gt;&gt; &gt;&gt; &amp;nbsp; &amp;nbsp;
> &amp;nbsp; &amp;nbsp; &amp;nbsp;
> > &amp;nbsp; },
> > &gt;&gt; &gt;&gt; &amp;nbsp; &amp;nbsp;
> &amp;nbsp; &amp;nbsp; },
> > &gt;&gt; &gt;&gt; &amp;nbsp; &amp;nbsp;
> &amp;nbsp; &amp;nbsp; key = {
> > &gt;&gt; &gt;&gt; &amp;nbsp; &amp;nbsp;
> &amp;nbsp; &amp;nbsp; &amp;nbsp;
> > &amp;nbsp; description = "the key of
> > &gt;&gt; chash
> > &gt;&gt; &gt;&gt; for dynamic load balancing",
> > &gt;&gt; &gt;&gt; &amp;nbsp; &amp;nbsp;
> &amp;nbsp; &amp;nbsp; &amp;nbsp;
> > &amp;nbsp; type = "string"
> > &gt;&gt; &gt;&gt; &amp;nbsp; &amp;nbsp;
> &amp;nbsp; &amp;nbsp; },
> > &gt;&gt; &gt;&gt;
> > &gt;&gt; &gt;&gt;
> > &gt;&gt; &gt;&gt; eg:
> > &gt;&gt; &gt;&gt; local function
> create_chash_hash_key(ctx, upstream)
> > &gt;&gt; &gt;&gt; &amp;nbsp; &amp;nbsp; local
> key = upstream.key&amp;nbsp;
> > &gt;&gt; &gt;&gt; &amp;nbsp; &amp;nbsp; local
> hash_on = upstream.hash_on
> > &gt;&gt; &gt;&gt; &amp;nbsp; &amp;nbsp; local
> chash_key
> > &gt;&gt; &gt;&gt; &amp;nbsp; &amp;nbsp; --
> from nginx variable
> > &gt;&gt; &gt;&gt; &amp;nbsp; &amp;nbsp; if
> hash_on == "vars" then&amp;nbsp;
> > &gt;&gt; &gt;&gt; &amp;nbsp; &amp;nbsp;
> &amp;nbsp; &amp;nbsp; chash_key =
> > ctx.var[key]
> > &gt;&gt; &gt;&gt; &amp;nbsp; &amp;nbsp;
> elseif hash_on == "header"
> > then&amp;nbsp;
> > &gt;&gt; &gt;&gt; &amp;nbsp; &amp;nbsp;
> &amp;nbsp; &amp;nbsp; chash_key =
> > ngx.req.get_headers()[key]
> > &gt;&gt; &gt;&gt; &amp;nbsp; &amp;nbsp;
> elseif hash_on == "cookie"
> > then&amp;nbsp;
> > &gt;&gt; &gt;&gt; &amp;nbsp; &amp;nbsp;
> &amp;nbsp; &amp;nbsp; chash_key =
> > ctx.var["cookie_" .. key]
> > &gt;&gt; &gt;&gt; &amp;nbsp; &amp;nbsp;
> &amp;nbsp; &amp;nbsp; -- TODO
> > chash_key doesn't exist, set-cookie
> > &gt;&gt; &gt;&gt; &amp;nbsp; &amp;nbsp; end
> > &gt;&gt; &gt;&gt; &amp;nbsp; &amp;nbsp; if
> not chash_key then&amp;nbsp;
> > &gt;&gt; &gt;&gt; &amp;nbsp; &amp;nbsp;
> &amp;nbsp; &amp;nbsp; chash_key =
> > ctx.var["remote_addr"]
> > &gt;&gt; &gt;&gt; &amp;nbsp; &amp;nbsp; end
> > &gt;&gt; &gt;&gt; &amp;nbsp; &amp;nbsp;
> return chash_key
> > &gt;&gt; &gt;&gt; end
> > &gt;&gt; &gt;&gt;
> > &gt;&gt; &gt;&gt;
> > &gt;&gt; &gt;&gt; hash_on type desc:
> > &gt;&gt; &gt;&gt; 1 vars: fetchs nginx variable
> > &gt;&gt; &gt;&gt; 2 header: custom headers or
> standard http headers
> > &gt;&gt; &gt;&gt; 3 cookie: fetch chash key from
> cookie. It can be used to
> > sticky session
> > &gt;&gt; &gt;&gt; 4 consumer: hash by consumer_id
> > &gt;&gt; &gt;&gt; If the specified chash key is not
> present, use default
> > key:
> > &gt;&gt; &gt;&gt; remote_addr(it can also provide
> default settings).
> > &gt;&gt; &gt;&gt;
> > &gt;&gt; &gt;&gt;
> > &gt;&gt; &gt;&gt; everybody have a better idea?
> > &gt;&gt; &gt;&gt;
> > &gt;&gt; &gt;&gt; github issue:
> > &gt;&gt; &gt;&gt;
> https://github.com/apache/incubator-apisix/issues/992
> > <https://github.com/apache/incubator-apisix/issues/992>>;
> &gt;&gt <
> https://github.com/apache/incubator-apisix/issues/992&gt;&gt>;
> > &gt;
> > &gt;&gt; &gt;
> > &gt;&gt;
> > &gt;