Commit 68d0daef authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

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; }
	}



git-svn-id: http://www.varnish-cache.org/svn/trunk/varnish-cache@4985 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent e8dae502
......@@ -10,18 +10,20 @@ server s1 {
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 {
......
......@@ -264,7 +264,7 @@ vcc_ParseProbeSpec(struct tokenlist *tl)
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 != '}') {
......@@ -373,6 +373,28 @@ vcc_ParseProbeSpec(struct tokenlist *tl)
SkipToken(tl, '}');
}
/*--------------------------------------------------------------------
* 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
*
......@@ -496,9 +518,21 @@ vcc_ParseHostDef(struct tokenlist *tl, int serial, const char *vgcname)
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;
......
......@@ -116,7 +116,8 @@ enum var_type {
enum ref_type {
R_FUNC,
R_ACL,
R_BACKEND
R_BACKEND,
R_PROBE
};
struct ref {
......@@ -158,6 +159,7 @@ int vcc_ParseAction(struct tokenlist *tl);
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, ...);
......
......@@ -570,6 +570,7 @@ static struct toplev {
{ "sub", vcc_Function },
{ "backend", vcc_ParseDirector },
{ "director", vcc_ParseDirector },
{ "probe", vcc_ParseProbe },
{ NULL, NULL }
};
......
......@@ -86,6 +86,7 @@ vcc_typename(struct tokenlist *tl, const struct ref *r)
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 @@ vcc_CheckReferences(struct tokenlist *tl)
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 @@ vcc_CheckReferences(struct tokenlist *tl)
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);
}
......
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