my last email image should be:
https://sh-ht.oss-cn-shanghai.aliyuncs.com/cimg/sh-ht/web_20191223/900866_a74e7cb48163ab29b21cfd6486f89867.png


李凌 <[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.
>
>
>
>
> 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
>> >
>> >

Reply via email to