Round robind on backend by paths

Hi… to everyone

using haproxy v2.3.4

we need to know if is possible create a round robin if i set with

  acl foo_rr path_beg -i /roundrobindpath
  use backend web_rr_instances_be_https if foo_rr

  backend web_rr_instances_be_https
    mode        http
    balance roundrobin
    option httpchk
    cookie srvid insert preserve nocache httponly secure
    server web1  1.2.3.4:80/rr_path_1 check inter 5s weight 50 id 1 cookie web1_
    server web1  1.2.3.4:80/rr_path_2 check inter 5s weight 50 id 2 cookie web1_
    server web2  1.2.3.5:80/rr_path_1 check inter 5s weight 50 id 3 cookie web2_
    server web2  1.2.3.5:80/rr_path_2 check inter 5s weight 50 id 4 cookie web2_

as syntax config haproxy is ok but result isn’t expected…

on the logs we got

/roundrobindpath not found 404… i want to know if match with that path can hit any of paths on backends… if this possible ?

thanks in advance

Hi @lukastribus any idea with this ?

This is a invalid configuration. If the configurations parsers allows it, then the parser should be improved.

You can load balance between different servers, you can’t load-balance between paths directly.

What you you expect exactly from this configuration? That the URI is always statically rewritten to /rr_path_1 or /rr_path_2 without any consideration for what the client send?

I can think of a way to do this in haproxy, but it’s certainly not “nice”:

  • you could just load-balance between the actual servers
  • in addition to that, you could probably randomly rewrite the URI to either /rr_path_1 or /rr_path_2 (with rand(), ACLs and rewrite statements.

So in the end, you’d rewrite the destination URI randomly between the 2 paths, while also load-balancing between the two actually servers, which is probably what you want.

“What you you expect exactly from this configuration? That the URI is always statically rewritten to /rr_path_1 or /rr_path_2 without any consideration for what the client send?”

yes

“So in the end, you’d rewrite the destination URI randomly between the 2 paths, while also load-balancing between the two actually servers, which is probably what you want.”

how would be the backend block syntax using this rand ?

@lukastribus hi again

i tried using

http-request set-uri https://%[req.hdr(Host)]%[path]%[rand(3)] if web_rr
or
http-request set-uri %[url,regsub(^/pat_rr,/pat_rr[rand(3)],)] if web_rr

setting on frontend and/or backend and nothing… can’t hit the redirect.

always out 503 or 400 status code

are there just 2 rr_path as mentioned or are they more in reality?

I’m just seeing that you configured cookies as well. Do you need stickiness as well? Between the paths also? Because that will certainly not work, even if we figure out the exact syntax to make my proposal work.

mmm… i have to ask to developer about that sticket if need to balance. and yes we have for now 3paths … the example here was with 2 to give you an idea
othe other thing I did was read the doc about rand() function and i saw rand(2) is starting from 0,1,2 (means i need to set my path using 0 i guess) or without 0 because phisically we have path_rr1,2,3 and not path_rr,1,2 or path_rr0,1,2 to use with rand …

@lukastribus

ok forget cookie. let’s see the proposal for test it.

This works for me, varying the path between /path_rr1, /path_rr2 and /path_rr3

http-request set-path /path_rr%[rand(3),add(1)]

It adds 1 so it doesn’t start from zero.

hi @lukastribus

that not work for me…keep receiving 404

on frontend i got

acl web_rr path_beg -i /rr_path
use_backend web_rr_be if dom_example web_rr

on backend

  backend web_rr_be
    mode        http
    balance roundrobin
    option httpchk
    http-request set-path /path_rr%[rand(3),add(1)]
    server web1  1.2.3.4:80 check inter 5s weight 50 id 1
    server web2  1.2.3.5:80 check inter 5s weight 50 id 2

test: curl --head https://www.example.com/path_rr
HTTP/1.1 404 Not Found

on haproxy logs

main_fe~ web1_rr_be/web1 0/0/3/4/7 404 1406 - - ---- 1/1/0/0/0 0/0 {www.exmaple.com |like Gecko) “GET /rr_path HTTP/1.1”
main_fe~ web1_rr_be/web2 0/0/3/4/7 404 1406 - - ---- 1/1/0/0/0 0/0 {www.exmaple.com |like Gecko) “GET /rr_path HTTP/1.1”
main_fe~ web1_rr_be/web1 0/0/3/4/7 404 1406 - - ---- 1/1/0/0/0 0/0 {www.exmaple.com |like Gecko) “GET /rr_path HTTP/1.1”

i send generic rr_path and the logs show randon function ok… but not works :frowning:

in fact not using this mechanism… and setting like before using this. is the same url like logs but hit the site ok

on frontend old config

acl web path_beg -i /path1
acl web path_beg -i /path2
acl web path_beg -i /path3
use_backend web_rr_be if dom_example web

on backend

  backend web_rr_be
    mode        http
    balance roundrobin
    option httpchk
    server web1  1.2.3.4:80 check inter 5s weight 50 id 1
    server web2  1.2.3.5:80 check inter 5s weight 50 id 2

I don’t know what your backend server needs, I just provided a configuration that does what you requested.

Test against your backend server directly, without haproxy involved, once you know what your backend server wants, you will know how to configure haproxy.

ok … thanks for all your help… i think this would be close for now.