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

Feature request: migrate to java.time #8491

Open
mostolog opened this issue Oct 13, 2017 · 2 comments
Open

Feature request: migrate to java.time #8491

mostolog opened this issue Oct 13, 2017 · 2 comments

Comments

@mostolog
Copy link

mostolog commented Oct 13, 2017

Hi

During some tests with Logstash 6.0.0-rc1 we have encountered a few errors parsing dates from different locales (some logs come in English, while other come in other languages) and, it looks like it could be related to Joda-Time being case-sensitive.

        ...
	mutate {
		add_field => {
			"date" => "11/Oct/2017:13:30:26 +0200"
			}
		}
	date {
		timezone => "Europe/Madrid"
		match => ["date", "dd/MMM/yyyy:HH:mm:ss Z"]
		locale => "es"
		tag_on_failure => "error_date"
	}
        ...

Specifically, If month pattern MMM is used and Joda expects 'oct' but found 'Oct'
Examples: https://discuss.elastic.co/t/timestamp-month-name-date-matching/25538

Is there any other function Logstash could use to be case-insensitive instead? https://stackoverflow.com/a/10797809

As stated by their own page (http://www.joda.org/joda-time/) migrating to java.time is advised.

As requested in #7149, I would like to ask for a library parameter to enable the usage of java.time instead of Joda-Time in the event of backwards-compatibility issues. Otherwise a complete migration would be gracefully welcomed.

On the other hand, it would be really good knowing if there's a workaround, other than lowercasing month strings in order Joda being able to parse date in a case-insensitive manner.

Thanks,
Regards

CC: @magnusbaeck

@jordansissel
Copy link
Contributor

jordansissel commented Oct 24, 2017

This feature request is about an implementation detail, not a behavior. Let's focus on behaviors.

You mention that "Oct" fails to parse, but "oct" is successful, and you say java.time will solve this.

However, I find that it does not solve it.

Reproducing your case, using MMM with locale "es", I find both Joda-Time and java.time are reject "Oct" and accept "oct" when locale is "es"

  • Joda-Time "oct" vs "Oct" with locale "es"
# "oct" - works.
>> org.joda.time.format.DateTimeFormat.forPattern("MMM").withLocale(java.util.Locale.forLanguageTag("es")).parseDateTime("oct").getMonthOfYear
=> 10

# "Oct" fails
>> org.joda.time.format.DateTimeFormat.forPattern("MMM").withLocale(java.util.Locale.forLanguageTag("es")).parseDateTime("Oct").getMonthOfYear
Java::JavaLang::IllegalArgumentException: Invalid format: "Oct"
  • java.time
# "oct" works
>> java.time.format.DateTimeFormatter.ofPattern("MMM").withLocale(java.util.Locale.forLanguageTag("es")).parse("oct").get(java.time.temporal.ChronoField::MONTH_OF_YEAR)
=> 10

# "Oct" fails
>> java.time.format.DateTimeFormatter.ofPattern("MMM").withLocale(java.util.Locale.forLanguageTag("es")).parse("Oct").get(java.time.temporal.ChronoField::MONTH_OF_YEAR)
Java::JavaTimeFormat::DateTimeParseException: Text 'Oct' could not be parsed at index 0

@mostolog
Copy link
Author

Hi @jordansissel

You are right, this was about an implementation detail at the beginning

As months (and days) in spanish have first letter capital, parsing uppercased strings should work.
eg: https://stackoverflow.com/a/38251032

So, this was an issue to fix how current implementation (which uses joda.time) does the parsing.

However. as joda.time is deprecated, I then suggested ensuring this case-sensitive issue would be fixed when/if migrated to java.time.

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

No branches or pull requests

2 participants