Skip to content

Conversation

@cosmo0920
Copy link
Contributor

@cosmo0920 cosmo0920 commented Oct 31, 2025

The PR #11055 removed the routes_mask guard, which exposed a design flaw in the previous logic. Unconditional routes were being forced through prepare_logs() first. The proper fix is to allow unconditional routes to short-circuit early, so that chunk_trace routes are wired correctly.
With this change, the core_chunk_trace unit test will no longer fail.


Enter [N/A] in the box, if an item is not applicable to your change.

Testing
Before we can approve your change; please submit the following in a comment:

  • Example configuration file for the change
  • Debug log output from testing the change
  • Attached Valgrind output that shows no leaks or memory corruption was found

If this is a change to packaging of containers or native binaries then please confirm it works for all targets.

  • Run local packaging test showing all targets (including any new ones) build.
  • Set ok-package-test label to test for all targets (requires maintainer to do).

Documentation

  • Documentation required for this feature

Backporting

  • Backport to latest stable release.

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

  • Refactor
    • Improved routing condition evaluation logic with optimized control flow to handle edge cases more efficiently.

The PR #11055 removed the
routes_mask guard, which exposed a design flaw in the previous logic.
Unconditional routes were being forced through prepare_logs() first.
The proper fix is to allow unconditional routes to short-circuit early,
so that chunk_trace routes are wired correctly.
With this change, the core_chunk_trace unit test will no longer fail.

Signed-off-by: Hiroshi Hatake <[email protected]>
@coderabbitai
Copy link

coderabbitai bot commented Oct 31, 2025

Walkthrough

This PR refactors the flb_router_path_should_route function in src/flb_router_condition.c by adding an early guard that returns FLB_TRUE when a path exists but path->route is NULL, and removes a duplicate check that appeared later, resulting in optimized early short-circuit behavior.

Changes

Cohort / File(s) Summary
Router condition early return optimization
src/flb_router_condition.c
Added early guard in flb_router_path_should_route to return FLB_TRUE when path->route is NULL; removed duplicate NULL check that appeared after LOGS chunk context handling, consolidating the logic path.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • Single file with focused guard clause repositioning
  • Verify that early return for NULL path->route is semantically correct across all calling contexts
  • Confirm removal of duplicate check doesn't mask any conditional logic that depended on later evaluation

Suggested labels

backport to v4.0.x

Suggested reviewers

  • koleini
  • fujimotos

Poem

🐰 A path without a route to show,
Now caught before the function's flow,
Early guard hops in with might,
One true return does set things right,
Hopping faster, cleaner code—we go!

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 (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The pull request title "router_condition: Fix unconditional route check in routing" directly addresses the main change in the codebase. The PR modifies the flb_router_path_should_route function in src/flb_router_condition.c to add an early guard that handles the case where path->route is NULL (unconditional routes), which is precisely what the title describes as "unconditional route check." The title is specific to the router_condition component, concise at 58 characters and 7 words, and clearly conveys the primary purpose of the fix without vague terminology or noise. It accurately summarizes the bug fix from a developer's perspective by identifying both the component and the nature of the correction.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch cosmo0920-fix-failing-core_chunk_trace-test

📜 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 f879a93 and 6f9b009.

📒 Files selected for processing (1)
  • src/flb_router_condition.c (1 hunks)
⏰ 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). (30)
  • GitHub Check: pr-windows-build / call-build-windows-package (Windows 64bit, x64, x64-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 32bit, x86, x86-windows-static, 3.31.6)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SIMD=Off, 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_THREAD=On, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SIMD=On, 3.31.6, clang, clang++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SIMD=Off, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_COVERAGE=On, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SANITIZE_THREAD=On, 3.31.6, clang, clang++)
  • 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 (-DSANITIZE_UNDEFINED=On, 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 (-DSANITIZE_UNDEFINED=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_ADDRESS=On, 3.31.6, gcc, g++)
  • 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, 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, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_JEMALLOC=On, 3.31.6, clang, clang++)
  • GitHub Check: PR - fuzzing test
  • GitHub Check: pr-compile-without-cxx (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, gcc, g++, 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, clang, clang++, ubuntu-24.04, clang-14)
  • GitHub Check: pr-compile-centos-7
🔇 Additional comments (1)
src/flb_router_condition.c (1)

268-270: LGTM! Early return correctly implements unconditional routing.

The early guard properly handles unconditional routes (where path->route is NULL) by returning FLB_TRUE immediately. This fixes the reported bug where unconditional routes were incorrectly forced through prepare_logs() (line 277), and aligns with the semantic expectation that a NULL route means "route unconditionally."

The behavior change is significant but correct:

  • Before: NULL path->route would call flb_route_condition_eval() with NULL, which returns FLB_FALSE (line 226)
  • After: NULL path->route short-circuits to return FLB_TRUE (unconditional routing)

This also provides a performance benefit by avoiding unnecessary log preparation for unconditional routes.


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.

@edsiper
Copy link
Member

edsiper commented Nov 1, 2025

great catch! thank you

@edsiper edsiper merged commit f5597d8 into master Nov 1, 2025
58 checks passed
@edsiper edsiper deleted the cosmo0920-fix-failing-core_chunk_trace-test branch November 1, 2025 02:13
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.

3 participants