Commit c5c908a8 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Implement parsing of .window and .threshold in backend polling specifications.

.window is how many of the latest polls we examine.
.threshold is how many must have succeeded for the backend to be healthy.

	.window = 40;
	.threshold = 30;
		// Thirty of the last fourty polls must have succeed.

	.threshold = 4;
		// The last four polls must have succeeded.

Default values:
	.window = 8;
	.threshold = 3;



git-svn-id: http://www.varnish-cache.org/svn/trunk@3098 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent 12d17a57
......@@ -51,6 +51,8 @@ struct vrt_backend_probe {
char *request;
double timeout;
double interval;
unsigned window;
unsigned threshold;
};
/*
......
......@@ -336,18 +336,23 @@ vcc_ParseProbe(struct tokenlist *tl)
{
struct fld_spec *fs;
struct token *t_field;
struct token *t_did = NULL;
struct token *t_did = NULL, *t_window = NULL, *t_threshold = NULL;
unsigned window, threshold;
fs = vcc_FldSpec(tl,
"?url",
"?request",
"?timeout",
"?interval",
"?window",
"?threshold",
NULL);
ExpectErr(tl, '{');
vcc_NextToken(tl);
window = 8;
threshold = 3;
Fb(tl, 0, "\t.probe = {\n");
while (tl->t->tok != '}') {
......@@ -388,6 +393,16 @@ vcc_ParseProbe(struct tokenlist *tl)
vcc_TimeVal(tl);
ERRCHK(tl);
Fb(tl, 0, ",\n");
} else if (vcc_IdIs(t_field, "window")) {
t_window = tl->t;
window = vcc_UintVal(tl);
vcc_NextToken(tl);
ERRCHK(tl);
} else if (vcc_IdIs(t_field, "threshold")) {
t_threshold = tl->t;
threshold = vcc_UintVal(tl);
vcc_NextToken(tl);
ERRCHK(tl);
} else {
vcc_ErrToken(tl, t_field);
vcc_ErrWhere(tl, t_field);
......@@ -398,6 +413,33 @@ vcc_ParseProbe(struct tokenlist *tl)
ExpectErr(tl, ';');
vcc_NextToken(tl);
}
if (t_threshold == NULL && t_window != NULL) {
vsb_printf(tl->sb, "Must specify .threshold with .window\n");
vcc_ErrWhere(tl, t_window);
return;
} else if (t_threshold != NULL && t_window == NULL) {
if (threshold > 64) {
vsb_printf(tl->sb, "Threshold must be 64 or less.\n");
vcc_ErrWhere(tl, t_threshold);
return;
}
window = threshold + 1;
} else if (window > 64) {
AN(t_window);
vsb_printf(tl->sb, "Window must be 64 or less.\n");
vcc_ErrWhere(tl, t_window);
return;
}
if (threshold > window ) {
vsb_printf(tl->sb,
"Threshold can not be greater than window.\n");
vcc_ErrWhere(tl, t_threshold);
AN(t_window);
vcc_ErrWhere(tl, t_window);
}
Fb(tl, 0, "\t\t.window = %u,\n", window);
Fb(tl, 0, "\t\t.threshold = %u\n", threshold);
Fb(tl, 0, "\t},\n");
ExpectErr(tl, '}');
vcc_NextToken(tl);
......
......@@ -331,6 +331,8 @@ vcl_output_lang_h(struct vsb *sb)
vsb_cat(sb, " char *request;\n");
vsb_cat(sb, " double timeout;\n");
vsb_cat(sb, " double interval;\n");
vsb_cat(sb, " unsigned window;\n");
vsb_cat(sb, " unsigned threshold;\n");
vsb_cat(sb, "};\n");
vsb_cat(sb, "\n");
vsb_cat(sb, "/*\n");
......
......@@ -214,6 +214,7 @@ warns $foh
puts $fo "#include \"config.h\""
puts $fo "#include <stdio.h>"
puts $fo "#include <ctype.h>"
puts $fo "#include \"config.h\""
puts $fo "#include \"vcc_priv.h\""
puts $fo "#include \"vsb.h\""
......
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