-
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
parser: Support 'System' timezone in Time_Offset #7994
Conversation
Resolves a bug that caused 8 of test cases being skipped in test_parser_tzone_offset Signed-off-by: Sijmen Huizenga <[email protected]>
Signed-off-by: Sijmen Huizenga <[email protected]>
Add the 'System' option to Time_Offset that uses the system timezone to compute the UTC offset during startup. As proposed in fluent#593 Signed-off-by: Sijmen Huizenga <[email protected]>
8a0860a
to
33e624f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for doing this, I hope a maintainer accepts this change.
@@ -1008,6 +1025,11 @@ int flb_parser_tzone_offset(const char *str, int len, int *tmdiff) | |||
return 0; | |||
} | |||
|
|||
/* Check system timezones */ | |||
if (*p == 'S') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably worth doing a strncmp
here instead of just checking the first character.
@@ -1040,7 +1062,7 @@ int flb_parser_tzone_offset(const char *str, int len, int *tmdiff) | |||
min = ((p[2] - '0') * 10) + (p[3] - '0'); | |||
} | |||
|
|||
if (hour < 0 || hour > 59 || min < 0 || min > 59) { | |||
if (hour < 0 || hour > 23 || min < 0 || min > 59) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lol
@@ -123,6 +128,35 @@ int flb_parser_regex_do(struct flb_parser *parser, | |||
void **out_buf, size_t *out_size, | |||
struct flb_time *out_time); | |||
|
|||
static char* mock_timezone(char *tz) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be nicer if mock_timezone
returned an int with success, and took a pointer to where the original timezone should be returned. Then instead of doing perror
and exit
here, the test can see a -1
from this function and go through the existing acutest
failure pattern.
{ | ||
char *original_tz = getenv("TZ"); | ||
if (original_tz) { | ||
original_tz = strdup(original_tz); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what does strdup
ing the string into itself do?
unsetenv("TZ"); | ||
} | ||
tzset(); | ||
free(original_tz); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's up to you, but imo it's easier to keep track of free
s if they happen in the same scope as the allocation. I think it would make more sense if undo_mock_timezone
wasn't in charge of freeing original_tz
, and instead the test did this after using it to undo the mock timezone.
*tmdiff = -_timezone; | ||
return 0; | ||
#else | ||
time_t currentTime = time(NULL); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This only works for timezones that don't have DST; you need to calculate the offset for the timestamp of each record, not just capture the current offset at process start time. Different log entries will have different offsets because of DST.
This PR is stale because it has been open 45 days with no activity. Remove stale label or comment or this will be closed in 10 days. |
This PR is stale because it has been open 45 days with no activity. Remove stale label or comment or this will be closed in 10 days. |
it's a pity this MR is not progressing |
I've opened an alternative PR: #8164 |
This PR is stale because it has been open 45 days with no activity. Remove stale label or comment or this will be closed in 10 days. |
This PR is stale because it has been open 45 days with no activity. Remove stale label or comment or this will be closed in 10 days. |
Superseded by #8164. |
This introduces the
System
choice for theTime_Offset
parser option. This new option uses the system timezone to automatically compute the UTC offset. This resolves #593.To test this change I had to fix a few bugs in the unit tests related to time-offset-parsing. These bug fixes are included in this pr. See individual commits for the individual bug fixes.
This implementation is inspired by #4849
Testing
Before we can approve your change; please submit the following in a comment:
If this is a change to packaging of containers or native binaries then please confirm it works for all targets.
ok-package-test
label to test for all targets (requires maintainer to do).Documentation
fluent/fluent-bit-docs#1215
Backporting
Not required.
Fluent Bit is licensed under Apache 2.0, by submitting this pull request I understand that this code will be released under the terms of that license.