Skip to content

Conversation

edsiper
Copy link
Member

@edsiper edsiper commented Oct 18, 2025

Summary

  • rename the router YAML implementation to flb_router_config and have it consume flb_cf sections instead of detached variants
  • refresh the internal router config tests to exercise the new parser helpers and file-based fixtures
  • add a runtime route-precedence regression test that loads a YAML pipeline and asserts the default route output selection

Testing

  • cmake -S . -B build
  • ctest --test-dir build -R router_config -V (no tests were found)

Summary by CodeRabbit

  • New Features

    • Added telemetry routing capabilities to direct logs, metrics, and traces to different outputs based on conditions.
    • Support for route conditions, processors, and output fallbacks.
  • Documentation

    • Added comprehensive routing configuration documentation covering signal types, condition evaluation, and fallback behavior.
  • Tests

    • Added unit tests for routing configuration parsing.
    • Added runtime tests for router precedence validation.

Copy link

coderabbitai bot commented Oct 18, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

This PR introduces a telemetry routing system for Fluent Bit, comprising documentation, public API definitions (structs and functions), router condition evaluation logic, configuration parsing from YAML, and comprehensive unit and runtime tests with test data files. The implementation supports signal-based routing (logs, metrics, traces) with condition evaluation and output fallback handling.

Changes

Cohort / File(s) Summary
Documentation
ROUTER.md
New file documenting routing overview, configuration structure, signal types, condition evaluation, output fallbacks, retry behavior, metrics, and cleanup helpers.
Public API Definitions
include/fluent-bit/flb_router.h
Added enum flb_router_signal (LOGS, METRICS, TRACES, ANY) and seven new structs (flb_route_condition_rule, flb_route_condition, flb_route_output, flb_route_processor_property, flb_route_processor, flb_route, flb_input_routes) for routing data structures. Added function declarations for signal detection, condition evaluation (per-signal and aggregated), configuration parsing, and cleanup.
Router Implementation
src/flb_router_condition.c, src/flb_router_config.c
New implementations: condition evaluation with signal-to-function dispatch, and comprehensive YAML configuration parsing with validation, error handling, and memory cleanup.
Build System
src/CMakeLists.txt, tests/internal/CMakeLists.txt, tests/runtime/CMakeLists.txt
Updated to include new source files (flb_router_condition.c, flb_router_config.c, router_config.c) and runtime test (router_precedence.c).
Unit Test Data
tests/internal/data/config_format/yaml/routing/basic.yaml, metrics.yaml, multi_signal.yaml
New YAML test fixtures defining example routing configurations with log/metric routes, conditions, outputs, and fallbacks.
Unit Tests
tests/internal/router_config.c
Comprehensive test module with helpers for config construction, five test functions covering basic parsing, duplicate route validation, file-based parsing, multi-signal routing, and metrics-specific routing.
Runtime Test Data & Tests
tests/runtime/data/router/precedence.yaml, tests/runtime/router_precedence.c
New runtime test fixture and test function validating route precedence, default condition evaluation, and event chunk matching.

Sequence Diagram(s)

sequenceDiagram
    participant Config as YAML Config
    participant Parser as flb_router_config_parse()
    participant Validator as Validators<br/>(signal, rules, etc.)
    participant Memory as Data Structures<br/>(routes, conditions)
    participant List as input_routes List

    Config->>Parser: Parse inputs & routes
    activate Parser
    Parser->>Validator: Validate signal flags
    activate Validator
    Validator-->>Parser: OK/Error
    deactivate Validator
    Parser->>Validator: Validate condition rules<br/>field alignment
    activate Validator
    Validator-->>Parser: OK/Error
    deactivate Validator
    Parser->>Memory: Allocate & populate<br/>input_routes, routes,<br/>conditions, outputs
    activate Memory
    Memory-->>Parser: Constructed trees
    deactivate Memory
    Parser->>List: Append input_routes
    activate List
    List-->>Parser: Added
    deactivate List
    Parser-->>Config: Return success/failure
    deactivate Parser
Loading
sequenceDiagram
    participant Event as Event Chunk
    participant Signal as flb_router_signal_from_chunk()
    participant Router as flb_route_condition_eval()
    participant Evaluator as Per-Signal<br/>Evaluator<br/>(logs/metrics/traces)
    participant Route as Route Match<br/>Decision

    Event->>Signal: chunk.type
    activate Signal
    Signal-->>Router: signal (LOGS/METRICS/TRACES/0)
    deactivate Signal
    
    activate Router
    Router->>Router: Check route null<br/>& signals bitmask
    alt Route has no condition
        Router->>Route: Return TRUE
    else Route has default condition
        Router->>Route: Return TRUE
    else Route condition has no rules
        Router->>Route: Return TRUE
    else Route condition has rules
        Router->>Evaluator: Dispatch by signal
        activate Evaluator
        Evaluator-->>Route: Evaluate rules<br/>(logs/metrics/traces)<br/>Return TRUE/FALSE
        deactivate Evaluator
    else Unknown signal
        Router->>Route: Return FALSE
    end
    deactivate Router
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~50 minutes

The PR introduces substantial new functionality spanning multiple logical layers: public API definitions with eight new data structures, two implementation files with dense logic including configuration parsing and condition evaluation, extensive memory management with cleanup paths, and comprehensive test coverage. While individual cohorts (test data, build files) are straightforward, the core implementation files (flb_router_config.c in particular) contain heterogeneous parsing and validation logic requiring careful review of correctness, memory safety, and error handling paths.

Suggested reviewers

  • koleini
  • fujimotos

Poem

🐰 Hops through routes with glee,
Logs and metrics routed free,
Signals caught, conditions checked,
Fallbacks ready, none are wrecked!
What a hop-tastic routing quest,
Fluent Bit's telemetry, truly blessed!

✨ 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 eduardo-implement-unified-routing-for-fluent-bit

📜 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 36db973 and 67575f6.

📒 Files selected for processing (13)
  • ROUTER.md (1 hunks)
  • include/fluent-bit/flb_router.h (3 hunks)
  • src/CMakeLists.txt (1 hunks)
  • src/flb_router_condition.c (1 hunks)
  • src/flb_router_config.c (1 hunks)
  • tests/internal/CMakeLists.txt (1 hunks)
  • tests/internal/data/config_format/yaml/routing/basic.yaml (1 hunks)
  • tests/internal/data/config_format/yaml/routing/metrics.yaml (1 hunks)
  • tests/internal/data/config_format/yaml/routing/multi_signal.yaml (1 hunks)
  • tests/internal/router_config.c (1 hunks)
  • tests/runtime/CMakeLists.txt (1 hunks)
  • tests/runtime/data/router/precedence.yaml (1 hunks)
  • tests/runtime/router_precedence.c (1 hunks)

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

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +102 to +108
if (route->condition->is_default) {
return FLB_TRUE;
}

if (cfl_list_is_empty(&route->condition->rules) == 0) {
return FLB_TRUE;
}

Choose a reason for hiding this comment

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

P1 Badge Conditions with rules always succeed

The router condition evaluator returns FLB_TRUE whenever route->condition->rules is non-empty, so any route that declares at least one rule will match every chunk regardless of its contents. This bypasses the signal-specific evaluators entirely (they are never called) and causes conditional routes to supersede default routes even though the rule logic is not yet implemented. As a result, routing decisions will ignore the configured predicates and send all traffic to the first conditional route.

Useful? React with 👍 / 👎.

Comment on lines +499 to +503
if (add_processor_properties(processor, kvlist) != 0) {
route_processors_destroy(&processor->properties);
if (processor->name) {
flb_sds_destroy(processor->name);
}

Choose a reason for hiding this comment

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

P1 Badge Processor cleanup misinterprets property list

When add_processor_properties fails, the code calls route_processors_destroy(&processor->properties) for cleanup. route_processors_destroy expects a list of struct flb_route_processor, but processor->properties contains struct flb_route_processor_property. Iterating that list as if it contained processors will dereference invalid fields and free bogus pointers, leading to crashes or memory corruption on malformed input or allocation failures. The cleanup needs a dedicated routine that frees properties rather than invoking the processor list destructor.

Useful? React with 👍 / 👎.

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.

1 participant