Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for epoch timestamps and configurable output format #3860

Merged
merged 4 commits into from
Dec 20, 2023

Conversation

kkondaka
Copy link
Collaborator

Description

Supports input timestamp to be of epoch_second, epoch_milli or epoch_nano.
Also added support to configure output timestamp format. It can be also epoch timestamp or any of the formats allowed by DateTimeFormatter.

Resolves #2929

Issues Resolved

Resolves #2929

Check List

  • [X ] New functionality includes testing.
  • [X ] New functionality has a documentation issue. Please link to it in this PR.
    • New functionality has javadoc added
  • [ X] Commits are signed with a real name per the DCO

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

@@ -38,6 +38,7 @@ default void parse(
Consumer<Record<Event>> eventConsumer) throws IOException {
Objects.requireNonNull(inputFile);
Objects.requireNonNull(eventConsumer);
System.out.println("======InputFile==="+inputFile);
Copy link
Member

Choose a reason for hiding this comment

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

Please remove this println.

long epochMillis = 0L;
long epochNanos = 0L;
ZonedDateTime zonedDateTime;
if (inputFormat.equals("epoch_second")) {
Copy link
Member

Choose a reason for hiding this comment

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

Generally, you should avoid conditionals in tests. It becomes harder to know if your test is correct or not.

You can split this into multiple tests. Or, you can refactor to include the input and expected output data as arguments.

}
if (numberValue != null) {
int timestampLength = sourceTimestamp.length();
if (timestampLength > LENGTH_OF_EPOCH_IN_MILLIS) {
Copy link
Member

Choose a reason for hiding this comment

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

I think we should invert these conditionals. Let's look at the list of epoch_ values the user configures and then find the best fit from there.

This currently starts by inferring it and then seeing if the user has that. But, what if the value is very far in time from what we would typically expect?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think this is similar to providing two patterns like ["dd-mm-YYYY", "YYYY-mm-dd"] and the input not matching either one. Similarly, if the input has 13 digits and the pattern is ["epoch_second"] we should not match it. Basically, the pattern "epoch_second" should be treated as matching for 10-digit number, "epoch_milli" should be treated as matching for 13-digit number, and "epoch_nano" should be treated as matching 19-digit number. Because any other matching could result in silent errors.

Copy link
Member

Choose a reason for hiding this comment

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

We discussed offline. We will be more lenient on going back in time, but not forward in time. And we will only allow the selection of only one of the epoch_ configurations. Users won't select multiple of these for now.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The current code already allows epoch times from the past but not from the future. Added check to make sure only one of the three "epoch_" patterns are allowed.

Krishna Kondaka added 2 commits December 19, 2023 01:41
dlvenable
dlvenable previously approved these changes Dec 19, 2023
}
return true;
}

@AssertTrue(message = "match can have a minimum and maximum of 1 entry and at least one pattern.")
Copy link
Member

Choose a reason for hiding this comment

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

Is this message meant to reference output format being invalid?

Signed-off-by: Krishna Kondaka <[email protected]>
@kkondaka kkondaka merged commit f19de03 into opensearch-project:main Dec 20, 2023
47 checks passed
opensearch-trigger-bot bot pushed a commit that referenced this pull request Jan 11, 2024
* Add support for epoch timestamps and configurable output format

Signed-off-by: Krishna Kondaka <[email protected]>

* Add support for epoch timestamps and configurable output format

Signed-off-by: Krishna Kondaka <[email protected]>

* Addressed review comments

Signed-off-by: Krishna Kondaka <[email protected]>

* Addressed review comments

Signed-off-by: Krishna Kondaka <[email protected]>

---------

Signed-off-by: Krishna Kondaka <[email protected]>
Co-authored-by: Krishna Kondaka <[email protected]>
(cherry picked from commit f19de03)
@kkondaka kkondaka deleted the data-epoch-ns branch May 13, 2024 05:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Date processor to convert from epoch_milli or epoch_second
4 participants