Repository navigation
time: fix wrong %N/%L subseconds when EventTime and Integer times share a second - #5634
Conversation
TimeFormatter#format_with_subsec checks its cache with EventTime.eq?, which compares only the seconds when one side is an EventTime and the other an Integer. With a %N or %L time_format, an Integer time that followed an EventTime of the same second got the cached string of the EventTime, so it was written with the subsecond part of another event. This happens when one output gets events from clients that send EventTime and from clients that send Integer times. Only reuse a cache slot when the cached time and the given time have the same class. Signed-off-by: Lucas Barros <lucasbarros.kam@gmail.com>
Watson1978
left a comment
There was a problem hiding this comment.
Thanks for the clear report and the reproduction.
I reproduced the wrong subsecond on master and confirmed that this branch fixes it in both orders: an Integer time after an EventTime, and an EventTime after an Integer time. The new test fails with master's lib and passes here.
I also ran test_time_formatter.rb, test_event_time.rb, test_formatter.rb, plugin/test_formatter_out_file.rb, plugin/test_out_stdout.rb and plugin_helper/test_inject.rb. All pass except the two injects hostname automatically detected cases, which also fail on master.
I'd like the comparison fixed in Fluent::EventTime.eq? rather than at the call site. Please see the inline comment.
EventTime.eq? compared an EventTime and an Integer by their seconds, so format_with_subsec had to reject mixed classes before calling it. Make eq? return false for different classes and drop the check at the call site. Signed-off-by: Lucas Barros <lucasbarros.kam@gmail.com>
|
Moved the class check into
|
Watson1978
left a comment
There was a problem hiding this comment.
Thanks for the update. e182fd6 moves the same-class check into EventTime.eq?, restores format_with_subsec to the version on master, changes the two mixed EventTime/Integer assertions to refute, and updates the test comments.
I checked it again. The new test fails with master's lib and passes here. test_time_formatter.rb, test_event_time.rb, test_formatter.rb, plugin/test_formatter_out_file.rb and plugin/test_out_stdout.rb pass. plugin_helper/test_inject.rb has only the two injects hostname automatically detected failures, which also happen on master.
LGTM.
Which issue(s) this PR fixes:
No issue. Found while checking event times in the
nanosecond_precisionpath of fluent-logger-ruby.What this PR does / why we need it:
TimeFormatter#format_with_subsecchecks its two cache slots withFluent::EventTime.eq?. When one side is anEventTimeand the other anInteger,eq?falls back toEventTime#==, which compares the seconds only. So with a%N/%Ltime_format, an Integer time that comes right after an EventTime of the same second gets the cached string of that EventTime, i.e. it is written with the subsecond part of a different event. The reverse order is also affected: an EventTime that follows an Integer time of the same second reuses the Integer's cached string and loses its subsecond part.This is easy to hit when one output receives events from clients that send
EventTimeand from clients that send Integer times (older loggers,time_as_integer, etc.).This PR makes
EventTime.eq?return false when the arguments have different classes.format_with_subsecdelegates the comparison to it, so a slot is reused only when the cached time and the given time have the same class. The two mixed EventTime/Integer assertions intest/test_event_time.rbare updated accordingly.Reproduction:
Send two forward messages on one connection, first with an EventTime
1700000000.123456789, then with the Integer time1700000000:master:
this branch:
Tests:
test_format_with_subsec_integer_and_event_time_of_the_same_secondintest/test_time_formatter.rbcovers EventTime followed by Integer with%N, and Integer followed by EventTime with%3N. It fails on master with<"20140927 000000.000000000"> expected but was <"20140927 000000.123456789">. Also rantest_time_formatter,test_event_time,test_time_parser,test_formatter,plugin/test_formatter_*,test_out_stdout,test_out_file,test_filter_record_transformerandplugin_helper/test_injectlocally (Ruby 4.0.7); all green except the twoinjects hostname automatically detectedcases intest_inject, which fail the same way on master on this machine.Docs Changes:
None.
Release Note:
time: fix incorrect subseconds in
%N/%Ltime formats when EventTime and Integer times for the same second are mixed.