pack: JSON output rounds doubles to 16 significant digits (%.16g) and loses precision
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
- 72/100
Hướng nghiên cứu
Đọc msgpack2json_scalar() trong src/flb_pack.c quanh dòng 1061, nơi có chuỗi định dạng %.16g, và kiểm tra cách các nhánh float/double xung quanh được dispatch. Build lại fluent-bit và chạy lại lệnh dummy -> stdout json_lines từ báo cáo, hoặc các test pack dưới tests/internal/, để xác nhận việc cắt cụt trước khi sửa. Hoàn tất nghĩa là 1728517471.3315752 và 1728488902.8078704 vẫn giữ nguyên trong khi 0.1 vẫn in ra là 0.1. Đọc PR đang mở #12129 trước, vì nó thay đổi cùng chuỗi định dạng và có thể đã bao phủ trường hợp này.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Bug Report
Describe the bug
When a record is converted from msgpack to JSON, non-integral doubles are printed with %.16g (msgpack2json_scalar() in src/flb_pack.c):
A double can need 17 significant digits to round-trip. Any value that needs the 17th digit is silently rounded, and the number in the JSON output parses back to a different double than the one in the record.
For example, 1728517471.3315752 is emitted as 1728517471.331575.
This affects every output that builds JSON through flb_msgpack_raw_to_json_sds() / flb_pack_msgpack_to_json_format(), including stdout (json, json_lines) and out_stackdriver.
To Reproduce
- Example log message if applicable:
{"ts":1728517471.3315752,"a":0.1,"b":1728488902.8078704}
- Steps to reproduce the problem:
docker run --rm fluent/fluent-bit:5.2.0 /fluent-bit/bin/fluent-bit -q -f 1 \
-i dummy -p 'dummy={"ts":1728517471.3315752,"a":0.1,"b":1728488902.8078704}' -p samples=1 \
-o stdout -p format=json_lines
Output:
{"date":1795462835.007555,"ts":1728517471.331575,"a":0.1,"b":1728488902.80787}
| Field | Input | Output |
|---|---|---|
ts |
1728517471.3315752 |
1728517471.331575 |
b |
1728488902.8078704 |
1728488902.80787 |
a |
0.1 |
0.1 |
Expected behavior
A double keeps its value through the msgpack to JSON conversion, so the output contains "ts":1728517471.3315752 and "b":1728488902.8078704.
Your Environment
- Version used: 5.2.0 (official container image, git commit e0149076aeff009d35fd495e55379cb78f1eb53f). The same line is on
masterat 4aa872100d58f0a531a7193b73c0b603c7fa444c. We first saw it on 4.2.8. - Configuration: see the command above.
- Environment name and version (e.g. Kubernetes? What version?): Docker for the reproduction. We first saw it on Kubernetes.
- Server type and version: N/A
- Operating System and version: Linux
- Filters and plugins:
dummyinput andstdoutoutput for the reproduction. We first saw it withtailandout_stackdriver.
Additional context
We hit this with out_stackdriver. Applications that log an epoch-seconds timestamp as a float, such as a ts field of 1728517471.3315752, have 10 digits before the decimal point, so only 6 digits after it survive. The value stored in Cloud Logging then differs from the value the application wrote. Any other float field that needs 17 significant digits is affected in the same way.
%.16g was introduced in #1439, replacing %f, on the assumption that 16 digits are enough. 15 significant digits is the most that always survives decimal to double to decimal. Going from a double to decimal and back to the same double can need 17.
Related:
- #6447 reports a different symptom from the same format string. It was closed by the stale bot.
- #12129 (open) replaces
%.16gwith shortest round-trip formatting. From its description it should fix this case as well. I have not tested it against the values above.
Changing the format string to %.17g always round-trips, but it prints 0.1 as 0.10000000000000001. Shortest round-trip formatting, as in #12129, avoids that.
- Ngôn ngữ chính
- C
- Star
- 8.2k
- Fork
- 2k
- Merge trung bình
- 2 ngày 16 giờ
- Pull request đã merge (30 ngày)
- 72
Chuẩn bị môi trường
Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.
- Có Dockerfile hoặc tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- 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.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của fluent/fluent-bit
-
status: waiting-for-triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 63/100
fluent/fluent-bit#12787 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
in_tail: files falsely detected as rotated on macOS with threaded inputs, causing duplicate recordsĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
fluent/fluent-bit#12780 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
status: waiting-for-triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
fluent/fluent-bit#12683 · 2 bình luận · 6 reaction ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
fluent/fluent-bit#12657 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
http: Transfer-Encoding chunked plus Content-Length hangs forever (CL branch shadows the chunked path)Có thể đã có người làm @sarankumar1325 đã nhận 25 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
fluent/fluent-bit#12656 · 3 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của fluent/fluent-bit
Issue tương tự
-
parsedate: two-digit year "70" is read as 2070, so cookies deleted with expires=...01-Jan-70... are keptCó thể đã có người làm @lazerg đã nhận hôm nay. Đang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 88/100
Maintainer thường phản hồi trong vòng 1 ngày
-
bug game: 0100FF500E34A000 game: 0400FF500E34A001 mac packing
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 2 ngày
-
clang:frontend clang:openmp crash
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
llvm/llvm-project#245442 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug 🐞
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
valkey-io/valkey-glide#7848 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
needs-triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
InauguralSystems/EigenScript#2518 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày