From 0da08df4eb51ae5826762bab8f54dc13da5b5d73 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 8 Jul 2015 19:04:08 +0200 Subject: [PATCH] Stream logs if possible and remove size limit --- src/lib/Hydra/Controller/Build.pm | 18 +++++++++--------- src/lib/Hydra/Controller/Root.pm | 4 ++-- src/lib/Hydra/View/NixLog.pm | 30 ++++++++++++++++++++++++++++++ 3 files changed, 41 insertions(+), 11 deletions(-) create mode 100644 src/lib/Hydra/View/NixLog.pm diff --git a/src/lib/Hydra/Controller/Build.pm b/src/lib/Hydra/Controller/Build.pm index 126f534b..005902dd 100644 --- a/src/lib/Hydra/Controller/Build.pm +++ b/src/lib/Hydra/Controller/Build.pm @@ -136,9 +136,12 @@ sub showLog { notFound($c, "The build log of derivation ‘$drvPath’ is not available.") unless defined $logPath; - my $size = stat($logPath)->size; - error($c, "This build log is too big to display ($size bytes).") - if $size >= 64 * 1024 * 1024; + # Don't send logs that we can't stream. + my $size = stat($logPath)->size; # FIXME: not so meaningful for compressed logs + error($c, "This build log is too big to display ($size bytes).") unless + $mode eq "raw" + || (($mode eq "tail" || $mode eq "tail-reload") && $logPath !~ /\.bz2$/) + || $size < 64 * 1024 * 1024; if (!$mode) { # !!! quick hack @@ -150,12 +153,9 @@ sub showLog { } elsif ($mode eq "raw") { - if ($logPath !~ /.bz2$/) { - $c->serve_static_file($logPath); - } else { - $c->stash->{'plain'} = { data => (scalar logContents($logPath)) || " " }; - $c->forward('Hydra::View::Plain'); - } + $c->stash->{logPath} = $logPath; + $c->forward('Hydra::View::NixLog'); + return; } elsif ($mode eq "tail-reload") { diff --git a/src/lib/Hydra/Controller/Root.pm b/src/lib/Hydra/Controller/Root.pm index cf437be7..822b7ad8 100644 --- a/src/lib/Hydra/Controller/Root.pm +++ b/src/lib/Hydra/Controller/Root.pm @@ -352,8 +352,8 @@ sub log :Local :Args(1) { my $logPath = findLog($c, $path, @outpaths); notFound($c, "The build log of $path is not available.") unless defined $logPath; - $c->stash->{'plain'} = { data => (scalar logContents($logPath)) || " " }; - $c->forward('Hydra::View::Plain'); + $c->stash->{logPath} = $logPath; + $c->forward('Hydra::View::NixLog'); } diff --git a/src/lib/Hydra/View/NixLog.pm b/src/lib/Hydra/View/NixLog.pm new file mode 100644 index 00000000..4cbb2a74 --- /dev/null +++ b/src/lib/Hydra/View/NixLog.pm @@ -0,0 +1,30 @@ +package Hydra::View::NixLog; + +use strict; +use base qw/Catalyst::View/; +use Hydra::Helper::CatalystUtils; + +sub process { + my ($self, $c) = @_; + + my $logPath = $c->stash->{logPath}; + + $c->response->content_type('text/plain'); + + my $fh = new IO::Handle; + + if ($logPath =~ /\.bz2$/) { + open $fh, "bzip2 -dc < '$logPath' |" or die; + } else { + open $fh, "<$logPath" or die; + } + binmode($fh); + + setCacheHeaders($c, 365 * 24 * 60 * 60); + + $c->response->body($fh); + + return 1; +} + +1;