How to check if server supports in vcl_recv

I have a rather complicated varnish configuration. I can not use directors and perform routes manually.

//webservice1 and webservice2 has probes working there set req.backend = webservice1; if (req.backend.healthy) { #redirect there } set req.backend = webservice2; if(req.backend.healthy) { #change parameters with regex and redirect } 

It works. But it looks very lame.

Is there any “legal” way to find out if a backend is healthy? Like this:

 if(webservice2.healthy) { #change parameters with regex and redirect } 

This does not work, obviously.

+4
source share
2 answers

I have done a lot of research about this and this is the only way to do it (if you do not want to write vmod).

Assuming you always want to answer webservice1 if it is not sick, I can offer a little refactoring:

 set req.backend = webservice1; if(!req.backend.healthy) { set req.backend = webservice2; #change parameters with regex } # redirect here 
+1
source

After much searching with google, I found a link where they talk about switching to V4.

code:

 if(!req.backend.healthy) { #your logic } 

valid for varnish 3 and not for varnish 4.

For varnish 4:

Take a look here: https://www.varnish-cache.org/docs/4.0/users-guide/vcl-grace.html#users-guide-handling-misbehaving-servers

So the solution would be:

 import std; set req.backend_hint = webservice1; if (!std.healthy(req.backend_hint)) { set req.backend_hint = webservice2; } 

Hope this helps you :)

+1
source

Source: https://habr.com/ru/post/1434097/


All Articles