Ori.livneh has submitted this change and it was merged.

Change subject: varnish: Route requests with 'X-Wikimedia-Debug=1' to 
test_wikipedia backend
......................................................................


varnish: Route requests with 'X-Wikimedia-Debug=1' to test_wikipedia backend

One of the debugging facilities we have available to us is testwiki. Unlike
other wikis, //test.wikipedia.org/ is served by a dedicated Varnish backend,
which maps requests to a single host, mw1017.

This is handy, but limited. It'd be better to be able to have a means of
routing requests for any wiki to mw1017 using a special request header.

This change configures Varnish to handle requests containing an
'X-Wikimedia-Debug=1' header by skipping the cache and routing the request to
mw1017.

Change-Id: I2e4a5474615dd161782d011022fa86399e52ebf1
---
M modules/varnish/templates/vcl/wikimedia.vcl.erb
M templates/varnish/bits.inc.vcl.erb
M templates/varnish/mobile-backend.inc.vcl.erb
M templates/varnish/mobile-frontend.inc.vcl.erb
M templates/varnish/text-backend.inc.vcl.erb
M templates/varnish/text-common.inc.vcl.erb
M templates/varnish/text-frontend.inc.vcl.erb
7 files changed, 43 insertions(+), 25 deletions(-)

Approvals:
  Ori.livneh: Verified; Looks good to me, approved
  BBlack: Looks good to me, but someone else must approve



diff --git a/modules/varnish/templates/vcl/wikimedia.vcl.erb 
b/modules/varnish/templates/vcl/wikimedia.vcl.erb
index 9522dfe..80e3a24 100644
--- a/modules/varnish/templates/vcl/wikimedia.vcl.erb
+++ b/modules/varnish/templates/vcl/wikimedia.vcl.erb
@@ -378,6 +378,13 @@
        /* Function vcl_error in <%= @vcl %>.inc.vcl will be appended here */
 }
 
+sub vcl_hash {
+       if (req.http.X-Wikimedia-Debug) {
+               hash_data(req.http.X-Wikimedia-Debug);
+       }
+       /* Function vcl_hash in <%= @vcl %>.inc.vcl will be appended here */
+}
+
 
 /* Include the VCL file for this role */
 include "<%= @vcl %>.inc.vcl";
diff --git a/templates/varnish/bits.inc.vcl.erb 
b/templates/varnish/bits.inc.vcl.erb
index 132856b..037a74d 100644
--- a/templates/varnish/bits.inc.vcl.erb
+++ b/templates/varnish/bits.inc.vcl.erb
@@ -38,6 +38,11 @@
        }
 
        if (req.http.host == "<%= @cluster_options.fetch("bits_domain", 
"bits.wikimedia.org") %>") {
+<% if @vcl_config.fetch("cluster_tier", "1") == "1" -%>
+               if (req.http.X-Wikimedia-Debug == "1") {
+                       set req.backend = test_wikipedia;
+               }
+<% end -%>
                // For https-only wikis, the redirect from http to https for 
bits assets should occur
                // in varnish instead of apache, since the apache redirect and 
mediawiki doesn't
                // vary by protocol. This can result in a redirect loop and 
