BBlack has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/303578

Change subject: VCL: emit X-Cache-Status response header
......................................................................

VCL: emit X-Cache-Status response header

This header has one of 5 simple values:
hit - cache hit
miss - cache miss on supposedly-cacheable object
pass - traffic was un-cacheable according to applayer
   (includes e.g. logged-in wiki page traffic, some API requests)
int - "internal" response - varnish generated the content
   (typically beacons and error pages)
bug - some kind of error happened in determining status

Bug: T142410
Change-Id: I770e1c3762b4c587e3f2fb7ebec3cf96e2f05602
---
M modules/varnish/templates/vcl/wikimedia-frontend.vcl.erb
1 file changed, 20 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/operations/puppet 
refs/changes/78/303578/1

diff --git a/modules/varnish/templates/vcl/wikimedia-frontend.vcl.erb 
b/modules/varnish/templates/vcl/wikimedia-frontend.vcl.erb
index 1983be4b..0217b84 100644
--- a/modules/varnish/templates/vcl/wikimedia-frontend.vcl.erb
+++ b/modules/varnish/templates/vcl/wikimedia-frontend.vcl.erb
@@ -347,11 +347,29 @@
        call wm_common_xcache_deliver;
 
        // At the frontends, copy X-Cache-Int to X-Cache and delete X-Cache-Int
-       // This prevents double-set from confusing varnishlog-based stats
-       // grepping for X-Cache: and seeing double-set on varnish4
+       // This prevents double-set of X-Cache in log parsing on varnish4.
+       // In this block we also decipher X-Cache into an overall X-Cache-Status
+       // output header with one of 5 simple values: hit, miss, pass, int, or
+       // bug.
        if (<%= @req_method %> != "PURGE") {
                set resp.http.X-Cache = resp.http.X-Cache-Int;
                unset resp.http.X-Cache-Int;
+               if (resp.http.X-Cache ~ "hit") {
+                       set resp.http.X-Cache-Status = "hit";
+               } elsif (resp.http.X-Cache ~ "int") {
+                       set resp.http.X-Cache-Status = "int";
+               } elsif (resp.http.X-Cache ~ "pass,[^,]+$") {
+                       // The special pass regex above is because we have
+                       // layer-differential pass rules where a frontend may
+                       // intentionally pass traffic that a backend does not,
+                       // which should still count as a true 'miss' if the
+                       // backend misses it.
+                       set resp.http.X-Cache-Status = "pass";
+               } elsif (resp.http.X-Cache ~ "miss") {
+                       set resp.http.X-Cache-Status = "miss";
+               } else {
+                       set resp.http.X-Cache-Status = "bug";
+               }
        }
 
        std.collect(resp.http.Via);

-- 
To view, visit https://gerrit.wikimedia.org/r/303578
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I770e1c3762b4c587e3f2fb7ebec3cf96e2f05602
Gerrit-PatchSet: 1
Gerrit-Project: operations/puppet
Gerrit-Branch: production
Gerrit-Owner: BBlack <bbl...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to