How to compare 'bereq.backend' and 'req.backend_hint' against a director/backend in Varnish 4.1

Plöger, Ronald ronald.ploeger at gmx.de
Fri Dec 16 08:37:52 CET 2016


Hi Dridi,

thank you for your quick answer.

 > Nice to see some varnishtest usage!

We do love varnishtest :-)

 > What you can do instead is this:
 >
 >     if ( bereq.backend == d1.backend() ) {
 >         ...
 >     }

 >
 > It will work depending on the semantics of the VMOD object. For
 > objects defined in VMOD directors, it should work with all of them
 > except the hash director. It appears to fail in Varnish 4.1.3 on my
 > system. Please check with the latest 4.1 and open a bug if that's
 > still the case. It works on the master branch, I haven't tried the 5.0
 > release.

We are testing against "varnishd (varnish-4.1.4 revision 4529ff7)" from 
"https://repo.varnish-cache.org/ubuntu/" and I adapted the test to use 
"d1.backend()"

------------------------------------------------------------------------------------------------------

varnishtest "Test backends and directors"

server s1 {
   rxreq
   txresp -status 200
} -start


varnish v1 -vcl {
   import std;
   import directors;
   backend b1 {
     .host = "${s1_addr}";
     .port = "${s1_port}";
   }

   sub vcl_init {
     new d1 = directors.round_robin();
     d1.add_backend(b1);
   }

   sub vcl_recv {
     set req.backend_hint = d1.backend();
   }

   sub vcl_backend_response {
     std.log("xxxxxxxx-vcl_backend_response-bereq: " + bereq.backend);
     std.log("xxxxxxxx-vcl_backend_response-beresp: " + beresp.backend);
     if ( bereq.backend == d1.backend() ) {
       set beresp.http.X-Backend-Response = "d1";
     }
   }

   sub vcl_deliver {
     std.log("xxxxxxxx-vcl_deliver: " + req.backend_hint);
     if ( req.backend_hint == d1.backend() ) {
       set resp.http.X-Backend-Deliver = "d1";
     }
   }

} -start

client c1 {
   txreq
   rxresp
   expect resp.status == 200
   expect resp.http.X-Backend-Response == "d1"
   expect resp.http.X-Backend-Deliver == "d1"
} -run
------------------------------------------------------------------------------------------------------

But this also does not compile:

**** v1    0.5 CLI RX| Message from VCC-compiler:\n
**** v1    0.5 CLI RX| Backend not found: 'd1.backend'\n
**** v1    0.5 CLI RX| ('<vcl.inline>' Line 22 Pos 27)\n
**** v1    0.5 CLI RX|     if ( bereq.backend == d1.backend() ) {\n
**** v1    0.5 CLI RX| --------------------------##########------\n

So I am going to open a bug/issue here 
"https://github.com/varnishcache/varnish-cache", right?


Thanks again and best regards,

Ronald





More information about the varnish-misc mailing list