0

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:

  1. backend is down (health check from all servers failed).
  2. 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?

Shikloshi
  • 101
  • 2

1 Answers1

0

My approach - you still implement this in healthcheck. You simply measure response timings, calculate average and return for instance 503 HTTP status on /api/responsetime if the average is too high. I do not think there is a variable which stores response time which could be used for ACLs. Event if it existed - each ACL path is processed for each request independently - you still need to calculate ACL based on current request context (including its individual process time which you will get AFTER it has returned from processing from the upstream server).

The other way is to have external service measure these timings and disable/enable the server through admin socket.