public inbox for pbs-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Dominik Csapak <d.csapak@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH proxmox-backup] server/worker_task: fix 'unknown' status for some big task logs
Date: Thu,  3 Sep 2020 11:39:35 +0200	[thread overview]
Message-ID: <20200903093935.18536-1-d.csapak@proxmox.com> (raw)

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





             reply	other threads:[~2020-09-03  9:39 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-03  9:39 Dominik Csapak [this message]
2020-09-03 10:36 ` Dietmar Maurer
2020-09-03 10:46   ` Dominik Csapak
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=20200903093935.18536-1-d.csapak@proxmox.com \
    --to=d.csapak@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