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 3B7059229E; Tue, 11 Oct 2022 16:00:31 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 1E3A61DF6B; Tue, 11 Oct 2022 16:00:01 +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)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS; Tue, 11 Oct 2022 15:59:59 +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 E1AFB4249C; Tue, 11 Oct 2022 15:59:53 +0200 (CEST) From: Daniel Tschlatscher To: pve-devel@lists.proxmox.com, pbs-devel@lists.proxmox.com, pmg-devel@lists.proxmox.com Date: Tue, 11 Oct 2022 15:59:02 +0200 Message-Id: <20221011135902.610515-4-d.tschlatscher@proxmox.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20221011135902.610515-1-d.tschlatscher@proxmox.com> References: <20221011135902.610515-1-d.tschlatscher@proxmox.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL -0.164 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 SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record 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: [pve-devel] [PATCH manager v3] 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: Tue, 11 Oct 2022 14:00:31 -0000 The read tasklog API call now streams the log file if the limit parameter is set to 0. If not, it should behave the same as before. This is done in preparation for the task log download button to be added in the TaskViewer. Signed-off-by: Daniel Tschlatscher --- changes from v2 * replaced helper call with inline implementation * changed compression cutoff to 1024 * replaced stat($filename)→size call with "-s" PVE/API2/Tasks.pm | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/PVE/API2/Tasks.pm b/PVE/API2/Tasks.pm index 9cd1e56b..3bc00704 100644 --- a/PVE/API2/Tasks.pm +++ b/PVE/API2/Tasks.pm @@ -349,7 +349,7 @@ __PACKAGE__->register_method({ minimum => 0, default => 50, optional => 1, - description => "The maximum amount of lines that should be printed.", + description => "The maximum amount of lines that should be printed. A limit of 0 streams the file directly, otherwise lines are json encoded.", }, }, }, @@ -387,6 +387,29 @@ __PACKAGE__->register_method({ $rpcenv->check($user, "/nodes/$node", [ 'Sys.Audit' ]); } + if ($limit == 0) { + # 1024 is a practical cutoff for the size distribution of our log files. + my $use_compression = ( -s $filename ) > 1024; + + my $fh; + if ($use_compression) { + open($fh, "-|", "/usr/bin/gzip", "-c", "$filename") + or die "Could not create compressed file stream for $filename - $!"; + } else { + open($fh, '<', $filename) or die "Could not open file $filename - $!"; + } + + return { + download => { + fh => $fh, + stream => 1, + 'content-encoding' => $use_compression ? 'gzip' : undef, + 'content-type' => "text/plain", + 'content-disposition' => "attachment; filename=\"".$param->{upid}."\"", + }, + }, + } + my ($count, $lines) = PVE::Tools::dump_logfile($filename, $start, $limit); $rpcenv->set_result_attrib('total', $count); -- 2.30.2