Skip to content

Instantly share code, notes, and snippets.

@rezan
Created May 7, 2020 13:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rezan/a6a1a3cce9174cbb80fd9da4db45d71e to your computer and use it in GitHub Desktop.
Save rezan/a6a1a3cce9174cbb80fd9da4db45d71e to your computer and use it in GitHub Desktop.
Varnish - goto and fallback
varnishtest "Goto and fallbacks"
server s1 {
rxreq
txresp
expect req.url == "/probe"
accept
rxreq
txresp
expect req.url == "/client"
# Fail this backend
} -start
server s2 {
rxreq
txresp
expect req.url == "/fallback"
} -start
varnish v1 -vcl {
import directors;
import goto;
probe p {
.url = "/probe";
.interval = 2s;
.window = 2;
.threshold = 2;
.timeout = 0.1s;
}
backend s2 {
.host = "${s2_addr}";
.port = "${s2_port}";
}
sub vcl_init {
new s1 = goto.dns_director("${s1_addr}:${s1_port}", probe = p);
new fallback = directors.fallback();
fallback.add_backend(s1.backend());
fallback.add_backend(s2);
}
sub vcl_recv {
set req.backend_hint = fallback.backend();
return (pass);
}
sub vcl_backend_response {
set beresp.http.backend = beresp.backend;
}
} -start
delay 1.0
client c1 {
txreq -url "/client"
rxresp
expect resp.status == 200
expect resp.http.backend ~ "^goto"
delay 2.0
txreq -url "/fallback"
rxresp
expect resp.status == 200
expect resp.http.backend == "s2"
} -run
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment