Skip to content

parse fractional-second ISO-8601 timestamps in syslog parser#21

Open
HrachShah wants to merge 1 commit into
mainfrom
fix/syslog-parser-tz-microseconds
Open

parse fractional-second ISO-8601 timestamps in syslog parser#21
HrachShah wants to merge 1 commit into
mainfrom
fix/syslog-parser-tz-microseconds

Conversation

@HrachShah

Copy link
Copy Markdown
Owner

SyslogParser.PATTERNS[1] already accepts timestamps with optional
fractional seconds and an optional Z or numeric offset:
\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:.\d+)?(?:Z|[+-]\d{2}:\d{2})?

But _parse_timestamp only knew about:
'%Y-%m-%dT%H:%M:%S.%f' (no offset)
'%Y-%m-%dT%H:%M:%S%z' (no fractional)

So an input like '2025-03-20T10:15:32.123Z' or
'2025-03-20T10:15:32.123+02:00' was matched by the regex and
can_parse() returned True, but parse() then set timestamp=None and
the time_distribution, source/time-range reports, and start-time/
end-time filters all silently lost those entries. This format is
the default for rsyslog with RFC 5424 templates and for journald
exporters, so it is by far the most common modern syslog format.

Add '%Y-%m-%dT%H:%M:%S.%f%z' to the format list and normalize the
trailing 'Z' to '+00:00' before passing the string to strptime.
Two new tests pin the behavior for both the Z suffix and the
numeric offset variants.

SyslogParser.PATTERNS[1] already accepts timestamps with optional
fractional seconds and an optional Z or numeric offset:
  \d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|[+-]\d{2}:\d{2})?

But _parse_timestamp only knew about:
  '%Y-%m-%dT%H:%M:%S.%f'   (no offset)
  '%Y-%m-%dT%H:%M:%S%z'    (no fractional)

So an input like '2025-03-20T10:15:32.123Z' or
'2025-03-20T10:15:32.123+02:00' was matched by the regex and
can_parse() returned True, but parse() then set timestamp=None and
the time_distribution, source/time-range reports, and start-time/
end-time filters all silently lost those entries. This format is
the default for rsyslog with RFC 5424 templates and for journald
exporters, so it is by far the most common modern syslog format.

Add '%Y-%m-%dT%H:%M:%S.%f%z' to the format list and normalize the
trailing 'Z' to '+00:00' before passing the string to strptime.
Two new tests pin the behavior for both the Z suffix and the
numeric offset variants.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry @HrachShah, you have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

@coderabbitai

coderabbitai Bot commented Jun 23, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@HrachShah, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 41 minutes and 55 seconds. Learn how PR review limits work.

Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file).

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits.

🚦 How do rate limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan refill rate.

For paid Pro and Pro+ PR reviews, CodeRabbit uses rolling per-developer review limits. Reviews become available again as older review attempts age out of the rolling limit window.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: bb1ac2bc-7c6f-4489-b261-d0be7ee51990

📥 Commits

Reviewing files that changed from the base of the PR and between e93757f and 02802f7.

📒 Files selected for processing (2)
  • src/log_analyzer_cli/parsers/syslog.py
  • tests/test_parsers.py
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/syslog-parser-tz-microseconds

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant