From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id E86699348A for ; Wed, 4 Jan 2023 13:29:28 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id C86D31E76E for ; Wed, 4 Jan 2023 13:29:28 +0100 (CET) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS for ; Wed, 4 Jan 2023 13:29:27 +0100 (CET) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 2FDE94502B for ; Wed, 4 Jan 2023 13:29:27 +0100 (CET) Message-ID: Date: Wed, 4 Jan 2023 13:29:26 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.6.0 Content-Language: en-US To: Proxmox VE development discussion , Daniel Tschlatscher References: <20221201125014.359413-1-d.tschlatscher@proxmox.com> <20221201125014.359413-2-d.tschlatscher@proxmox.com> From: Stefan Sterz In-Reply-To: <20221201125014.359413-2-d.tschlatscher@proxmox.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.763 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment NICE_REPLY_A -1.708 Looks like a legit reply (A) SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: Re: [pve-devel] [PATCH manager v5 1/3] make task log downloadable in the PVE manager backend X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 04 Jan 2023 12:29:29 -0000 small nit in-line On 12/1/22 13:50, Daniel Tschlatscher wrote: > The read_tasklog API call now stream the whole log file if the query > parameter 'download' is set to true. > This is done in preparation for the task log download button to be > added in the TaskViewer. > > Signed-off-by: Daniel Tschlatscher > --- > No changes from v4 > > PVE/API2/Tasks.pm | 48 ++++++++++++++++++++++++++++++++++++++++------- > 1 file changed, 41 insertions(+), 7 deletions(-) > > diff --git a/PVE/API2/Tasks.pm b/PVE/API2/Tasks.pm > index 9cd1e56b..16041720 100644 > --- a/PVE/API2/Tasks.pm > +++ b/PVE/API2/Tasks.pm > @@ -342,15 +342,20 @@ __PACKAGE__->register_method({ > minimum => 0, > default => 0, > optional => 1, > - description => "The line number to start printing at.", > + description => "Start at this line when reading the tasklog", > }, > limit => { > type => 'integer', > minimum => 0, > default => 50, > optional => 1, > - description => "The maximum amount of lines that should be printed.", > + description => "The amount of lines to read from the tasklog.", > }, > + download => { > + type => 'boolean', > + optional => 1, > + description => "Whether the tasklog file should be downloaded. This parameter can't be used in conjunction with other parameters", > + } > }, > }, > returns => { > @@ -378,8 +383,6 @@ __PACKAGE__->register_method({ > my $rpcenv = PVE::RPCEnvironment::get(); > my $user = $rpcenv->get_user(); > my $node = $param->{node}; > - my $start = $param->{start} // 0; > - my $limit = $param->{limit} // 50; > > $convert_token_task->($task); > > @@ -387,11 +390,42 @@ __PACKAGE__->register_method({ > $rpcenv->check($user, "/nodes/$node", [ 'Sys.Audit' ]); > } > > - my ($count, $lines) = PVE::Tools::dump_logfile($filename, $start, $limit); > + my $download = $param->{download} // 0; > > - $rpcenv->set_result_attrib('total', $count); > + if ($download) { > + die "Parameter 'download' can't be used with other parameters\n" > + if (defined($param->{start}) || defined($param->{limit})); nit: personally not a fan of this, you are already stretching this over two lines, you may as well have a more readable `if (cond) {die}` imo > > - return $lines; > + my $fh; > + my $use_compression = ( -s $filename ) > 1024; > + > + # 1024 is a practical cutoff for the size distribution of our log files. > + if ($use_compression) { > + open($fh, "-|", "/usr/bin/gzip", "-c", "$filename") > + or die "Could not create compressed file stream for file '$filename' - $!\n"; > + } else { > + open($fh, '<', $filename) or die "Could not open file '$filename' - $!\n"; > + } > + > + return { > + download => { > + fh => $fh, > + stream => 1, > + 'content-encoding' => $use_compression ? 'gzip' : undef, > + 'content-type' => "text/plain", > + 'content-disposition' => "attachment; filename=\"".$param->{upid}."\"", > + }, > + }, > + } else { > + my $start = $param->{start} // 0; > + my $limit = $param->{limit} // 50; > + > + my ($count, $lines) = PVE::Tools::dump_logfile($filename, $start, $limit); > + > + $rpcenv->set_result_attrib('total', $count); > + > + return $lines; > + } > }}); > >