[master] 365c745 Add failure handing in vcl_backend_*{}.
Poul-Henning Kamp
phk at FreeBSD.org
Tue Feb 7 00:24:05 CET 2017
commit 365c745f0f216c5b9da613ee3f1f0c93bf501953
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Mon Feb 6 23:22:46 2017 +0000
Add failure handing in vcl_backend_*{}.
Add a new global counter 'vcl_fail' which counts all VCL_RET_FAIL.
diff --git a/bin/varnishd/cache/cache_fetch.c b/bin/varnishd/cache/cache_fetch.c
index 05ad0bf..9433bcf 100644
--- a/bin/varnishd/cache/cache_fetch.c
+++ b/bin/varnishd/cache/cache_fetch.c
@@ -280,7 +280,7 @@ vbf_stp_startfetch(struct worker *wrk, struct busyobj *bo)
VCL_backend_fetch_method(bo->vcl, wrk, NULL, bo, NULL);
bo->uncacheable = bo->do_pass;
- if (wrk->handling == VCL_RET_ABANDON)
+ if (wrk->handling == VCL_RET_ABANDON || wrk->handling == VCL_RET_FAIL)
return (F_STP_FAIL);
assert (wrk->handling == VCL_RET_FETCH);
@@ -442,7 +442,7 @@ vbf_stp_startfetch(struct worker *wrk, struct busyobj *bo)
VCL_backend_response_method(bo->vcl, wrk, NULL, bo, NULL);
- if (wrk->handling == VCL_RET_ABANDON) {
+ if (wrk->handling == VCL_RET_ABANDON || wrk->handling == VCL_RET_FAIL) {
bo->htc->doclose = SC_RESP_CLOSE;
VDI_Finish(bo->wrk, bo);
return (F_STP_FAIL);
@@ -859,7 +859,7 @@ vbf_stp_error(struct worker *wrk, struct busyobj *bo)
AZ(VSB_finish(synth_body));
- if (wrk->handling == VCL_RET_ABANDON) {
+ if (wrk->handling == VCL_RET_ABANDON || wrk->handling == VCL_RET_FAIL) {
VSB_destroy(&synth_body);
return (F_STP_FAIL);
}
diff --git a/bin/varnishd/cache/cache_vcl.c b/bin/varnishd/cache/cache_vcl.c
index 967c563..b950a96 100644
--- a/bin/varnishd/cache/cache_vcl.c
+++ b/bin/varnishd/cache/cache_vcl.c
@@ -1057,6 +1057,8 @@ vcl_call_method(struct worker *wrk, struct req *req, struct busyobj *bo,
func(&ctx);
VSLb(vsl, SLT_VCL_return, "%s", VCL_Return_Name(wrk->handling));
wrk->cur_method |= 1; // Magic marker
+ if (wrk->handling == VCL_RET_FAIL)
+ wrk->stats->vcl_fail++;
/*
* VCL/Vmods are not allowed to make permanent allocations from
diff --git a/bin/varnishtest/tests/v00051.vtc b/bin/varnishtest/tests/v00051.vtc
index 8a36d61..56eee1e 100644
--- a/bin/varnishtest/tests/v00051.vtc
+++ b/bin/varnishtest/tests/v00051.vtc
@@ -37,6 +37,7 @@ client c1 {
expect resp.reason == "VCL failed"
} -run
+varnish v1 -expect vcl_fail == 1
varnish v1 -expect sc_vcl_failure == 1
logexpect l1 -wait
@@ -59,6 +60,7 @@ client c1 {
expect resp.reason == "OK"
} -run
+varnish v1 -expect vcl_fail == 2
# NB: This is correct, req->doclose = SC_VCL_FAILURE latches
varnish v1 -expect sc_vcl_failure == 2
@@ -93,6 +95,7 @@ client c1 {
expect_close
} -run
+varnish v1 -expect vcl_fail == 3
varnish v1 -expect sc_vcl_failure == 3
logexpect l1 -wait
@@ -123,6 +126,7 @@ client c1 {
expect resp.reason == "VCL failed"
} -run
+varnish v1 -expect vcl_fail == 4
varnish v1 -expect sc_vcl_failure == 4
logexpect l1 -wait
@@ -157,6 +161,7 @@ client c1 {
expect resp.reason == "VCL failed"
} -run
+varnish v1 -expect vcl_fail == 5
varnish v1 -expect sc_vcl_failure == 5
logexpect l1 -wait
@@ -190,6 +195,7 @@ client c1 {
expect resp.reason == "VCL failed"
} -run
+varnish v1 -expect vcl_fail == 6
varnish v1 -expect sc_vcl_failure == 6
logexpect l1 -wait
@@ -223,6 +229,7 @@ client c1 {
expect resp.reason == "VCL failed"
} -run
+varnish v1 -expect vcl_fail == 7
varnish v1 -expect sc_vcl_failure == 7
logexpect l1 -wait
@@ -253,6 +260,7 @@ client c1 {
expect resp.reason == "VCL failed"
} -run
+varnish v1 -expect vcl_fail == 8
varnish v1 -expect sc_vcl_failure == 8
logexpect l1 -wait
@@ -283,6 +291,7 @@ client c1 {
expect resp.reason == "VCL failed"
} -run
+varnish v1 -expect vcl_fail == 9
varnish v1 -expect sc_vcl_failure == 9
logexpect l1 -wait
@@ -313,6 +322,105 @@ client c1 {
expect resp.reason == "VCL failed"
} -run
+varnish v1 -expect vcl_fail == 10
+varnish v1 -expect sc_vcl_failure == 10
+
+logexpect l1 -wait
+
+#######################################################################
+# Fail in vcl_backend_fetch
+
+varnish v1 -vcl+backend {
+ import debug;
+ sub vcl_backend_fetch {
+ debug.fail();
+ set bereq.http.not = "Should not happen";
+ }
+}
+
+logexpect l1 -v v1 -g raw {
+ expect * 1025 VCL_call "BACKEND_FETCH"
+ expect 0 1025 Debug "Forced failure"
+ expect 0 1025 VCL_return "fail"
+} -start
+
+client c1 {
+ txreq -url /backend_fetch
+ rxresp
+ expect resp.status == 503
+ expect resp.reason == "Service Unavailable"
+} -run
+
+varnish v1 -expect vcl_fail == 11
+varnish v1 -expect sc_vcl_failure == 10
+
+logexpect l1 -wait
+
+#######################################################################
+# Fail in vcl_backend_error
+
+server s1 {
+ rxreq
+ expect req.url == /backend_error
+} -start
+
+varnish v1 -vcl+backend {
+ import debug;
+ sub vcl_backend_error {
+ debug.fail();
+ set bereq.http.not = "Should not happen";
+ }
+}
+
+logexpect l1 -v v1 -g raw {
+ expect * 1028 VCL_call "BACKEND_ERROR"
+ expect 0 1028 Debug "Forced failure"
+ expect 0 1028 VCL_return "fail"
+} -start
+
+client c1 {
+ txreq -url /backend_error
+ rxresp
+ expect resp.status == 503
+ expect resp.reason == "Service Unavailable"
+} -run
+
+varnish v1 -expect vcl_fail == 12
+varnish v1 -expect sc_vcl_failure == 10
+
+logexpect l1 -wait
+
+#######################################################################
+# Fail in vcl_backend_response
+
+server s1 {
+ rxreq
+ expect req.url == /backend_response
+ txresp
+} -start
+
+varnish v1 -vcl+backend {
+ import debug;
+ sub vcl_backend_response {
+ debug.fail();
+ set bereq.http.not = "Should not happen";
+ }
+}
+
+logexpect l1 -v v1 -g raw {
+ expect * 1031 VCL_call "BACKEND_RESPONSE"
+ expect 0 1031 Debug "Forced failure"
+ expect 0 1031 VCL_return "fail"
+} -start
+
+client c1 {
+ txreq -url /backend_response
+ rxresp
+ expect resp.status == 503
+ expect resp.reason == "Service Unavailable"
+} -run
+
+varnish v1 -expect vcl_fail == 13
varnish v1 -expect sc_vcl_failure == 10
logexpect l1 -wait
diff --git a/include/tbl/vsc_f_main.h b/include/tbl/vsc_f_main.h
index 97e25ef..c81d858 100644
--- a/include/tbl/vsc_f_main.h
+++ b/include/tbl/vsc_f_main.h
@@ -495,6 +495,11 @@ VSC_FF(n_vcl_discard, uint64_t, 0, 'c', 'i', diag,
""
)
+VSC_FF(vcl_fail, uint64_t, 1, 'c', 'i', info,
+ "VCL failures",
+ "Count of failures which prevented VCL from completing."
+)
+
/*--------------------------------------------------------------------*/
VSC_FF(bans, uint64_t, 0, 'g', 'i', info,
diff --git a/lib/libvcc/generate.py b/lib/libvcc/generate.py
index 7dcafc3..a9ff86b 100755
--- a/lib/libvcc/generate.py
+++ b/lib/libvcc/generate.py
@@ -130,15 +130,15 @@ returns = (
('backend_fetch',
"B",
- ('fetch', 'abandon')
+ ('fail', 'fetch', 'abandon')
),
('backend_response',
"B",
- ('deliver', 'retry', 'abandon')
+ ('fail', 'deliver', 'retry', 'abandon')
),
('backend_error',
"B",
- ('deliver', 'retry', 'abandon')
+ ('fail', 'deliver', 'retry', 'abandon')
),
###############################################################
More information about the varnish-commit
mailing list