Created
May 7, 2020 13:59
-
-
Save rezan/a6a1a3cce9174cbb80fd9da4db45d71e to your computer and use it in GitHub Desktop.
Varnish - goto and fallback
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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