I'm trying to implement a way to 'fake' a server response directly from haproxy
while servers are down or slow (exceed some limit).
I wrote a lua script which is loaded into haproxy (and is registered as a core.service) that mimic the server behavior in a light weight and fast way.
Now I need to make the backend choice according to the rules:
- backend is down (health check from all servers failed).
- backend is slow enough and I don't want to wait for a real response.
for the first part I managed to go with:
acl backend_down nbsrv(be) lt 1
...
use_backend fallback_backend if backend_down
backend fallback_backend
http-request use-service lua.fallback_service
I can't seem to find a good way for the second part. How can I check for response time and make decisions in the configuration upon the result?