-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Wrong epoch timestamp after Daylight Savings Time #3195
Comments
@repeatedly When you have a chance, would you mind taking a look at this? |
Hmm, It may need to reset |
@kenhys Just noticed the label that was assigned to this issue -- I'm not sure "feature request" is the appropriate label for this. This issue is describing a flaw in existing functionality, not requesting brand new functionality -- as such, I believe this should be assigned the "bug report" label instead. |
Better Workaround: As mentioned in my original post, one workaround for Fluentd's Daylight Savings Time (DST) bug is to restart Fluentd after every DST change on the underlying host. However, that is error-prone, inconvenient and not sustainable long-term. Thankfully, I have discovered another, better workaround: Simply change the time zone of the underlying host (where Fluentd is installed) to UTC (and restart Fluentd afterwards so it sees the new time zone) -- since the host time zone no longer has DST, it will no longer trigger Fluentd's DST bug. Unlike the earlier workaround, this only needs to be done once per host. ps: To be clear, this is just a workaround for the DST bug, not an actual solution for it! A true, long-term solution would be to actually fix the bug in Fluentd's source code, so that these workarounds are not required. |
@pranavmarla in my case, changing the timezone in UTC would not be feasible for reasons unrelated to fluentd. I may have to use the restart of the service for the change to take effect, which is inconvinient. As you mentioned, the issue I am seeing is due to Daylight saving time change.
When the Daylight saving time changes, it keeps writing to a log file that is one hour in future or behind.
@repeatedly , @kenhys are there any plans to fix it in a future release? |
In this case, the following parser: Lines 258 to 260 in 6a3b221
and the following Line 240 in 6a3b221
Since always |
@pranavmarla Although the above code has fault, you can avoid it by your configuration.
Since the trailing - time_format %Y-%m-%dT%H:%M:%S.%NZ
+ time_format %Y-%m-%dT%H:%M:%S.%N%z It will create correct epoch times. |
Shouldn't use `Time.now.localtime.utc_offset` as time offset for event times because incoming events might have past or future time with different DST. In addition, require strptime 0.2.4 or later to parse `Z` as UTC: nurse/strptime@39bbe26 Fix #3195 Signed-off-by: Takuro Ashie <ashie@clear-code.com>
… Time Fluentd generates wrong epoch timestamp when a configuration doesn't specify timezone (should be parsed as UTC) and Daylight Saving Time is started or ended while running Fluentd. It's because utc_offset at start up is always used to convert localtime to UTC. This commit parses event times correctly as UTC without complicated calculation by adding `%z` to a time format and `Z` to a time value on calling `strptime` for such cases. In addition, require strptime 0.2.4 or later to parse `Z` as UTC: nurse/strptime@39bbe26 Fix #3195 Signed-off-by: Takuro Ashie <ashie@clear-code.com>
Thanks for taking a look at this @ashie! It's been a long time since I've worked on this code but:
|
I'm not sure the exact specification of the API but I confirmed actual behaviour: $ irb
irb(main):001:0> require 'time'
=> true
irb(main):002:0> Time.strptime("2020-12-08T20:00:00.000000000Z", "%Y-%m-%dT%H:%M:%S.%N%z")
=> 2020-12-08 20:00:00 UTC And strptime gem also support it: nurse/strptime@39bbe26
Of course it intends to tell Fluentd the timezone. |
Cool, thanks for explaining @ashie ! |
Signed-off-by: Takuro Ashie <ashie@clear-code.com>
… Time Fluentd generates wrong epoch timestamp when a configuration doesn't specify timezone (should be parsed as UTC) and Daylight Saving Time is started or ended while running Fluentd. It's because utc_offset at start up is always used to convert localtime to UTC. This commit parses event times correctly as UTC without complicated calculation by adding `%z` to a time format and `Z` to a time value on calling `strptime` for such cases. In addition, require strptime 0.2.4 or later to parse `Z` as UTC: nurse/strptime@39bbe26 Fix #3195 Signed-off-by: Takuro Ashie <ashie@clear-code.com>
Describe the bug
Summary
Essentially, when Fluentd is told to parse a UTC timestamp present in incoming logs and convert it to the equivalent epoch timestamp, but Fluentd is installed in a location where the local time zone's offset from UTC changes (eg. due to Daylight Savings Time) then, every time the offset changes, Fluentd will generate the wrong epoch timestamp for all subsequent logs. Currently, the only way to fix this is to restart Fluentd after the offset changes, so that it "sees" the new UTC offset, every time the offset changes.
I believe this is effectively the same issue as #2806, opened back in Jan.
Details
I have Fluentd agents which receive logs, process them (including extracting the preexisting UTC timestamp in the log, generating the equivalent epoch timestamp, and setting that as the official log timestamp) and then forward them on. The host machines (where the Fluentd agents are installed) are located in the Eastern time zone (ET).
On Nov 1, Daylight Savings Time (DST) ended -- i.e. the local time zone on the hosts changed from Eastern Daylight Time (EDT) (UTC - 4) to Eastern Standard Time (EST) (UTC - 5). After that, I noticed that the logs coming from Fluentd suddenly had the wrong timestamp -- specifically, they were 1 hour in the future.
As a short term fix, I was able to resolve this issue by simply restarting all the agents (till then, they had been running continuously since Sep). However, based on my testing, it looks like there is a bug in the way Fluentd generates its timestamp and, when DST begins again on March 14 2021, I expect a similar issue to occur, except that this time the timestamp will be 1 hour in the past -- thus, a long term fix needs to be made to Fluentd's code.
Steps to Reproduce
Summary
Another way of restating the problem is that Fluentd will ONLY generate the correct epoch timestamp when:
Thus, we can clearly demonstrate this bug by:
Details
Fluentd Config
To demonstrate this bug, I've created a simple Fluentd config that accepts input logs via HTTP, parses the UTC timestamp contained within, and prints the processed logs to stdout.
Note that, for clarity, I print each log to stdout twice -- once with an epoch timestamp, and once with a regular Fluentd timestamp (i.e. a well-formatted timestamp in the local time zone).
Test Input
We will create two sample logs to send to Fluentd, that are identical except for the month of their UTC timestamp
2020-09-08T20:00:00.000000000Z
2020-12-08T20:00:00.000000000Z
Expected behaviour
Each UTC timestamp should ALWAYS be converted by Fluentd to the SAME equivalent epoch timestamp, regardless of the local time zone on the host! After all, by definition, epoch timestamps are supposed to be a time zone-agnostic way of referring to a particular point in time.
Sep 8 2020, 8 pm UTC -> 1599595200.00000000
Dec 8 2020, 8 pm UTC -> 1607457600.00000000
Steps
Scenario 1: DST in effect on the host
Note: By default, at least on my machine, chronyd notices that the date is wrong, and fixes it, within ~2 minutes!
Compare the expected epoch timestamp to the actual epoch timestamp:
Thus, since DST is in effect on the host, and this is a DST log, Fluentd generates the correct epoch timestamp.
Compare the expected epoch timestamp to the actual epoch timestamp:
Note that the actual epoch timestamp is off by 1 hour (in the future) -- i.e. it corresponds to Dec 8, 2020 at 9 pm UTC!
Thus, since DST is in effect on the host, but this is a non-DST log, Fluentd generates the wrong epoch timestamp!
This corresponds to the situation described at the beginning of this issue, which led me to discover this bug: After Nov 1, all new incoming logs were non-DST logs but, since my Fluentd agent had been running continuously since Sep, it apparently, wrongly, thought that DST was still in effect on the underlying host.
################
Scenario 2: DST not in effect on the host
Compare the expected epoch timestamp to the actual epoch timestamp:
Note that the actual epoch timestamp is off by 1 hour (in the past) -- i.e. it corresponds to Sep 8, 2020 at 7 pm UTC!
Thus, since DST is not in effect on the host, but this is a DST log, Fluentd generates the wrong epoch timestamp!
This corresponds to what the situation will be after March 14, 2021: After March 14, all new incoming logs will be DST logs but, since my Fluentd agent will have been running continuously since Dec, it will wrongly think that DST is still not in effect on the underlying host.
Compare the expected epoch timestamp to the actual epoch timestamp:
Thus, since DST is not in effect on the host, and this is a non-DST log, Fluentd generates the correct epoch timestamp.
Environment
4.0.1
1.11.2
The text was updated successfully, but these errors were encountered: