Skip to content

Add support to nanoseconds#165

Merged
kaisecheng merged 9 commits intologstash-plugins:mainfrom
kaisecheng:support_ms_ns
Mar 3, 2026
Merged

Add support to nanoseconds#165
kaisecheng merged 9 commits intologstash-plugins:mainfrom
kaisecheng:support_ms_ns

Conversation

@kaisecheng
Copy link
Copy Markdown
Contributor

@kaisecheng kaisecheng commented Mar 2, 2026

Add nanosecond precision support via java.time

Introduce a precision configuration option ("ms" | "ns", default: "ms")
that controls whether parsed timestamps are stored with millisecond or
nanosecond resolution.

In "ns" mode:

  • Custom-pattern formats use java.time-based parsers.
  • All formats pass a full java.time.Instant (preserving nanosecond precision)
      to the Logstash Timestamp constructor.
  • If no timezone is configured, the default falls back to the JVM timezone,
      matching the existing joda-time behavior in "ms" mode.

In "ms" mode:

  • ISO8601 and UNIX now accept up to 9 fractional-second digits (previously limited to 3);
      sub-millisecond digits are truncated on write.
  • Custom-pattern formats continue to use the joda-time parser.
  • UNIX_MS and TAI64N formats are unchanged.
  • All formats pass a java.time.Instant truncated to millisecond precision
      to preserve the behavior of joda-time's Instant.

Fixes: #161

Add unit test classes for CasualISO8601Parser, TAI64NParser, and
UnixMillisEpochParser. Expand JodaParserTest and UnixEpochParserTest
with year-guessing, DST edge cases, locale, and all input types.
Trim DateFilterTest to integration-only tests. Slim date_spec.rb,
keeping wiring and Ruby-layer sanity checks.
Introduce a `precision` configuration option ("ms" | "ns", default: "ms")
that controls whether parsed timestamps are stored with millisecond or
nanosecond resolution.

In "ns" mode:
- Custom-pattern formats use java.time-based parsers.
- All formats pass a full java.time.Instant (preserving nanosecond precision)
  to the Logstash Timestamp constructor.
- If no timezone is configured, the default falls back to the JVM timezone,
  matching the existing joda-time behavior in "ms" mode.

In "ms" mode:
- ISO8601 now accepts up to 9 fractional-second digits (previously limited to 3);
  sub-millisecond digits are truncated on write.
- Custom-pattern formats continue to use the joda-time parser.
- Numeric formats are unchanged.
- All formats pass a java.time.Instant truncated to millisecond precision
  to preserve the behavior of joda-time's Instant.
@donoghuc donoghuc self-requested a review March 2, 2026 22:55
Copy link
Copy Markdown

@donoghuc donoghuc left a comment

Choose a reason for hiding this comment

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

Couple small things inline.

Build this in to a logstash container (with 9.3.1 version) and played around with it. It seems good!

Not sure if there are major performance considerations, I may try to poke a that a bit more. :)

@kaisecheng kaisecheng requested a review from donoghuc March 3, 2026 17:25
Copy link
Copy Markdown

@donoghuc donoghuc left a comment

Choose a reason for hiding this comment

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

Thanks for doing the updates in separate commits. That made it super easy to review! This is solid :shipit:

@kaisecheng kaisecheng merged commit 450690b into logstash-plugins:main Mar 3, 2026
3 checks passed
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.

Allow for nanosecond timestamps

2 participants