-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Time_Format %s is not handled properly #2388
Comments
Thanks for reporting this issue. I was able to isolate the problem in the following test case: /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
#define _XOPEN_SOURCE
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
int main()
{
char *p;
char *secs = "1595492168";
char out[32];
struct tm tm;
p = strptime(secs, "%s", &tm);
strftime(out, sizeof(out) - 1, "%s", &tm);
printf("input => %s\n", secs);
printf("strftime() => %s\n", out);
printf("timegm() => %lu\n", (long) timegm(&tm));
printf("mktime() => %lu\n", (long) mktime(&tm));
return 0;
} testing the output we get: $ ./strptime
input => 1595492168
strftime() => 1595492168
timegm() => 1595470568
mktime() => 1595492168 In our code, we are using @fujimotos would you please re-validate my findings on this ?, the guilty function is this: we need to evaluate any side effects of using |
@eduardo IIUC, if we use mktime() here, it will break the more
Indeed: strptime("1970-01-01 02:00:00 +0100", '%Y-%m-%d %H:%M:%S %z', &tm)
// Current logic
ret = flb_parser_tm2time(&tm);
printf("%li", ret); // 3600 (correct)
// Replace timegm with mktime()
ret = flb_parser_tm2time_mktime(&tm);
printf("%li", ret); // -28800 (???) Talking about an actionable mitigation measure, I think @LionelCons can set [PARSER]
Name test
Format regex
Regex ^(?<time>.+)$
Time_Key time
Time_Format %s
TIme_Offset +0400 This should resolve the issue described in OP. |
As discussed in #593, I cannot use In any case, the fact that |
Hmmm... I think I have found where the problem is.
This logic fails to see that Adding something like |
Looking elsewhere in the same file, it seems that the "year detection" at https://github.com/fluent/fluent-bit/blob/master/src/flb_parser.c#L187 is also broken. The code only checks for |
hmm, the main problem relies on the handling of tm_gmtoff field structure from struct tm by strptime(3), and it's a mess, for short: "strptime(2) implementation works differently on glibc, bionic, freebsd...etc" when a %s is specified, some implementations prefers to convert the parsed time internally with localtime_r(3) while others with gmtime_r(3):
and we are not alone on this: @fujimotos : this is not new :) ! remember a while ago you added a BSD copy as flb_strptime.c. Looking at the code the |
note: the year detection as pointed out by @LionelCons is required, so when |
I submit a patch to use our strptime(3) implementation to #2433. Before:
After:
The year hack issue mentioned by #2388 (comment) is also fixed by #2432. |
Already fixed as of 1.6.0. |
Time_Format
could be%s
which is documented instrptime
as "The number of seconds since the Epoch, 1970-01-01 00:00:00 +0000 (UTC)".Unfortunately, Fluent Bit does not treat it as the number of seconds since the Epoch and it applies an offset.
Here is the configuration used to reproduce the issue:
Then:
You see that the event timestamp is 1595499368 and it differs from 1595492168 by two hours.
The text was updated successfully, but these errors were encountered: