]> err.no Git - varnish/commitdiff
Implement parsing of .window and .threshold in backend polling specifications.
authorphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Mon, 18 Aug 2008 08:18:43 +0000 (08:18 +0000)
committerphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Mon, 18 Aug 2008 08:18:43 +0000 (08:18 +0000)
.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
varnish-cache/lib/libvcl/vcc_backend.c
varnish-cache/lib/libvcl/vcc_fixed_token.c
varnish-cache/lib/libvcl/vcc_gen_fixed_token.tcl

index d9b77cc13bfa30ef3c7002597197d508f49cef47..f0b3b1a701278d80833c844bde64503cac9219f2 100644 (file)
@@ -51,6 +51,8 @@ struct vrt_backend_probe {
        char            *request;
        double          timeout;
        double          interval;
+       unsigned        window;
+       unsigned        threshold;
 };
 
 /*
index 288364ddc4d2750683485855e272c25ae7000a1e..0119a920f037b59bb149c9cdbc6a734885816840 100644 (file)
@@ -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);
index 11faab76dc33017191844f08f7252aee1f300e79..3b7f0f3ba139abea8daef453808f3a43a58f6d56 100644 (file)
@@ -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");
index 050587c09a9015070560b605b450aa08e56df57a..2e69c874f6a28ac7077c8fb142e6829188b5aaa8 100755 (executable)
@@ -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\""