Volodymyr Litovka wrote:
seeking for recommendation on how to redirect **every Nth packet** for
the following configuration:
acl region1 src -f /etc/haproxy/region1.txt
redirect prefix https://another.url code 302 if region1
The problem behind this - we're serving the existing client base and
cannot manage it (this is out of our control - so playing with ACL is
meaningless; ACL describes the entire client base in some region). Now
we're introducing new functionality by redirecting customers to the new
endpoint. Being unsure in performance characteristics of underlying
things (this is also out of our control) the only we can do, without
breaking the things, is to gradually increase load by redirecting every
20th request, then every 10th request, then every 5th and finally, stop
redirecting and use new backend for all requests.
If you do not require a "stable" redistribution of the requests, then
this should be fairly easy to accomplish. You could augment your
settings like this:
acl region1_percentage rand(100) -m int lt 5
http-request redirect prefix https://another.url code 302 if region1
region1_percentage
The "5" used in the "region1_percentage" acl corresponds to 5 percent,
as this is equivalent to "every 20th request", as you wrote.
Note that this code picks the requests that will be redirected randomly,
yielding an *average* redirect rate of 5 percent. If you need to
redirect strictly every 20th request, in the order they come in, you
could track all requests from region 1 using a stick table and change
the acl to use the request count from the stick table. It could be done
like this:
stick-table type integer size 10 store http_req_cnt
http-request track-sc0 int(1) if region1
acl region1_percentage sc0_http_req_cnt,mod(proc.percent) -m int eq 5 25
45 65 85
http-request redirect prefix https://another.url code 302 if region1
region1_percentage
This code may require some tweaking, depending on existing stick table
use in your current setup. And this would also require a line like
"set-var percent int(100)" in the global section.
Jens