4

I have pretty sophisticated varnish config. I can't really use the directors and doing the 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
}

This works. But looks really lame.

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

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

This is not working, obviously.

NewRK
  • 409
  • 3
  • 15

2 Answers2

2

After a lot of search with google, i found this link, where they are speaking about migration to V4.

the code :

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

is 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 will be:

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

I hope this help you :)

skonsoft
  • 1,786
  • 5
  • 22
  • 43
  • 1
    He didn't ask for a Varnish 4 solution, but is good to have both versions. – Redithion Sep 21 '15 at 14:03
  • Funny part is that 3 years later I was upgrading from varnish 3 to 4 and I ran into the same problem. I googled around and run into your answer. Good so far. I decided to upvote it, and once I logged in I figured that I'm looking at my old question. – NewRK Jun 29 '17 at 18:13
1

I've been doing a lot of research about this and that's the only way to accomplish it (unless you want to write a vmod).

Assuming you always want to respond with webservice1 unless it's sick, I may suggest a little refactoring:

set req.backend = webservice1;
if(!req.backend.healthy) {
     set req.backend = webservice2;
     #change parameters with regex
}
# redirect here
Redithion
  • 986
  • 1
  • 19
  • 32