You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@apisix.apache.org by "Li Ling(Lien)" <li...@apache.org> on 2020/08/05 13:15:37 UTC

[DISCUSS] How about have geoip variables available in conditional routing

rencently I am thinking about have Geo routing in APISIX,
scenario:
    1、I want route user‘s request from country request intoto different
upstream host.
    2、When users from outside China redirect to international homepage(many
video sites like youku.com they ban users from outside china).


here is two solution I digged into:

1、intergrate nginx module https://github.com/leev/ngx_http_geoip2_module and
do variable matching.
     disadvantage: we need calculate the geo data from ip info for every
request,which is so inefficient.


2、https://luarocks.org/modules/agladysh/lua-geoip
     intergrate this lua module into lua-resty-radixtree, when geo_ip_*
parameter is set in the routes, we calculate the ip country info from geoip
library.so  that  it wont calculate the geo data for each request.

Re: [DISCUSS] How about have geoip variables available in conditional routing

Posted by YuanSheng Wang <me...@apache.org>.
On Fri, Aug 14, 2020 at 9:01 PM vincixu <vi...@apache.org> wrote:

> Not every request, just the requests which enable the geo plugin.
>

We can not get the plugin list before matching route.
That is why I advise we should support to fetch `city` info from `ctx.var`.


>
> YuanSheng Wang <me...@apache.org> 于2020年8月14日周五 下午3:17写道:
>
> > > parse IP to city(or any geo results) and put it to header before route
> > matching
> >
> > we can not do this before route matching for every request.  For example,
> > not all routes
> > require user city information.
> >
> > we should only do the parse when we need it. and we only parse the info
> we
> > need.
> >
> > so the `ctx.var` is a good way for us.
> >
> >
> > On Fri, Aug 14, 2020 at 9:47 AM vincixu <vi...@apache.org> wrote:
> >
> > > I think APISIX has already supported it.All we need to do is just parse
> > IP
> > > to city(or any geo results) and put it to header before route matching,
> > so
> > > users could define route with parsed result.
> > > Am I misunderstanding something?
> > >
> >
> >
> > --
> >
> > *MembPhis*
> > My GitHub: https://github.com/membphis
> > Apache APISIX: https://github.com/apache/incubator-apisix
> >
>


-- 

*MembPhis*
My GitHub: https://github.com/membphis
Apache APISIX: https://github.com/apache/incubator-apisix

Re: [DISCUSS] How about have geoip variables available in conditional routing

Posted by vincixu <vi...@apache.org>.
Not every request, just the requests which enable the geo plugin.

YuanSheng Wang <me...@apache.org> 于2020年8月14日周五 下午3:17写道:

> > parse IP to city(or any geo results) and put it to header before route
> matching
>
> we can not do this before route matching for every request.  For example,
> not all routes
> require user city information.
>
> we should only do the parse when we need it. and we only parse the info we
> need.
>
> so the `ctx.var` is a good way for us.
>
>
> On Fri, Aug 14, 2020 at 9:47 AM vincixu <vi...@apache.org> wrote:
>
> > I think APISIX has already supported it.All we need to do is just parse
> IP
> > to city(or any geo results) and put it to header before route matching,
> so
> > users could define route with parsed result.
> > Am I misunderstanding something?
> >
>
>
> --
>
> *MembPhis*
> My GitHub: https://github.com/membphis
> Apache APISIX: https://github.com/apache/incubator-apisix
>

Re: [DISCUSS] How about have geoip variables available in conditional routing

Posted by YuanSheng Wang <me...@apache.org>.
> parse IP to city(or any geo results) and put it to header before route
matching

we can not do this before route matching for every request.  For example,
not all routes
require user city information.

we should only do the parse when we need it. and we only parse the info we
need.

so the `ctx.var` is a good way for us.


On Fri, Aug 14, 2020 at 9:47 AM vincixu <vi...@apache.org> wrote:

> I think APISIX has already supported it.All we need to do is just parse IP
> to city(or any geo results) and put it to header before route matching, so
> users could define route with parsed result.
> Am I misunderstanding something?
>


-- 

*MembPhis*
My GitHub: https://github.com/membphis
Apache APISIX: https://github.com/apache/incubator-apisix

Re: [DISCUSS] How about have geoip variables available in conditional routing

Posted by vincixu <vi...@apache.org>.
I think APISIX has already supported it.All we need to do is just parse IP
to city(or any geo results) and put it to header before route matching, so
users could define route with parsed result.
Am I misunderstanding something?

Re: [DISCUSS] How about have geoip variables available in conditional routing

Posted by YuanSheng Wang <me...@apache.org>.
On Sun, Aug 9, 2020 at 2:20 PM Ming Wen <we...@apache.org> wrote:

> You misunderstood the meaning of vinci and me.
> We hope to use plugin to do the parse from IP to city etc., not how to use
> it in plugin.


> We hope to use plugin to do the parse from IP to city etc.,

It only supports parsing the IP into a city in the plug-in, which is not
enough.
We should allow users to use `city` in `routers` or `plugins`, need to
support them
at the same time.


