[PATCH] Add support for setting the expected response for backend probes.
Tollef Fog Heen
tfheen at err.no
Fri Oct 23 11:49:14 CEST 2009
Syntax is
backend b0 {
.host = "127.0.0.1";
.probe = {
.url = "/test.jpg";
.timeout = 224 ms;
.expected_response = 204;
}
}
---
varnish-cache/bin/varnishd/cache_backend_poll.c | 5 ++++-
varnish-cache/include/vrt.h | 1 +
varnish-cache/lib/libvcl/vcc_backend.c | 9 ++++++++-
3 files changed, 13 insertions(+), 2 deletions(-)
diff --git a/varnish-cache/bin/varnishd/cache_backend_poll.c b/varnish-cache/bin/varnishd/cache_backend_poll.c
index 2ab08ca..fe7f8b3 100644
--- a/varnish-cache/bin/varnishd/cache_backend_poll.c
+++ b/varnish-cache/bin/varnishd/cache_backend_poll.c
@@ -237,7 +237,7 @@ vbp_poke(struct vbp_target *vt)
i = sscanf(vt->resp_buf, "HTTP/%*f %u %s", &resp, buf);
- if (i == 2 && resp == 200)
+ if (i == 2 && resp == vt->probe.expected_response)
vt->happy |= 1;
}
@@ -340,6 +340,9 @@ vbp_wrk_poll_backend(void *priv)
if (vt->probe.threshold == ~0U)
vt->probe.initial = vt->probe.threshold - 1;
+ if (vt->probe.expected_response == 0)
+ vt->probe.expected_response = 200;
+
if (vt->probe.initial > vt->probe.threshold)
vt->probe.initial = vt->probe.threshold;
diff --git a/varnish-cache/include/vrt.h b/varnish-cache/include/vrt.h
index 5f6250e..2a7ef3a 100644
--- a/varnish-cache/include/vrt.h
+++ b/varnish-cache/include/vrt.h
@@ -55,6 +55,7 @@ struct vrt_backend_probe {
unsigned window;
unsigned threshold;
unsigned initial;
+ unsigned expected_response;
};
/*
diff --git a/varnish-cache/lib/libvcl/vcc_backend.c b/varnish-cache/lib/libvcl/vcc_backend.c
index c0b206c..2575107 100644
--- a/varnish-cache/lib/libvcl/vcc_backend.c
+++ b/varnish-cache/lib/libvcl/vcc_backend.c
@@ -343,7 +343,7 @@ vcc_ParseProbe(struct tokenlist *tl)
struct token *t_field;
struct token *t_did = NULL, *t_window = NULL, *t_threshold = NULL;
struct token *t_initial = NULL;
- unsigned window, threshold, initial;
+ unsigned window, threshold, initial, expected_response;
fs = vcc_FldSpec(tl,
"?url",
@@ -353,6 +353,7 @@ vcc_ParseProbe(struct tokenlist *tl)
"?window",
"?threshold",
"?initial",
+ "?expected_response",
NULL);
ExpectErr(tl, '{');
@@ -361,6 +362,7 @@ vcc_ParseProbe(struct tokenlist *tl)
window = 0;
threshold = 0;
initial = 0;
+ expected_response = 0;
Fb(tl, 0, "\t.probe = {\n");
while (tl->t->tok != '}') {
@@ -411,6 +413,10 @@ vcc_ParseProbe(struct tokenlist *tl)
threshold = vcc_UintVal(tl);
vcc_NextToken(tl);
ERRCHK(tl);
+ } else if (vcc_IdIs(t_field, "expected_response")) {
+ expected_response = vcc_UintVal(tl);
+ vcc_NextToken(tl);
+ ERRCHK(tl);
} else {
vcc_ErrToken(tl, t_field);
vcc_ErrWhere(tl, t_field);
@@ -457,6 +463,7 @@ vcc_ParseProbe(struct tokenlist *tl)
Fb(tl, 0, "\t\t.initial = %u,\n", initial);
else
Fb(tl, 0, "\t\t.initial = ~0U,\n", initial);
+ Fb(tl, 0, "\t\t.expected_response = %u,\n", expected_response);
Fb(tl, 0, "\t},\n");
ExpectErr(tl, '}');
vcc_NextToken(tl);
--
1.6.3.3
--=-=-=--
More information about the varnish-misc
mailing list