Skip to content
Permalink
Browse files

Reinstitute multi-line VSL queries

Forcing one line per query can lead to very long lines for cases where
we can't decompose OR-able individual queries. Where newline previously
acted as a mere space between tokens, the backslash-newline sequence now
fills that void.
  • Loading branch information...
Dridi committed Jun 5, 2019
1 parent de44cc3 commit 11b8a7ebdb30516b4181c8ae61e9b0ce150f08de
Showing with 51 additions and 3 deletions.
  1. +28 −2 bin/varnishtest/tests/u00014.vtc
  2. +17 −0 doc/sphinx/reference/vsl-query.rst
  3. +6 −1 lib/libvarnishapi/vxp_lexer.c
@@ -54,7 +54,8 @@ shell -err -expect "Query expression error" {

shell -err -expect "Query expression error" {
varnishncsa -d -n ${v1_name} -q '
* ~ "Incomplete quoted string
* ~ "Incomplete quoted
string"
'
}

@@ -137,7 +138,32 @@ shell -match "^500 503 $" {
./ncsa.sh -Q query1.vslq -q 'RespStatus == 503'
}

# Make v1 log a multiline VSL record and query it
shell -match "^500 $" {
set -e

tee query1_cont.vslq <<-EOF | wc -l | grep -q 4 # ensure 4 lines
# line continuation
RespStatus \\
== \\
500
EOF

./ncsa.sh -Q query1_cont.vslq
}

shell -err -expect "Query expression error" {
set -e

tee string_cont.vslq <<-EOF | wc -l | grep -q 3 # ensure 3 lines
# quoted string continuation
* ~ "very long \\
string"
EOF

varnishncsa -d -n ${v1_name} -Q string_cont.vslq
}

# Make v1 log a multiline VSL record and query it (hardly useful)

logexpect l1 -v v1 -g raw -q {CLI ~ "\\nvcl1.s1"} {
expect 0 0 CLI "vcl1.s1 +healthy"
@@ -151,6 +151,23 @@ is identical to this query::
Comments can be used and will be ignored, they start with the ``'#'``
character, which may be more useful when the query is read from a file.

For very long queries that couldn't easily be split into multiple queries
it is possible to break them into multiple lines with a backslash preceding
an end of line.

For example this query::

BerespStatus >= 500

is identical to this query::

BerespStatus \
>= \
500

A backslash-newline sequence doesn't continue a comment on the next line
and isn't allowed in a quoted string.

Record selection criteria
-------------------------

@@ -106,6 +106,11 @@ vxp_Lexer(struct vxp *vxp)
continue;
}

if (*p == '\\' && p[1] == '\n') {
p += 2;
continue;
}

/* Skip comments */
if (*p == '#') {
while (p < vxp->e && *p != '\n')
@@ -128,7 +133,7 @@ vxp_Lexer(struct vxp *vxp)
for (q = p + 1; q < vxp->e; q++) {
if (*q == '\\') {
q++;
if (q == vxp->e)
if (q == vxp->e || *q == '\n')
break;
} else if (*q == '\n') {
break;

0 comments on commit 11b8a7e

Please sign in to comment.
You can’t perform that action at this time.