>
> YuanSheng Wang <me...@apache.org> 于 2020年8月9日周日 下午1:37写道:
>
> > On Fri, Aug 7, 2020 at 3:34 PM vincixu <vi...@apache.org> wrote:
> >
> > > This example is about how to route request.
> > >
> >
> > ```
> > -- plugin
> >
> > function _M.access(conf, ctx)
> >     local client_city = ctx.var.geoip_city
> >     -- your code
> > end
> > ```
> >
> > that is the way how to use it in the plugin. I think it is an easy way.
> >
> > Here is the way we get the cookie item [1] from `vars`, we can use the
> same
> > way.
> >
> > [1] https://github.com/apache/apisix/blob/master/apisix/core/ctx.lua#L76
> >
> >
> > > I think before this, we should talk about how to convert "geoip" to the
> > > "geoip_city": using plugin or other ways.
> > >
> > > YuanSheng Wang <me...@apache.org> 于2020年8月7日周五 下午12:38写道:
> > >
> > > > Here are two examples:
> > > >
> > > > ```
> > > > # route
> > > > $ curl http://127.0.0.1:9080/apisix/admin/routes/1 -X PUT -i -d '
> > > > {
> > > >     "uri": "/index.html",
> > > >     "vars": [
> > > >         ["geoip_city", "==", "beijing"],
> > > >     ],
> > > >     "upstream": {
> > > >         "type": "roundrobin",
> > > >         "nodes": {
> > > >             "127.0.0.1:80": 1
> > > >         }
> > > >     }
> > > > }'
> > > > ```
> > > >
> > > > ```
> > > > -- plugin
> > > >
> > > > function _M.access(conf, ctx)
> > > >     local client_city = ctx.var.geoip_city
> > > >     -- your code
> > > > end
> > > > ```
> > > >
> > > > On Fri, Aug 7, 2020 at 9:53 AM YuanSheng Wang <me...@apache.org>
> > > wrote:
> > > >
> > > > > > > only get geo_city info  when the geoip condition is set, we
> don't
> > > > need
> > > > > > > calculate ip geo information for every request.
> > > > > > agreed, geo_ip should not calculated ervery request.
> > > > >
> > > > > please take a look at the `cookie` of `vars` [1]. we should use the
> > > same
> > > > > way.
> > > > >
> > > > > If we refer to geoip variables, the GeoIP library will be called to
> > get
> > > > > the value.
> > > > > If we do not refer to these variables, the GeoIP library will never
> > be
> > > > > called.
> > > > >
> > > > > > The request condition can not only be placed on the `route`, but
> > the
> > > > > plugin
> > > > > > also has this capability.
> > > > >
> > > > > `vars` is the easiest way to support both `route` and `plugin`.
> > > > >
> > > > > [1]
> > > https://github.com/apache/apisix/blob/master/apisix/core/ctx.lua#L76
> > > > >
> > > > >
> > > > >
> > > > >> > integrate maxmind code into lua-resty-radixtree, only when the
> > route
> > > > >> with
> > > > >> > geo condition is matched , then we calculate the geo ip info.
> > > > >> so why not take geo_ip as a plugin?
> > > > >> Plugin orchestration is particularly well suited for this.
> > > > >> The request condition can not only be placed on the route, but the
> > > > plugin
> > > > >> also has this capability.
> > > > >>
> > > > >> Thanks,
> > > > >> Ming Wen, Apache APISIX & Apache SkyWalking
> > > > >> Twitter: _WenMing
> > > > >>
> > > > >>
> > > > >> Li Ling(Lien) <li...@apache.org> 于2020年8月6日周四 下午7:29写道:
> > > > >>
> > > > >> > IMO,the the geoip-route is a feature of *route* module,it
> > shouldn't
> > > > >> > involved with vars module,
> > > > >> > and only get geo_city info  when the geoip condition is set, we
> > > don't
> > > > >> need
> > > > >> > calculate ip geo information for every request.
> > > > >> >
> > > > >> > here is my solution:
> > > > >> >   integrate maxmind code into lua-resty-radixtree, only when the
> > > route
> > > > >> with
> > > > >> > geo condition is matched , then we calculate the geo ip info.
> > > > >> >
> > > > >> > YuanSheng Wang <me...@apache.org> 于2020年8月6日周四 下午6:00写道:
> > > > >> >
> > > > >> > > >   1、I want route user‘s request from country request into
> > > > different
> > > > >> > > upstream
> > > > >> > > host.
> > > > >> > >
> > > > >> > > I think AIPSIX needs to support this feature. it is a useful
> > > feature
> > > > >> for
> > > > >> > > the user.
> > > > >> > > We do not need to update `resty-radixtree`, only update
> > `ctx.vars`
> > > > is
> > > > >> > > enough.
> > > > >> > >
> > > > >> > > for example, a way to get the city: `ctx.vars.geo_city` .
> > > > >> > >
> > > > >> > > Then the users can use it in `route` or `plugin`, both of the
> > way
> > > > are
> > > > >> > fine.
> > > > >> > >
> > > > >> > > On Thu, Aug 6, 2020 at 8:55 AM Ming Wen <we...@apache.org>
> > > wrote:
> > > > >> > >
> > > > >> > > > Optional features should be implemented by plugins,
> > > > >> > > > and the core should be keep simple.
> > > > >> > > >
> > > > >> > > > Thanks,
> > > > >> > > > Ming Wen, Apache APISIX & Apache SkyWalking
> > > > >> > > > Twitter: _WenMing
> > > > >> > > >
> > > > >> > > >
> > > > >> > > > YuanSheng Wang <me...@apache.org> 于2020年8月6日周四 上午8:28写道:
> > > > >> > > >
> > > > >> > > > > On Thu, Aug 6, 2020 at 7:39 AM Ming Wen <
> wenming@apache.org
> > >
> > > > >> wrote:
> > > > >> > > > >
> > > > >> > > > > > IMO, implement geo_ip as plugin is better, not in the
> > route.
> > > > >> > > > > >
> > > > >> > > > >
> > > > >> > > > > I would like to implement it in `route`.
> > > > >> > > > >
> > > > >> > > > > It may be a condition, we can support it in `vars'.
> > > > >> > > > >
> > > > >> > > > >
> > > > >> > > > > >
> > > > >> > > > > > And https://luarocks.org/modules/agladysh/lua-geoip is
> > not
> > > a
> > > > >> good
> > > > >> > > > > > approach,
> > > > >> > > > > > lua-resty-maxminddb[1] is good for APISIX.
> > > > >> > > > > >
> > > > >> > > > >
> > > > >> > > > > this library is better. agree +1
> > > > >> > > > >
> > > > >> > > > >
> > > > >> > > > > >
> > > > >> > > > > > [1] https://github.com/anjia0532/lua-resty-maxminddb
> > > > >> > > > > >
> > > > >> > > > > > Thanks,
> > > > >> > > > > > Ming Wen, Apache APISIX & Apache SkyWalking
> > > > >> > > > > > Twitter: _WenMing
> > > > >> > > > > >
> > > > >> > > > > >
> > > > >> > > > > > JinChao Shuai <sh...@apache.org> 于2020年8月6日周四
> > > > 上午1:47写道:
> > > > >> > > > > >
> > > > >> > > > > > > I also agree with the second approach and to `Yansheng
> > > Wang`
> > > > >> that
> > > > >> > > > users
> > > > >> > > > > > can
> > > > >> > > > > > > use their own GeoIP database.
> > > > >> > > > > > >
> > > > >> > > > > > > YuanSheng Wang <me...@apache.org> 于2020年8月5日周三
> > > > 下午11:40写道:
> > > > >> > > > > > >
> > > > >> > > > > > > > Of course, the second way is better for APISIX.
> > > > >> > > > > > > >
> > > > >> > > > > > > > The `lua-geoip` is under Dual license, we need to
> > > confirm
> > > > >> if we
> > > > >> > > can
> > > > >> > > > > use
> > > > >> > > > > > > > this library.
> > > > >> > > > > > > >
> > > > >> > > > > > > > The users needs to download the GeoIP database by
> > > himself,
> > > > >> > Apache
> > > > >> > > > > > APISIX
> > > > >> > > > > > > > can
> > > > >> > > > > > > > not ship with the GeoIP data(under LGPL 2.1).
> > > > >> > > > > > > >
> > > > >> > > > > > > >
> > > > >> > > > > > > > On Wed, Aug 5, 2020 at 9:16 PM Li Ling(Lien) <
> > > > >> > liling@apache.org>
> > > > >> > > > > > wrote:
> > > > >> > > > > > > >
> > > > >> > > > > > > > > rencently I am thinking about have Geo routing in
> > > > APISIX,
> > > > >> > > > > > > > > scenario:
> > > > >> > > > > > > > >     1、I want route user‘s request from country
> > request
> > > > >> intoto
> > > > >> > > > > > different
> > > > >> > > > > > > > > upstream host.
> > > > >> > > > > > > > >     2、When users from outside China redirect to
> > > > >> international
> > > > >> > > > > > > > homepage(many
> > > > >> > > > > > > > > video sites like youku.com they ban users from
> > > outside
> > > > >> > china).
> > > > >> > > > > > > > >
> > > > >> > > > > > > > >
> > > > >> > > > > > > > > here is two solution I digged into:
> > > > >> > > > > > > > >
> > > > >> > > > > > > > > 1、intergrate nginx module
> > > > >> > > > > > > https://github.com/leev/ngx_http_geoip2_module
> > > > >> > > > > > > > > and
> > > > >> > > > > > > > > do variable matching.
> > > > >> > > > > > > > >      disadvantage: we need calculate the geo data
> > from
> > > > ip
> > > > >> > info
> > > > >> > > > for
> > > > >> > > > > > > every
> > > > >> > > > > > > > > request,which is so inefficient.
> > > > >> > > > > > > > >
> > > > >> > > > > > > > >
> > > > >> > > > > > > > > 2、https://luarocks.org/modules/agladysh/lua-geoip
> > > > >> > > > > > > > >      intergrate this lua module into
> > > > lua-resty-radixtree,
> > > > >> > when
> > > > >> > > > > > geo_ip_*
> > > > >> > > > > > > > > parameter is set in the routes, we calculate the
> ip
> > > > >> country
> > > > >> > > info
> > > > >> > > > > from
> > > > >> > > > > > > > geoip
> > > > >> > > > > > > > > library.so  that  it wont calculate the geo data
> for
> > > > each
> > > > >> > > > request.
> > > > >> > > > > > > > >
> > > > >> > > > > > > >
> > > > >> > > > > > > >
> > > > >> > > > > > > > --
> > > > >> > > > > > > >
> > > > >> > > > > > > > *MembPhis*
> > > > >> > > > > > > > My GitHub: https://github.com/membphis
> > > > >> > > > > > > > Apache APISIX:
> > > https://github.com/apache/incubator-apisix
> > > > >> > > > > > > >
> > > > >> > > > > > >
> > > > >> > > > > > >
> > > > >> > > > > > > --
> > > > >> > > > > > > Thanks,
> > > > >> > > > > > > Janko
> > > > >> > > > > > >
> > > > >> > > > > >
> > > > >> > > > >
> > > > >> > > > >
> > > > >> > > > > --
> > > > >> > > > >
> > > > >> > > > > *MembPhis*
> > > > >> > > > > My GitHub: https://github.com/membphis
> > > > >> > > > > Apache APISIX: https://github.com/apache/incubator-apisix
> > > > >> > > > >
> > > > >> > > >
> > > > >> > >
> > > > >> > >
> > > > >> > > --
> > > > >> > >
> > > > >> > > *MembPhis*
> > > > >> > > My GitHub: https://github.com/membphis
> > > > >> > > Apache APISIX: https://github.com/apache/incubator-apisix
> > > > >> > >
> > > > >> >
> > > > >>
> > > > >
> > > > >
> > > > > --
> > > > >
> > > > > *MembPhis*
> > > > > My GitHub: https://github.com/membphis
> > > > > Apache APISIX: https://github.com/apache/incubator-apisix
> > > > >
> > > >
> > > >
> > > > --
> > > >
> > > > *MembPhis*
> > > > My GitHub: https://github.com/membphis
> > > > Apache APISIX: https://github.com/apache/incubator-apisix
> > > >
> > >
> >
> >
> > --
> >
> > *MembPhis*
> > My GitHub: https://github.com/membphis
> > Apache APISIX: https://github.com/apache/incubator-apisix
> >
>


-- 

*MembPhis*
My GitHub: https://github.com/membphis
Apache APISIX: https://github.com/apache/incubator-apisix

Re: [DISCUSS] How about have geoip variables available in conditional routing

Posted by Ming Wen <we...@apache.org>.
You misunderstood the meaning of vinci and me.
We hope to use plugin to do the parse from IP to city etc., not how to use
it in plugin.

YuanSheng Wang <me...@apache.org> 于 2020年8月9日周日 下午1:37写道:

> On Fri, Aug 7, 2020 at 3:34 PM vincixu <vi...@apache.org> wrote:
>
> > This example is about how to route request.
> >
>
> ```
> -- plugin
>
> function _M.access(conf, ctx)
>     local client_city = ctx.var.geoip_city
>     -- your code
> end
> ```
>
> that is the way how to use it in the plugin. I think it is an easy way.
>
> Here is the way we get the cookie item [1] from `vars`, we can use the same
> way.
>
> [1] https://github.com/apache/apisix/blob/master/apisix/core/ctx.lua#L76
>
>
> > I think before this, we should talk about how to convert "geoip" to the
> > "geoip_city": using plugin or other ways.
> >
> > YuanSheng Wang <me...@apache.org> 于2020年8月7日周五 下午12:38写道:
> >
> > > Here are two examples:
> > >
> > > ```
> > > # route
> > > $ curl http://127.0.0.1:9080/apisix/admin/routes/1 -X PUT -i -d '
> > > {
> > >     "uri": "/index.html",
> > >     "vars": [
> > >         ["geoip_city", "==", "beijing"],
> > >     ],
> > >     "upstream": {
> > >         "type": "roundrobin",
> > >         "nodes": {
> > >             "127.0.0.1:80": 1
> > >         }
> > >     }
> > > }'
> > > ```
> > >
> > > ```
> > > -- plugin
> > >
> > > function _M.access(conf, ctx)
> > >     local client_city = ctx.var.geoip_city
> > >     -- your code
> > > end
> > > ```
> > >
> > > On Fri, Aug 7, 2020 at 9:53 AM YuanSheng Wang <me...@apache.org>
> > wrote:
> > >
> > > > > > only get geo_city info  when the geoip condition is set, we don't
> > > need
> > > > > > calculate ip geo information for every request.
> > > > > agreed, geo_ip should not calculated ervery request.
> > > >
> > > > please take a look at the `cookie` of `vars` [1]. we should use the
> > same
> > > > way.
> > > >
> > > > If we refer to geoip variables, the GeoIP library will be called to
> get
> > > > the value.
> > > > If we do not refer to these variables, the GeoIP library will never
> be
> > > > called.
> > > >
> > > > > The request condition can not only be placed on the `route`, but
> the
> > > > plugin
> > > > > also has this capability.
> > > >
> > > > `vars` is the easiest way to support both `route` and `plugin`.
> > > >
> > > > [1]
> > https://github.com/apache/apisix/blob/master/apisix/core/ctx.lua#L76
> > > >
> > > >
> > > >
> > > >> > integrate maxmind code into lua-resty-radixtree, only when the
> route
> > > >> with
> > > >> > geo condition is matched , then we calculate the geo ip info.
> > > >> so why not take geo_ip as a plugin?
> > > >> Plugin orchestration is particularly well suited for this.
> > > >> The request condition can not only be placed on the route, but the
> > > plugin
> > > >> also has this capability.
> > > >>
> > > >> Thanks,
> > > >> Ming Wen, Apache APISIX & Apache SkyWalking
> > > >> Twitter: _WenMing
> > > >>
> > > >>
> > > >> Li Ling(Lien) <li...@apache.org> 于2020年8月6日周四 下午7:29写道:
> > > >>
> > > >> > IMO,the the geoip-route is a feature of *route* module,it
> shouldn't
> > > >> > involved with vars module,
> > > >> > and only get geo_city info  when the geoip condition is set, we
> > don't
> > > >> need
> > > >> > calculate ip geo information for every request.
> > > >> >
> > > >> > here is my solution:
> > > >> >   integrate maxmind code into lua-resty-radixtree, only when the
> > route
> > > >> with
> > > >> > geo condition is matched , then we calculate the geo ip info.
> > > >> >
> > > >> > YuanSheng Wang <me...@apache.org> 于2020年8月6日周四 下午6:00写道:
> > > >> >
> > > >> > > >   1、I want route user‘s request from country request into
> > > different
> > > >> > > upstream
> > > >> > > host.
> > > >> > >
> > > >> > > I think AIPSIX needs to support this feature. it is a useful
> > feature
> > > >> for
> > > >> > > the user.
> > > >> > > We do not need to update `resty-radixtree`, only update
> `ctx.vars`
> > > is
> > > >> > > enough.
> > > >> > >
> > > >> > > for example, a way to get the city: `ctx.vars.geo_city` .
> > > >> > >
> > > >> > > Then the users can use it in `route` or `plugin`, both of the
> way
> > > are
> > > >> > fine.
> > > >> > >
> > > >> > > On Thu, Aug 6, 2020 at 8:55 AM Ming Wen <we...@apache.org>
> > wrote:
> > > >> > >
> > > >> > > > Optional features should be implemented by plugins,
> > > >> > > > and the core should be keep simple.
> > > >> > > >
> > > >> > > > Thanks,
> > > >> > > > Ming Wen, Apache APISIX & Apache SkyWalking
> > > >> > > > Twitter: _WenMing
> > > >> > > >
> > > >> > > >
> > > >> > > > YuanSheng Wang <me...@apache.org> 于2020年8月6日周四 上午8:28写道:
> > > >> > > >
> > > >> > > > > On Thu, Aug 6, 2020 at 7:39 AM Ming Wen <wenming@apache.org
> >
> > > >> wrote:
> > > >> > > > >
> > > >> > > > > > IMO, implement geo_ip as plugin is better, not in the
> route.
> > > >> > > > > >
> > > >> > > > >
> > > >> > > > > I would like to implement it in `route`.
> > > >> > > > >
> > > >> > > > > It may be a condition, we can support it in `vars'.
> > > >> > > > >
> > > >> > > > >
> > > >> > > > > >
> > > >> > > > > > And https://luarocks.org/modules/agladysh/lua-geoip is
> not
> > a
> > > >> good
> > > >> > > > > > approach,
> > > >> > > > > > lua-resty-maxminddb[1] is good for APISIX.
> > > >> > > > > >
> > > >> > > > >
> > > >> > > > > this library is better. agree +1
> > > >> > > > >
> > > >> > > > >
> > > >> > > > > >
> > > >> > > > > > [1] https://github.com/anjia0532/lua-resty-maxminddb
> > > >> > > > > >
> > > >> > > > > > Thanks,
> > > >> > > > > > Ming Wen, Apache APISIX & Apache SkyWalking
> > > >> > > > > > Twitter: _WenMing
> > > >> > > > > >
> > > >> > > > > >
> > > >> > > > > > JinChao Shuai <sh...@apache.org> 于2020年8月6日周四
> > > 上午1:47写道:
> > > >> > > > > >
> > > >> > > > > > > I also agree with the second approach and to `Yansheng
> > Wang`
> > > >> that
> > > >> > > > users
> > > >> > > > > > can
> > > >> > > > > > > use their own GeoIP database.
> > > >> > > > > > >
> > > >> > > > > > > YuanSheng Wang <me...@apache.org> 于2020年8月5日周三
> > > 下午11:40写道:
> > > >> > > > > > >
> > > >> > > > > > > > Of course, the second way is better for APISIX.
> > > >> > > > > > > >
> > > >> > > > > > > > The `lua-geoip` is under Dual license, we need to
> > confirm
> > > >> if we
> > > >> > > can
> > > >> > > > > use
> > > >> > > > > > > > this library.
> > > >> > > > > > > >
> > > >> > > > > > > > The users needs to download the GeoIP database by
> > himself,
> > > >> > Apache
> > > >> > > > > > APISIX
> > > >> > > > > > > > can
> > > >> > > > > > > > not ship with the GeoIP data(under LGPL 2.1).
> > > >> > > > > > > >
> > > >> > > > > > > >
> > > >> > > > > > > > On Wed, Aug 5, 2020 at 9:16 PM Li Ling(Lien) <
> > > >> > liling@apache.org>
> > > >> > > > > > wrote:
> > > >> > > > > > > >
> > > >> > > > > > > > > rencently I am thinking about have Geo routing in
> > > APISIX,
> > > >> > > > > > > > > scenario:
> > > >> > > > > > > > >     1、I want route user‘s request from country
> request
> > > >> intoto
> > > >> > > > > > different
> > > >> > > > > > > > > upstream host.
> > > >> > > > > > > > >     2、When users from outside China redirect to
> > > >> international
> > > >> > > > > > > > homepage(many
> > > >> > > > > > > > > video sites like youku.com they ban users from
> > outside
> > > >> > china).
> > > >> > > > > > > > >
> > > >> > > > > > > > >
> > > >> > > > > > > > > here is two solution I digged into:
> > > >> > > > > > > > >
> > > >> > > > > > > > > 1、intergrate nginx module
> > > >> > > > > > > https://github.com/leev/ngx_http_geoip2_module
> > > >> > > > > > > > > and
> > > >> > > > > > > > > do variable matching.
> > > >> > > > > > > > >      disadvantage: we need calculate the geo data
> from
> > > ip
> > > >> > info
> > > >> > > > for
> > > >> > > > > > > every
> > > >> > > > > > > > > request,which is so inefficient.
> > > >> > > > > > > > >
> > > >> > > > > > > > >
> > > >> > > > > > > > > 2、https://luarocks.org/modules/agladysh/lua-geoip
> > > >> > > > > > > > >      intergrate this lua module into
> > > lua-resty-radixtree,
> > > >> > when
> > > >> > > > > > geo_ip_*
> > > >> > > > > > > > > parameter is set in the routes, we calculate the ip
> > > >> country
> > > >> > > info
> > > >> > > > > from
> > > >> > > > > > > > geoip
> > > >> > > > > > > > > library.so  that  it wont calculate the geo data for
> > > each
> > > >> > > > request.
> > > >> > > > > > > > >
> > > >> > > > > > > >
> > > >> > > > > > > >
> > > >> > > > > > > > --
> > > >> > > > > > > >
> > > >> > > > > > > > *MembPhis*
> > > >> > > > > > > > My GitHub: https://github.com/membphis
> > > >> > > > > > > > Apache APISIX:
> > https://github.com/apache/incubator-apisix
> > > >> > > > > > > >
> > > >> > > > > > >
> > > >> > > > > > >
> > > >> > > > > > > --
> > > >> > > > > > > Thanks,
> > > >> > > > > > > Janko
> > > >> > > > > > >
> > > >> > > > > >
> > > >> > > > >
> > > >> > > > >
> > > >> > > > > --
> > > >> > > > >
> > > >> > > > > *MembPhis*
> > > >> > > > > My GitHub: https://github.com/membphis
> > > >> > > > > Apache APISIX: https://github.com/apache/incubator-apisix
> > > >> > > > >
> > > >> > > >
> > > >> > >
> > > >> > >
> > > >> > > --
> > > >> > >
> > > >> > > *MembPhis*
> > > >> > > My GitHub: https://github.com/membphis
> > > >> > > Apache APISIX: https://github.com/apache/incubator-apisix
> > > >> > >
> > > >> >
> > > >>
> > > >
> > > >
> > > > --
> > > >
> > > > *MembPhis*
> > > > My GitHub: https://github.com/membphis
> > > > Apache APISIX: https://github.com/apache/incubator-apisix
> > > >
> > >
> > >
> > > --
> > >
> > > *MembPhis*
> > > My GitHub: https://github.com/membphis
> > > Apache APISIX: https://github.com/apache/incubator-apisix
> > >
> >
>
>
> --
>
> *MembPhis*
> My GitHub: https://github.com/membphis
> Apache APISIX: https://github.com/apache/incubator-apisix
>

