]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 1357809 - Add endpoints for future cloud-services integration
authorDylan William Hardison <dylan@hardison.net>
Wed, 19 Apr 2017 13:50:38 +0000 (09:50 -0400)
committerDylan William Hardison <dylan@hardison.net>
Wed, 19 Apr 2017 19:44:08 +0000 (15:44 -0400)
.htaccess
Bugzilla/Install/Filesystem.pm
extensions/BMO/Extension.pm
heartbeat.cgi [new file with mode: 0644]

index f76d352e23103dee2ec9ae6dc7e3a21890395a09..3cc7c69eab2881645006288c404cc6a480072476 100644 (file)
--- a/.htaccess
+++ b/.htaccess
@@ -44,6 +44,19 @@ Redirect permanent /etiquette.html https://bugzilla.mozilla.org/page.cgi?id=etiq
 Redirect permanent /duplicates.html https://bugzilla.mozilla.org/duplicates.cgi
 
 RewriteEngine On
+# This rewrite rule skips over the rest, which is good because the load balancers
+# might hit this file once a second and we want apache to not take much time.
+# Note that this file is generated by checksetup.pl
+RewriteRule ^__lbheartbeat__$ - [L]
+
+# allow cloud-services to identify the version we're running.
+# version.json is also generated by checksetup.pl
+RewriteRule ^__version__$ version.json [L]
+
+# Unlike lbheartbeat, this endpoint is called less frequently (every five minutes or so)
+# heartbeat.cgi returns 200 if the DB and memcached are both working, and 500 otherwise.
+RewriteRule ^__heartbeat__$ heartbeat.cgi [L]
+
 RewriteRule ^template_cache/ - [F,L,NC]
 RewriteRule ^template_cache.deleteme/ - [F,L,NC]
 RewriteRule ^review(.*) page.cgi?id=splinter.html$1 [QSA]
index c0bc2626215f5c21d845ec9f59d1b75b1c63797d..c67823d7ad341e3e2d64f40d8f217ff06abb38fb 100644 (file)
@@ -623,12 +623,12 @@ sub _create_files {
     # It's not necessary to sort these, but it does make the
     # output of checksetup.pl look a bit nicer.
     foreach my $file (sort keys %files) {
-        unless (-e $file) {
+        my $info = $files{$file};
+        if ($info->{overwrite} or not -f $file) {
             print "Creating $file...\n";
-            my $info = $files{$file};
-            my $fh = new IO::File($file, O_WRONLY | O_CREAT, $info->{perms})
-                || die $!;
-            print $fh $info->{contents} if $info->{contents};
+            my $fh = IO::File->new( $file, O_WRONLY | O_CREAT, $info->{perms} )
+                or die "unable to write $file: $!";
+            print $fh $info->{contents} if exists $info->{contents};
             $fh->close;
         }
     }
index 40ab8424e3cf93a5c8dc753b9b82fd81813e49c4..1bf6ebf8ca524dcf2b328c72f7739bf439771aa6 100644 (file)
@@ -57,6 +57,8 @@ use List::Util qw(first);
 use Scalar::Util qw(blessed);
 use Sys::Syslog qw(:DEFAULT);
 use Text::Balanced qw( extract_bracketed extract_multiple );
+use File::Slurp qw(read_file);
+use JSON::XS;
 
 use Bugzilla::Extension::BMO::Constants;
 use Bugzilla::Extension::BMO::FakeBug;
@@ -2522,7 +2524,41 @@ sub _check_default_product_security_group {
 sub install_filesystem {
     my ($self, $args) = @_;
     my $files = $args->{files};
+    my $create_files = $args->{create_files};
     my $extensions_dir = bz_locations()->{extensionsdir};
+    $create_files->{__lbheartbeat__} = {
+        perms    => Bugzilla::Install::Filesystem::WS_SERVE,
+        contents => 'This mission is too important for me to allow you to jeopardize it.',
+    };
+
+
+    # version.json needs to have a source attribute pointing to
+    # our repository. We already have this information in the (static)
+    # contribute.json file, so parse that in
+    my $json = JSON::XS->new->pretty->utf8->canonical();
+    my $contribute = eval { 
+        $json->decode(scalar read_file(bz_locations()->{cgi_path} . "/contribute.json"));
+    };
+    my $commit = `git rev-parse HEAD`;
+    chomp $commit;
+
+    if (!$contribute) {
+        die "Missing or invalid contribute.json file";
+    }
+
+    my $version_obj = {
+        source  => $contribute->{repository}{url},
+        version => BUGZILLA_VERSION,
+        commit  => $commit // "unknown",
+        build   => $ENV{BUGZILLA_CI_BUILD} // "unknown",
+    };
+
+    $create_files->{'version.json'} = {
+        overwrite => 1,
+        perms     => Bugzilla::Install::Filesystem::WS_SERVE,
+        contents  => $json->encode($version_obj),
+    };
+
     $files->{"$extensions_dir/BMO/bin/migrate-github-pull-requests.pl"} = {
         perms => Bugzilla::Install::Filesystem::OWNER_EXECUTE
     };
diff --git a/heartbeat.cgi b/heartbeat.cgi
new file mode 100644 (file)
index 0000000..47f3d59
--- /dev/null
@@ -0,0 +1,45 @@
+#!/usr/bin/perl -T
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+# This Source Code Form is "Incompatible With Secondary Licenses", as
+# defined by the Mozilla Public License, v. 2.0.
+
+use 5.10.1;
+use strict;
+use warnings;
+
+use lib qw(. lib local/lib/perl5);
+
+use Bugzilla;
+use Bugzilla::Constants;
+use Bugzilla::Error;
+use Bugzilla::Update;
+
+my $ok = eval {
+    # Ensure that any Throw*Error calls just use die, rather than trying to return html...
+    Bugzilla->error_mode(ERROR_MODE_DIE);
+    my $memcached    = Bugzilla->memcached;
+    my $dbh          = Bugzilla->dbh;
+    my $database_ok  = $dbh->ping;
+    my $versions     = $memcached->{memcached}->server_versions;
+    my $memcached_ok = keys %$versions;
+
+    die "database not available"            unless $database_ok;
+    die "memcached server(s) not available" unless $memcached_ok;
+    die "mod_perl not configured?"          unless $ENV{MOD_PERL};
+    1;
+};
+warn "heartbeat error: $@" if !$ok && $@;
+
+my $cgi = Bugzilla->cgi;
+print $cgi->header(-type => 'text/plain', -status => $ok ? '200 OK' : '500 Internal Server Error');
+print $ok ? "Bugzilla OK\n" : "Bugzilla NOT OK\n";
+
+if ($ENV{MOD_PERL}) {
+    my $r = $cgi->r;
+    # doing this supresses the error document, but does not change the http response code.
+    $r->rflush;
+    $r->status(200);
+}