[master] 8fd8366fd Add VUT_OPT_Q to get a VSL query from a file
Dridi Boukelmoune
dridi.boukelmoune at gmail.com
Wed Jun 12 04:58:11 UTC 2019
commit 8fd8366fd55a7818fd66bff09bca3340de2b28c4
Author: Dridi Boukelmoune <dridi.boukelmoune at gmail.com>
Date: Fri May 17 13:55:43 2019 +0200
Add VUT_OPT_Q to get a VSL query from a file
diff --git a/bin/varnishhist/varnishhist_options.h b/bin/varnishhist/varnishhist_options.h
index 1bf1de7c7..44d710da4 100644
--- a/bin/varnishhist/varnishhist_options.h
+++ b/bin/varnishhist/varnishhist_options.h
@@ -91,6 +91,7 @@ HIS_OPT_p
#undef HIS_CLIENT
#undef HIS_PROF
HIS_OPT_P
+VUT_OPT_Q
VUT_OPT_q
VUT_OPT_r
VUT_OPT_t
diff --git a/bin/varnishlog/varnishlog_options.h b/bin/varnishlog/varnishlog_options.h
index ea0b4c698..8c9fd1db7 100644
--- a/bin/varnishlog/varnishlog_options.h
+++ b/bin/varnishlog/varnishlog_options.h
@@ -68,6 +68,7 @@ VUT_OPT_k
VSL_OPT_L
VUT_OPT_n
VUT_GLOBAL_OPT_P
+VUT_OPT_Q
VUT_OPT_q
VUT_OPT_r
VSL_OPT_R
diff --git a/bin/varnishncsa/varnishncsa_options.h b/bin/varnishncsa/varnishncsa_options.h
index 73765083f..8987a9615 100644
--- a/bin/varnishncsa/varnishncsa_options.h
+++ b/bin/varnishncsa/varnishncsa_options.h
@@ -86,6 +86,7 @@ VUT_OPT_h
VSL_OPT_L
VUT_OPT_n
VUT_GLOBAL_OPT_P
+VUT_OPT_Q
VUT_OPT_q
VUT_OPT_r
VSL_OPT_R
diff --git a/bin/varnishtest/tests/u00014.vtc b/bin/varnishtest/tests/u00014.vtc
index 244dcc08f..dc3138ae3 100644
--- a/bin/varnishtest/tests/u00014.vtc
+++ b/bin/varnishtest/tests/u00014.vtc
@@ -58,6 +58,15 @@ shell -err -expect "Query expression error" {
'
}
+shell -err -expect "Query expression error" {
+ echo '# empty query file' >empty.vslq
+ varnishncsa -d -n ${v1_name} -Q empty.vslq
+}
+
+shell -err -expect "-Q missing.vslq: No such file or directory" {
+ varnishncsa -d -n ${v1_name} -Q missing.vslq
+}
+
shell -match "^500 $" {
# single query 1
./ncsa.sh -q 'RespStatus == 500'
@@ -90,7 +99,40 @@ shell -match "^500 503 $" {
'
}
+shell -match "^500 503 $" {
+ cat >query.vslq <<-EOF
+ # query 1
+ RespStatus == 500
+
+ # query 2
+ RespStatus == 503
+ EOF
+ ./ncsa.sh -Q query.vslq
+}
+
shell -match "^500 503 $" {
# multiple -q options
./ncsa.sh -q 'RespStatus == 500' -q 'RespStatus == 503'
}
+
+shell -match "^500 503 $" {
+ # multiple -Q options
+
+ cat >query1.vslq <<-EOF
+ # query 1
+ RespStatus == 500
+ EOF
+
+ cat >query2.vslq <<-EOF
+ # query 2
+ RespStatus == 503
+ EOF
+
+ ./ncsa.sh -Q query1.vslq -Q query2.vslq
+}
+
+shell -match "^500 503 $" {
+ # mix -Q and -q options
+
+ ./ncsa.sh -Q query1.vslq -q 'RespStatus == 503'
+}
diff --git a/bin/varnishtop/varnishtop_options.h b/bin/varnishtop/varnishtop_options.h
index 6605d463a..2a6c312e7 100644
--- a/bin/varnishtop/varnishtop_options.h
+++ b/bin/varnishtop/varnishtop_options.h
@@ -73,6 +73,7 @@ VSL_OPT_I
VSL_OPT_L
VUT_OPT_n
TOP_OPT_p
+VUT_OPT_Q
VUT_OPT_q
VUT_OPT_r
VUT_OPT_t
diff --git a/doc/sphinx/reference/vsl-query.rst b/doc/sphinx/reference/vsl-query.rst
index 67cf2f02d..072747f4c 100644
--- a/doc/sphinx/reference/vsl-query.rst
+++ b/doc/sphinx/reference/vsl-query.rst
@@ -149,7 +149,7 @@ is identical to this query::
(*Error) or (BerespStatus >= 500)
Comments can be used and will be ignored, they start with the ``'#'``
-character.
+character, which may be more useful when the query is read from a file.
Record selection criteria
-------------------------
diff --git a/include/vut_options.h b/include/vut_options.h
index 6b4675c18..7aacaaaec 100644
--- a/include/vut_options.h
+++ b/include/vut_options.h
@@ -73,10 +73,18 @@
" the host name is used." \
)
+#define VUT_OPT_Q \
+ VOPT("Q:", "[-Q <file>]", "VSL query file", \
+ "Specifies the file containing the VSL query to use." \
+ " When multiple -Q or -q options are specified, all" \
+ " queries are considered as if the 'or' operator was" \
+ " used to combine them." \
+ )
+
#define VUT_OPT_q \
VOPT("q:", "[-q <query>]", "VSL query", \
- "Specifies the VSL query to use. When multiple -q" \
- " options are specified, all queries are considered" \
+ "Specifies the VSL query to use. When multiple -q or" \
+ " -Q options are specified, all queries are considered" \
" as if the 'or' operator was used to combine them." \
)
diff --git a/lib/libvarnishapi/vut.c b/lib/libvarnishapi/vut.c
index 0fdce6634..db7f97116 100644
--- a/lib/libvarnishapi/vut.c
+++ b/lib/libvarnishapi/vut.c
@@ -51,6 +51,7 @@
#include "miniobj.h"
#include "vcs.h"
#include "vsb.h"
+#include "vfil.h"
#include "vut.h"
@@ -195,8 +196,19 @@ VUT_Arg(struct VUT *vut, int opt, const char *arg)
AN(arg);
REPLACE(vut->P_arg, arg);
return (1);
+ case 'Q':
+ AN(arg);
+ p = VFIL_readfile(NULL, arg, NULL);
+ if (p == NULL) {
+ VUT_Error(vut, 1, "-Q %s: %s", arg, strerror(errno));
+ return (-1);
+ }
+ vut_arg_q(vut, p);
+ free(p);
+ return (1);
case 'q':
/* Query to use */
+ AN(arg);
vut_arg_q(vut, arg);
return (1);
case 'r':
More information about the varnish-commit
mailing list