Re: [DISCUSS] How about have geoip variables available in conditional routing

Posted by YuanSheng Wang <me...@apache.org>.
On Fri, Aug 7, 2020 at 3:34 PM vincixu <vi...@apache.org> wrote:

> This example is about how to route request.
>

```
-- plugin

function _M.access(conf, ctx)
    local client_city = ctx.var.geoip_city
    -- your code
end
```

that is the way how to use it in the plugin. I think it is an easy way.

Here is the way we get the cookie item [1] from `vars`, we can use the same
way.

[1] https://github.com/apache/apisix/blob/master/apisix/core/ctx.lua#L76


> I think before this, we should talk about how to convert "geoip" to the
> "geoip_city": using plugin or other ways.
>
> YuanSheng Wang <me...@apache.org> 于2020年8月7日周五 下午12:38写道:
>
> > Here are two examples:
> >
> > ```
> > # route
> > $ curl http://127.0.0.1:9080/apisix/admin/routes/1 -X PUT -i -d '
> > {
> >     "uri": "/index.html",
> >     "vars": [
> >         ["geoip_city", "==", "beijing"],
> >     ],
> >     "upstream": {
> >         "type": "roundrobin",
> >         "nodes": {
> >             "127.0.0.1:80": 1
> >         }
> >     }
> > }'
> > ```
> >
> > ```
> > -- plugin
> >
> > function _M.access(conf, ctx)
> >     local client_city = ctx.var.geoip_city
> >     -- your code
> > end
> > ```
> >
> > On Fri, Aug 7, 2020 at 9:53 AM YuanSheng Wang <me...@apache.org>
> wrote:
> >
> > > > > only get geo_city info  when the geoip condition is set, we don't
> > need
> > > > > calculate ip geo information for every request.
> > > > agreed, geo_ip should not calculated ervery request.
> > >
> > > please take a look at the `cookie` of `vars` [1]. we should use the
> same
> > > way.
> > >
> > > If we refer to geoip variables, the GeoIP library will be called to get
> > > the value.
> > > If we do not refer to these variables, the GeoIP library will never be
> > > called.
> > >
> > > > The request condition can not only be placed on the `route`, but the
> > > plugin
> > > > also has this capability.
> > >
> > > `vars` is the easiest way to support both `route` and `plugin`.
> > >
> > > [1]
> https://github.com/apache/apisix/blob/master/apisix/core/ctx.lua#L76
> > >
> > >
> > >
> > >> > integrate maxmind code into lua-resty-radixtree, only when the route
> > >> with
> > >> > geo condition is matched , then we calculate the geo ip info.
> > >> so why not take geo_ip as a plugin?
> > >> Plugin orchestration is particularly well suited for this.
> > >> The request condition can not only be placed on the route, but the
> > plugin
> > >> also has this capability.
> > >>
> > >> Thanks,
> > >> Ming Wen, Apache APISIX & Apache SkyWalking
> > >> Twitter: _WenMing
> > >>
> > >>
> > >> Li Ling(Lien) <li...@apache.org> 于2020年8月6日周四 下午7:29写道:
> > >>
> > >> > IMO,the the geoip-route is a feature of *route* module,it shouldn't
> > >> > involved with vars module,
> > >> > and only get geo_city info  when the geoip condition is set, we
> don't
> > >> need
> > >> > calculate ip geo information for every request.
> > >> >
> > >> > here is my solution:
> > >> >   integrate maxmind code into lua-resty-radixtree, only when the
> route
> > >> with
> > >> > geo condition is matched , then we calculate the geo ip info.
> > >> >
> > >> > YuanSheng Wang <me...@apache.org> 于2020年8月6日周四 下午6:00写道:
> > >> >
> > >> > > >   1、I want route user‘s request from country request into
> > different
> > >> > > upstream
> > >> > > host.
> > >> > >
> > >> > > I think AIPSIX needs to support this feature. it is a useful
> feature
> > >> for
> > >> > > the user.
> > >> > > We do not need to update `resty-radixtree`, only update `ctx.vars`
> > is
> > >> > > enough.
> > >> > >
> > >> > > for example, a way to get the city: `ctx.vars.geo_city` .
> > >> > >
> > >> > > Then the users can use it in `route` or `plugin`, both of the way
> > are
> > >> > fine.
> > >> > >
> > >> > > On Thu, Aug 6, 2020 at 8:55 AM Ming Wen <we...@apache.org>
> wrote:
> > >> > >
> > >> > > > Optional features should be implemented by plugins,
> > >> > > > and the core should be keep simple.
> > >> > > >
> > >> > > > Thanks,
> > >> > > > Ming Wen, Apache APISIX & Apache SkyWalking
> > >> > > > Twitter: _WenMing
> > >> > > >
> > >> > > >
> > >> > > > YuanSheng Wang <me...@apache.org> 于2020年8月6日周四 上午8:28写道:
> > >> > > >
> > >> > > > > On Thu, Aug 6, 2020 at 7:39 AM Ming Wen <we...@apache.org>
> > >> wrote:
> > >> > > > >
> > >> > > > > > IMO, implement geo_ip as plugin is better, not in the route.
> > >> > > > > >
> > >> > > > >
> > >> > > > > I would like to implement it in `route`.
> > >> > > > >
> > >> > > > > It may be a condition, we can support it in `vars'.
> > >> > > > >
> > >> > > > >
> > >> > > > > >
> > >> > > > > > And https://luarocks.org/modules/agladysh/lua-geoip is not
> a
> > >> good
> > >> > > > > > approach,
> > >> > > > > > lua-resty-maxminddb[1] is good for APISIX.
> > >> > > > > >
> > >> > > > >
> > >> > > > > this library is better. agree +1
> > >> > > > >
> > >> > > > >
> > >> > > > > >
> > >> > > > > > [1] https://github.com/anjia0532/lua-resty-maxminddb
> > >> > > > > >
> > >> > > > > > Thanks,
> > >> > > > > > Ming Wen, Apache APISIX & Apache SkyWalking
> > >> > > > > > Twitter: _WenMing
> > >> > > > > >
> > >> > > > > >
> > >> > > > > > JinChao Shuai <sh...@apache.org> 于2020年8月6日周四
> > 上午1:47写道:
> > >> > > > > >
> > >> > > > > > > I also agree with the second approach and to `Yansheng
> Wang`
> > >> that
> > >> > > > users
> > >> > > > > > can
> > >> > > > > > > use their own GeoIP database.
> > >> > > > > > >
> > >> > > > > > > YuanSheng Wang <me...@apache.org> 于2020年8月5日周三
> > 下午11:40写道:
> > >> > > > > > >
> > >> > > > > > > > Of course, the second way is better for APISIX.
> > >> > > > > > > >
> > >> > > > > > > > The `lua-geoip` is under Dual license, we need to
> confirm
> > >> if we
> > >> > > can
> > >> > > > > use
> > >> > > > > > > > this library.
> > >> > > > > > > >
> > >> > > > > > > > The users needs to download the GeoIP database by
> himself,
> > >> > Apache
> > >> > > > > > APISIX
> > >> > > > > > > > can
> > >> > > > > > > > not ship with the GeoIP data(under LGPL 2.1).
> > >> > > > > > > >
> > >> > > > > > > >
> > >> > > > > > > > On Wed, Aug 5, 2020 at 9:16 PM Li Ling(Lien) <
> > >> > liling@apache.org>
> > >> > > > > > wrote:
> > >> > > > > > > >
> > >> > > > > > > > > rencently I am thinking about have Geo routing in
> > APISIX,
> > >> > > > > > > > > scenario:
> > >> > > > > > > > >     1、I want route user‘s request from country request
> > >> intoto
> > >> > > > > > different
> > >> > > > > > > > > upstream host.
> > >> > > > > > > > >     2、When users from outside China redirect to
> > >> international
> > >> > > > > > > > homepage(many
> > >> > > > > > > > > video sites like youku.com they ban users from
> outside
> > >> > china).
> > >> > > > > > > > >
> > >> > > > > > > > >
> > >> > > > > > > > > here is two solution I digged into:
> > >> > > > > > > > >
> > >> > > > > > > > > 1、intergrate nginx module
> > >> > > > > > > https://github.com/leev/ngx_http_geoip2_module
> > >> > > > > > > > > and
> > >> > > > > > > > > do variable matching.
> > >> > > > > > > > >      disadvantage: we need calculate the geo data from
> > ip
> > >> > info
> > >> > > > for
> > >> > > > > > > every
> > >> > > > > > > > > request,which is so inefficient.
> > >> > > > > > > > >
> > >> > > > > > > > >
> > >> > > > > > > > > 2、https://luarocks.org/modules/agladysh/lua-geoip
> > >> > > > > > > > >      intergrate this lua module into
> > lua-resty-radixtree,
> > >> > when
> > >> > > > > > geo_ip_*
> > >> > > > > > > > > parameter is set in the routes, we calculate the ip
> > >> country
> > >> > > info
> > >> > > > > from
> > >> > > > > > > > geoip
> > >> > > > > > > > > library.so  that  it wont calculate the geo data for
> > each
> > >> > > > request.
> > >> > > > > > > > >
> > >> > > > > > > >
> > >> > > > > > > >
> > >> > > > > > > > --
> > >> > > > > > > >
> > >> > > > > > > > *MembPhis*
> > >> > > > > > > > My GitHub: https://github.com/membphis
> > >> > > > > > > > Apache APISIX:
> https://github.com/apache/incubator-apisix
> > >> > > > > > > >
> > >> > > > > > >
> > >> > > > > > >
> > >> > > > > > > --
> > >> > > > > > > Thanks,
> > >> > > > > > > Janko
> > >> > > > > > >
> > >> > > > > >
> > >> > > > >
> > >> > > > >
> > >> > > > > --
> > >> > > > >
> > >> > > > > *MembPhis*
> > >> > > > > My GitHub: https://github.com/membphis
> > >> > > > > Apache APISIX: https://github.com/apache/incubator-apisix
> > >> > > > >
> > >> > > >
> > >> > >
> > >> > >
> > >> > > --
> > >> > >
> > >> > > *MembPhis*
> > >> > > My GitHub: https://github.com/membphis
> > >> > > Apache APISIX: https://github.com/apache/incubator-apisix
> > >> > >
> > >> >
> > >>
> > >
> > >
> > > --
> > >
> > > *MembPhis*
> > > My GitHub: https://github.com/membphis
> > > Apache APISIX: https://github.com/apache/incubator-apisix
> > >
> >
> >
> > --
> >
> > *MembPhis*
> > My GitHub: https://github.com/membphis
> > Apache APISIX: https://github.com/apache/incubator-apisix
> >
>


-- 

*MembPhis*
My GitHub: https://github.com/membphis
Apache APISIX: https://github.com/apache/incubator-apisix

Re: [DISCUSS] How about have geoip variables available in conditional routing

Posted by vincixu <vi...@apache.org>.
This example is about how to route request.
I think before this, we should talk about how to convert "geoip" to the
"geoip_city": using plugin or other ways.

YuanSheng Wang <me...@apache.org> 于2020年8月7日周五 下午12:38写道:

> Here are two examples:
>
> ```
> # route
> $ curl http://127.0.0.1:9080/apisix/admin/routes/1 -X PUT -i -d '
> {
>     "uri": "/index.html",
>     "vars": [
>         ["geoip_city", "==", "beijing"],
>     ],
>     "upstream": {
>         "type": "roundrobin",
>         "nodes": {
>             "127.0.0.1:80": 1
>         }
>     }
> }'
> ```
>
> ```
> -- plugin
>
> function _M.access(conf, ctx)
>     local client_city = ctx.var.geoip_city
>     -- your code
> end
> ```
>
> On Fri, Aug 7, 2020 at 9:53 AM YuanSheng Wang <me...@apache.org> wrote:
>
> > > > only get geo_city info  when the geoip condition is set, we don't
> need
> > > > calculate ip geo information for every request.
> > > agreed, geo_ip should not calculated ervery request.
> >
> > please take a look at the `cookie` of `vars` [1]. we should use the same
> > way.
> >
> > If we refer to geoip variables, the GeoIP library will be called to get
> > the value.
> > If we do not refer to these variables, the GeoIP library will never be
> > called.
> >
> > > The request condition can not only be placed on the `route`, but the
> > plugin
> > > also has this capability.
> >
> > `vars` is the easiest way to support both `route` and `plugin`.
> >
> > [1] https://github.com/apache/apisix/blob/master/apisix/core/ctx.lua#L76
> >
> >
> >
> >> > integrate maxmind code into lua-resty-radixtree, only when the route
> >> with
> >> > geo condition is matched , then we calculate the geo ip info.
> >> so why not take geo_ip as a plugin?
> >> Plugin orchestration is particularly well suited for this.
> >> The request condition can not only be placed on the route, but the
> plugin
> >> also has this capability.
> >>
> >> Thanks,
> >> Ming Wen, Apache APISIX & Apache SkyWalking
> >> Twitter: _WenMing
> >>
> >>
> >> Li Ling(Lien) <li...@apache.org> 于2020年8月6日周四 下午7:29写道:
> >>
> >> > IMO,the the geoip-route is a feature of *route* module,it shouldn't
> >> > involved with vars module,
> >> > and only get geo_city info  when the geoip condition is set, we don't
> >> need
> >> > calculate ip geo information for every request.
> >> >
> >> > here is my solution:
> >> >   integrate maxmind code into lua-resty-radixtree, only when the route
> >> with
> >> > geo condition is matched , then we calculate the geo ip info.
> >> >
> >> > YuanSheng Wang <me...@apache.org> 于2020年8月6日周四 下午6:00写道:
> >> >
> >> > > >   1、I want route user‘s request from country request into
> different
> >> > > upstream
> >> > > host.
> >> > >
> >> > > I think AIPSIX needs to support this feature. it is a useful feature
> >> for
> >> > > the user.
> >> > > We do not need to update `resty-radixtree`, only update `ctx.vars`
> is
> >> > > enough.
> >> > >
> >> > > for example, a way to get the city: `ctx.vars.geo_city` .
> >> > >
> >> > > Then the users can use it in `route` or `plugin`, both of the way
> are
> >> > fine.
> >> > >
> >> > > On Thu, Aug 6, 2020 at 8:55 AM Ming Wen <we...@apache.org> wrote:
> >> > >
> >> > > > Optional features should be implemented by plugins,
> >> > > > and the core should be keep simple.
> >> > > >
> >> > > > Thanks,
> >> > > > Ming Wen, Apache APISIX & Apache SkyWalking
> >> > > > Twitter: _WenMing
> >> > > >
> >> > > >
> >> > > > YuanSheng Wang <me...@apache.org> 于2020年8月6日周四 上午8:28写道:
> >> > > >
> >> > > > > On Thu, Aug 6, 2020 at 7:39 AM Ming Wen <we...@apache.org>
> >> wrote:
> >> > > > >
> >> > > > > > IMO, implement geo_ip as plugin is better, not in the route.
> >> > > > > >
> >> > > > >
> >> > > > > I would like to implement it in `route`.
> >> > > > >
> >> > > > > It may be a condition, we can support it in `vars'.
> >> > > > >
> >> > > > >
> >> > > > > >
> >> > > > > > And https://luarocks.org/modules/agladysh/lua-geoip is not a
> >> good
> >> > > > > > approach,
> >> > > > > > lua-resty-maxminddb[1] is good for APISIX.
> >> > > > > >
> >> > > > >
> >> > > > > this library is better. agree +1
> >> > > > >
> >> > > > >
> >> > > > > >
> >> > > > > > [1] https://github.com/anjia0532/lua-resty-maxminddb
> >> > > > > >
> >> > > > > > Thanks,
> >> > > > > > Ming Wen, Apache APISIX & Apache SkyWalking
> >> > > > > > Twitter: _WenMing
> >> > > > > >
> >> > > > > >
> >> > > > > > JinChao Shuai <sh...@apache.org> 于2020年8月6日周四
> 上午1:47写道:
> >> > > > > >
> >> > > > > > > I also agree with the second approach and to `Yansheng Wang`
> >> that
> >> > > > users
> >> > > > > > can
> >> > > > > > > use their own GeoIP database.
> >> > > > > > >
> >> > > > > > > YuanSheng Wang <me...@apache.org> 于2020年8月5日周三
> 下午11:40写道:
> >> > > > > > >
> >> > > > > > > > Of course, the second way is better for APISIX.
> >> > > > > > > >
> >> > > > > > > > The `lua-geoip` is under Dual license, we need to confirm
> >> if we
> >> > > can
> >> > > > > use
> >> > > > > > > > this library.
> >> > > > > > > >
> >> > > > > > > > The users needs to download the GeoIP database by himself,
> >> > Apache
> >> > > > > > APISIX
> >> > > > > > > > can
> >> > > > > > > > not ship with the GeoIP data(under LGPL 2.1).
> >> > > > > > > >
> >> > > > > > > >
> >> > > > > > > > On Wed, Aug 5, 2020 at 9:16 PM Li Ling(Lien) <
> >> > liling@apache.org>
> >> > > > > > wrote:
> >> > > > > > > >
> >> > > > > > > > > rencently I am thinking about have Geo routing in
> APISIX,
> >> > > > > > > > > scenario:
> >> > > > > > > > >     1、I want route user‘s request from country request
> >> intoto
> >> > > > > > different
> >> > > > > > > > > upstream host.
> >> > > > > > > > >     2、When users from outside China redirect to
> >> international
> >> > > > > > > > homepage(many
> >> > > > > > > > > video sites like youku.com they ban users from outside
> >> > china).
> >> > > > > > > > >
> >> > > > > > > > >
> >> > > > > > > > > here is two solution I digged into:
> >> > > > > > > > >
> >> > > > > > > > > 1、intergrate nginx module
> >> > > > > > > https://github.com/leev/ngx_http_geoip2_module
> >> > > > > > > > > and
> >> > > > > > > > > do variable matching.
> >> > > > > > > > >      disadvantage: we need calculate the geo data from
> ip
> >> > info
> >> > > > for
> >> > > > > > > every
> >> > > > > > > > > request,which is so inefficient.
> >> > > > > > > > >
> >> > > > > > > > >
> >> > > > > > > > > 2、https://luarocks.org/modules/agladysh/lua-geoip
> >> > > > > > > > >      intergrate this lua module into
> lua-resty-radixtree,
> >> > when
> >> > > > > > geo_ip_*
> >> > > > > > > > > parameter is set in the routes, we calculate the ip
> >> country
> >> > > info
> >> > > > > from
> >> > > > > > > > geoip
> >> > > > > > > > > library.so  that  it wont calculate the geo data for
> each
> >> > > > request.
> >> > > > > > > > >
> >> > > > > > > >
> >> > > > > > > >
> >> > > > > > > > --
> >> > > > > > > >
> >> > > > > > > > *MembPhis*
> >> > > > > > > > My GitHub: https://github.com/membphis
> >> > > > > > > > Apache APISIX: https://github.com/apache/incubator-apisix
> >> > > > > > > >
> >> > > > > > >
> >> > > > > > >
> >> > > > > > > --
> >> > > > > > > Thanks,
> >> > > > > > > Janko
> >> > > > > > >
> >> > > > > >
> >> > > > >
> >> > > > >
> >> > > > > --
> >> > > > >
> >> > > > > *MembPhis*
> >> > > > > My GitHub: https://github.com/membphis
> >> > > > > Apache APISIX: https://github.com/apache/incubator-apisix
> >> > > > >
> >> > > >
> >> > >
> >> > >
> >> > > --
> >> > >
> >> > > *MembPhis*
> >> > > My GitHub: https://github.com/membphis
> >> > > Apache APISIX: https://github.com/apache/incubator-apisix
> >> > >
> >> >
> >>
> >
> >
> > --
> >
> > *MembPhis*
> > My GitHub: https://github.com/membphis
> > Apache APISIX: https://github.com/apache/incubator-apisix
> >
>
>
> --
>
> *MembPhis*
> My GitHub: https://github.com/membphis
> Apache APISIX: https://github.com/apache/incubator-apisix
>

