1
0
Fork 0
mirror of https://github.com/NixOS/hydra.git synced 2024-10-17 16:37:26 -04:00

Merge pull request #1400 from SuperSandro2000/feat/buildlogs-zstd

CompressLog: Add zstd compression
This commit is contained in:
Jörg Thalheim 2024-08-21 09:43:39 +02:00 committed by GitHub
commit 9ee3c6aea2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 41 additions and 8 deletions

View file

@ -42,7 +42,7 @@ Sets CircleCI status.
## Compress build logs ## Compress build logs
Compresses build logs after a build with bzip2. Compresses build logs after a build with bzip2 or zstd.
### Configuration options ### Configuration options
@ -50,6 +50,14 @@ Compresses build logs after a build with bzip2.
Enable log compression Enable log compression
- `compress_build_logs_compression`
Which compression format to use. Valid values are bzip2 (default) and zstd.
- `compress_build_logs_silent`
Whether to compress logs silently.
### Example ### Example
```xml ```xml

View file

@ -408,6 +408,7 @@ in
requires = [ "hydra-init.service" ]; requires = [ "hydra-init.service" ];
after = [ "hydra-init.service" ]; after = [ "hydra-init.service" ];
restartTriggers = [ hydraConf ]; restartTriggers = [ hydraConf ];
path = [ pkgs.zstd ];
environment = env // { environment = env // {
PGPASSFILE = "${baseDir}/pgpass-queue-runner"; # grrr PGPASSFILE = "${baseDir}/pgpass-queue-runner"; # grrr
HYDRA_DBI = "${env.HYDRA_DBI};application_name=hydra-notify"; HYDRA_DBI = "${env.HYDRA_DBI};application_name=hydra-notify";
@ -458,10 +459,15 @@ in
# logs automatically after a step finishes, but this doesn't work # logs automatically after a step finishes, but this doesn't work
# if the queue runner is stopped prematurely. # if the queue runner is stopped prematurely.
systemd.services.hydra-compress-logs = systemd.services.hydra-compress-logs =
{ path = [ pkgs.bzip2 ]; { path = [ pkgs.bzip2 pkgs.zstd ];
script = script =
'' ''
find ${baseDir}/build-logs -type f -name "*.drv" -mtime +3 -size +0c | xargs -r bzip2 -v -f set -eou pipefail
compression=$(sed -nr 's/compress_build_logs_compression = ()/\1/p' ${baseDir}/hydra.conf)
if [[ $compression == zstd ]]; then
compression="zstd --rm"
fi
find ${baseDir}/build-logs -type f -name "*.drv" -mtime +3 -size +0c | xargs -r $compression --force --quiet
''; '';
startAt = "Sun 01:45"; startAt = "Sun 01:45";
}; };

View file

@ -174,6 +174,9 @@ sub getDrvLogPath {
for ($fn . $bucketed, $fn . $bucketed . ".bz2") { for ($fn . $bucketed, $fn . $bucketed . ".bz2") {
return $_ if -f $_; return $_ if -f $_;
} }
for ($fn . $bucketed, $fn . $bucketed . ".zst") {
return $_ if -f $_;
}
return undef; return undef;
} }

View file

@ -9,11 +9,24 @@ use Hydra::Helper::CatalystUtils;
sub stepFinished { sub stepFinished {
my ($self, $step, $logPath) = @_; my ($self, $step, $logPath) = @_;
my $doCompress = $self->{config}->{'compress_build_logs'} // "1"; my $doCompress = $self->{config}->{'compress_build_logs'} // '1';
my $silent = $self->{config}->{'compress_build_logs_silent'} // '0';
my $compression = $self->{config}->{'compress_build_logs_compression'} // 'bzip2';
if ($doCompress eq "1" && -e $logPath) { if (not -e $logPath or $doCompress ne "1") {
print STDERR "compressing $logPath...\n"; return;
system("bzip2", "--force", $logPath); }
if ($silent ne '1') {
print STDERR "compressing '$logPath' with $compression...\n";
}
if ($compression eq 'bzip2') {
system('bzip2', '--force', $logPath);
} elsif ($compression eq 'zstd') {
system('zstd', '--rm', '--quiet', '-T0', $logPath);
} else {
print STDERR "unknown compression type '$compression'\n";
} }
} }

View file

@ -16,7 +16,10 @@ sub process {
my $tail = int($c->stash->{tail} // "0"); my $tail = int($c->stash->{tail} // "0");
if ($logPath =~ /\.bz2$/) { if ($logPath =~ /\.zst$/) {
my $doTail = $tail ? "| tail -n '$tail'" : "";
open($fh, "-|", "zstd -dc < '$logPath' $doTail") or die;
} elsif ($logPath =~ /\.bz2$/) {
my $doTail = $tail ? "| tail -n '$tail'" : ""; my $doTail = $tail ? "| tail -n '$tail'" : "";
open($fh, "-|", "bzip2 -dc < '$logPath' $doTail") or die; open($fh, "-|", "bzip2 -dc < '$logPath' $doTail") or die;
} else { } else {