[6.0] 84fe7970e Warn about too many (>100) VCLs.
Reza Naghibi
reza at naghibi.com
Tue May 19 19:39:08 UTC 2020
commit 84fe7970e75adbaef15671d18777a0bf54b4240f
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Wed Aug 15 12:37:22 2018 +0000
Warn about too many (>100) VCLs.
Two new paramters allow the limit and than handling (ignore, warn, fail)
to be configured.
Fixes #2713
diff --git a/bin/varnishd/mgt/mgt_vcl.c b/bin/varnishd/mgt/mgt_vcl.c
index 049cee5af..c0fadf475 100644
--- a/bin/varnishd/mgt/mgt_vcl.c
+++ b/bin/varnishd/mgt/mgt_vcl.c
@@ -53,6 +53,7 @@
#include "tbl/vcl_states.h"
static const char * const VCL_STATE_LABEL = "label";
+static int vcl_count;
struct vclprog;
struct vmodfile;
@@ -252,6 +253,8 @@ mgt_vcl_add(const char *name, const char *state)
vp->warm = 1;
VTAILQ_INSERT_TAIL(&vclhead, vp, list);
+ if (vp->state != VCL_STATE_LABEL)
+ vcl_count++;
return (vp);
}
@@ -269,6 +272,8 @@ mgt_vcl_del(struct vclprog *vp)
mgt_vcl_dep_del(VTAILQ_FIRST(&vp->dfrom));
VTAILQ_REMOVE(&vclhead, vp, list);
+ if (vp->state != VCL_STATE_LABEL)
+ vcl_count--;
if (vp->fname != NULL) {
if (!MGT_DO_DEBUG(DBG_VCL_KEEP))
AZ(unlink(vp->fname));
@@ -566,6 +571,12 @@ mgt_new_vcl(struct cli *cli, const char *vclname, const char *vclsrc,
if (C_flag) {
bprintf(buf, ".CflagTest.%d", (int)getpid());
vclname = buf;
+ } else if (vcl_count >= mgt_param.max_vcl &&
+ mgt_param.max_vcl_handling == 2) {
+ VCLI_Out(cli, "Too many (%d) VCLs already loaded\n", vcl_count);
+ VCLI_Out(cli, "(See max_vcl and max_vcl_handling parameters)");
+ VCLI_SetResult(cli, CLIS_CANT);
+ return;
}
if (state == NULL)
@@ -592,6 +603,14 @@ mgt_new_vcl(struct cli *cli, const char *vclname, const char *vclsrc,
if (active_vcl == NULL)
active_vcl = vp;
+ if (cli->result == CLIS_OK &&
+ vcl_count > mgt_param.max_vcl &&
+ mgt_param.max_vcl_handling == 1) {
+ VCLI_Out(cli, "%d VCLs loaded\n", vcl_count);
+ VCLI_Out(cli, "Remember to vcl.discard the old/unused VCLs.\n");
+ VCLI_Out(cli, "(See max_vcl and max_vcl_handling parameters)");
+ }
+
if (!MCH_Running())
return;
diff --git a/bin/varnishtest/tests/v00025.vtc b/bin/varnishtest/tests/v00025.vtc
index 699137b0f..d3d0cf684 100644
--- a/bin/varnishtest/tests/v00025.vtc
+++ b/bin/varnishtest/tests/v00025.vtc
@@ -7,7 +7,23 @@ server s1 {
txresp
} -start
-varnish v1 -syntax 4.0 -arg "-i J.F.Nobody" -vcl+backend {
+# Test max_vcl param
+varnish v1 -arg "-i J.F.Nobody" -vcl+backend { } -start
+
+varnish v1 -cliok "param.set max_vcl 2"
+varnish v1 -cliok "param.set max_vcl_handling 2"
+
+varnish v1 -vcl+backend { }
+varnish v1 -errvcl {Too many (2) VCLs already loaded} {}
+
+varnish v1 -cliok "param.set max_vcl_handling 1"
+
+varnish v1 -cliexpect "Remember to vcl.discard the old/unused VCLs." \
+ {vcl.inline foobar "vcl 4.1; backend b1 {.host=\"${s1_addr}\";}"}
+
+varnish v1 -cliok "param.set max_vcl 100"
+
+varnish v1 -syntax 4.0 -vcl+backend {
import std;
import directors;
@@ -78,7 +94,7 @@ varnish v1 -syntax 4.0 -arg "-i J.F.Nobody" -vcl+backend {
set bereq.connect_timeout = 10s;
}
-} -start
+}
client c1 {
txreq
diff --git a/include/tbl/params.h b/include/tbl/params.h
index 71d425195..deecd2051 100644
--- a/include/tbl/params.h
+++ b/include/tbl/params.h
@@ -1537,6 +1537,38 @@ PARAM(
/* func */ NULL
)
+PARAM(
+ /* name */ max_vcl_handling,
+ /* typ */ uint,
+ /* min */ "0",
+ /* max */ "2",
+ /* default */ "1",
+ /* units */ NULL,
+ /* flags */ 0,
+ /* s-text */
+ "Behaviour when attempting to exceed max_vcl loaded VCL.\n"
+ "\n* 0 - Ignore max_vcl parameter.\n"
+ "\n* 1 - Issue warning.\n"
+ "\n* 2 - Refuse loading VCLs.",
+ /* l-text */ "",
+ /* func */ NULL
+)
+
+PARAM(
+ /* name */ max_vcl,
+ /* typ */ uint,
+ /* min */ "0",
+ /* max */ NULL,
+ /* default */ "100",
+ /* units */ NULL,
+ /* flags */ 0,
+ /* s-text */
+ "Threshold of loaded VCL programs. (VCL labels are not counted.)"
+ " Parameter max_vcl_handling determines behaviour.",
+ /* l-text */ "",
+ /* func */ NULL
+)
+
PARAM(
/* name */ vsm_free_cooldown,
/* typ */ timeout,
More information about the varnish-commit
mailing list