assets not loading.
@@ -68,7 +73,7 @@
 sub vcl_fetch {
        // Do not serialize calls for non-cachable objects.
        // Removing this would break debug=true in mediawiki.
-       if (beresp.ttl <= 0s) {
+       if (beresp.ttl <= 0s || req.http.X-Wikimedia-Debug == "1") {
                set beresp.ttl = 120s;
                return (hit_for_pass);
        }
diff --git a/templates/varnish/mobile-backend.inc.vcl.erb 
b/templates/varnish/mobile-backend.inc.vcl.erb
index 7e72ce6..208dadf 100644
--- a/templates/varnish/mobile-backend.inc.vcl.erb
+++ b/templates/varnish/mobile-backend.inc.vcl.erb
@@ -7,13 +7,13 @@
        // FIXME: restrict access
 
        if (req.http.host ~ "^test\.") {
-<% if @vcl_config.fetch("cluster_tier", "1") == "1" -%>
-               set req.backend = test_wikipedia;
-<% end -%>
-               return (pass);
+               set req.http.X-Wikimedia-Debug = "1";
        }
+
 <% if @vcl_config.fetch("cluster_tier", "1") == "1" -%>
-       if (req.url ~ "^/w/api\.php") {
+       if (req.http.X-Wikimedia-Debug == "1") {
+               set req.backend = test_wikipedia;
+       } else if (req.url ~ "^/w/api\.php") {
                set req.backend = api;
        }
 <% end -%>
@@ -35,7 +35,7 @@
                set beresp.ttl = 60 s;
        }
 
-       if (beresp.ttl <= 0s) {
+       if (beresp.ttl <= 0s || req.http.X-Wikimedia-Debug == "1") {
                set beresp.ttl = 120s;
                return (hit_for_pass);
        }
diff --git a/templates/varnish/mobile-frontend.inc.vcl.erb 
b/templates/varnish/mobile-frontend.inc.vcl.erb
index d6502a7..aaca51e 100644
--- a/templates/varnish/mobile-frontend.inc.vcl.erb
+++ b/templates/varnish/mobile-frontend.inc.vcl.erb
@@ -93,7 +93,7 @@
        }
 
        if (req.http.host ~ "^test\.") {
-               return (pass);
+               set req.http.X-Wikimedia-Debug = "1";
        }
 
        set req.hash_ignore_busy = true;
@@ -129,7 +129,7 @@
                set beresp.ttl = 60 s;
        }
 
-       if (beresp.ttl <= 0s) {
+       if (beresp.ttl <= 0s || req.http.X-Wikimedia-Debug == "1") {
                set beresp.ttl = 120s;
                return (hit_for_pass);
        }
diff --git a/templates/varnish/text-backend.inc.vcl.erb 
b/templates/varnish/text-backend.inc.vcl.erb
index 1d4971f..3de0d48 100644
--- a/templates/varnish/text-backend.inc.vcl.erb
+++ b/templates/varnish/text-backend.inc.vcl.erb
@@ -26,14 +26,15 @@
        call vcl_recv_purge;
        call restrict_access;
 
+       if (req.http.host ~ "^test\.") {
+               set req.http.X-Wikimedia-Debug = "1";
+       }
+
 <% if @vcl_config.fetch("cluster_tier", "1") == "1" -%>
        if (req.url ~ "^/w/api\.php") {
                set req.backend = api;
        } else if (req.url ~ "^/w/thumb(_handler)?\.php") {
                set req.backend = rendering;
-       }
-       if (req.http.host ~ "^test\.") {
-               set req.backend = test_wikipedia;
        }
 <% end -%>
 
@@ -44,7 +45,15 @@
                set req.hash_ignore_busy = true;
        }
 
-       call pass_requests;
+<% if @vcl_config.fetch("cluster_tier", "1") == "1" -%>
+       if (req.http.X-Wikimedia-Debug == "1") {
+               set req.backend = test_wikipedia;
+       }
+<% end -%>
+
+       if (req.request != "GET" && req.request != "HEAD") {
+               return (pass);
+       }
 
        call evaluate_cookie;
 
@@ -81,7 +90,7 @@
                }
        }
 
-       if (beresp.ttl <= 0s) {
+       if (beresp.ttl <= 0s || req.http.X-Wikimedia-Debug == "1") {
                set beresp.ttl = 120s;
                return (hit_for_pass);
        }
diff --git a/templates/varnish/text-common.inc.vcl.erb 
b/templates/varnish/text-common.inc.vcl.erb
index cf40c04..10d376d 100644
--- a/templates/varnish/text-common.inc.vcl.erb
+++ b/templates/varnish/text-common.inc.vcl.erb
@@ -1,14 +1,5 @@
 // Common functions for the Text Varnish cluster
 
-sub pass_requests {
-       if (req.request != "GET" && req.request != "HEAD") {
-               return (pass);
-       }
-       if (req.http.Host ~ "^test\.") {
-               return (pass);
-       }
-}
-
 sub cookie_munging {
        // This header is saved, and restored before sending it to MediaWiki
        if (req.restarts == 0) {
diff --git a/templates/varnish/text-frontend.inc.vcl.erb 
b/templates/varnish/text-frontend.inc.vcl.erb
index e491cef..ae7fcc6 100644
--- a/templates/varnish/text-frontend.inc.vcl.erb
+++ b/templates/varnish/text-frontend.inc.vcl.erb
@@ -92,12 +92,18 @@
        call normalize_path;
        call mobile_redirect;
 
+       if (req.http.host ~ "^test\.") {
+               set req.http.X-Wikimedia-Debug = "1";
+       }
+
        if (req.url ~ "^/wiki/Special:CentralAutoLogin/") {
                set req.backend = backend_random;
                set req.hash_ignore_busy = true;
        }
 
-       call pass_requests;
+       if (req.request != "GET" && req.request != "HEAD") {
+               return (pass);
+       }
 
        // Users that just logged out, should not get a 304 for their
        // (locally cached) logged in pages.
@@ -119,7 +125,7 @@
 }
 
 sub vcl_fetch {
-       if (beresp.ttl <= 0s) {
+       if (beresp.ttl <= 0s || req.http.X-Wikimedia-Debug == "1") {
                set beresp.ttl = 120s;
                return (hit_for_pass);
        }

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I2e4a5474615dd161782d011022fa86399e52ebf1
Gerrit-PatchSet: 21
Gerrit-Project: operations/puppet
Gerrit-Branch: production
Gerrit-Owner: Ori.livneh <o...@wikimedia.org>
Gerrit-Reviewer: BBlack <bbl...@wikimedia.org>
Gerrit-Reviewer: Faidon Liambotis <fai...@wikimedia.org>
Gerrit-Reviewer: Giuseppe Lavagetto <glavage...@wikimedia.org>
Gerrit-Reviewer: Mark Bergsma <m...@wikimedia.org>
Gerrit-Reviewer: Ori.livneh <o...@wikimedia.org>
Gerrit-Reviewer: Tim Starling <tstarl...@wikimedia.org>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to