Hi,

I didn't think about such trick, it works!

Thank a lot!

On 23/01/2019 11:48, Jarno Huuskonen wrote:
Hi,

On Wed, Jan 23, Thomas Hilaire wrote:
Hi,

I want to implement a rate-limit system using the sticky table of
HAProxy. Consider that I have 100 servers, and a limit of 10
requests per server, the ACL would be:

     http-request track-sc0 int(1) table GlobalRequestsTracker
     http-request deny deny_status 429 if {
sc0_http_req_rate(GlobalRequestsTracker),div(100) gt 10 }

Now if I want to make this dynamic depending on the healthy servers
count, I need to replace the hardcoded `100` per the `nbsrv`
converter like this:

     http-request track-sc0 int(1) table GlobalRequestsTracker
     http-request deny deny_status 429 if {
sc0_http_req_rate(GlobalRequestsTracker),div(nbsrv(MyBackend)) gt 10
}

But I'm getting the error:

     error detected while parsing an 'http-request deny' condition :
invalid args in converter 'div' : expects an integer or a variable
name in ACL expression
'sc0_http_req_rate(GlobalRequestsTracker),div(nbsrv(MyBackend))'.

Is there a way to use `nbsrv` as a variable inside the `div` operator?
Untested: does something like this work:

http-request set-var(req.dummy) nbsrv(GlobalRequestsTracker)
http-request deny deny_status 429 if { 
sc0_http_req_rate(GlobalRequestsTracker),div(req.dummy) gt 10 }

-Jarno

Reply via email to