-
Notifications
You must be signed in to change notification settings - Fork 494
Add support for usec precision when parsing time #2709
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
Conversation
This user does not have permission to start the build. Can one of the admins verify this patch and start the build? |
1 similar comment
This user does not have permission to start the build. Can one of the admins verify this patch and start the build? |
@kira-syslogng ok to test |
Build SUCCESS |
This is actually something I had on my shortlist to implement, and in exactly the same manner (using %f to follow Python's lead here). Thank you. There's one more problem I originally wanted to solve: since the microseconds part is optional, the dot should be parsed as the part of that piece, and I know %f does not consume the dot, but maybe we should implement a %F which does. An example:
Hmm I just noticed that %F is already taken, maybe we could use a multi-letter variant, like "%.f" what do you think? |
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.
Nicely done! Appreciate the testcases as well. I had some nitpicks as comments, but those are all optional.
Build SUCCESS |
I amended my commit with style fixes, and added a new one to eat extra digit in the usec field as suggested. Regarding consuming the dot
As you can see, the old format seems to use a coma Maybe we can keep it that way for now, and rely on users feedback to determine if it should be extended it in the future? |
I think it makes sense, and there's one more place this could be addressed: introduce support for multiple format() arguments to date-parser, trying them in order and accepting the timestamp at first success. For example:
This would handle either ',' or '.' and even with the fractions omitted. I have a relevant use-case in the cisco-parser:
Would you give this a go, even in a separate PR? That would be awesome. |
@bazsi I added a few commits to move the code around. Is it what you expected? Regarding adding support for multiple formats to |
Build SUCCESS |
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 have some minor requests in comments, but the code looks good. If you guys these I can approve this.
Build SUCCESS |
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 looks good. Maybe you could squash your commits so that other reviewers will have an easier time reviewing the changes. Thanks. But if you do that, please make sure that non-functional changes (e.g. moving of the code) remain separated from functional changes.
@bazsi, I am back from holidays 🌴 I squashed the related commits as requested and rebased my work on top of the master branch. |
Build SUCCESS |
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.
Looks good to me. Thank you for your contribution!
Python added a '%f' field ("Microsecond as a decimal number") in it's strptime() implementation to parse times with subsecond precision. Borrow this idea and implement it in syslog-ng using the same field descriptor. Eat all digitis when reading microseconds: if the field has a nanosecond precision, the value will be truncated at the microsecond and the parser will be able to process the information following the sub-second information.
Update strptime_with_tz() signature so that it's parameters match those of wall_clock_time_strptime(). While here, get rid of _u_char and _uint macros: these macros where introduced when borrowing code from NetBSD, since the code has forked it makes no sense to keep them around. No functional change.
Remove trptime-tz.c and trptime-tz.h which are now useless. No functional change.
SYSLOG_NG_HAVE_TIMEZONE is always set.
Build SUCCESS |
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.
Good job! Approved on my part too.
Support for a %f field was added in syslog-ng/syslog-ng#2709
The conditional assignment to wct->wct_gmtoff was [removed in syslog-ng#2709][1] because we though that the field previously did not exist in some circumstances which where not true anymore. In fact, the macros is here to help us detect what `timezone` is, since it's not the same on all platforms: On Linux, timezone is declared in time.h as: extern long int timezone; On FreeBSD, timezone is declared in time.h as: char *timezone(int zone, int dst); As a consequence, the assignment on FreeBSD produce a compiler error: ``` CC lib/timeutils/libsyslog_ng_la-wallclocktime.lo lib/timeutils/wallclocktime.c:551:37: error: invalid argument type 'char *(*)(int, int)' to unary expression wct->wct_gmtoff = -(timezone); ^~~~~~~~~~~ 1 error generated. ``` Re-add the removed #ifdef to fix the build on FreeBSD. [1]: syslog-ng#2709 (comment)
Python added a
%f
field ("Microsecond as a decimal number") in it's strptime() implementation to parse times with subsecond precision.Borrow this idea and implement it in syslog-ng using the same field descriptor.
TODO:
%f
field to parse microseconds;wall_clock_time_strptime()
see comment