Re: [DISCUSS] How about have geoip variables available in conditional routing

Posted by YuanSheng Wang <me...@apache.org>.
Here are two examples:

```
# route
$ curl http://127.0.0.1:9080/apisix/admin/routes/1 -X PUT -i -d '
{
    "uri": "/index.html",
    "vars": [
        ["geoip_city", "==", "beijing"],
    ],
    "upstream": {
        "type": "roundrobin",
        "nodes": {
            "127.0.0.1:80": 1
        }
    }
}'
```

```
-- plugin

function _M.access(conf, ctx)
    local client_city = ctx.var.geoip_city
    -- your code
end
```

On Fri, Aug 7, 2020 at 9:53 AM YuanSheng Wang <me...@apache.org> wrote:

> > > only get geo_city info  when the geoip condition is set, we don't need
> > > calculate ip geo information for every request.
> > agreed, geo_ip should not calculated ervery request.
>
> please take a look at the `cookie` of `vars` [1]. we should use the same
> way.
>
> If we refer to geoip variables, the GeoIP library will be called to get
> the value.
> If we do not refer to these variables, the GeoIP library will never be
> called.
>
> > The request condition can not only be placed on the `route`, but the
> plugin
> > also has this capability.
>
> `vars` is the easiest way to support both `route` and `plugin`.
>
> [1] https://github.com/apache/apisix/blob/master/apisix/core/ctx.lua#L76
>
>
>
>> > integrate maxmind code into lua-resty-radixtree, only when the route
>> with
>> > geo condition is matched , then we calculate the geo ip info.
>> so why not take geo_ip as a plugin?
>> Plugin orchestration is particularly well suited for this.
>> The request condition can not only be placed on the route, but the plugin
>> also has this capability.
>>
>> Thanks,
>> Ming Wen, Apache APISIX & Apache SkyWalking
>> Twitter: _WenMing
>>
>>
>> Li Ling(Lien) <li...@apache.org> 于2020年8月6日周四 下午7:29写道:
>>
>> > IMO,the the geoip-route is a feature of *route* module,it shouldn't
>> > involved with vars module,
>> > and only get geo_city info  when the geoip condition is set, we don't
>> need
>> > calculate ip geo information for every request.
>> >
>> > here is my solution:
>> >   integrate maxmind code into lua-resty-radixtree, only when the route
>> with
>> > geo condition is matched , then we calculate the geo ip info.
>> >
>> > YuanSheng Wang <me...@apache.org> 于2020年8月6日周四 下午6:00写道:
>> >
>> > > >   1、I want route user‘s request from country request into different
>> > > upstream
>> > > host.
>> > >
>> > > I think AIPSIX needs to support this feature. it is a useful feature
>> for
>> > > the user.
>> > > We do not need to update `resty-radixtree`, only update `ctx.vars` is
>> > > enough.
>> > >
>> > > for example, a way to get the city: `ctx.vars.geo_city` .
>> > >
>> > > Then the users can use it in `route` or `plugin`, both of the way are
>> > fine.
>> > >
>> > > On Thu, Aug 6, 2020 at 8:55 AM Ming Wen <we...@apache.org> wrote:
>> > >
>> > > > Optional features should be implemented by plugins,
>> > > > and the core should be keep simple.
>> > > >
>> > > > Thanks,
>> > > > Ming Wen, Apache APISIX & Apache SkyWalking
>> > > > Twitter: _WenMing
>> > > >
>> > > >
>> > > > YuanSheng Wang <me...@apache.org> 于2020年8月6日周四 上午8:28写道:
>> > > >
>> > > > > On Thu, Aug 6, 2020 at 7:39 AM Ming Wen <we...@apache.org>
>> wrote:
>> > > > >
>> > > > > > IMO, implement geo_ip as plugin is better, not in the route.
>> > > > > >
>> > > > >
>> > > > > I would like to implement it in `route`.
>> > > > >
>> > > > > It may be a condition, we can support it in `vars'.
>> > > > >
>> > > > >
>> > > > > >
>> > > > > > And https://luarocks.org/modules/agladysh/lua-geoip is not a
>> good
>> > > > > > approach,
>> > > > > > lua-resty-maxminddb[1] is good for APISIX.
>> > > > > >
>> > > > >
>> > > > > this library is better. agree +1
>> > > > >
>> > > > >
>> > > > > >
>> > > > > > [1] https://github.com/anjia0532/lua-resty-maxminddb
>> > > > > >
>> > > > > > Thanks,
>> > > > > > Ming Wen, Apache APISIX & Apache SkyWalking
>> > > > > > Twitter: _WenMing
>> > > > > >
>> > > > > >
>> > > > > > JinChao Shuai <sh...@apache.org> 于2020年8月6日周四 上午1:47写道:
>> > > > > >
>> > > > > > > I also agree with the second approach and to `Yansheng Wang`
>> that
>> > > > users
>> > > > > > can
>> > > > > > > use their own GeoIP database.
>> > > > > > >
>> > > > > > > YuanSheng Wang <me...@apache.org> 于2020年8月5日周三 下午11:40写道:
>> > > > > > >
>> > > > > > > > Of course, the second way is better for APISIX.
>> > > > > > > >
>> > > > > > > > The `lua-geoip` is under Dual license, we need to confirm
>> if we
>> > > can
>> > > > > use
>> > > > > > > > this library.
>> > > > > > > >
>> > > > > > > > The users needs to download the GeoIP database by himself,
>> > Apache
>> > > > > > APISIX
>> > > > > > > > can
>> > > > > > > > not ship with the GeoIP data(under LGPL 2.1).
>> > > > > > > >
>> > > > > > > >
>> > > > > > > > On Wed, Aug 5, 2020 at 9:16 PM Li Ling(Lien) <
>> > liling@apache.org>
>> > > > > > wrote:
>> > > > > > > >
>> > > > > > > > > rencently I am thinking about have Geo routing in APISIX,
>> > > > > > > > > scenario:
>> > > > > > > > >     1、I want route user‘s request from country request
>> intoto
>> > > > > > different
>> > > > > > > > > upstream host.
>> > > > > > > > >     2、When users from outside China redirect to
>> international
>> > > > > > > > homepage(many
>> > > > > > > > > video sites like youku.com they ban users from outside
>> > china).
>> > > > > > > > >
>> > > > > > > > >
>> > > > > > > > > here is two solution I digged into:
>> > > > > > > > >
>> > > > > > > > > 1、intergrate nginx module
>> > > > > > > https://github.com/leev/ngx_http_geoip2_module
>> > > > > > > > > and
>> > > > > > > > > do variable matching.
>> > > > > > > > >      disadvantage: we need calculate the geo data from ip
>> > info
>> > > > for
>> > > > > > > every
>> > > > > > > > > request,which is so inefficient.
>> > > > > > > > >
>> > > > > > > > >
>> > > > > > > > > 2、https://luarocks.org/modules/agladysh/lua-geoip
>> > > > > > > > >      intergrate this lua module into lua-resty-radixtree,
>> > when
>> > > > > > geo_ip_*
>> > > > > > > > > parameter is set in the routes, we calculate the ip
>> country
>> > > info
>> > > > > from
>> > > > > > > > geoip
>> > > > > > > > > library.so  that  it wont calculate the geo data for each
>> > > > request.
>> > > > > > > > >
>> > > > > > > >
>> > > > > > > >
>> > > > > > > > --
>> > > > > > > >
>> > > > > > > > *MembPhis*
>> > > > > > > > My GitHub: https://github.com/membphis
>> > > > > > > > Apache APISIX: https://github.com/apache/incubator-apisix
>> > > > > > > >
>> > > > > > >
>> > > > > > >
>> > > > > > > --
>> > > > > > > Thanks,
>> > > > > > > Janko
>> > > > > > >
>> > > > > >
>> > > > >
>> > > > >
>> > > > > --
>> > > > >
>> > > > > *MembPhis*
>> > > > > My GitHub: https://github.com/membphis
>> > > > > Apache APISIX: https://github.com/apache/incubator-apisix
>> > > > >
>> > > >
>> > >
>> > >
>> > > --
>> > >
>> > > *MembPhis*
>> > > My GitHub: https://github.com/membphis
>> > > Apache APISIX: https://github.com/apache/incubator-apisix
>> > >
>> >
>>
>
>
> --
>
> *MembPhis*
> My GitHub: https://github.com/membphis
> Apache APISIX: https://github.com/apache/incubator-apisix
>


-- 

*MembPhis*
My GitHub: https://github.com/membphis
Apache APISIX: https://github.com/apache/incubator-apisix

Re: [DISCUSS] How about have geoip variables available in conditional routing

Posted by Ming Wen <we...@apache.org>.
> But here is also a disadvantages  that this plugin must work at
> rewrite_phase and be a global rule, because mapping action must execute
> before route matching
We can use two methods to solve this issue:
plugin orchestration and dynamic modification upstreams in plugin.
Both of features are on the way.

Thanks,
Ming Wen, Apache APISIX & Apache SkyWalking
Twitter: _WenMing


vincixu <vi...@apache.org> 于2020年8月7日周五 上午11:05写道:

> +1 for plugin way.
> The feature is simple mapping action, "geo_ip -> geo_city or geo_country".
> It likes request-rewrite plugin, but have more logic.We can implement it as
> a plugin and have advantage as below:
> 1. the parameter's option could easy changed by user, such should read geo
> ip from  what source (header or query or cookie), what name it could be
> etc.
> 2. make APISIX route logic clean
>
> But here is also a disadvantages  that this plugin must work at
> rewrite_phase and be a global rule, because mapping action must execute
> before route matching
>
> YuanSheng Wang <me...@apache.org> 于2020年8月7日周五 上午9:53写道:
>
> > > > only get geo_city info  when the geoip condition is set, we don't
> need
> > > > calculate ip geo information for every request.
> > > agreed, geo_ip should not calculated ervery request.
> >
> > please take a look at the `cookie` of `vars` [1]. we should use the same
> > way.
> >
> > If we refer to geoip variables, the GeoIP library will be called to get
> the
> > value.
> > If we do not refer to these variables, the GeoIP library will never be
> > called.
> >
> > > The request condition can not only be placed on the `route`, but the
> > plugin
> > > also has this capability.
> >
> > `vars` is the easiest way to support both `route` and `plugin`.
> >
> > [1] https://github.com/apache/apisix/blob/master/apisix/core/ctx.lua#L76
> >
> >
> >
> > > > integrate maxmind code into lua-resty-radixtree, only when the route
> > with
> > > > geo condition is matched , then we calculate the geo ip info.
> > > so why not take geo_ip as a plugin?
> > > Plugin orchestration is particularly well suited for this.
> > > The request condition can not only be placed on the route, but the
> plugin
> > > also has this capability.
> > >
> > > Thanks,
> > > Ming Wen, Apache APISIX & Apache SkyWalking
> > > Twitter: _WenMing
> > >
> > >
> > > Li Ling(Lien) <li...@apache.org> 于2020年8月6日周四 下午7:29写道:
> > >
> > > > IMO,the the geoip-route is a feature of *route* module,it shouldn't
> > > > involved with vars module,
> > > > and only get geo_city info  when the geoip condition is set, we don't
> > > need
> > > > calculate ip geo information for every request.
> > > >
> > > > here is my solution:
> > > >   integrate maxmind code into lua-resty-radixtree, only when the
> route
> > > with
> > > > geo condition is matched , then we calculate the geo ip info.
> > > >
> > > > YuanSheng Wang <me...@apache.org> 于2020年8月6日周四 下午6:00写道:
> > > >
> > > > > >   1、I want route user‘s request from country request into
> different
> > > > > upstream
> > > > > host.
> > > > >
> > > > > I think AIPSIX needs to support this feature. it is a useful
> feature
> > > for
> > > > > the user.
> > > > > We do not need to update `resty-radixtree`, only update `ctx.vars`
> is
> > > > > enough.
> > > > >
> > > > > for example, a way to get the city: `ctx.vars.geo_city` .
> > > > >
> > > > > Then the users can use it in `route` or `plugin`, both of the way
> are
> > > > fine.
> > > > >
> > > > > On Thu, Aug 6, 2020 at 8:55 AM Ming Wen <we...@apache.org>
> wrote:
> > > > >
> > > > > > Optional features should be implemented by plugins,
> > > > > > and the core should be keep simple.
> > > > > >
> > > > > > Thanks,
> > > > > > Ming Wen, Apache APISIX & Apache SkyWalking
> > > > > > Twitter: _WenMing
> > > > > >
> > > > > >
> > > > > > YuanSheng Wang <me...@apache.org> 于2020年8月6日周四 上午8:28写道:
> > > > > >
> > > > > > > On Thu, Aug 6, 2020 at 7:39 AM Ming Wen <we...@apache.org>
> > > wrote:
> > > > > > >
> > > > > > > > IMO, implement geo_ip as plugin is better, not in the route.
> > > > > > > >
> > > > > > >
> > > > > > > I would like to implement it in `route`.
> > > > > > >
> > > > > > > It may be a condition, we can support it in `vars'.
> > > > > > >
> > > > > > >
> > > > > > > >
> > > > > > > > And https://luarocks.org/modules/agladysh/lua-geoip is not a
> > > good
> > > > > > > > approach,
> > > > > > > > lua-resty-maxminddb[1] is good for APISIX.
> > > > > > > >
> > > > > > >
> > > > > > > this library is better. agree +1
> > > > > > >
> > > > > > >
> > > > > > > >
> > > > > > > > [1] https://github.com/anjia0532/lua-resty-maxminddb
> > > > > > > >
> > > > > > > > Thanks,
> > > > > > > > Ming Wen, Apache APISIX & Apache SkyWalking
> > > > > > > > Twitter: _WenMing
> > > > > > > >
> > > > > > > >
> > > > > > > > JinChao Shuai <sh...@apache.org> 于2020年8月6日周四
> 上午1:47写道:
> > > > > > > >
> > > > > > > > > I also agree with the second approach and to `Yansheng
> Wang`
> > > that
> > > > > > users
> > > > > > > > can
> > > > > > > > > use their own GeoIP database.
> > > > > > > > >
> > > > > > > > > YuanSheng Wang <me...@apache.org> 于2020年8月5日周三
> 下午11:40写道:
> > > > > > > > >
> > > > > > > > > > Of course, the second way is better for APISIX.
> > > > > > > > > >
> > > > > > > > > > The `lua-geoip` is under Dual license, we need to confirm
> > if
> > > we
> > > > > can
> > > > > > > use
> > > > > > > > > > this library.
> > > > > > > > > >
> > > > > > > > > > The users needs to download the GeoIP database by
> himself,
> > > > Apache
> > > > > > > > APISIX
> > > > > > > > > > can
> > > > > > > > > > not ship with the GeoIP data(under LGPL 2.1).
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > On Wed, Aug 5, 2020 at 9:16 PM Li Ling(Lien) <
> > > > liling@apache.org>
> > > > > > > > wrote:
> > > > > > > > > >
> > > > > > > > > > > rencently I am thinking about have Geo routing in
> APISIX,
> > > > > > > > > > > scenario:
> > > > > > > > > > >     1、I want route user‘s request from country request
> > > intoto
> > > > > > > > different
> > > > > > > > > > > upstream host.
> > > > > > > > > > >     2、When users from outside China redirect to
> > > international
> > > > > > > > > > homepage(many
> > > > > > > > > > > video sites like youku.com they ban users from outside
> > > > china).
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > here is two solution I digged into:
> > > > > > > > > > >
> > > > > > > > > > > 1、intergrate nginx module
> > > > > > > > > https://github.com/leev/ngx_http_geoip2_module
> > > > > > > > > > > and
> > > > > > > > > > > do variable matching.
> > > > > > > > > > >      disadvantage: we need calculate the geo data from
> ip
> > > > info
> > > > > > for
> > > > > > > > > every
> > > > > > > > > > > request,which is so inefficient.
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > 2、https://luarocks.org/modules/agladysh/lua-geoip
> > > > > > > > > > >      intergrate this lua module into
> lua-resty-radixtree,
> > > > when
> > > > > > > > geo_ip_*
> > > > > > > > > > > parameter is set in the routes, we calculate the ip
> > country
> > > > > info
> > > > > > > from
> > > > > > > > > > geoip
> > > > > > > > > > > library.so  that  it wont calculate the geo data for
> each
> > > > > > request.
> > > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > --
> > > > > > > > > >
> > > > > > > > > > *MembPhis*
> > > > > > > > > > My GitHub: https://github.com/membphis
> > > > > > > > > > Apache APISIX:
> https://github.com/apache/incubator-apisix
> > > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > --
> > > > > > > > > Thanks,
> > > > > > > > > Janko
> > > > > > > > >
> > > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > --
> > > > > > >
> > > > > > > *MembPhis*
> > > > > > > My GitHub: https://github.com/membphis
> > > > > > > Apache APISIX: https://github.com/apache/incubator-apisix
> > > > > > >
> > > > > >
> > > > >
> > > > >
> > > > > --
> > > > >
> > > > > *MembPhis*
> > > > > My GitHub: https://github.com/membphis
> > > > > Apache APISIX: https://github.com/apache/incubator-apisix
> > > > >
> > > >
> > >
> >
> >
> > --
> >
> > *MembPhis*
> > My GitHub: https://github.com/membphis
> > Apache APISIX: https://github.com/apache/incubator-apisix
> >
>

