Commit a652bea1 authored by Tollef Fog Heen's avatar Tollef Fog Heen

Merge r4356, r4357: Don't half-close probes, add .expected_response

r4356:
Don't halfclose the backend polling TCP connection after sending the
request, some backends gets confused by this.

Add a ".status" to backend polling, to configure the expected HTTP
status code for a good poll.

Fixes #584

r4357:
.expected_response is a better idea than .status

Tip o' the hat to: tfheen



git-svn-id: http://www.varnish-cache.org/svn/branches/2.0@4381 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent 3aa8da01
......@@ -173,23 +173,6 @@ vbp_poke(struct vbp_target *vt)
}
vt->good_xmit |= 1;
/* And do a shutdown(WR) so we know that the backend got it */
i = shutdown(s, SHUT_WR);
if (i != 0) {
vt->err_shut |= 1;
TCP_close(&s);
return;
}
vt->good_shut |= 1;
/* Check if that took too long time */
t_now = TIM_real();
tmo = (int)round((t_end - t_now) * 1e3);
if (tmo < 0) {
TCP_close(&s);
return;
}
pfd->fd = s;
rlen = 0;
do {
......@@ -236,7 +219,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.exp_status)
vt->happy |= 1;
}
......@@ -335,6 +318,8 @@ vbp_wrk_poll_backend(void *priv)
vt->probe.window = 8;
if (vt->probe.threshold == 0)
vt->probe.threshold = 3;
if (vt->probe.exp_status == 0)
vt->probe.exp_status = 200;
if (vt->probe.threshold == ~0U)
vt->probe.initial = vt->probe.threshold - 1;
......
......@@ -33,8 +33,6 @@ BITMAP(good_ipv4, '4', "Good IPv4", 0)
BITMAP(good_ipv6, '6', "Good IPv6", 0)
BITMAP( err_xmit, 'x', "Error Xmit", 0)
BITMAP(good_xmit, 'X', "Good Xmit", 0)
BITMAP( err_shut, 's', "Error Shut", 0)
BITMAP(good_shut, 'S', "Good Shut", 0)
BITMAP( err_recv, 'r', "Error Recv", 0)
BITMAP(good_recv, 'R', "Good Recv", 0)
BITMAP(happy, 'H', "Happy", 1)
......@@ -185,3 +185,11 @@ varnish v1 -badvcl {
}
}
varnish v1 -badvcl {
backend b1 {
.host = "127.0.0.1";
.probe = { .expected_response = 13; }
}
}
......@@ -2,6 +2,16 @@
test "VCL: test backend probe syntax"
# Check status definition
varnish v1 -vcl {
backend b1 {
.host = "127.0.0.1";
.probe = {
.expected_response = 204;
}
}
}
# Check url definition
varnish v1 -vcl {
backend b1 {
......
......@@ -52,6 +52,7 @@ struct vrt_backend_probe {
const char *request;
double timeout;
double interval;
unsigned exp_status;
unsigned window;
unsigned threshold;
unsigned initial;
......
......@@ -341,11 +341,12 @@ 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, status;
fs = vcc_FldSpec(tl,
"?url",
"?request",
"?expected_response",
"?timeout",
"?interval",
"?window",
......@@ -359,6 +360,7 @@ vcc_ParseProbe(struct tokenlist *tl)
window = 0;
threshold = 0;
initial = 0;
status = 0;
Fb(tl, 0, "\t.probe = {\n");
while (tl->t->tok != '}') {
......@@ -404,6 +406,17 @@ vcc_ParseProbe(struct tokenlist *tl)
initial = vcc_UintVal(tl);
vcc_NextToken(tl);
ERRCHK(tl);
} else if (vcc_IdIs(t_field, "expected_response")) {
status = vcc_UintVal(tl);
if (status < 100 || status > 999) {
vsb_printf(tl->sb,
"Must specify .status with exactly three "
" digits (100 <= x <= 999)\n");
vcc_ErrWhere(tl, tl->t);
return;
}
vcc_NextToken(tl);
ERRCHK(tl);
} else if (vcc_IdIs(t_field, "threshold")) {
t_threshold = tl->t;
threshold = vcc_UintVal(tl);
......@@ -455,6 +468,8 @@ vcc_ParseProbe(struct tokenlist *tl)
Fb(tl, 0, "\t\t.initial = %u,\n", initial);
else
Fb(tl, 0, "\t\t.initial = ~0U,\n", initial);
if (status > 0)
Fb(tl, 0, "\t\t.exp_status = %u,\n", status);
Fb(tl, 0, "\t},\n");
ExpectErr(tl, '}');
vcc_NextToken(tl);
......
......@@ -246,13 +246,14 @@ vcl_output_lang_h(struct vsb *sb)
vsb_cat(sb, "on\n */\n\nextern void *vrt_magic_string_end;\n");
vsb_cat(sb, "\nstruct vrt_backend_probe {\n\tconst char\t*url;\n");
vsb_cat(sb, "\tconst char\t*request;\n\tdouble\t\ttimeout;\n");
vsb_cat(sb, "\tdouble\t\tinterval;\n\tunsigned\twindow;\n");
vsb_cat(sb, "\tunsigned\tthreshold;\n\tunsigned\tinitial;\n");
vsb_cat(sb, "};\n\n/*\n * A backend is a host+port somewhere on the");
vsb_cat(sb, " network\n */\nstruct vrt_backend {\n");
vsb_cat(sb, "\tconst char\t\t\t*vcl_name;\n\tconst char\t\t\t*ident");
vsb_cat(sb, ";\n\n\tconst char\t\t\t*hosthdr;\n");
vsb_cat(sb, "\n\tconst unsigned char\t\t*ipv4_sockaddr;\n");
vsb_cat(sb, "\tdouble\t\tinterval;\n\tunsigned\texp_status;\n");
vsb_cat(sb, "\tunsigned\twindow;\n\tunsigned\tthreshold;\n");
vsb_cat(sb, "\tunsigned\tinitial;\n};\n\n/*\n");
vsb_cat(sb, " * A backend is a host+port somewhere on the network\n");
vsb_cat(sb, " */\nstruct vrt_backend {\n\tconst char\t\t\t*vcl_name");
vsb_cat(sb, ";\n\tconst char\t\t\t*ident;\n\n");
vsb_cat(sb, "\tconst char\t\t\t*hosthdr;\n\n");
vsb_cat(sb, "\tconst unsigned char\t\t*ipv4_sockaddr;\n");
vsb_cat(sb, "\tconst unsigned char\t\t*ipv6_sockaddr;\n");
vsb_cat(sb, "\n\tdouble\t\t\t\tconnect_timeout;\n");
vsb_cat(sb, "\tdouble\t\t\t\tfirst_byte_timeout;\n");
......@@ -324,9 +325,9 @@ vcl_output_lang_h(struct vsb *sb)
/* ../../include/vrt_obj.h */
vsb_cat(sb, "/*\n * $Id: vcc_gen_obj.tcl 4082 2009-05-19 07:14:00Z ");
vsb_cat(sb, "sky $\n *\n * NB: This file is machine generated, DO ");
vsb_cat(sb, "NOT EDIT!\n *\n * Edit vcc_gen_obj.tcl instead\n");
vsb_cat(sb, "/*\n * $Id$\n");
vsb_cat(sb, " *\n * NB: This file is machine generated, DO NOT EDI");
vsb_cat(sb, "T!\n *\n * Edit vcc_gen_obj.tcl instead\n");
vsb_cat(sb, " */\n\nstruct sockaddr * VRT_r_client_ip(const struct ");
vsb_cat(sb, "sess *);\nstruct sockaddr * VRT_r_server_ip(struct ses");
vsb_cat(sb, "s *);\nconst char * VRT_r_server_hostname(struct sess ");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment