Skip to content

time: keep leading zeros in the fraction for time_type float - #5718

Merged
Watson1978 merged 2 commits into
fluent:masterfrom
og-orca:fix-float-time-leading-zeros
Dec 3, 2026
Merged

Watson1978 merged 2 commits into
fluent:masterfrom
og-orca:fix-float-time-leading-zeros

Conversation

@og-orca

@og-orca og-orca commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Which issue(s) this PR fixes:
Fixes #5715

What this PR does / why we need it:
With time_type float, the out_file formatter dropped the fraction of a time when the fraction was under 0.1 second. 1700000000.012345678 came out as 1700000000.0.

The line in format_float was meant to put zeros in front of the nanoseconds, but it replaced them with the zeros. Now it pads the nanoseconds with rjust(9, '0') only when they have fewer than 9 digits, so the fraction of an EventTime or a Time always has 9 digits.

I ran the config from the issue on master and on this branch:

Before and after

The new test has three times from the issue (the fourth, .123456789, is covered by an existing test) plus 1 nanosecond. All four cases fail on master. I also timed 3 million calls to format and it's about the same, 0.56 s now and 0.55 s before.

Docs Changes:
None

Release Note:
time: keep leading zeros in the fraction for time_type float, so that the out_file formatter no longer drops a fraction under 0.1 second

Signed-off-by: og-orca <301901286+og-orca@users.noreply.github.com>

@Watson1978 Watson1978 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix. I ran the configuration from #5715 on master and on this branch. This branch writes all four times with 9 fraction digits. The new tests fail on master and pass here.

I have one request about speed. Please see the inline comment.

Comment thread lib/fluent/time.rb Resolved
@Watson1978 Watson1978 added bug Something isn't working backport to v1.19 We will backport this fix to the LTS branch labels Dec 3, 2026
Signed-off-by: og-orca <301901286+og-orca@users.noreply.github.com>

@Watson1978 Watson1978 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for applying the suggestion. I checked it again at 6c7f2e7. With the configuration from #5715, the out_file formatter writes all four times with 9 fraction digits, and test/test_time_formatter.rb passes. In the benchmark from my previous comment, NumericTimeFormatter#format now takes about the same time as on master (0.56 s and 0.54 s for 3 million calls with YJIT).

@Watson1978 Watson1978 added this to the v1.21.0 milestone Dec 3, 2026
@Watson1978
Watson1978 merged commit 628bb21 into fluent:master Dec 3, 2026
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport to v1.19 We will backport this fix to the LTS branch bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

out_file formatter with time_type float drops the fraction of a time under 0.1 second

2 participants