Re: [DISCUSS] How about have geoip variables available in conditional routing

Posted by vincixu <vi...@apache.org>.
+1 for plugin way.
The feature is simple mapping action, "geo_ip -> geo_city or geo_country".
It likes request-rewrite plugin, but have more logic.We can implement it as
a plugin and have advantage as below:
1. the parameter's option could easy changed by user, such should read geo
ip from  what source (header or query or cookie), what name it could be etc.
2. make APISIX route logic clean

But here is also a disadvantages  that this plugin must work at
rewrite_phase and be a global rule, because mapping action must execute
before route matching

YuanSheng Wang <me...@apache.org> 于2020年8月7日周五 上午9:53写道:

> > > only get geo_city info  when the geoip condition is set, we don't need
> > > calculate ip geo information for every request.
> > agreed, geo_ip should not calculated ervery request.
>
> please take a look at the `cookie` of `vars` [1]. we should use the same
> way.
>
> If we refer to geoip variables, the GeoIP library will be called to get the
> value.
> If we do not refer to these variables, the GeoIP library will never be
> called.
>
> > The request condition can not only be placed on the `route`, but the
> plugin
> > also has this capability.
>
> `vars` is the easiest way to support both `route` and `plugin`.
>
> [1] https://github.com/apache/apisix/blob/master/apisix/core/ctx.lua#L76
>
>
>
> > > integrate maxmind code into lua-resty-radixtree, only when the route
> with
> > > geo condition is matched , then we calculate the geo ip info.
> > so why not take geo_ip as a plugin?
> > Plugin orchestration is particularly well suited for this.
> > The request condition can not only be placed on the route, but the plugin
> > also has this capability.
> >
> > Thanks,
> > Ming Wen, Apache APISIX & Apache SkyWalking
> > Twitter: _WenMing
> >
> >
> > Li Ling(Lien) <li...@apache.org> 于2020年8月6日周四 下午7:29写道:
> >
> > > IMO,the the geoip-route is a feature of *route* module,it shouldn't
> > > involved with vars module,
> > > and only get geo_city info  when the geoip condition is set, we don't
> > need
> > > calculate ip geo information for every request.
> > >
> > > here is my solution:
> > >   integrate maxmind code into lua-resty-radixtree, only when the route
> > with
> > > geo condition is matched , then we calculate the geo ip info.
> > >
> > > YuanSheng Wang <me...@apache.org> 于2020年8月6日周四 下午6:00写道:
> > >
> > > > >   1、I want route user‘s request from country request into different
> > > > upstream
> > > > host.
> > > >
> > > > I think AIPSIX needs to support this feature. it is a useful feature
> > for
> > > > the user.
> > > > We do not need to update `resty-radixtree`, only update `ctx.vars` is
> > > > enough.
> > > >
> > > > for example, a way to get the city: `ctx.vars.geo_city` .
> > > >
> > > > Then the users can use it in `route` or `plugin`, both of the way are
> > > fine.
> > > >
> > > > On Thu, Aug 6, 2020 at 8:55 AM Ming Wen <we...@apache.org> wrote:
> > > >
> > > > > Optional features should be implemented by plugins,
> > > > > and the core should be keep simple.
> > > > >
> > > > > Thanks,
> > > > > Ming Wen, Apache APISIX & Apache SkyWalking
> > > > > Twitter: _WenMing
> > > > >
> > > > >
> > > > > YuanSheng Wang <me...@apache.org> 于2020年8月6日周四 上午8:28写道:
> > > > >
> > > > > > On Thu, Aug 6, 2020 at 7:39 AM Ming Wen <we...@apache.org>
> > wrote:
> > > > > >
> > > > > > > IMO, implement geo_ip as plugin is better, not in the route.
> > > > > > >
> > > > > >
> > > > > > I would like to implement it in `route`.
> > > > > >
> > > > > > It may be a condition, we can support it in `vars'.
> > > > > >
> > > > > >
> > > > > > >
> > > > > > > And https://luarocks.org/modules/agladysh/lua-geoip is not a
> > good
> > > > > > > approach,
> > > > > > > lua-resty-maxminddb[1] is good for APISIX.
> > > > > > >
> > > > > >
> > > > > > this library is better. agree +1
> > > > > >
> > > > > >
> > > > > > >
> > > > > > > [1] https://github.com/anjia0532/lua-resty-maxminddb
> > > > > > >
> > > > > > > Thanks,
> > > > > > > Ming Wen, Apache APISIX & Apache SkyWalking
> > > > > > > Twitter: _WenMing
> > > > > > >
> > > > > > >
> > > > > > > JinChao Shuai <sh...@apache.org> 于2020年8月6日周四 上午1:47写道:
> > > > > > >
> > > > > > > > I also agree with the second approach and to `Yansheng Wang`
> > that
> > > > > users
> > > > > > > can
> > > > > > > > use their own GeoIP database.
> > > > > > > >
> > > > > > > > YuanSheng Wang <me...@apache.org> 于2020年8月5日周三 下午11:40写道:
> > > > > > > >
> > > > > > > > > Of course, the second way is better for APISIX.
> > > > > > > > >
> > > > > > > > > The `lua-geoip` is under Dual license, we need to confirm
> if
> > we
> > > > can
> > > > > > use
> > > > > > > > > this library.
> > > > > > > > >
> > > > > > > > > The users needs to download the GeoIP database by himself,
> > > Apache
> > > > > > > APISIX
> > > > > > > > > can
> > > > > > > > > not ship with the GeoIP data(under LGPL 2.1).
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > On Wed, Aug 5, 2020 at 9:16 PM Li Ling(Lien) <
> > > liling@apache.org>
> > > > > > > wrote:
> > > > > > > > >
> > > > > > > > > > rencently I am thinking about have Geo routing in APISIX,
> > > > > > > > > > scenario:
> > > > > > > > > >     1、I want route user‘s request from country request
> > intoto
> > > > > > > different
> > > > > > > > > > upstream host.
> > > > > > > > > >     2、When users from outside China redirect to
> > international
> > > > > > > > > homepage(many
> > > > > > > > > > video sites like youku.com they ban users from outside
> > > china).
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > here is two solution I digged into:
> > > > > > > > > >
> > > > > > > > > > 1、intergrate nginx module
> > > > > > > > https://github.com/leev/ngx_http_geoip2_module
> > > > > > > > > > and
> > > > > > > > > > do variable matching.
> > > > > > > > > >      disadvantage: we need calculate the geo data from ip
> > > info
> > > > > for
> > > > > > > > every
> > > > > > > > > > request,which is so inefficient.
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > 2、https://luarocks.org/modules/agladysh/lua-geoip
> > > > > > > > > >      intergrate this lua module into lua-resty-radixtree,
> > > when
> > > > > > > geo_ip_*
> > > > > > > > > > parameter is set in the routes, we calculate the ip
> country
> > > > info
> > > > > > from
> > > > > > > > > geoip
> > > > > > > > > > library.so  that  it wont calculate the geo data for each
> > > > > request.
> > > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > --
> > > > > > > > >
> > > > > > > > > *MembPhis*
> > > > > > > > > My GitHub: https://github.com/membphis
> > > > > > > > > Apache APISIX: https://github.com/apache/incubator-apisix
> > > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > --
> > > > > > > > Thanks,
> > > > > > > > Janko
> > > > > > > >
> > > > > > >
> > > > > >
> > > > > >
> > > > > > --
> > > > > >
> > > > > > *MembPhis*
> > > > > > My GitHub: https://github.com/membphis
> > > > > > Apache APISIX: https://github.com/apache/incubator-apisix
> > > > > >
> > > > >
> > > >
> > > >
> > > > --
> > > >
> > > > *MembPhis*
> > > > My GitHub: https://github.com/membphis
> > > > Apache APISIX: https://github.com/apache/incubator-apisix
> > > >
> > >
> >
>
>
> --
>
> *MembPhis*
> My GitHub: https://github.com/membphis
> Apache APISIX: https://github.com/apache/incubator-apisix
>

Re: [DISCUSS] How about have geoip variables available in conditional routing

Posted by YuanSheng Wang <me...@apache.org>.
> > only get geo_city info  when the geoip condition is set, we don't need
> > calculate ip geo information for every request.
> agreed, geo_ip should not calculated ervery request.

please take a look at the `cookie` of `vars` [1]. we should use the same
way.

If we refer to geoip variables, the GeoIP library will be called to get the
value.
If we do not refer to these variables, the GeoIP library will never be
called.

> The request condition can not only be placed on the `route`, but the
plugin
> also has this capability.

`vars` is the easiest way to support both `route` and `plugin`.

[1] https://github.com/apache/apisix/blob/master/apisix/core/ctx.lua#L76



> > integrate maxmind code into lua-resty-radixtree, only when the route with
> > geo condition is matched , then we calculate the geo ip info.
> so why not take geo_ip as a plugin?
> Plugin orchestration is particularly well suited for this.
> The request condition can not only be placed on the route, but the plugin
> also has this capability.
>
> Thanks,
> Ming Wen, Apache APISIX & Apache SkyWalking
> Twitter: _WenMing
>
>
> Li Ling(Lien) <li...@apache.org> 于2020年8月6日周四 下午7:29写道:
>
> > IMO,the the geoip-route is a feature of *route* module,it shouldn't
> > involved with vars module,
> > and only get geo_city info  when the geoip condition is set, we don't
> need
> > calculate ip geo information for every request.
> >
> > here is my solution:
> >   integrate maxmind code into lua-resty-radixtree, only when the route
> with
> > geo condition is matched , then we calculate the geo ip info.
> >
> > YuanSheng Wang <me...@apache.org> 于2020年8月6日周四 下午6:00写道:
> >
> > > >   1、I want route user‘s request from country request into different
> > > upstream
> > > host.
> > >
> > > I think AIPSIX needs to support this feature. it is a useful feature
> for
> > > the user.
> > > We do not need to update `resty-radixtree`, only update `ctx.vars` is
> > > enough.
> > >
> > > for example, a way to get the city: `ctx.vars.geo_city` .
> > >
> > > Then the users can use it in `route` or `plugin`, both of the way are
> > fine.
> > >
> > > On Thu, Aug 6, 2020 at 8:55 AM Ming Wen <we...@apache.org> wrote:
> > >
> > > > Optional features should be implemented by plugins,
> > > > and the core should be keep simple.
> > > >
> > > > Thanks,
> > > > Ming Wen, Apache APISIX & Apache SkyWalking
> > > > Twitter: _WenMing
> > > >
> > > >
> > > > YuanSheng Wang <me...@apache.org> 于2020年8月6日周四 上午8:28写道:
> > > >
> > > > > On Thu, Aug 6, 2020 at 7:39 AM Ming Wen <we...@apache.org>
> wrote:
> > > > >
> > > > > > IMO, implement geo_ip as plugin is better, not in the route.
> > > > > >
> > > > >
> > > > > I would like to implement it in `route`.
> > > > >
> > > > > It may be a condition, we can support it in `vars'.
> > > > >
> > > > >
> > > > > >
> > > > > > And https://luarocks.org/modules/agladysh/lua-geoip is not a
> good
> > > > > > approach,
> > > > > > lua-resty-maxminddb[1] is good for APISIX.
> > > > > >
> > > > >
> > > > > this library is better. agree +1
> > > > >
> > > > >
> > > > > >
> > > > > > [1] https://github.com/anjia0532/lua-resty-maxminddb
> > > > > >
> > > > > > Thanks,
> > > > > > Ming Wen, Apache APISIX & Apache SkyWalking
> > > > > > Twitter: _WenMing
> > > > > >
> > > > > >
> > > > > > JinChao Shuai <sh...@apache.org> 于2020年8月6日周四 上午1:47写道:
> > > > > >
> > > > > > > I also agree with the second approach and to `Yansheng Wang`
> that
> > > > users
> > > > > > can
> > > > > > > use their own GeoIP database.
> > > > > > >
> > > > > > > YuanSheng Wang <me...@apache.org> 于2020年8月5日周三 下午11:40写道:
> > > > > > >
> > > > > > > > Of course, the second way is better for APISIX.
> > > > > > > >
> > > > > > > > The `lua-geoip` is under Dual license, we need to confirm if
> we
> > > can
> > > > > use
> > > > > > > > this library.
> > > > > > > >
> > > > > > > > The users needs to download the GeoIP database by himself,
> > Apache
> > > > > > APISIX
> > > > > > > > can
> > > > > > > > not ship with the GeoIP data(under LGPL 2.1).
> > > > > > > >
> > > > > > > >
> > > > > > > > On Wed, Aug 5, 2020 at 9:16 PM Li Ling(Lien) <
> > liling@apache.org>
> > > > > > wrote:
> > > > > > > >
> > > > > > > > > rencently I am thinking about have Geo routing in APISIX,
> > > > > > > > > scenario:
> > > > > > > > >     1、I want route user‘s request from country request
> intoto
> > > > > > different
> > > > > > > > > upstream host.
> > > > > > > > >     2、When users from outside China redirect to
> international
> > > > > > > > homepage(many
> > > > > > > > > video sites like youku.com they ban users from outside
> > china).
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > here is two solution I digged into:
> > > > > > > > >
> > > > > > > > > 1、intergrate nginx module
> > > > > > > https://github.com/leev/ngx_http_geoip2_module
> > > > > > > > > and
> > > > > > > > > do variable matching.
> > > > > > > > >      disadvantage: we need calculate the geo data from ip
> > info
> > > > for
> > > > > > > every
> > > > > > > > > request,which is so inefficient.
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > 2、https://luarocks.org/modules/agladysh/lua-geoip
> > > > > > > > >      intergrate this lua module into lua-resty-radixtree,
> > when
> > > > > > geo_ip_*
> > > > > > > > > parameter is set in the routes, we calculate the ip country
> > > info
> > > > > from
> > > > > > > > geoip
> > > > > > > > > library.so  that  it wont calculate the geo data for each
> > > > request.
> > > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > --
> > > > > > > >
> > > > > > > > *MembPhis*
> > > > > > > > My GitHub: https://github.com/membphis
> > > > > > > > Apache APISIX: https://github.com/apache/incubator-apisix
> > > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > --
> > > > > > > Thanks,
> > > > > > > Janko
> > > > > > >
> > > > > >
> > > > >
> > > > >
> > > > > --
> > > > >
> > > > > *MembPhis*
> > > > > My GitHub: https://github.com/membphis
> > > > > Apache APISIX: https://github.com/apache/incubator-apisix
> > > > >
> > > >
> > >
> > >
> > > --
> > >
> > > *MembPhis*
> > > My GitHub: https://github.com/membphis
> > > Apache APISIX: https://github.com/apache/incubator-apisix
> > >
> >
>


