r4985 - in trunk/varnish-cache: bin/varnishtest/tests lib/libvcl
phk at varnish-cache.org
phk at varnish-cache.org
Tue Jun 22 15:36:18 CEST 2010
Author: phk
Date: 2010-06-22 15:36:18 +0200 (Tue, 22 Jun 2010)
New Revision: 4985
Modified:
trunk/varnish-cache/bin/varnishtest/tests/v00014.vtc
trunk/varnish-cache/lib/libvcl/vcc_backend.c
trunk/varnish-cache/lib/libvcl/vcc_compile.h
trunk/varnish-cache/lib/libvcl/vcc_parse.c
trunk/varnish-cache/lib/libvcl/vcc_xref.c
Log:
Make it possible to declare stand-alone backend probes and reference
them by name:
probe foo {
.url = "/";
.timeout = 1s;
}
director default random {
{ .backend = {.host = "10.0.0.1"; .probe = foo; } .weight = 1; }
{ .backend = {.host = "10.0.0.2"; .probe = foo; } .weight = 1; }
{ .backend = {.host = "10.0.0.3"; .probe = foo; } .weight = 1; }
{ .backend = {.host = "10.0.0.4"; .probe = foo; } .weight = 1; }
{ .backend = {.host = "10.0.0.5"; .probe = foo; } .weight = 1; }
{ .backend = {.host = "10.0.0.6"; .probe = foo; } .weight = 1; }
{ .backend = {.host = "10.0.0.7"; .probe = foo; } .weight = 1; }
}
Modified: trunk/varnish-cache/bin/varnishtest/tests/v00014.vtc
===================================================================
--- trunk/varnish-cache/bin/varnishtest/tests/v00014.vtc 2010-06-22 13:01:22 UTC (rev 4984)
+++ trunk/varnish-cache/bin/varnishtest/tests/v00014.vtc 2010-06-22 13:36:18 UTC (rev 4985)
@@ -10,18 +10,20 @@
varnish v1 -vcl {
+ probe foo {
+ .url = "/";
+ .timeout = 1s;
+ .interval = 1s;
+ .window = 3;
+ .threshold = 2;
+ .initial = 0;
+ }
+
backend default {
.host = "${s1_addr}";
.port = "${s1_port}";
.max_connections = 1;
- .probe = {
- .url = "/";
- .timeout = 1s;
- .interval = 1s;
- .window = 3;
- .threshold = 2;
- .initial = 0;
- }
+ .probe = foo;
}
sub vcl_recv {
Modified: trunk/varnish-cache/lib/libvcl/vcc_backend.c
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcc_backend.c 2010-06-22 13:01:22 UTC (rev 4984)
+++ trunk/varnish-cache/lib/libvcl/vcc_backend.c 2010-06-22 13:36:18 UTC (rev 4985)
@@ -264,7 +264,7 @@
threshold = 0;
initial = 0;
status = 0;
- Fh(tl, 0, "static const struct vrt_backend_probe vgc_probe_%d = {\n",
+ Fh(tl, 0, "static const struct vrt_backend_probe vgc_probe__%d = {\n",
tl->nprobe++);
while (tl->t->tok != '}') {
@@ -374,6 +374,28 @@
}
/*--------------------------------------------------------------------
+ * Parse and emit a probe definition
+ */
+
+void
+vcc_ParseProbe(struct tokenlist *tl)
+{
+ struct token *t_probe;
+
+ vcc_NextToken(tl); /* ID: probe */
+
+ vcc_ExpectCid(tl); /* ID: name */
+ ERRCHK(tl);
+ t_probe = tl->t;
+ vcc_NextToken(tl);
+ vcc_AddDef(tl, t_probe, R_PROBE);
+
+ Fh(tl, 0, "\n#define vgc_probe_%.*s\tvgc_probe__%d\n",
+ PF(t_probe), tl->nprobe);
+ vcc_ParseProbeSpec(tl);
+}
+
+/*--------------------------------------------------------------------
* Parse and emit a backend host definition
*
* The struct vrt_backend is emitted to Fh().
@@ -496,9 +518,21 @@
saint = u;
SkipToken(tl, ';');
} else if (vcc_IdIs(t_field, "probe") && tl->t->tok == '{') {
- Fb(tl, 0, "\t.probe = &vgc_probe_%d,\n", tl->nprobe);
+ Fb(tl, 0, "\t.probe = &vgc_probe__%d,\n", tl->nprobe);
vcc_ParseProbeSpec(tl);
ERRCHK(tl);
+ } else if (vcc_IdIs(t_field, "probe") && tl->t->tok == ID) {
+ Fb(tl, 0, "\t.probe = &vgc_probe_%.*s,\n", PF(tl->t));
+ vcc_AddRef(tl, tl->t, R_PROBE);
+ vcc_NextToken(tl);
+ SkipToken(tl, ';');
+ } else if (vcc_IdIs(t_field, "probe")) {
+ vsb_printf(tl->sb,
+ "Expected '{' or name of probe.");
+ vcc_ErrToken(tl, tl->t);
+ vsb_printf(tl->sb, " at\n");
+ vcc_ErrWhere(tl, tl->t);
+ return;
} else {
ErrInternal(tl);
return;
Modified: trunk/varnish-cache/lib/libvcl/vcc_compile.h
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcc_compile.h 2010-06-22 13:01:22 UTC (rev 4984)
+++ trunk/varnish-cache/lib/libvcl/vcc_compile.h 2010-06-22 13:36:18 UTC (rev 4985)
@@ -116,7 +116,8 @@
enum ref_type {
R_FUNC,
R_ACL,
- R_BACKEND
+ R_BACKEND,
+ R_PROBE
};
struct ref {
@@ -158,6 +159,7 @@
struct fld_spec;
typedef void parsedirector_f(struct tokenlist *tl);
+void vcc_ParseProbe(struct tokenlist *tl);
void vcc_ParseDirector(struct tokenlist *tl);
void vcc_ParseBackendHost(struct tokenlist *tl, int serial, char **nm);
struct fld_spec * vcc_FldSpec(struct tokenlist *tl, const char *first, ...);
Modified: trunk/varnish-cache/lib/libvcl/vcc_parse.c
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcc_parse.c 2010-06-22 13:01:22 UTC (rev 4984)
+++ trunk/varnish-cache/lib/libvcl/vcc_parse.c 2010-06-22 13:36:18 UTC (rev 4985)
@@ -570,6 +570,7 @@
{ "sub", vcc_Function },
{ "backend", vcc_ParseDirector },
{ "director", vcc_ParseDirector },
+ { "probe", vcc_ParseProbe },
{ NULL, NULL }
};
Modified: trunk/varnish-cache/lib/libvcl/vcc_xref.c
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcc_xref.c 2010-06-22 13:01:22 UTC (rev 4984)
+++ trunk/varnish-cache/lib/libvcl/vcc_xref.c 2010-06-22 13:36:18 UTC (rev 4985)
@@ -86,6 +86,7 @@
case R_FUNC: return ("function");
case R_ACL: return ("acl");
case R_BACKEND: return ("backend");
+ case R_PROBE: return ("probe");
default:
ErrInternal(tl);
vsb_printf(tl->sb, "Ref ");
@@ -153,6 +154,7 @@
struct ref *r;
const char *type;
int nerr = 0;
+ const char *sep = "";
VTAILQ_FOREACH(r, &tl->refs, list) {
if (r->defcnt != 0 && r->refcnt != 0)
@@ -163,15 +165,16 @@
if (r->defcnt == 0) {
vsb_printf(tl->sb,
- "Undefined %s %.*s, first reference:\n",
- type, PF(r->name));
+ "%sUndefined %s %.*s, first reference:\n",
+ sep, type, PF(r->name));
vcc_ErrWhere(tl, r->name);
continue;
}
- vsb_printf(tl->sb, "Unused %s %.*s, defined:\n",
- type, PF(r->name));
+ vsb_printf(tl->sb, "%sUnused %s %.*s, defined:\n",
+ sep, type, PF(r->name));
vcc_ErrWhere(tl, r->name);
+ sep = "\n";
}
return (nerr);
}
More information about the varnish-commit
mailing list