[ 
https://issues.apache.org/jira/browse/FLUME-2889?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15188873#comment-15188873
 ] 

Tristan Stevens commented on FLUME-2889:
----------------------------------------

The current algorithm is as follows:

1. Set the year of the parsed date to this year.
2. If that sets the time after now and indeed more than one month after now 
then set the year one year previous to now (this is good).
3. else, if that sets the time to before now and indeed more than one month 
before now then set the year to one year in advance to now.

The flaw is that given syslog is historic, it's quite possible to get logs that 
are more than one month old - much more likely than having logs 11 months in 
the future.

So the code should read:

3. else, if that sets the time to before now but not more than 11 months before 
now (implying that the time should be < 1 month in the future) only then set 
the year to one year in advance to now.

This gives us a 12 months window of tolerance, 1 month ahead and 11 months 
prior.

Illustration of current behaviour:

//Clock is about to roll into 2020 - we should expect anything 
February-December to be 2019 and anything January to be 2020
Current date is: 30/12/2019 13:14:15UTC

dateString = "Mar 03 01:02:03"; - comes back as 2020
dateString = "Jun 03 01:02:03"; - comes back as 2020
dateString = "Oct 03 01:02:03"; - comes back as 2020

//Clock is June 2020 - we should expect anything August-December to be 2019 and 
anything January to July to be 2020
Current date is: 21/06/2020 13:14:15UTC

dateString = "Mar 03 01:02:03"; - comes back as 2021
dateString = "Jan 2 01:02:03"; - comes back as 2021
dateString = "Jan 21 01:02:03"; - comes back as 2021

I've written a patch that adds in unit tests for these cases and others, plus 
that fixes the code. I'm currently looking at whether SyslogUtils has a similar 
problem.    

> Fixes to  DateTime computations
> -------------------------------
>
>                 Key: FLUME-2889
>                 URL: https://issues.apache.org/jira/browse/FLUME-2889
>             Project: Flume
>          Issue Type: Bug
>    Affects Versions: v1.6.0
>            Reporter: Roshan Naik
>            Assignee: Roshan Naik
>             Fix For: v1.7.0
>
>         Attachments: FLUME-2889-2.patch, FLUME-2889.3.patch, FLUME-2889.patch
>
>
> date.withYear(year+1)  can lead to incorrect date calculations .. for example 
> if  the date is Feb 29th.   need to use date.plusYears(1) instead.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to