-- 

*MembPhis*
My GitHub: https://github.com/membphis
Apache APISIX: https://github.com/apache/incubator-apisix

Re: [DISCUSS] How about have geoip variables available in conditional routing

Posted by Ming Wen <we...@apache.org>.
> only get geo_city info  when the geoip condition is set, we don't need
> calculate ip geo information for every request.
agreed, geo_ip should not calculated ervery request.

> integrate maxmind code into lua-resty-radixtree, only when the route with
> geo condition is matched , then we calculate the geo ip info.
so why not take geo_ip as a plugin?
Plugin orchestration is particularly well suited for this.
The request condition can not only be placed on the route, but the plugin
also has this capability.

Thanks,
Ming Wen, Apache APISIX & Apache SkyWalking
Twitter: _WenMing


Li Ling(Lien) <li...@apache.org> 于2020年8月6日周四 下午7:29写道:

> IMO,the the geoip-route is a feature of *route* module,it shouldn't
> involved with vars module,
> and only get geo_city info  when the geoip condition is set, we don't need
> calculate ip geo information for every request.
>
> here is my solution:
>   integrate maxmind code into lua-resty-radixtree, only when the route with
> geo condition is matched , then we calculate the geo ip info.
>
> YuanSheng Wang <me...@apache.org> 于2020年8月6日周四 下午6:00写道:
>
> > >   1、I want route user‘s request from country request into different
> > upstream
> > host.
> >
> > I think AIPSIX needs to support this feature. it is a useful feature for
> > the user.
> > We do not need to update `resty-radixtree`, only update `ctx.vars` is
> > enough.
> >
> > for example, a way to get the city: `ctx.vars.geo_city` .
> >
> > Then the users can use it in `route` or `plugin`, both of the way are
> fine.
> >
> > On Thu, Aug 6, 2020 at 8:55 AM Ming Wen <we...@apache.org> wrote:
> >
> > > Optional features should be implemented by plugins,
> > > and the core should be keep simple.
> > >
> > > Thanks,
> > > Ming Wen, Apache APISIX & Apache SkyWalking
> > > Twitter: _WenMing
> > >
> > >
> > > YuanSheng Wang <me...@apache.org> 于2020年8月6日周四 上午8:28写道:
> > >
> > > > On Thu, Aug 6, 2020 at 7:39 AM Ming Wen <we...@apache.org> wrote:
> > > >
> > > > > IMO, implement geo_ip as plugin is better, not in the route.
> > > > >
> > > >
> > > > I would like to implement it in `route`.
> > > >
> > > > It may be a condition, we can support it in `vars'.
> > > >
> > > >
> > > > >
> > > > > And https://luarocks.org/modules/agladysh/lua-geoip is not a good
> > > > > approach,
> > > > > lua-resty-maxminddb[1] is good for APISIX.
> > > > >
> > > >
> > > > this library is better. agree +1
> > > >
> > > >
> > > > >
> > > > > [1] https://github.com/anjia0532/lua-resty-maxminddb
> > > > >
> > > > > Thanks,
> > > > > Ming Wen, Apache APISIX & Apache SkyWalking
> > > > > Twitter: _WenMing
> > > > >
> > > > >
> > > > > JinChao Shuai <sh...@apache.org> 于2020年8月6日周四 上午1:47写道:
> > > > >
> > > > > > I also agree with the second approach and to `Yansheng Wang` that
> > > users
> > > > > can
> > > > > > use their own GeoIP database.
> > > > > >
> > > > > > YuanSheng Wang <me...@apache.org> 于2020年8月5日周三 下午11:40写道:
> > > > > >
> > > > > > > Of course, the second way is better for APISIX.
> > > > > > >
> > > > > > > The `lua-geoip` is under Dual license, we need to confirm if we
> > can
> > > > use
> > > > > > > this library.
> > > > > > >
> > > > > > > The users needs to download the GeoIP database by himself,
> Apache
> > > > > APISIX
> > > > > > > can
> > > > > > > not ship with the GeoIP data(under LGPL 2.1).
> > > > > > >
> > > > > > >
> > > > > > > On Wed, Aug 5, 2020 at 9:16 PM Li Ling(Lien) <
> liling@apache.org>
> > > > > wrote:
> > > > > > >
> > > > > > > > rencently I am thinking about have Geo routing in APISIX,
> > > > > > > > scenario:
> > > > > > > >     1、I want route user‘s request from country request intoto
> > > > > different
> > > > > > > > upstream host.
> > > > > > > >     2、When users from outside China redirect to international
> > > > > > > homepage(many
> > > > > > > > video sites like youku.com they ban users from outside
> china).
> > > > > > > >
> > > > > > > >
> > > > > > > > here is two solution I digged into:
> > > > > > > >
> > > > > > > > 1、intergrate nginx module
> > > > > > https://github.com/leev/ngx_http_geoip2_module
> > > > > > > > and
> > > > > > > > do variable matching.
> > > > > > > >      disadvantage: we need calculate the geo data from ip
> info
> > > for
> > > > > > every
> > > > > > > > request,which is so inefficient.
> > > > > > > >
> > > > > > > >
> > > > > > > > 2、https://luarocks.org/modules/agladysh/lua-geoip
> > > > > > > >      intergrate this lua module into lua-resty-radixtree,
> when
> > > > > geo_ip_*
> > > > > > > > parameter is set in the routes, we calculate the ip country
> > info
> > > > from
> > > > > > > geoip
> > > > > > > > library.so  that  it wont calculate the geo data for each
> > > request.
> > > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > --
> > > > > > >
> > > > > > > *MembPhis*
> > > > > > > My GitHub: https://github.com/membphis
> > > > > > > Apache APISIX: https://github.com/apache/incubator-apisix
> > > > > > >
> > > > > >
> > > > > >
> > > > > > --
> > > > > > Thanks,
> > > > > > Janko
> > > > > >
> > > > >
> > > >
> > > >
> > > > --
> > > >
> > > > *MembPhis*
> > > > My GitHub: https://github.com/membphis
> > > > Apache APISIX: https://github.com/apache/incubator-apisix
> > > >
> > >
> >
> >
> > --
> >
> > *MembPhis*
> > My GitHub: https://github.com/membphis
> > Apache APISIX: https://github.com/apache/incubator-apisix
> >
>

Re: [DISCUSS] How about have geoip variables available in conditional routing

Posted by "Li Ling(Lien)" <li...@apache.org>.
IMO,the the geoip-route is a feature of *route* module,it shouldn't
involved with vars module,
and only get geo_city info  when the geoip condition is set, we don't need
calculate ip geo information for every request.

here is my solution:
  integrate maxmind code into lua-resty-radixtree, only when the route with
geo condition is matched , then we calculate the geo ip info.

YuanSheng Wang <me...@apache.org> 于2020年8月6日周四 下午6:00写道:

> >   1、I want route user‘s request from country request into different
> upstream
> host.
>
> I think AIPSIX needs to support this feature. it is a useful feature for
> the user.
> We do not need to update `resty-radixtree`, only update `ctx.vars` is
> enough.
>
> for example, a way to get the city: `ctx.vars.geo_city` .
>
> Then the users can use it in `route` or `plugin`, both of the way are fine.
>
> On Thu, Aug 6, 2020 at 8:55 AM Ming Wen <we...@apache.org> wrote:
>
> > Optional features should be implemented by plugins,
> > and the core should be keep simple.
> >
> > Thanks,
> > Ming Wen, Apache APISIX & Apache SkyWalking
> > Twitter: _WenMing
> >
> >
> > YuanSheng Wang <me...@apache.org> 于2020年8月6日周四 上午8:28写道:
> >
> > > On Thu, Aug 6, 2020 at 7:39 AM Ming Wen <we...@apache.org> wrote:
> > >
> > > > IMO, implement geo_ip as plugin is better, not in the route.
> > > >
> > >
> > > I would like to implement it in `route`.
> > >
> > > It may be a condition, we can support it in `vars'.
> > >
> > >
> > > >
> > > > And https://luarocks.org/modules/agladysh/lua-geoip is not a good
> > > > approach,
> > > > lua-resty-maxminddb[1] is good for APISIX.
> > > >
> > >
> > > this library is better. agree +1
> > >
> > >
> > > >
> > > > [1] https://github.com/anjia0532/lua-resty-maxminddb
> > > >
> > > > Thanks,
> > > > Ming Wen, Apache APISIX & Apache SkyWalking
> > > > Twitter: _WenMing
> > > >
> > > >
> > > > JinChao Shuai <sh...@apache.org> 于2020年8月6日周四 上午1:47写道:
> > > >
> > > > > I also agree with the second approach and to `Yansheng Wang` that
> > users
> > > > can
> > > > > use their own GeoIP database.
> > > > >
> > > > > YuanSheng Wang <me...@apache.org> 于2020年8月5日周三 下午11:40写道:
> > > > >
> > > > > > Of course, the second way is better for APISIX.
> > > > > >
> > > > > > The `lua-geoip` is under Dual license, we need to confirm if we
> can
> > > use
> > > > > > this library.
> > > > > >
> > > > > > The users needs to download the GeoIP database by himself, Apache
> > > > APISIX
> > > > > > can
> > > > > > not ship with the GeoIP data(under LGPL 2.1).
> > > > > >
> > > > > >
> > > > > > On Wed, Aug 5, 2020 at 9:16 PM Li Ling(Lien) <li...@apache.org>
> > > > wrote:
> > > > > >
> > > > > > > rencently I am thinking about have Geo routing in APISIX,
> > > > > > > scenario:
> > > > > > >     1、I want route user‘s request from country request intoto
> > > > different
> > > > > > > upstream host.
> > > > > > >     2、When users from outside China redirect to international
> > > > > > homepage(many
> > > > > > > video sites like youku.com they ban users from outside china).
> > > > > > >
> > > > > > >
> > > > > > > here is two solution I digged into:
> > > > > > >
> > > > > > > 1、intergrate nginx module
> > > > > https://github.com/leev/ngx_http_geoip2_module
> > > > > > > and
> > > > > > > do variable matching.
> > > > > > >      disadvantage: we need calculate the geo data from ip info
> > for
> > > > > every
> > > > > > > request,which is so inefficient.
> > > > > > >
> > > > > > >
> > > > > > > 2、https://luarocks.org/modules/agladysh/lua-geoip
> > > > > > >      intergrate this lua module into lua-resty-radixtree, when
> > > > geo_ip_*
> > > > > > > parameter is set in the routes, we calculate the ip country
> info
> > > from
> > > > > > geoip
> > > > > > > library.so  that  it wont calculate the geo data for each
> > request.
> > > > > > >
> > > > > >
> > > > > >
> > > > > > --
> > > > > >
> > > > > > *MembPhis*
> > > > > > My GitHub: https://github.com/membphis
> > > > > > Apache APISIX: https://github.com/apache/incubator-apisix
> > > > > >
> > > > >
> > > > >
> > > > > --
> > > > > Thanks,
> > > > > Janko
> > > > >
> > > >
> > >
> > >
> > > --
> > >
> > > *MembPhis*
> > > My GitHub: https://github.com/membphis
> > > Apache APISIX: https://github.com/apache/incubator-apisix
> > >
> >
>
>
> --
>
> *MembPhis*
> My GitHub: https://github.com/membphis
> Apache APISIX: https://github.com/apache/incubator-apisix
>

