public inbox for pbs-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Dominik Csapak <d.csapak@proxmox.com>
To: Dietmar Maurer <dietmar@proxmox.com>,
	Proxmox Backup Server development discussion
	<pbs-devel@lists.proxmox.com>
Subject: Re: [pbs-devel] [PATCH proxmox-backup] server/worker_task: fix 'unknown' status for some big task logs
Date: Thu, 3 Sep 2020 12:46:46 +0200	[thread overview]
Message-ID: <eea41a5a-b944-39c8-fc9b-572ecb9b3dd6@proxmox.com> (raw)
In-Reply-To: <2037251149.686.1599129383852@webmail.proxmox.com>

On 9/3/20 12:36 PM, Dietmar Maurer wrote:
> cant we simply skip the first line?
> 
> let reader = BufReader::new(file);
> let lines = reader.lines();
> lines.next()?; // skip first
> 
> // Then parse the rest
> for line in lines {
> 
> }

no for two reasons:

if the task log contains only one line (this happens, e.g. 'TASK OK')
or if the last Log line is exactly 8k long (i am not sure that could happen)

for the first we could check if the file is < 8k long

> 
>> On 09/03/2020 11:39 AM Dominik Csapak <d.csapak@proxmox.com> wrote:
>>
>>   
>> when trying to parse the task status, we seek 8k from the end
>> which may be into the middle of a line, so the datetime parsing
>> can fail (when the log message contains ': ')
>> so try the next line when the first datetime parsing fails
>>
>> if it was really a broken datetime, we now return either
>> the datetime of the next line or an 'Unknown' TaskState
>> (which was the fallback of most call sites anyway)
>>
>> Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
>> ---
>> we could save the error for later returning, but
>> since that does not matter most of the time i did not do that
>> but if wanted i can send a v2 or fixup for that
>>
>>   src/server/worker_task.rs | 17 ++++++++++++++---
>>   1 file changed, 14 insertions(+), 3 deletions(-)
>>
>> diff --git a/src/server/worker_task.rs b/src/server/worker_task.rs
>> index a9e4a36a..f6d12ac3 100644
>> --- a/src/server/worker_task.rs
>> +++ b/src/server/worker_task.rs
>> @@ -209,14 +209,25 @@ pub fn upid_read_status(upid: &UPID) -> Result<TaskState, Error> {
>>   
>>       let reader = BufReader::new(file);
>>   
>> +    let mut first_line = true;
>>       for line in reader.lines() {
>>           let line = line?;
>>   
>>           let mut iter = line.splitn(2, ": ");
>>           if let Some(time_str) = iter.next() {
>> -            endtime = chrono::DateTime::parse_from_rfc3339(time_str)
>> -                .map_err(|err| format_err!("cannot parse '{}': {}", time_str, err))?
>> -                .timestamp();
>> +            let dt_parse_res = chrono::DateTime::parse_from_rfc3339(time_str)
>> +                .map_err(|err| format_err!("cannot parse timestamp '{}': {}", time_str, err));
>> +            endtime = if first_line {
>> +                first_line = false;
>> +                match dt_parse_res {
>> +                    Ok(dt) => dt.timestamp(),
>> +                    // we maybe seeked into the middle of a line,
>> +                    // so ignore errors on the first
>> +                    Err(_) => continue,
>> +                }
>> +            } else {
>> +                dt_parse_res?.timestamp()
>> +            };
>>           } else {
>>               continue;
>>           }
>> -- 
>> 2.20.1
>>
>>
>>
>> _______________________________________________
>> pbs-devel mailing list
>> pbs-devel@lists.proxmox.com
>> https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel





  reply	other threads:[~2020-09-03 10:46 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-03  9:39 Dominik Csapak
2020-09-03 10:36 ` Dietmar Maurer
2020-09-03 10:46   ` Dominik Csapak [this message]
2020-09-04  8:51     ` Dietmar Maurer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=eea41a5a-b944-39c8-fc9b-572ecb9b3dd6@proxmox.com \
    --to=d.csapak@proxmox.com \
    --cc=dietmar@proxmox.com \
    --cc=pbs-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal