Skip to content

fix: keep nano-precise timestamps in Java Event APIs#15048

Open
yaauie wants to merge 2 commits intoelastic:mainfrom
yaauie:nano-precise-event-timestamp
Open

fix: keep nano-precise timestamps in Java Event APIs#15048
yaauie wants to merge 2 commits intoelastic:mainfrom
yaauie:nano-precise-event-timestamp

Conversation

@yaauie
Copy link
Copy Markdown
Member

@yaauie yaauie commented May 10, 2023

Release notes

Improves the Java Event API's Event#getEventTimestamp() and Event#setEventTimestamp(Instant) to retain the available precision.

What does this PR do?

  • uses Instant directly to keep its nano-precision instead of routing through Instant#toEpochMilli which limits us to milli-precision
  • adds tests for observed behaviour
  • improves the Event constructor's ability to deal with modern java.time inputs in the @timestamp field (mirroring what was previously done with joda time)

Why is it important/What is the impact to the user?

  • When plugins use the Java Event API, Event#getEventTimestamp should be just-as-precise as otherwise available using Event#getField:
    Optional.ofNullable(event.getField("@timestamp"))
        .map(Timestamp#toInstant)
        .orElse(null)
  • When plugins use the Java Event API, Event#setEventTimestamp(Instant) should retain the full precision of the provided Instant, as can also be done with Event#setField(Timestamp):
    event.setField("@timestamp", new Timestamp(instant));

Checklist

  • My code follows the style guidelines of this project
  • I have commented my code, particularly in hard-to-understand areas
  • [ ] I have made corresponding changes to the documentation
  • [ ] I have made corresponding change to the default configuration files (and/or docker env variables)
  • I have added tests that prove my fix is effective or that my feature works

Related issues

@mergify
Copy link
Copy Markdown
Contributor

mergify bot commented Mar 5, 2025

This pull request does not have a backport label. Could you fix it @yaauie? 🙏
To fixup this pull request, you need to add the backport labels for the needed
branches, such as:

  • backport-8./d is the label to automatically backport to the 8./d branch. /d is the digit.
  • backport-8.x is the label to automatically backport to the 8.x branch.

@mergify
Copy link
Copy Markdown
Contributor

mergify bot commented Mar 5, 2025

backport-8.x has been added to help with the transition to the new branch 8.x.
If you don't need it please use backport-skip label.

@mergify mergify bot added the backport-8.x Automated backport to the 8.x branch with mergify label Mar 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport-8.x Automated backport to the 8.x branch with mergify status:needs-review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants