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) server-digest SHA256) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 1D2F091690; Thu, 8 Sep 2022 13:19:49 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 059F91BC7A; Thu, 8 Sep 2022 13:19:49 +0200 (CEST) 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; Thu, 8 Sep 2022 13:19:48 +0200 (CEST) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 1D4C544557; Thu, 8 Sep 2022 13:19:48 +0200 (CEST) Message-ID: <2c38612d-4d28-0f46-56bc-34755da79835@proxmox.com> Date: Thu, 8 Sep 2022 13:19:46 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.13.0 Content-Language: en-US To: Stefan Sterz , pve-devel@lists.proxmox.com, pbs-devel@lists.proxmox.com, pmg-devel@lists.proxmox.com References: <20220907085633.89113-1-d.tschlatscher@proxmox.com> <20220907085633.89113-6-d.tschlatscher@proxmox.com> From: Daniel Tschlatscher In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-SPAM-LEVEL: Spam detection results: 0 AWL 2.036 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 -4.199 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 T_SCC_BODY_TEXT_LINE -0.01 - URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [tasks.pm] Subject: Re: [pmg-devel] [PATCH pmg-api v2 5/7] revised task log download function in the PMG backend X-BeenThere: pmg-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Mail Gateway development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 08 Sep 2022 11:19:49 -0000 On 9/8/22 11:36, Stefan Sterz wrote: > On 9/7/22 10:56, Daniel Tschlatscher wrote: >> With the newly added button in the tasklog the implementation for the >> PMG server needs to be adapted. I saw an opportunity here to clear >> some redundant code for displaying the tasklog and replace it with a >> call to dump_logfile(), akin to how this is handled in pve-manager. >> >> The tasklog download functionality now streams the file by invoking >> the newly created function in pve-common. >> >> Signed-off-by: Daniel Tschlatscher >> --- >> src/PMG/API2/Tasks.pm | 34 +++++++++++----------------------- >> 1 file changed, 11 insertions(+), 23 deletions(-) >> >> diff --git a/src/PMG/API2/Tasks.pm b/src/PMG/API2/Tasks.pm >> index 598fb4d..0fd3780 100644 >> --- a/src/PMG/API2/Tasks.pm >> +++ b/src/PMG/API2/Tasks.pm >> @@ -5,6 +5,7 @@ use warnings; >> use POSIX; >> use IO::File; >> use File::ReadBackwards; >> +use File::stat; >> use PVE::Tools; >> use PVE::SafeSyslog; >> use PVE::RESTHandler; >> @@ -272,33 +273,20 @@ __PACKAGE__->register_method({ >> >> my $restenv = PMG::RESTEnvironment->get(); >> >> - my $fh = IO::File->new($filename, "r"); >> - raise_param_exc({ upid => "no such task - unable to open file - $!" }) if !$fh; >> + my $start = $param->{start} // 0; >> + my $limit = $param->{limit} // 50; >> >> - my $start = $param->{start} || 0; >> - my $limit = $param->{limit} || 50; >> - my $count = 0; >> - my $line; >> - while (defined ($line = <$fh>)) { >> - next if $count++ < $start; >> - next if $limit <= 0; >> - chomp $line; >> - push @$lines, { n => $count, t => $line}; >> - $limit--; >> - } >> + if ($limit == 0) { >> + # TCP Max Transfer Unit size is 1500, compression for lower numbers has no effect >> + my $use_compression = stat($filename)->size > 1500; >> + return PVE::Tools::stream_logfile($filename, $param->{upid}, $use_compression); > > I am pretty sure that should be `stream_file` and not `stream_logfile`. > We've already discussed this off list, but I wanted to document it here too. > Thanks for catching this! Yes, I switched something up here when preparing the series. The function call here should be "stream_file". >> + } else { >> + my ($count, $lines) = PVE::Tools::dump_logfile($filename, $start, $limit); >> >> - close($fh); >> + $restenv->set_result_attrib('total', $count); >> >> - # HACK: ExtJS store.guaranteeRange() does not like empty array >> - # so we add a line >> - if (!$count) { >> - $count++; >> - push @$lines, { n => $count, t => "no content"}; >> + return $lines; >> } >> - >> - $restenv->set_result_attrib('total', $count); >> - >> - return $lines; >> }}); >> >> >