out_file formatter with time_type float drops the fraction of a time under 0.1 second
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
调研方向
阅读 lib/fluent/time.rb 中的 NumericTimeFormatter#format_float,以及 test/test_time_formatter.rb 中现有的格式化器用例。为纳秒位数不足 9 位的分数时间添加测试,例如 1700000000.012345678,并验证输出保留全部 9 位小数。Issue 指出了受影响的方法和测试文件,报告中的预期值则定义了修复完成的标准。
由索引模型根据 Issue 内容生成。
描述
Describe the bug
With time_type float, the out_file formatter drops the fractional part of a time when it is less than 0.1 second. For example, 1700000000.012345678 is written as 1700000000.0, and 1700000000.000005000 as 1700000000.00000.
NumericTimeFormatter#format_float should pad the nanoseconds with leading zeros to 9 digits. Instead, it replaces them with the zeros (time.rb L460):
nsec_s = time.nsec.to_s
nsec_s = '0' * (9 - nsec_s.size) if nsec_s.size < 9
This affects out_file and any output that uses <format> @type out_file with time_type float. time_type float in <inject> uses a different conversion and is not affected. The existing test only uses .123456789 (test_time_formatter.rb L356-L362).
To Reproduce
- Create the input file below.
- Run Fluentd with the configuration below.
{"time":"1700000000.123456789","case":"control"}
{"time":"1700000000.012345678","case":"under 0.1 s"}
{"time":"1700000000.000005000","case":"5 microseconds"}
{"time":"1700000000.000000000","case":"zero"}
Output of the out_file formatter on master (31157cba) and v1.20.1:
1700000000.123456789 test {"time":"1700000000.123456789","case":"control"}
1700000000.0 test {"time":"1700000000.012345678","case":"under 0.1 s"}
1700000000.00000 test {"time":"1700000000.000005000","case":"5 microseconds"}
1700000000.00000000 test {"time":"1700000000.000000000","case":"zero"}
With the same configuration, <inject> gives 1700000000.012345 and 1700000000.000005.
Expected behavior
The fractional part is padded to 9 digits:
1700000000.123456789
1700000000.012345678
1700000000.000005000
1700000000.000000000
Your Environment
- Fluentd version: master (31157cba) and v1.20.1
- Package version: -
- Operating system: Ubuntu 24.04.5 LTS
- Kernel version: 6.8.0-151-generic
- Ruby: 4.0.10
Your Configuration
<source>
@type tail
tag test
path /path/to/input.log
pos_file /path/to/input.pos
read_from_head true
<parse>
@type json
time_key time
time_type string
time_format %s.%N
keep_time_key true
</parse>
</source>
<match test>
@type copy
<store>
@type stdout
<format>
@type out_file
time_type float
</format>
</store>
<store>
@type stdout
<inject>
time_key float_time
time_type float
</inject>
</store>
</match>
Your Error Log
No error is logged.
Additional context
A possible fix is nsec_s = nsec_s.rjust(9, '0') and a test with a time whose nanoseconds have fewer than 9 digits. The code has been like this since 3a8038d9 (2016).
- 主要语言
- Ruby
- 星标
- 13.6k
- 派生
- 1.4k
- 平均合并
- 1 天 10 小时
- 30 天内合并 PR
- 79
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
fluent/fluentd 的其他 Issue
-
bug
难度 2/5 1-3 小时 新手友好度 82/100
维护者通常 1 天内回复
-
A <secondary> output cannot roll back a chunk: rollback_write always raises ArgumentError可能已有人在做 @lbarrosby 于 18 天前认领。 未关闭bug
难度 1/5 1 小时以内 新手友好度 88/100
维护者通常 1 天内回复
-
parser_syslog: message_format auto parses RFC 3164 messages with an RFC 3339 timestamp as RFC 5424可能已有人在做 @rafayqayyum 于 17 天前认领。 未关闭bug
难度 2/5 1-3 小时 新手友好度 79/100
维护者通常 1 天内回复
-
parser_syslog: the regexp engine for RFC 5424 can match the header later in the message and corrupt the record可能已有人在做 @rafayqayyum 于 17 天前认领。 未关闭bug
难度 2/5 1-3 小时 新手友好度 79/100
维护者通常 1 天内回复
-
in_tail with the multiline parser stops reading a file at a non-ASCII line when format_firstline is a UTF-8 regexp可能已有人在做 @RjyavardhanSingh 今天认领。 未关闭bug
难度 3/5 1-2 天 新手友好度 35/100
维护者通常 1 天内回复
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 68/100
维护者通常 1 天内回复
-
🐛 bug 👩💻 équipe CE
难度 2/5 1-3 小时 新手友好度 68/100
betagouv/conseillers-entreprises#4835 ·
维护者通常 1 天内回复
-
backlog enhancement github_actions priority: low risk: low
难度 2/5 1-3 小时 新手友好度 77/100
davidteren/mutineer#646 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 62/100
metanorma/isodoc#965 · 1 条评论 ·
维护者通常 1 天内回复
-
verified
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 4 天内回复