Skip to content

Conversation

@edsiper
Copy link
Member

@edsiper edsiper commented Sep 24, 2025

Fixes #10927

After the last refactoring, we are missing to check the return value when multiple parsers are loaded in a chain. Issue was not found before because the missing unit test for that specific case.

This PR implements the fix and proper unit test to avoid regressions.


Fluent Bit is licensed under Apache 2.0, by submitting this pull request I understand that this code will be released under the terms of that license.

Summary by CodeRabbit

  • Bug Fixes

    • Multiline parsing now stops when a sub-parser fails, allowing alternative parsers to handle input.
    • Avoids unintended buffering of payloads for mixed Docker/CRI lines, including inputs without trailing newlines.
    • Improves reliability of chained log-format parsing and behavior during flush operations.
  • Tests

    • Added regression test validating Docker→CRI parser chaining, immediate CRI consumption, and correct outputs on flush.

@coderabbitai
Copy link

coderabbitai bot commented Sep 24, 2025

Walkthrough

Multiline parser now propagates a negative return from a sub-parser in text input flow (returns -1 immediately), enabling the next parser in the chain to handle the input; a regression test for a docker→CRI parser chain (non-newline-terminated input + explicit flush) was added and expectations updated.

Changes

Cohort / File(s) Summary
Multiline parser logic
src/multiline/flb_ml.c
For FLB_ML_TYPE_TEXT in ml_append_try_parser, if a sub-parser returns < 0, the function now returns -1 immediately instead of continuing to treat the line as processed, allowing chain handoff.
Tests: docker→CRI chain & expectations
tests/internal/multiline.c
Adds docker_cri_chain_input and docker_cri_chain_output, implements test_parser_docker_cri_chain (feeds non-newline-terminated CRI-like input, explicit flush), updates container_mix_output expectations (adds/repositions docker fragments), and registers the new test in TEST_LIST.

Sequence Diagram(s)

sequenceDiagram
    autonumber
    participant Src as SourceLine
    participant Chain as ParserChain
    participant Dock as DockerParser
    participant CRI as CRIParser

    Src->>Chain: deliver(line)
    Chain->>Dock: try parse(line)
    alt Docker returns < 0 (decline/error)
        Dock-->>Chain: -1
        note right of Chain #E8F6F3: New behavior — propagate failure immediately
        Chain->>CRI: try parse(line)
        CRI-->>Chain: success / records
    else Docker accepts or buffers
        Dock-->>Chain: success / buffer
    end
    Chain-->>Src: result / next action
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Poem

I twitch my ears at parsers’ rhyme,
Docker shrugs — "not mine this time",
I hop along to CRI's bright gate,
No stray crumbs linger, none to sate.
A tidy flush, a happy fate. 🐇✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title succinctly and accurately summarizes the primary change: fixing handling of a return error in multiline parsing; it is concise, relevant to the flb_ml.c change and the added test, and readable for teammates scanning history.
Linked Issues Check ✅ Passed The patch restores the missing return-value check in ml_append_try_parser so a failing sub-parser returns -1 and allows the next parser in a chain (docker→cri) to handle the input, and it adds a regression test that exercises this chain; these code changes directly address the linked issue #10927 by preventing docker+cri chaining from merging separate lines into oversized records.
Out of Scope Changes Check ✅ Passed The changes are limited to one production file (src/multiline/flb_ml.c) and test updates/additions in tests/internal/multiline.c (including updated expected outputs) which are directly related to the fix; I found no unrelated production code changes outside the stated objectives.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch multiline-docker-issue

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 65078e3 and ca90813.

