Bypassing down status for certain requests

We use a combination of healthchecks and “backup” config to redirect requests to a “service unavailable” site if the main service fails and haproxy has marked all the backend servers as down.

For requests that match certain conditions, we’d like to be able to “override” the down status, and proxy certain traffic to the main servers rather than the failover one.

Example conditions would be requests with a “secret” override URL param (e.g. ?override-key=foo") that developers could use to check the backend services before bringing them back up, or e.g. a specific URL (e.g. “/healthcheck”) our monitoring uses. Currently, when a service is down, the request to “/healthcheck” is answered by the failover service, which means our monitoring doesn’t mark the service as down.

I’ve read in the docs about “force-persist” options, but these require you to already have a session cookie for a specific backend. Is there a way to use “force-persist” but without a cookie for requests that match the above conditions/ACLs, and have haproxy ignore the “down” status of the backend servers?

You could use static server cookies like this:

backend example
 cookie hapsrv indirect preserve
 server server1 cookie server1
 server server2 cookie server2

And let your application (in dev mode) set specific server cookies (hapsrv=server2 for example). For monitoring purposes you should rather check the health status as seen from haproxy (if you want to see if haproxy considers the server up) or directly (if you want to get a healthcheck that is indipendent of the haproxy healthcheck).

You can do the former by using the admin or stats socket. The latter simply means not going through haproxy but directly querying backends.