From: Stoiko Ivanov <s.ivanov@proxmox.com>
To: pmg-devel@lists.proxmox.com
Subject: [pmg-devel] [RFC pmg-log-tracker 1/2] rfc3339 timestamps: counter-offset timezone
Date: Tue, 27 Jun 2023 21:46:49 +0200 [thread overview]
Message-ID: <20230627194650.34027-2-s.ivanov@proxmox.com> (raw)
In-Reply-To: <20230627194650.34027-1-s.ivanov@proxmox.com>
the old time-format had no timezone-information so the API treats the
result as 'timezoned-epoch' and subtracts the timezone-offset
In order to support both formats add the timezone-offset to the
already offset time - so that the subtraction in the API is canceled
out.
This can luckily be dropped once we drop support for traditional
syslog format.
inspired by parse_rfc3339_do in proxmox-time
Signed-off-by: Stoiko Ivanov <s.ivanov@proxmox.com>
---
src/main.rs | 27 +++++++++++++++++++++++----
1 file changed, 23 insertions(+), 4 deletions(-)
diff --git a/src/main.rs b/src/main.rs
index e7bffd8..6c4a555 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -2263,12 +2263,31 @@ fn parse_time_with_year(data: &'_ [u8]) -> Option<(time_t, &'_ [u8])> {
timestamp_buffer[0..year_time_len].copy_from_slice(year_time);
timestamp_buffer[year_time_len..timestamp_len].copy_from_slice(timezone);
- match proxmox_time::parse_rfc3339(unsafe {
+ let epoch = match proxmox_time::parse_rfc3339(unsafe {
std::str::from_utf8_unchecked(×tamp_buffer[0..timestamp_len])
}) {
- Ok(ltime) => Some((ltime, data)),
- Err(_err) => None,
- }
+ Ok(ltime) => ltime,
+ Err(_err) => return None,
+ };
+
+ // FIXME: the traditional syslog format does not have timezone information, so the api-backend
+ // shifts the time by the offset (i.e. parse_time_no_year returns timestamps in local time)
+ // readd the TZ-offset here to match the broken format
+ // drop after legacy parsing is dropped.
+ let tz = timezone[0];
+ if tz == b'Z' {
+ return Some((epoch, data));
+ }
+
+ let hours = (timezone[1] as i32 - 48) * 10 + (timezone[2] as i32 - 48);
+ let mins = (timezone[4] as i32 - 48) * 10 + (timezone[5] as i32 - 48);
+ let offset = hours * 3600 + mins * 60;
+ let epoch = match tz {
+ b'+' => epoch + offset as i64,
+ b'-' => epoch - offset as i64,
+ _ => unreachable!(), // already checked in parse_rfc3339
+ };
+ Some((epoch, data))
}
fn parse_time_no_year(data: &'_ [u8], cur_year: i64, cur_month: i64) -> Option<(time_t, &'_ [u8])> {
--
2.39.2
next prev parent reply other threads:[~2023-06-27 19:47 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-27 19:46 [pmg-devel] [RFC pmg-log-tracker 0/2] fix rfc3339 output from logtracker Stoiko Ivanov
2023-06-27 19:46 ` Stoiko Ivanov [this message]
2023-06-28 7:27 ` [pmg-devel] [RFC pmg-log-tracker 1/2] rfc3339 timestamps: counter-offset timezone Dominik Csapak
2023-06-27 19:46 ` [pmg-devel] [RFC pmg-log-tracker 2/2] tests: update rfc3339 testoutput Stoiko Ivanov
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=20230627194650.34027-2-s.ivanov@proxmox.com \
--to=s.ivanov@proxmox.com \
--cc=pmg-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