📒 Files selected for processing (2)
  • src/multiline/flb_ml.c (1 hunks)
  • tests/internal/multiline.c (3 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
tests/internal/multiline.c (4)
src/flb_config.c (2)
  • flb_config_init (225-438)
  • flb_config_exit (440-617)
src/multiline/flb_ml.c (4)
  • flb_ml_create (871-923)
  • flb_ml_append_text (667-757)
  • flb_ml_flush_pending_now (143-149)
  • flb_ml_destroy (984-1009)
src/multiline/flb_ml_parser.c (1)
  • flb_ml_parser_instance_create (261-312)
src/multiline/flb_ml_stream.c (1)
  • flb_ml_stream_create (223-276)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (29)
  • GitHub Check: pr-windows-build / call-build-windows-package (Windows 32bit, x86, x86-windows-static, 3.31.6)
  • GitHub Check: pr-windows-build / call-build-windows-package (Windows 64bit (Arm64), amd64_arm64, -DCMAKE_SYSTEM_NAME=Windows -DCMA...
  • GitHub Check: pr-windows-build / call-build-windows-package (Windows 64bit, x64, x64-windows-static, 3.31.6)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SANITIZE_MEMORY=On, 3.31.6, clang, clang++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SIMD=Off, 3.31.6, clang, clang++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SIMD=On, 3.31.6, clang, clang++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_ARROW=On, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SIMD=On, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SANITIZE_MEMORY=On, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DSANITIZE_ADDRESS=On, 3.31.6, clang, clang++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SANITIZE_THREAD=On, 3.31.6, clang, clang++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_COVERAGE=On, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SIMD=Off, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SANITIZE_THREAD=On, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DSANITIZE_UNDEFINED=On, 3.31.6, clang, clang++)
  • GitHub Check: run-ubuntu-unit-tests (-DSANITIZE_UNDEFINED=On, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_JEMALLOC=Off, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_JEMALLOC=On, 3.31.6, clang, clang++)
  • GitHub Check: run-ubuntu-unit-tests (-DSANITIZE_ADDRESS=On, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SMALL=On, 3.31.6, clang, clang++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SMALL=On, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_JEMALLOC=On, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_JEMALLOC=Off, 3.31.6, clang, clang++)
  • GitHub Check: pr-compile-centos-7
  • GitHub Check: pr-compile-system-libs (-DFLB_PREFER_SYSTEM_LIBS=On, 3.31.6, gcc, g++, ubuntu-24.04, clang-14)
  • GitHub Check: pr-compile-system-libs (-DFLB_PREFER_SYSTEM_LIBS=On, 3.31.6, gcc, g++, ubuntu-22.04, clang-12)
  • GitHub Check: pr-compile-system-libs (-DFLB_PREFER_SYSTEM_LIBS=On, 3.31.6, clang, clang++, ubuntu-24.04, clang-14)
  • GitHub Check: pr-compile-system-libs (-DFLB_PREFER_SYSTEM_LIBS=On, 3.31.6, clang, clang++, ubuntu-22.04, clang-12)
  • GitHub Check: PR - fuzzing test
🔇 Additional comments (5)
src/multiline/flb_ml.c (1)

609-616: Fix correctly propagates parser failure in chained configuration.

The change ensures that when a sub-parser fails to consume text input (returns -1), the failure is immediately propagated to the caller. This allows the next parser in the chain to attempt processing the input, which is essential for proper Docker-CRI chain handling.

tests/internal/multiline.c (4)

110-125: Updated test expectations align with new chaining behavior.

The updated container_mix_output expectations correctly reflect that when docker parser is first in the chain, it will now properly decline CRI-formatted lines, allowing them to be immediately consumed by the CRI parser instead of being buffered.


127-144: Comprehensive regression test for docker-cri chain issue.

Good test coverage for the reported issue. The test mimics the exact scenario from issue #10927 where CRI log lines without trailing newlines should be immediately processed by the CRI parser rather than buffered by the docker parser.


631-691: Test validates immediate CRI processing in chained configuration.

The test properly validates that:

  1. CRI messages are immediately processed when docker parser declines them
  2. No buffering occurs until flush timer expires
  3. All three messages are correctly emitted as separate records

The explicit flush at line 681 and the assertion at line 684 ensure that all records are processed immediately without relying on timeout-based flushing.


1650-1650: Test integration verified

test_parser_docker_cri_chain is implemented in tests/internal/multiline.c and registered in TEST_LIST; it creates the multiline context and stream (flb_ml_create / flb_ml_stream_create) consistent with other parser tests — no changes required.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (2)
tests/internal/multiline.c (2)

127-145: Add stderr and partial (P) variants to harden the regression guard.

Optional: expand coverage to ensure both streams and partial records are correctly declined by docker and consumed by CRI without buffering.

Apply this diff to extend the datasets minimally:

 struct record_check docker_cri_chain_input[] = {
   {"2025-09-22T19:07:06.115398289Z stdout F first message"},
   {"2025-09-22T19:07:06.116725604Z stdout F second message"},
   {"2025-09-22T19:07:08.582112316Z stdout F third message"},
+  {"2025-09-22T19:07:09.000000000Z stderr F fourth message"},
+  {"2025-09-22T19:07:10.000000000Z stdout P partial "},
+  {"2025-09-22T19:07:10.000000001Z stdout F tail"},
 };
 
 struct record_check docker_cri_chain_output[] = {
   {"first message"},
   {"second message"},
   {"third message"},
+  {"fourth message"},
+  {"partial tail"},
 };

Note: Add corresponding assertion count update in the test below.


631-691: Capture and assert parser return codes for earlier failure detection.

Small robustness win: check flb_ml_append_text return values.

Apply this diff:

-        /* Package as msgpack */
-        flb_ml_append_text(ml, stream_id, &tm, r->buf, len);
+        /* Package as msgpack */
+        ret = flb_ml_append_text(ml, stream_id, &tm, r->buf, len);
+        TEST_CHECK(ret >= 0);
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5052074 and 65078e3.

📒 Files selected for processing (1)
  • tests/internal/multiline.c (3 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
tests/internal/multiline.c (4)
src/flb_config.c (2)
  • flb_config_init (225-438)
  • flb_config_exit (440-617)
src/multiline/flb_ml.c (4)
  • flb_ml_create (871-923)
  • flb_ml_append_text (667-757)
  • flb_ml_flush_pending_now (143-149)
  • flb_ml_destroy (984-1009)
src/multiline/flb_ml_parser.c (1)
  • flb_ml_parser_instance_create (261-312)
src/multiline/flb_ml_stream.c (1)
  • flb_ml_stream_create (223-276)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (29)
  • GitHub Check: pr-windows-build / call-build-windows-package (Windows 32bit, x86, x86-windows-static, 3.31.6)
  • GitHub Check: pr-windows-build / call-build-windows-package (Windows 64bit (Arm64), amd64_arm64, -DCMAKE_SYSTEM_NAME=Windows -DCMA...
  • GitHub Check: pr-windows-build / call-build-windows-package (Windows 64bit, x64, x64-windows-static, 3.31.6)
  • GitHub Check: pr-compile-system-libs (-DFLB_PREFER_SYSTEM_LIBS=On, 3.31.6, gcc, g++, ubuntu-22.04, clang-12)
  • GitHub Check: pr-compile-system-libs (-DFLB_PREFER_SYSTEM_LIBS=On, 3.31.6, clang, clang++, ubuntu-24.04, clang-14)
  • GitHub Check: pr-compile-system-libs (-DFLB_PREFER_SYSTEM_LIBS=On, 3.31.6, clang, clang++, ubuntu-22.04, clang-12)
  • GitHub Check: pr-compile-system-libs (-DFLB_PREFER_SYSTEM_LIBS=On, 3.31.6, gcc, g++, ubuntu-24.04, clang-14)
  • GitHub Check: pr-compile-centos-7
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_ARROW=On, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SIMD=Off, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SIMD=On, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SIMD=Off, 3.31.6, clang, clang++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SANITIZE_THREAD=On, 3.31.6, clang, clang++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SIMD=On, 3.31.6, clang, clang++)
  • GitHub Check: run-ubuntu-unit-tests (-DSANITIZE_UNDEFINED=On, 3.31.6, clang, clang++)
  • GitHub Check: PR - fuzzing test
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SANITIZE_THREAD=On, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SANITIZE_MEMORY=On, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SANITIZE_MEMORY=On, 3.31.6, clang, clang++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_COVERAGE=On, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DSANITIZE_ADDRESS=On, 3.31.6, clang, clang++)
  • GitHub Check: run-ubuntu-unit-tests (-DSANITIZE_UNDEFINED=On, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DSANITIZE_ADDRESS=On, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_JEMALLOC=Off, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_JEMALLOC=On, 3.31.6, clang, clang++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_JEMALLOC=Off, 3.31.6, clang, clang++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SMALL=On, 3.31.6, clang, clang++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SMALL=On, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_JEMALLOC=On, 3.31.6, gcc, g++)
🔇 Additional comments (4)
tests/internal/multiline.c (4)

110-115: Comment clarifies intended interleaving semantics—good.

Accurately documents the expected flush order between docker-buffered fragments and CRI records in a chained setup.


123-125: Updated expectations match actual arrival order.

Placing "bbccdd-out\n" and "dd-err\n" after the CRI outputs aligns with input sequencing and the chain handoff behavior.


680-685: Good: explicit flush + count check prevents latent buffering.

Ensures no pending records remain and guards against regressions in chain handoff.


1650-1650: Test registered in TEST_LIST—consistent naming and placement.

Keeps suite coverage coherent.

Signed-off-by: Eduardo Silva <eduardo@chronosphere.io>
Signed-off-by: Eduardo Silva <eduardo@chronosphere.io>
@edsiper edsiper force-pushed the multiline-docker-issue branch from 65078e3 to ca90813 Compare September 24, 2025 13:25
@edsiper
Copy link
Member Author

edsiper commented Sep 24, 2025

rebased on top of master, #10930 should fix the processor issue

@edsiper edsiper deleted the multiline-docker-issue branch September 24, 2025 14:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CloudWatch partial logs loss and wrapped logs instead of being emitted individually

2 participants