Re: [DISCUSS] How about have geoip variables available in conditional routing

Posted by YuanSheng Wang <me...@apache.org>.
>   1、I want route user‘s request from country request into different upstream
host.

I think AIPSIX needs to support this feature. it is a useful feature for
the user.
We do not need to update `resty-radixtree`, only update `ctx.vars` is
enough.

for example, a way to get the city: `ctx.vars.geo_city` .

Then the users can use it in `route` or `plugin`, both of the way are fine.

On Thu, Aug 6, 2020 at 8:55 AM Ming Wen <we...@apache.org> wrote:

> Optional features should be implemented by plugins,
> and the core should be keep simple.
>
> Thanks,
> Ming Wen, Apache APISIX & Apache SkyWalking
> Twitter: _WenMing
>
>
> YuanSheng Wang <me...@apache.org> 于2020年8月6日周四 上午8:28写道:
>
> > On Thu, Aug 6, 2020 at 7:39 AM Ming Wen <we...@apache.org> wrote:
> >
> > > IMO, implement geo_ip as plugin is better, not in the route.
> > >
> >
> > I would like to implement it in `route`.
> >
> > It may be a condition, we can support it in `vars'.
> >
> >
> > >
> > > And https://luarocks.org/modules/agladysh/lua-geoip is not a good
> > > approach,
> > > lua-resty-maxminddb[1] is good for APISIX.
> > >
> >
> > this library is better. agree +1
> >
> >
> > >
> > > [1] https://github.com/anjia0532/lua-resty-maxminddb
> > >
> > > Thanks,
> > > Ming Wen, Apache APISIX & Apache SkyWalking
> > > Twitter: _WenMing
> > >
> > >
> > > JinChao Shuai <sh...@apache.org> 于2020年8月6日周四 上午1:47写道:
> > >
> > > > I also agree with the second approach and to `Yansheng Wang` that
> users
> > > can
> > > > use their own GeoIP database.
> > > >
> > > > YuanSheng Wang <me...@apache.org> 于2020年8月5日周三 下午11:40写道:
> > > >
> > > > > Of course, the second way is better for APISIX.
> > > > >
> > > > > The `lua-geoip` is under Dual license, we need to confirm if we can
> > use
> > > > > this library.
> > > > >
> > > > > The users needs to download the GeoIP database by himself, Apache
> > > APISIX
> > > > > can
> > > > > not ship with the GeoIP data(under LGPL 2.1).
> > > > >
> > > > >
> > > > > On Wed, Aug 5, 2020 at 9:16 PM Li Ling(Lien) <li...@apache.org>
> > > wrote:
> > > > >
> > > > > > rencently I am thinking about have Geo routing in APISIX,
> > > > > > scenario:
> > > > > >     1、I want route user‘s request from country request intoto
> > > different
> > > > > > upstream host.
> > > > > >     2、When users from outside China redirect to international
> > > > > homepage(many
> > > > > > video sites like youku.com they ban users from outside china).
> > > > > >
> > > > > >
> > > > > > here is two solution I digged into:
> > > > > >
> > > > > > 1、intergrate nginx module
> > > > https://github.com/leev/ngx_http_geoip2_module
> > > > > > and
> > > > > > do variable matching.
> > > > > >      disadvantage: we need calculate the geo data from ip info
> for
> > > > every
> > > > > > request,which is so inefficient.
> > > > > >
> > > > > >
> > > > > > 2、https://luarocks.org/modules/agladysh/lua-geoip
> > > > > >      intergrate this lua module into lua-resty-radixtree, when
> > > geo_ip_*
> > > > > > parameter is set in the routes, we calculate the ip country info
> > from
> > > > > geoip
> > > > > > library.so  that  it wont calculate the geo data for each
> request.
> > > > > >
> > > > >
> > > > >
> > > > > --
> > > > >
> > > > > *MembPhis*
> > > > > My GitHub: https://github.com/membphis
> > > > > Apache APISIX: https://github.com/apache/incubator-apisix
> > > > >
> > > >
> > > >
> > > > --
> > > > Thanks,
> > > > Janko
> > > >
> > >
> >
> >
> > --
> >
> > *MembPhis*
> > My GitHub: https://github.com/membphis
> > Apache APISIX: https://github.com/apache/incubator-apisix
> >
>


-- 

*MembPhis*
My GitHub: https://github.com/membphis
Apache APISIX: https://github.com/apache/incubator-apisix

Re: [DISCUSS] How about have geoip variables available in conditional routing

Posted by Ming Wen <we...@apache.org>.
Optional features should be implemented by plugins,
and the core should be keep simple.

Thanks,
Ming Wen, Apache APISIX & Apache SkyWalking
Twitter: _WenMing


YuanSheng Wang <me...@apache.org> 于2020年8月6日周四 上午8:28写道:

> On Thu, Aug 6, 2020 at 7:39 AM Ming Wen <we...@apache.org> wrote:
>
> > IMO, implement geo_ip as plugin is better, not in the route.
> >
>
> I would like to implement it in `route`.
>
> It may be a condition, we can support it in `vars'.
>
>
> >
> > And https://luarocks.org/modules/agladysh/lua-geoip is not a good
> > approach,
> > lua-resty-maxminddb[1] is good for APISIX.
> >
>
> this library is better. agree +1
>
>
> >
> > [1] https://github.com/anjia0532/lua-resty-maxminddb
> >
> > Thanks,
> > Ming Wen, Apache APISIX & Apache SkyWalking
> > Twitter: _WenMing
> >
> >
> > JinChao Shuai <sh...@apache.org> 于2020年8月6日周四 上午1:47写道:
> >
> > > I also agree with the second approach and to `Yansheng Wang` that users
> > can
> > > use their own GeoIP database.
> > >
> > > YuanSheng Wang <me...@apache.org> 于2020年8月5日周三 下午11:40写道:
> > >
> > > > Of course, the second way is better for APISIX.
> > > >
> > > > The `lua-geoip` is under Dual license, we need to confirm if we can
> use
> > > > this library.
> > > >
> > > > The users needs to download the GeoIP database by himself, Apache
> > APISIX
> > > > can
> > > > not ship with the GeoIP data(under LGPL 2.1).
> > > >
> > > >
> > > > On Wed, Aug 5, 2020 at 9:16 PM Li Ling(Lien) <li...@apache.org>
> > wrote:
> > > >
> > > > > rencently I am thinking about have Geo routing in APISIX,
> > > > > scenario:
> > > > >     1、I want route user‘s request from country request intoto
> > different
> > > > > upstream host.
> > > > >     2、When users from outside China redirect to international
> > > > homepage(many
> > > > > video sites like youku.com they ban users from outside china).
> > > > >
> > > > >
> > > > > here is two solution I digged into:
> > > > >
> > > > > 1、intergrate nginx module
> > > https://github.com/leev/ngx_http_geoip2_module
> > > > > and
> > > > > do variable matching.
> > > > >      disadvantage: we need calculate the geo data from ip info for
> > > every
> > > > > request,which is so inefficient.
> > > > >
> > > > >
> > > > > 2、https://luarocks.org/modules/agladysh/lua-geoip
> > > > >      intergrate this lua module into lua-resty-radixtree, when
> > geo_ip_*
> > > > > parameter is set in the routes, we calculate the ip country info
> from
> > > > geoip
> > > > > library.so  that  it wont calculate the geo data for each request.
> > > > >
> > > >
> > > >
> > > > --
> > > >
> > > > *MembPhis*
> > > > My GitHub: https://github.com/membphis
> > > > Apache APISIX: https://github.com/apache/incubator-apisix
> > > >
> > >
> > >
> > > --
> > > Thanks,
> > > Janko
> > >
> >
>
>
> --
>
> *MembPhis*
> My GitHub: https://github.com/membphis
> Apache APISIX: https://github.com/apache/incubator-apisix
>

