Skip to content

Commit

Permalink
handling can be streaming-hit
Browse files Browse the repository at this point in the history
  • Loading branch information
gquintard committed Apr 16, 2024
1 parent fbeb731 commit aa7d058
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 2 deletions.
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,25 @@ using the `-i/-I/-x/-X` arguments.
We'll use `typescript` notation to describe the object shape:
169: char *handling = "incomplete";
233: // don't overwrite handling if we're already erroring
235: if (!strcmp(handling, "fail") || !strcmp(handling, "abandon")) {
238: handling = "miss";
240: handling = "pass";
242: handling = "pipe";
244: handling = "synth";
246: handling = "fetched";
248: handling = "error";
250: handling = "synth";
257: if (!strcmp(handling, "fail") || !strcmp(handling, "abandon")) {
260: handling = "streaming-hit";
262: handling = "hit";
274: handling = "retry";
276: handling = "restart";
278: handling = "fail";
280: handling = "abandon";
``` typescript
{
req: { // describes the request as seen by the remote (either client, or backend)
Expand All @@ -74,6 +93,10 @@ We'll use `typescript` notation to describe the object shape:
hdrBytes: number, // ReqAcct, BereqAcct
bodyBytes: number, // ^ same
},
handling: "hit" | "miss" | "pass" |"pipe" |
"streaming-hit" | "fail" | "synth"
"abandon" | "fetched" | "error"
"retry" | "restart", // how the request was handled
timeline: Array<{name: string, timestamp: number}> // Timestamp
side: "backend" | "client",
id: string, // the transaction's vxid
Expand Down
17 changes: 15 additions & 2 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -231,10 +231,9 @@ static int process_group(struct VSL_data *vsl,
}

// don't overwrite handling if we're already erroring
// we don't need to handle HIT, SLT_Hit will take care of it
if (!strcmp(handling, "fail") || !strcmp(handling, "abandon")) {
break;
} else if (!strcmp(data, "HIT")) {
handling = "hit";
} else if (!strcmp(data, "MISS")) {
handling = "miss";
} else if (!strcmp(data, "PASS")) {
Expand All @@ -252,6 +251,20 @@ static int process_group(struct VSL_data *vsl,
}
break;

case SLT_Hit: {
unsigned _a, _e, _f;
float _b, _c, _d;
if (!strcmp(handling, "fail") || !strcmp(handling, "abandon")) {
break;
} else if (6 == sscanf(data, "%u %f %f %f %u %u", &_a, &_b, &_c, &_d, &_e, &_f)) {
handling = "streaming-hit";
} else {
handling = "hit";
}
break;
}


case SLT_VCL_return:
if (t->type == VSL_t_bereq &&
(!strcmp(data, "fetch") || !strcmp(data, "error"))) {
Expand Down
62 changes: 62 additions & 0 deletions tests/004.vtc
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
varnishtest "fail/abandon"

feature cmd jq

barrier b1 cond 2
barrier b2 cond 2

server s1 {
rxreq
txresp -nolen -hdr "Content-Length: 10"
barrier b1 sync
barrier b2 sync

delay 0.1
send "0123456789"
txresp
} -start

varnish v1 -vcl+backend {} -start

# miss
client c1 {
txreq -hdr "client: c1"
rxresp
} -start

barrier b1 sync
# streaming-hit
client c2 {
txreq -hdr "client: c2"
rxresphdrs
barrier b2 sync
rxrespbody
} -start

client c1 -wait
client c2 -wait

delay 0.1

# hit
client c3 {
txreq -hdr "client: c3"
rxresp
} -run

# give some time for the logs to land (0.1s is overly generous)
delay 0.1

shell {
# arguments: CLIENT HANDLING EXPECTED_VALUE
t() {
set -ex
test $(${varnishlog-json_bin} -n ${v1_name} -d | jq -r "select(.req.headers.client[0] == \"$1\") | .handling" ) = "$2"
}

${varnishlog-json_bin} -c -n ${v1_name} -d

t c1 miss
t c2 streaming-hit
t c3 hit
}

0 comments on commit aa7d058

Please sign in to comment.