Skip to content

Commit

Permalink
varnishncsa: Add hitmiss hitpass indicators to Varnish:handling
Browse files Browse the repository at this point in the history
  • Loading branch information
nigoroll committed Oct 29, 2024
1 parent f0379c8 commit af7b3d9
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 5 deletions.
12 changes: 10 additions & 2 deletions bin/varnishncsa/varnishncsa.c
Original file line number Diff line number Diff line change
Expand Up @@ -1071,17 +1071,25 @@ dispatch_f(struct VSL_data *vsl, struct VSL_transaction * const pt[],
case SLT_RespHeader:
process_hdr(&CTX.watch_resphdr, b, e);
break;
case SLT_HitMiss:
CTX.hitmiss = "miss";
CTX.handling = "hitmiss";
break;
case SLT_HitPass:
CTX.hitmiss = "miss";
CTX.handling = "hitpass";
break;
case SLT_VCL_call:
if (!strcasecmp(b, "recv")) {
CTX.hitmiss = "-";
CTX.handling = "-";
} else if (!strcasecmp(b, "hit")) {
CTX.hitmiss = "hit";
CTX.handling = "hit";
} else if (!strcasecmp(b, "miss")) {
} else if (!strcasecmp(b, "miss") && strcmp(CTX.handling, "hitmiss")) {
CTX.hitmiss = "miss";
CTX.handling = "miss";
} else if (!strcasecmp(b, "pass")) {
} else if (!strcasecmp(b, "pass") && strcmp(CTX.handling, "hitpass")) {
CTX.hitmiss = "miss";
CTX.handling = "pass";
} else if (!strcasecmp(b, "synth")) {
Expand Down
93 changes: 93 additions & 0 deletions bin/varnishtest/tests/u00002.vtc
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
varnishtest "varnishncsa handling"

server s1 {
rxreq
txresp
rxreq
txresp
} -start

varnish v1 -vcl+backend {
backend none none;

sub vcl_backend_fetch {
# XXX would like to do everything in v_b_e, but
# return(pass(x)) is not supported
if (bereq.url == "/hitpass") {
set bereq.backend = s1;
} else {
set bereq.backend = none;
}
}

sub vcl_backend_response {
set beresp.ttl = 1y;
return (pass(1y));
}

sub vcl_backend_error {
set beresp.status = 200;
set beresp.ttl = 1y;
set beresp.body = bereq.url;
if (bereq.url == "/hitmiss") {
set beresp.uncacheable = true;
}
return (deliver);
}

sub vcl_recv {
if (req.url == "/pass") {
return (pass);
}
if (req.url == "/synth") {
return (synth(204));
}
}
} -start

client c1 {
# prime
txreq -url "/hitmiss"
rxresp
expect resp.status == 200
txreq -url "/hitpass"
rxresp
expect resp.status == 200
txreq -url "/hit"
rxresp
expect resp.status == 200

# re-check
txreq -url "/hitmiss"
rxresp
expect resp.status == 200
txreq -url "/hitpass"
rxresp
expect resp.status == 200
txreq -url "/hit"
rxresp
expect resp.status == 200

# others
txreq -url "/pass"
rxresp
expect resp.status == 200
txreq -url "/synth"
rxresp
expect resp.status == 204
} -run

shell {
cat <<EOF >expect
miss /hitmiss
miss /hitpass
miss /hit
hitmiss /hitmiss
hitpass /hitpass
hit /hit
pass /pass
synth /synth
EOF
varnishncsa -d -n ${v1_name} -F "%{Varnish:handling}x %U" >have
diff -u expect have
}
3 changes: 3 additions & 0 deletions doc/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ Varnish Cache NEXT (2025-03-15)
.. PLEASE keep this roughly in commit order as shown by git-log / tig
(new to old)
* The ``hitmiss`` and ``hitpass`` handling indicators have been added to the
``Varnish:handling`` format of ``varnishncsa``.

* The scope of VCL variables `req.is_hitmiss` and `req.is_hitpass` is now restricted
to `vcl_miss, vcl_deliver, vcl_pass, vcl_synth` and `vcl_pass, vcl_deliver, vcl_synth`
respectively.
Expand Down
6 changes: 3 additions & 3 deletions doc/sphinx/reference/varnishncsa.rst
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,9 @@ Supported formatters are:
misses. In backend mode, this field is blank.

Varnish:handling
In client mode, one of the 'hit', 'miss', 'pass', 'pipe' or 'synth' strings
indicating how the request was handled. In backend mode, this field is
blank.
In client mode, one of the 'hit', 'hitmiss', 'hitpass', 'miss', 'pass',
'pipe' or 'synth' strings indicating how the request was handled. In
backend mode, this field is blank.

Varnish:side
Backend or client side. One of two values, 'b' or 'c', depending
Expand Down

0 comments on commit af7b3d9

Please sign in to comment.