Re: [DISCUSS] How about have geoip variables available in conditional routing

Posted by YuanSheng Wang <me...@apache.org>.
On Thu, Aug 6, 2020 at 7:39 AM Ming Wen <we...@apache.org> wrote:

> IMO, implement geo_ip as plugin is better, not in the route.
>

I would like to implement it in `route`.

It may be a condition, we can support it in `vars'.


>
> And https://luarocks.org/modules/agladysh/lua-geoip is not a good
> approach,
> lua-resty-maxminddb[1] is good for APISIX.
>

this library is better. agree +1


>
> [1] https://github.com/anjia0532/lua-resty-maxminddb
>
> Thanks,
> Ming Wen, Apache APISIX & Apache SkyWalking
> Twitter: _WenMing
>
>
> JinChao Shuai <sh...@apache.org> 于2020年8月6日周四 上午1:47写道:
>
> > I also agree with the second approach and to `Yansheng Wang` that users
> can
> > use their own GeoIP database.
> >
> > YuanSheng Wang <me...@apache.org> 于2020年8月5日周三 下午11:40写道:
> >
> > > Of course, the second way is better for APISIX.
> > >
> > > The `lua-geoip` is under Dual license, we need to confirm if we can use
> > > this library.
> > >
> > > The users needs to download the GeoIP database by himself, Apache
> APISIX
> > > can
> > > not ship with the GeoIP data(under LGPL 2.1).
> > >
> > >
> > > On Wed, Aug 5, 2020 at 9:16 PM Li Ling(Lien) <li...@apache.org>
> wrote:
> > >
> > > > rencently I am thinking about have Geo routing in APISIX,
> > > > scenario:
> > > >     1、I want route user‘s request from country request intoto
> different
> > > > upstream host.
> > > >     2、When users from outside China redirect to international
> > > homepage(many
> > > > video sites like youku.com they ban users from outside china).
> > > >
> > > >
> > > > here is two solution I digged into:
> > > >
> > > > 1、intergrate nginx module
> > https://github.com/leev/ngx_http_geoip2_module
> > > > and
> > > > do variable matching.
> > > >      disadvantage: we need calculate the geo data from ip info for
> > every
> > > > request,which is so inefficient.
> > > >
> > > >
> > > > 2、https://luarocks.org/modules/agladysh/lua-geoip
> > > >      intergrate this lua module into lua-resty-radixtree, when
> geo_ip_*
> > > > parameter is set in the routes, we calculate the ip country info from
> > > geoip
> > > > library.so  that  it wont calculate the geo data for each request.
> > > >
> > >
> > >
> > > --
> > >
> > > *MembPhis*
> > > My GitHub: https://github.com/membphis
> > > Apache APISIX: https://github.com/apache/incubator-apisix
> > >
> >
> >
> > --
> > Thanks,
> > Janko
> >
>


-- 

*MembPhis*
My GitHub: https://github.com/membphis
Apache APISIX: https://github.com/apache/incubator-apisix

Re: [DISCUSS] How about have geoip variables available in conditional routing

Posted by Ming Wen <we...@apache.org>.
IMO, implement geo_ip as plugin is better, not in the route.

And https://luarocks.org/modules/agladysh/lua-geoip is not a good approach,
lua-resty-maxminddb[1] is good for APISIX.

[1] https://github.com/anjia0532/lua-resty-maxminddb

Thanks,
Ming Wen, Apache APISIX & Apache SkyWalking
Twitter: _WenMing


JinChao Shuai <sh...@apache.org> 于2020年8月6日周四 上午1:47写道:

> I also agree with the second approach and to `Yansheng Wang` that users can
> use their own GeoIP database.
>
> YuanSheng Wang <me...@apache.org> 于2020年8月5日周三 下午11:40写道:
>
> > Of course, the second way is better for APISIX.
> >
> > The `lua-geoip` is under Dual license, we need to confirm if we can use
> > this library.
> >
> > The users needs to download the GeoIP database by himself, Apache APISIX
> > can
> > not ship with the GeoIP data(under LGPL 2.1).
> >
> >
> > On Wed, Aug 5, 2020 at 9:16 PM Li Ling(Lien) <li...@apache.org> wrote:
> >
> > > rencently I am thinking about have Geo routing in APISIX,
> > > scenario:
> > >     1、I want route user‘s request from country request intoto different
> > > upstream host.
> > >     2、When users from outside China redirect to international
> > homepage(many
> > > video sites like youku.com they ban users from outside china).
> > >
> > >
> > > here is two solution I digged into:
> > >
> > > 1、intergrate nginx module
> https://github.com/leev/ngx_http_geoip2_module
> > > and
> > > do variable matching.
> > >      disadvantage: we need calculate the geo data from ip info for
> every
> > > request,which is so inefficient.
> > >
> > >
> > > 2、https://luarocks.org/modules/agladysh/lua-geoip
> > >      intergrate this lua module into lua-resty-radixtree, when geo_ip_*
> > > parameter is set in the routes, we calculate the ip country info from
> > geoip
> > > library.so  that  it wont calculate the geo data for each request.
> > >
> >
> >
> > --
> >
> > *MembPhis*
> > My GitHub: https://github.com/membphis
> > Apache APISIX: https://github.com/apache/incubator-apisix
> >
>
>
> --
> Thanks,
> Janko
>

Re: [DISCUSS] How about have geoip variables available in conditional routing

Posted by JinChao Shuai <sh...@apache.org>.
I also agree with the second approach and to `Yansheng Wang` that users can
use their own GeoIP database.

YuanSheng Wang <me...@apache.org> 于2020年8月5日周三 下午11:40写道:

> Of course, the second way is better for APISIX.
>
> The `lua-geoip` is under Dual license, we need to confirm if we can use
> this library.
>
> The users needs to download the GeoIP database by himself, Apache APISIX
> can
> not ship with the GeoIP data(under LGPL 2.1).
>
>
> On Wed, Aug 5, 2020 at 9:16 PM Li Ling(Lien) <li...@apache.org> wrote:
>
> > rencently I am thinking about have Geo routing in APISIX,
> > scenario:
> >     1、I want route user‘s request from country request intoto different
> > upstream host.
> >     2、When users from outside China redirect to international
> homepage(many
> > video sites like youku.com they ban users from outside china).
> >
> >
> > here is two solution I digged into:
> >
> > 1、intergrate nginx module https://github.com/leev/ngx_http_geoip2_module
> > and
> > do variable matching.
> >      disadvantage: we need calculate the geo data from ip info for every
> > request,which is so inefficient.
> >
> >
> > 2、https://luarocks.org/modules/agladysh/lua-geoip
> >      intergrate this lua module into lua-resty-radixtree, when geo_ip_*
> > parameter is set in the routes, we calculate the ip country info from
> geoip
> > library.so  that  it wont calculate the geo data for each request.
> >
>
>
> --
>
> *MembPhis*
> My GitHub: https://github.com/membphis
> Apache APISIX: https://github.com/apache/incubator-apisix
>


-- 
Thanks,
Janko

Re: [DISCUSS] How about have geoip variables available in conditional routing

Posted by YuanSheng Wang <me...@apache.org>.
Of course, the second way is better for APISIX.

The `lua-geoip` is under Dual license, we need to confirm if we can use
this library.

The users needs to download the GeoIP database by himself, Apache APISIX can
not ship with the GeoIP data(under LGPL 2.1).


On Wed, Aug 5, 2020 at 9:16 PM Li Ling(Lien) <li...@apache.org> wrote:

> rencently I am thinking about have Geo routing in APISIX,
> scenario:
>     1、I want route user‘s request from country request intoto different
> upstream host.
>     2、When users from outside China redirect to international homepage(many
> video sites like youku.com they ban users from outside china).
>
>
> here is two solution I digged into:
>
> 1、intergrate nginx module https://github.com/leev/ngx_http_geoip2_module
> and
> do variable matching.
>      disadvantage: we need calculate the geo data from ip info for every
> request,which is so inefficient.
>
>
> 2、https://luarocks.org/modules/agladysh/lua-geoip
>      intergrate this lua module into lua-resty-radixtree, when geo_ip_*
> parameter is set in the routes, we calculate the ip country info from geoip
> library.so  that  it wont calculate the geo data for each request.
>


-- 

*MembPhis*
My GitHub: https://github.com/membphis
Apache APISIX: https://github.com/apache/incubator-apisix