From aa7d0583a309f8d4e3ddb7cc4871903ea6b15fcb Mon Sep 17 00:00:00 2001 From: Guillaume Quintard Date: Mon, 15 Apr 2024 19:21:39 -0700 Subject: [PATCH] handling can be streaming-hit --- README.md | 23 +++++++++++++++++++ main.c | 17 ++++++++++++-- tests/004.vtc | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 100 insertions(+), 2 deletions(-) create mode 100644 tests/004.vtc diff --git a/README.md b/README.md index b1b2bbd..8617926 100644 --- a/README.md +++ b/README.md @@ -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) @@ -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 diff --git a/main.c b/main.c index be48f63..06843cc 100644 --- a/main.c +++ b/main.c @@ -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")) { @@ -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"))) { diff --git a/tests/004.vtc b/tests/004.vtc new file mode 100644 index 0000000..6aae875 --- /dev/null +++ b/tests/004.vtc @@ -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 +}