----- Original Message -----
> From: "Willy Tarreau" <w...@1wt.eu>
> To: "Rajat Chopra" <rcho...@redhat.com>
> Cc: "haproxy" <haproxy@formilux.org>
> Sent: Friday, May 9, 2014 10:43:32 AM
> Subject: Re: Help with dynamic backend selection
>
> Hi Rajat,
>
> On Tue, May 06, 2014 at 07:34:34PM -0400, Rajat Chopra wrote:
> > Hi!
> > The new feature to dynamically select a backend has been going great
> > for me.
> > I use it like this and it all works like a charm :
> >
> > use_backend bk_%[hdr(host),host_to_backend.mapfile] if TRUE
> >
> >
> > Now I need help with a situation. Some of the servers meant for a
> > particular
> > hostname need path replacement. i.e. reqrep/resrep.
> > e.g. I have a set of 5 servers. While three of them need to be balanced for
> > any <hostname>/service1 requests, the other two need to be load balanced
> > for
> > <hostname>/service2 requests. How can I dynamically choose between two
> > backends depending on hostname+path_beg?
> >
> > Can I use something like this?
> >
> > use_backend bk_%[hdr(host),host_to_backend.mapfile]_%[path]
> >
> > where a request to <hostname>/service1 would mean look for a backend named
> > bk_hostname_service1.
> > Clearly it will not work like that because <hostname>/service1/login.php
> > will break the backend lookup.
>
> Absolutely. And you'd have to have as many backends as possible paths, which
> is not practical!
>
> Why don't you run that based on ACLs if you're certain that service2 will
> not cause any trouble ?
>
> Eg:
>
> use_backend bk_%[hdr(host),host_to_backend.mapfile]_%[path] if { path_beg
> /service2 }
> use_backend bk_%[hdr(host),host_to_backend.mapfile]
>
> But again, that requires that you know the exhaustive list of valid paths for
> service2. I don't know if that's your case or not, but that could be the
> solution.
Yes. Thats the only solution I could come up with. I would have the exhaustive
list as the script generates the config file, but I worry that with 150k
backends, what if each backend comes up with its own unique path_beg
requirement. It would defeat the purpose of the map.
Also. In this statement (use_backend
bk_%[hdr(host),host_to_backend.mapfile]_%[path] if { path_beg /service2 })
using _%[path] is not good, right? We need to use
'bk_%[hdr(host),map(mapfile)]_service2', right?
Wonder if we could use some pluggable logic for map. e.g. User can provide a
.so with the user defined map function. So my call will become :
use_backend bk_%[hdr(host),path,myown_func(path_to_dot_so)] if TRUE
And at config time, haproxy does a dlopen on path_to_dot_so, and expects that
dlsym finds a myown_func method. One that returns a string when given the two
arguments (host,path).
It may be useful for other dynamic user defined acls also.
Far fetched feature, eh? :)
Thanks for the help again.
Rajat