From 5cccd71534650199ab23f9c98290d688fb279981 Mon Sep 17 00:00:00 2001 From: phk Date: Mon, 18 Aug 2008 08:18:43 +0000 Subject: [PATCH] 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: svn+ssh://projects.linpro.no/svn/varnish/trunk@3098 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- varnish-cache/include/vrt.h | 2 + varnish-cache/lib/libvcl/vcc_backend.c | 44 ++++++++++++++++++- varnish-cache/lib/libvcl/vcc_fixed_token.c | 2 + .../lib/libvcl/vcc_gen_fixed_token.tcl | 1 + 4 files changed, 48 insertions(+), 1 deletion(-) diff --git a/varnish-cache/include/vrt.h b/varnish-cache/include/vrt.h index d9b77cc1..f0b3b1a7 100644 --- a/varnish-cache/include/vrt.h +++ b/varnish-cache/include/vrt.h @@ -51,6 +51,8 @@ struct vrt_backend_probe { char *request; double timeout; double interval; + unsigned window; + unsigned threshold; }; /* diff --git a/varnish-cache/lib/libvcl/vcc_backend.c b/varnish-cache/lib/libvcl/vcc_backend.c index 288364dd..0119a920 100644 --- a/varnish-cache/lib/libvcl/vcc_backend.c +++ b/varnish-cache/lib/libvcl/vcc_backend.c @@ -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); diff --git a/varnish-cache/lib/libvcl/vcc_fixed_token.c b/varnish-cache/lib/libvcl/vcc_fixed_token.c index 11faab76..3b7f0f3b 100644 --- a/varnish-cache/lib/libvcl/vcc_fixed_token.c +++ b/varnish-cache/lib/libvcl/vcc_fixed_token.c @@ -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"); diff --git a/varnish-cache/lib/libvcl/vcc_gen_fixed_token.tcl b/varnish-cache/lib/libvcl/vcc_gen_fixed_token.tcl index 050587c0..2e69c874 100755 --- a/varnish-cache/lib/libvcl/vcc_gen_fixed_token.tcl +++ b/varnish-cache/lib/libvcl/vcc_gen_fixed_token.tcl @@ -214,6 +214,7 @@ warns $foh puts $fo "#include \"config.h\"" puts $fo "#include " puts $fo "#include " +puts $fo "#include \"config.h\"" puts $fo "#include \"vcc_priv.h\"" puts $fo "#include \"vsb.h\"" -- 2.39.5