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

オープン 初心者向け
#5,715 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
86/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
ruby
領域
backend, testing

調査の方向性

lib/fluent/time.rb の NumericTimeFormatter#format_float と、test/test_time_formatter.rb にある既存のフォーマッターのケースを確認してください。ナノ秒が9桁未満の小数時刻(1700000000.012345678 など)のテストを追加し、出力に小数部の9桁すべてが保持されることを確認してください。Issueには影響を受けるメソッドとテストファイルが記載されており、報告された期待値によって修正完了の条件が定まります。

索引モデルが issue の本文から書いたものです。

説明

bug
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
  1. Create the input file below.
  2. 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時間
マージ済み PR(30日)
79

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

fluent/fluentd のほかの issue

fluent/fluentd の issue をすべて見る

似ている issue

Ruby の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。