Ema has submitted this change and it was merged. (
https://gerrit.wikimedia.org/r/350966 )
Change subject: varnish: Avoid std.fileread() and use new errorpage template
......................................................................
varnish: Avoid std.fileread() and use new errorpage template
* Switch to using the errorpage template. This means we can now
removed the awkward varnish/files/errorpage.html file which
previously had to contian unbalanced HTML with the closing tag
being in VCL.
* Change errorpage.inc.vcl to use regsub() instead of string
concatenation.
Bug: T113114
Change-Id: Id77d23a442ab9ba39bd683a93d43bb1a9de54d6b
---
D modules/varnish/files/errorpage.html
M modules/varnish/files/tests/text/12-rate-limiting.vtc
M modules/varnish/manifests/common/vcl.pp
A modules/varnish/templates/errorpage.body.html.erb
A modules/varnish/templates/errorpage.footer.html.erb
M modules/varnish/templates/errorpage.inc.vcl.erb
6 files changed, 28 insertions(+), 36 deletions(-)
Approvals:
Ema: Looks good to me, approved
jenkins-bot: Verified
diff --git a/modules/varnish/files/errorpage.html
b/modules/varnish/files/errorpage.html
deleted file mode 100644
index 395fdef..0000000
--- a/modules/varnish/files/errorpage.html
+++ /dev/null
@@ -1,26 +0,0 @@
-<!DOCTYPE html>
-<html lang=en>
-<meta charset=utf-8>
-<title>Wikimedia Error</title>
-<style>
-* { margin: 0; padding: 0; }
-body { background: #fff; font: 15px/1.6 sans-serif; color: #333; }
-.content { margin: 7% auto 0; padding: 2em 1em 1em; max-width: 640px; }
-.footer { clear: both; margin-top: 14%; border-top: 1px solid #e5e5e5;
background: #f9f9f9; padding: 2em 0; font-size: 0.8em; text-align: center; }
-img { float: left; margin: 0 2em 2em 0; }
-a img { border: 0; }
-h1 { margin-top: 1em; font-size: 1.2em; }
-p { margin: 0.7em 0 1em 0; }
-a { color: #0645AD; text-decoration: none; }
-a:hover { text-decoration: underline; }
-code { font-family: sans-serif; }
-.text-muted { color: #777; }
-</style>
-<div class="content" role="main">
-<a href="https://www.wikimedia.org"><img
src="https://www.wikimedia.org/static/images/wmf.png"
srcset="https://www.wikimedia.org/static/images/wmf-2x.png 2x" alt=Wikimedia
width=135 height=135></a>
-<h1>Error</h1>
-<p>Our servers are currently under maintenance or experiencing a technical
problem. Please <a href="" title="Reload this page"
onclick="window.location.reload(false); return false">try again</a> in a
few minutes.</p><p>See the error message at the bottom of this page for
more information.</p>
-</div>
-<div class="footer">
-<p>If you report this error to the Wikimedia System Administrators, please
include the details below.</p>
-<p class="text-muted"><code>
diff --git a/modules/varnish/files/tests/text/12-rate-limiting.vtc
b/modules/varnish/files/tests/text/12-rate-limiting.vtc
index ddc6191..541cc00 100644
--- a/modules/varnish/files/tests/text/12-rate-limiting.vtc
+++ b/modules/varnish/files/tests/text/12-rate-limiting.vtc
@@ -30,6 +30,8 @@
rxresp
expect resp.status == 429
expect resp.msg == "Too Many Requests"
+ expect resp.body ~ "See the error message at the bottom of this page"
+ expect resp.body ~ "<code>Request from"
expect resp.http.Retry-After == 1
delay 5
diff --git a/modules/varnish/manifests/common/vcl.pp
b/modules/varnish/manifests/common/vcl.pp
index 7761eb5..5054777 100644
--- a/modules/varnish/manifests/common/vcl.pp
+++ b/modules/varnish/manifests/common/vcl.pp
@@ -1,6 +1,19 @@
class varnish::common::vcl {
require ::varnish::common
+ $errorpage = {
+ title => 'Wikimedia Error',
+ pagetitle => 'Error',
+ logo_link => 'https://www.wikimedia.org',
+ logo_src => 'https://www.wikimedia.org/static/images/wmf.png',
+ logo_srcset => 'https://www.wikimedia.org/static/images/wmf-2x.png 2x',
+ logo_alt => 'Wikimedia',
+ content => template('varnish/errorpage.body.html.erb'),
+ # Placeholder "%error%" substituted at runtime in errorpage.inc.vcl
+ footer => template('varnish/errorpage.footer.html.erb'),
+ }
+ $errorpage_html = template('mediawiki/errorpage.html.erb')
+
file { '/etc/varnish/errorpage.inc.vcl':
owner => 'root',
group => 'root',
@@ -16,10 +29,7 @@
}
file { '/etc/varnish/errorpage.html':
- owner => 'root',
- group => 'root',
- mode => '0444',
- source => 'puppet:///modules/varnish/errorpage.html',
+ ensure => absent,
}
# VTC tests
diff --git a/modules/varnish/templates/errorpage.body.html.erb
b/modules/varnish/templates/errorpage.body.html.erb
new file mode 100644
index 0000000..2bae53b
--- /dev/null
+++ b/modules/varnish/templates/errorpage.body.html.erb
@@ -0,0 +1,5 @@
+<p>Our servers are currently under maintenance or experiencing a technical
problem.
+
+Please <a href="" title="Reload this page"
onclick="window.location.reload(false); return false">try again</a> in a
few minutes.</p>
+
+<p>See the error message at the bottom of this page for
more information.</p>
diff --git a/modules/varnish/templates/errorpage.footer.html.erb
b/modules/varnish/templates/errorpage.footer.html.erb
new file mode 100644
index 0000000..a49dabf
--- /dev/null
+++ b/modules/varnish/templates/errorpage.footer.html.erb
@@ -0,0 +1 @@
+<p>If you report this error to the Wikimedia System Administrators, please
include the details below.</p><p class="text-muted"><code>%error%</code></p>
diff --git a/modules/varnish/templates/errorpage.inc.vcl.erb
b/modules/varnish/templates/errorpage.inc.vcl.erb
index 3b52c6c..8cbc205 100644
--- a/modules/varnish/templates/errorpage.inc.vcl.erb
+++ b/modules/varnish/templates/errorpage.inc.vcl.erb
@@ -1,27 +1,27 @@
sub backend_error_errorpage {
set beresp.http.Content-Type = "text/html; charset=utf-8";
- synthetic(std.fileread("/etc/varnish/errorpage.html") +
+ synthetic(regsub({"<%= @errorpage_html %>"}, "%error%",
"Request from " + bereq.http.X-Client-IP +
" via " + server.hostname + " " + server.identity +
", Varnish XID " + bereq.xid + "<br>" +
regsub(beresp.http.X-Cache, ".+", "Upstream caches: \0<br>") +
"Error: " + beresp.status + ", " +
beresp.reason +
- " at " + now + "</code></p></div></html>"
- );
+ " at " + now
+ ));
}
sub synth_errorpage {
set resp.http.Content-Type = "text/html; charset=utf-8";
- synthetic(std.fileread("/etc/varnish/errorpage.html") +
+ synthetic(regsub({"<%= @errorpage_html %>"}, "%error%",
"Request from " + req.http.X-Client-IP +
" via " + server.hostname + " " + server.identity +
", Varnish XID " + req.xid + "<br>" +
regsub(resp.http.X-Cache, ".+", "Upstream caches: \0<br>") +
"Error: " + resp.status + ", " +
resp.reason +
- " at " + now + "</code></p></div></html>"
- );
+ " at " + now
+ ));
}
--
To view, visit https://gerrit.wikimedia.org/r/350966
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Id77d23a442ab9ba39bd683a93d43bb1a9de54d6b
Gerrit-PatchSet: 25
Gerrit-Project: operations/puppet
Gerrit-Branch: production
Gerrit-Owner: Krinkle <[email protected]>
Gerrit-Reviewer: BBlack <[email protected]>
Gerrit-Reviewer: Ema <[email protected]>
Gerrit-Reviewer: Giuseppe Lavagetto <[email protected]>
Gerrit-Reviewer: Krinkle <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits