Skip to content

Instantly share code, notes, and snippets.

@rezan
Created February 11, 2019 16:44
Show Gist options
  • Save rezan/68ec8352ed0527b9897c4045226e3c77 to your computer and use it in GitHub Desktop.
Save rezan/68ec8352ed0527b9897c4045226e3c77 to your computer and use it in GitHub Desktop.
Mark a backend as sick using VCL
varnishtest "Temporary sick backends"
server s1 {
rxreq
txresp
rxreq
txresp
} -start
varnish v1 -vcl+backend {
import directors;
import kvstore;
sub vcl_init {
# Use kvstore 0 for sick backends
kvstore.init(0, 25000);
new sick = directors.round_robin();
}
sub vcl_recv {
# Set Host as sick for 2s
if (req.method == "SICK") {
kvstore.set(0, req.http.Host, "sick", 2s);
return (synth(200));
}
# Is backend flagged as sick?
if (kvstore.get(0, req.http.Host, "") == "sick") {
set req.backend_hint = sick.backend();
}
return (pass);
}
} -start
client c1 {
txreq -hdr "Host: abc"
rxresp
expect resp.status == 200
txreq -req SICK -hdr "Host: abc"
rxresp
txreq -hdr "Host: abc"
rxresp
expect resp.status == 503
delay 3
txreq -hdr "Host: abc"
rxresp
expect resp.status == 200
} -run
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment