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

Đang mở Phù hợp với người mới
#5,715 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
86/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
ruby
Lĩnh vực
backend, testing

Hướng nghiên cứu

Đọc NumericTimeFormatter#format_float trong lib/fluent/time.rb và các trường hợp định dạng hiện có trong test/test_time_formatter.rb. Bổ sung kiểm thử cho các thời điểm dạng phân số có phần nano giây ít hơn 9 chữ số, chẳng hạn 1700000000.012345678, và xác minh đầu ra giữ đủ cả 9 chữ số phần lẻ. Issue nêu tên phương thức và tệp kiểm thử bị ảnh hưởng, còn các giá trị mong đợi được báo cáo xác định khi nào bản sửa lỗi hoàn tất.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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).

Ngôn ngữ chính
Ruby
Star
13.6k
Fork
1.4k
Merge trung bình
1 ngày 10 giờ
Pull request đã merge (30 ngày)
79

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của fluent/fluentd

Tất cả issue của fluent/fluentd

Issue tương tự

Thêm issue về Ruby

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.