BBlack has uploaded a new change for review.

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

Change subject: Text VCL: exclude lower-layer cache hits from hfp object 
creation
......................................................................

Text VCL: exclude lower-layer cache hits from hfp object creation

(and also, move the hfp block to common code)

Note the " hit(" regex match is the new X-Cache data format
recently introduced.  It will take up to 30 days for all old cache
objects recorded as " hit (" to expire out and make this change
fully effective.  We can't trust the older "hit (" style because
it's not a reliable indicator of a true cache hit on a real object

Change-Id: I7241260f63d9fc22c3268332c67b82b7df3be424
---
M templates/varnish/text-backend.inc.vcl.erb
M templates/varnish/text-common.inc.vcl.erb
M templates/varnish/text-frontend.inc.vcl.erb
3 files changed, 30 insertions(+), 18 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/operations/puppet 
refs/changes/77/259777/1

diff --git a/templates/varnish/text-backend.inc.vcl.erb 
b/templates/varnish/text-backend.inc.vcl.erb
index d8c2195..93b5672 100644
--- a/templates/varnish/text-backend.inc.vcl.erb
+++ b/templates/varnish/text-backend.inc.vcl.erb
@@ -99,15 +99,7 @@
                }
        }
 
-       if (req.http.X-Subdomain && (req.url ~ "mobileaction=" || req.url ~ 
"useformat=")) {
-               set beresp.ttl = 60 s;
-       }
-
-       if ((beresp.status < 500 && beresp.ttl <= 0s) || 
req.http.X-Wikimedia-Debug == "1" || req.http.X-Wikimedia-Security-Audit == 
"1") {
-               set req.http.X-CDIS = req.http.X-CDIS + "+chfp"; // 
+created-hit-for-pass
-               set beresp.ttl = 120s;
-               return (hit_for_pass);
-       }
+       call common_fetch;
 
        return (deliver);
 }
diff --git a/templates/varnish/text-common.inc.vcl.erb 
b/templates/varnish/text-common.inc.vcl.erb
index e8613fe..e765fee 100644
--- a/templates/varnish/text-common.inc.vcl.erb
+++ b/templates/varnish/text-common.inc.vcl.erb
@@ -93,3 +93,31 @@
        }
 <% end -%>
 }
+
+// fe+be common fetch code
+sub common_fetch {
+       if (req.http.X-Subdomain && (req.url ~ "mobileaction=" || req.url ~ 
"useformat=")) {
+               set beresp.ttl = 60 s;
+       }
+
+       // This block creates a 120s hit-for-pass object on certain
+       // uncacheable responses.  The conditions are that it's not a 5xx, the
+       // calculated TTL is <= 0, and very importantly that a deeper cache
+       // did not log it as a true cache hit.  This is because varnish may
+       // send recently-expired cache hit objects to another requesting
+       // varnish under grace-mode rules, and we don't want those creating
+       // hit-for-pass objects in the requesting varnish.
+       if (
+               (
+                       beresp.ttl <= 0s
+                       && beresp.status < 500
+                       && (!beresp.X-Cache || beresp.X-Cache !~ " hit\(")
+               )
+               || req.http.X-Wikimedia-Debug == "1"
+               || req.http.X-Wikimedia-Security-Audit == "1"
+       ) {
+               set req.http.X-CDIS = req.http.X-CDIS + "+chfp"; // 
+created-hit-for-pass
+               set beresp.ttl = 120s;
+               return (hit_for_pass);
+       }
+}
diff --git a/templates/varnish/text-frontend.inc.vcl.erb 
b/templates/varnish/text-frontend.inc.vcl.erb
index a1b6422..4b7103f 100644
--- a/templates/varnish/text-frontend.inc.vcl.erb
+++ b/templates/varnish/text-frontend.inc.vcl.erb
@@ -145,15 +145,7 @@
 }
 
 sub vcl_fetch {
-       if (req.http.X-Subdomain && (req.url ~ "mobileaction=" || req.url ~ 
"useformat=")) {
-               set beresp.ttl = 60 s;
-       }
-
-       if ((beresp.status < 500 && beresp.ttl <= 0s) || 
req.http.X-Wikimedia-Debug == "1" || req.http.X-Wikimedia-Security-Audit == 
"1") {
-               set req.http.X-CDIS = req.http.X-CDIS + "+chfp"; // 
+created-hit-for-pass
-               set beresp.ttl = 120s;
-               return (hit_for_pass);
-       }
+       call common_fetch;
 
        return (deliver);
 }

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I7241260f63d9fc22c3268332c67b82b7df3be424
Gerrit-PatchSet: 1
Gerrit-Project: operations/puppet
Gerrit-Branch: production
Gerrit-Owner: BBlack <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to