pack: JSON output rounds doubles to 16 significant digits (%.16g) and loses precision
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
調査の方向性
msgpack2json_scalar() を src/flb_pack.c の 1061 行目付近で読み、%.16g フォーマット文字列がある箇所と、周囲の float/double 分岐がどのようにディスパッチされるかを確認する。編集前に切り捨てを確認するため、fluent-bit を再ビルドし、レポートにある dummy -> stdout json_lines コマンド、または tests/internal/ 以下の pack テストを再実行する。完了とは、1728517471.3315752 と 1728488902.8078704 が保持され、0.1 が引き続き 0.1 として出力されることを意味する。同じフォーマット文字列を変更し、すでにこれをカバーしている可能性があるため、まずオープン PR #12129 を読む。
索引モデルが issue の本文から書いたものです。
説明
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.
- 主要言語
- C
- スター
- 8.2k
- フォーク
- 2k
- 平均マージ
- 2日 16時間
- マージ済み PR(30日)
- 72
環境構築
このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。
- Dockerfile または Docker Compose ファイルあり
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
fluent/fluent-bit のほかの issue
-
status: waiting-for-triage
難易度 2/5 1〜3時間 初心者へのやさしさ 63/100
fluent/fluent-bit#12787 ·
メンテナーはふだん 1 日以内に返信
-
in_tail: files falsely detected as rotated on macOS with threaded inputs, causing duplicate recordsオープン
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
fluent/fluent-bit#12780 ·
メンテナーはふだん 1 日以内に返信
-
status: waiting-for-triage
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
fluent/fluent-bit#12683 · コメント 2 件 · リアクション 6 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
fluent/fluent-bit#12657 ·
メンテナーはふだん 1 日以内に返信
-
http: Transfer-Encoding chunked plus Content-Length hangs forever (CL branch shadows the chunked path)対応中かも @sarankumar1325 が 25 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
fluent/fluent-bit#12656 · コメント 3 件 ·
メンテナーはふだん 1 日以内に返信
fluent/fluent-bit の issue をすべて見る
似ている issue
-
bug game: 0100FF500E34A000 game: 0400FF500E34A001 mac packing
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 2 日以内に返信
-
clang:frontend clang:openmp crash
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
llvm/llvm-project#245442 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
needs-triage
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
InauguralSystems/EigenScript#2518 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
Life-Framework/Life-Framework#4623 ·
メンテナーはふだん 1 日以内に返信
-
documentation
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
erkamyaman/rust-anything#354 ·
メンテナーはふだん 1 日以内に返信