Commit 8abfe28c authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Charge H2 traffic to ReqAcct VSL record.

All H2 frame headers gets charged to the sessions "session req"

All H2 frame bodies, except HEADERS, CONTIUATION and DATA also gets
charged to the "session req".

H2 frame bodies of HEADERS, CONTIUATION and DATA gets charged to the request.
parent f299ae88
......@@ -91,6 +91,7 @@ h2_bytes(struct req *req, enum vdp_action act, void **priv,
H2_F_DATA,
act == VDP_FINI ? H2FF_DATA_END_STREAM : H2FF_NONE,
len, ptr);
req->acct.resp_bodybytes += len;
H2_Send_Rel(r2->h2sess, r2);
return (0);
}
......@@ -256,6 +257,7 @@ h2_deliver(struct req *req, struct boc *boc, int sendbody)
H2_Send(req->wrk, r2, H2_F_HEADERS,
(sendbody ? 0 : H2FF_HEADERS_END_STREAM) | H2FF_HEADERS_END_HEADERS,
sz, req->ws->f);
req->acct.resp_hdrbytes += sz;
H2_Send_Rel(r2->h2sess, r2);
WS_Release(req->ws, 0);
......
......@@ -537,6 +537,7 @@ h2_rx_headers(struct worker *wrk, struct h2_sess *h2, struct h2_req *r2)
size_t l;
ASSERT_RXTHR(h2);
AN(r2);
if (r2->state != H2_S_IDLE)
return (H2CE_PROTOCOL_ERROR); // XXX spec ?
r2->state = H2_S_OPEN;
......@@ -559,6 +560,7 @@ h2_rx_headers(struct worker *wrk, struct h2_sess *h2, struct h2_req *r2)
VCL_Refresh(&wrk->vcl);
req->vcl = wrk->vcl;
wrk->vcl = NULL;
req->acct.req_hdrbytes += h2->rxf_len;
HTTP_Setup(req->http, req->ws, req->vsl, SLT_ReqMethod);
http_SetH(req->http, HTTP_HDR_PROTO, "HTTP/2.0");
......@@ -604,10 +606,12 @@ h2_rx_continuation(struct worker *wrk, struct h2_sess *h2, struct h2_req *r2)
h2_error h2e;
ASSERT_RXTHR(h2);
AN(r2);
if (r2->state != H2_S_OPEN)
return (H2CE_PROTOCOL_ERROR); // XXX spec ?
req = r2->req;
h2e = h2h_decode_bytes(h2, r2->decode, h2->rxf_data, h2->rxf_len);
r2->req->acct.req_hdrbytes += h2->rxf_len;
if (h2e != NULL) {
Lck_Lock(&h2->sess->mtx);
VSLb(h2->vsl, SLT_Debug, "HPACK(cont) %s", h2e->name);
......@@ -632,12 +636,14 @@ h2_rx_data(struct worker *wrk, struct h2_sess *h2, struct h2_req *r2)
unsigned wi;
(void)wrk;
AN(r2);
ASSERT_RXTHR(h2);
Lck_Lock(&h2->sess->mtx);
AZ(h2->mailcall);
h2->mailcall = r2;
h2->r_window -= h2->rxf_len;
r2->r_window -= h2->rxf_len;
// req_bodybytes accounted in CNT code.
if (r2->cond)
AZ(pthread_cond_signal(r2->cond));
while (h2->mailcall != NULL && h2->error == 0 && r2->error == 0)
......@@ -872,6 +878,7 @@ h2_rxframe(struct worker *wrk, struct h2_sess *h2)
HTC_RxPipeline(h2->htc, h2->htc->rxbuf_b + h2->rxf_len + 9);
h2_vsl_frame(h2, h2->htc->rxbuf_b, 9L + h2->rxf_len);
h2->srq->acct.req_hdrbytes += 9;
if (h2->rxf_type >= H2FMAX) {
// rfc7540,l,679,681
......@@ -882,12 +889,15 @@ h2_rxframe(struct worker *wrk, struct h2_sess *h2)
"H2: Unknown frame type 0x%02x (ignored)",
(uint8_t)h2->rxf_type);
Lck_Unlock(&h2->sess->mtx);
h2->srq->acct.req_bodybytes += h2->rxf_len;
return (1);
}
h2f = h2flist[h2->rxf_type];
AN(h2f->name);
AN(h2f->rxfunc);
if (h2f->overhead)
h2->srq->acct.req_bodybytes += h2->rxf_len;
if (h2->rxf_flags & ~h2f->flags) {
// rfc7540,l,687,688
......
......@@ -107,6 +107,9 @@ H2_Send_Frame(struct worker *wrk, const struct h2_sess *h2,
h2_mk_hdr(hdr, ftyp, flags, len, stream);
Lck_Lock(&h2->sess->mtx);
VSLb_bin(h2->vsl, SLT_H2TxHdr, 9, hdr);
h2->srq->acct.resp_hdrbytes += 9;
if (ftyp->overhead)
h2->srq->acct.resp_bodybytes += len;
Lck_Unlock(&h2->sess->mtx);
s = write(h2->sess->fd, hdr, sizeof hdr);
......
......@@ -11,7 +11,19 @@ server s1 {
varnish v1 -vcl+backend {} -cliok "param.set feature +http2" -start
varnish v1 -cliok "param.set debug +syncvsl"
logexpect l1 -v v1 -g raw {
expect * 1001 ReqAcct "80 7 87 106 8 114"
expect * 1000 ReqAcct "45 8 53 72 28 100"
} -start
client c1 {
stream 0 {
txping
rxping
} -run
stream 0 {
rxwinup
} -start
stream 1 {
txreq -req POST -hdr content-type text/plain -hdr content-length 7 -body request
......@@ -24,5 +36,8 @@ client c1 {
# Then, payload checks
expect resp.body == response
} -run
stream 0 -wait
} -run
logexpect l1 -wait
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment