Skip to content

routing: fix issue with missing input alias#11717

Merged
edsiper merged 3 commits intomasterfrom
routing-issue
Apr 16, 2026
Merged

routing: fix issue with missing input alias#11717
edsiper merged 3 commits intomasterfrom
routing-issue

Conversation

@edsiper
Copy link
Copy Markdown
Member

@edsiper edsiper commented Apr 15, 2026

Fixes input route binding when multiple inputs use the same plugin and only one declares routes. Previously, a routed input without alias could bind its routes to the wrong instance, which caused matching records from the intended input to never be routed. The router now binds route blocks to the exact input section that declared them.

This also adds regression coverage in both internal and Python integration tests. The new tests cover the reported dummy input case with and without alias, and verify that the routed third input emits the expected topic1 output in both normal and valgrind-strict integration runs.

Problem

  • routes: inside an input section could attach to the wrong input instance when several inputs shared the same plugin type and the routed one had no alias.
  • In the reported case, the third dummy input generated matching data, but the route conditions were evaluated on a different dummy instance.

Changes

  • Bind parsed route configs to the exact input section during config parsing.
  • Add internal regression coverage for mixed same-plugin input instances.
  • Add Python integration coverage under tests/integration/scenarios/out_stdout for both no-alias and alias cases.

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

  • New Features

    • Improved routing so condition-based routes bind to the exact input section even when that input lacks an alias, ensuring correct delivery of routed records.
  • Tests

    • Added integration and unit tests exercising routing with and without input aliases, validating route bindings, routed output, and related log messages.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 15, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: fc18efe9-a67d-4651-a6f1-e155a04798a5

📥 Commits

Reviewing files that changed from the base of the PR and between 0314cd5 and f5dd9f8.

📒 Files selected for processing (5)
  • src/flb_router_config.c
  • tests/integration/scenarios/out_stdout/config/out_stdout_routing_no_alias.yaml
  • tests/integration/scenarios/out_stdout/config/out_stdout_routing_with_alias.yaml
  • tests/integration/scenarios/out_stdout/tests/test_out_stdout_001.py
  • tests/internal/router_config.c
✅ Files skipped from review due to trivial changes (1)
  • tests/integration/scenarios/out_stdout/config/out_stdout_routing_no_alias.yaml
🚧 Files skipped from review as they are similar to previous changes (3)
  • tests/integration/scenarios/out_stdout/config/out_stdout_routing_with_alias.yaml
  • tests/integration/scenarios/out_stdout/tests/test_out_stdout_001.py
  • tests/internal/router_config.c

📝 Walkthrough

Walkthrough

This PR changes router parsing to bind routing rules to specific input instances by their iteration index. It adds find_input_instance_by_index(), threads an input_index through parse_input_section(), updates flb_router_config_parse() to increment the index during traversal, and adds integration and unit tests covering alias/no-alias scenarios.

Changes

Cohort / File(s) Summary
Router Config Core Logic
src/flb_router_config.c
Add find_input_instance_by_index(); make parse_input_section() accept size_t input_index and initialize input->instance from the indexed instance; update flb_router_config_parse() to track and pass input_index.
Integration Test Configs
tests/integration/scenarios/out_stdout/config/out_stdout_routing_no_alias.yaml, tests/integration/scenarios/out_stdout/config/out_stdout_routing_with_alias.yaml
Add two routing scenario YAMLs: one with a routed input lacking alias, one with aliased inputs; both exercise routing by topic and route to an aliased stdout output.
Integration Tests
tests/integration/scenarios/out_stdout/tests/test_out_stdout_001.py
Add two tests verifying routing binds to the intended input (with and without alias), checking emitted fields, route binding logs, and unmatched-route logging where applicable.
Unit Tests (router)
tests/internal/router_config.c
Add create_mixed_instance_route_inputs() helper and test_router_apply_config_routes_bind_to_exact_section_without_alias() to assert routes bind to the correct input instance when one input lacks an alias; register the test in TEST_LIST.

Sequence Diagram

sequenceDiagram
    participant Parser as Config Parser
    participant InputMgr as Input Instance Lookup
    participant Router as Router Config

    Parser->>Parser: iterate input sections
    Parser->>InputMgr: parse_input_section(config_section, input_index)
    InputMgr->>InputMgr: find_input_instance_by_index(config, input_index)
    InputMgr-->>Parser: return input instance (or NULL)
    Parser->>Parser: assign input->instance from returned value
    Parser->>Parser: increment input_index
    Parser->>Router: finish parsing, produce input_routes
    Router->>Router: apply routes using bound input instances
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • cosmo0920
  • koleini
  • fujimotos

"🐰 With twitching whiskers I hop through the code,
I count each input down the parsing road.
No alias? No problem — index finds the way,
Routes bind true, and tests all cheer hooray! 🎉"

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ 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%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly and clearly summarizes the main fix: binding routed inputs to the correct input section when aliases are missing, which is the core problem addressed across all file changes.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch routing-issue

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
Copy Markdown

@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: 2

🧹 Nitpick comments (1)
tests/internal/router_config.c (1)

1793-1797: Assert both direct routes target the expected outputs.

This only checks the fan-out count. A regression that still creates two paths but connects the wrong output instances would pass here. Please verify that input_three.routes_direct contains one path to output_one and one to output_two.

Based on learnings: Add regression tests for: mixed signals, processor drop/modify paths, multi-route fan-out, backlog + live ingestion parity.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/internal/router_config.c` around lines 1793 - 1797, The test only
asserts the fan-out count for input_three.routes_direct but not that the two
direct routes target the expected outputs; update the assertion after
flb_router_apply_config to iterate input_three.routes_direct and verify that one
route points to output_one and the other to output_two (e.g., inspect each
route's destination/output pointer or identifier on the route entries stored in
input_three.routes_direct and assert equality to output_one and output_two),
keeping the existing count check to ensure exactly two entries; use the same
list/traversal helpers already used in tests to find and assert the presence of
both outputs.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/flb_router_config.c`:
- Around line 1083-1111: find_input_instance_by_index is skipping list entries
with ins->p == NULL while the caller's indexing counts every input section,
causing index drift; remove the early continue and ensure the loop increments
the index for every list entry (i.e., treat NULL-ins as placeholders when
counting) so the comparison "if (index == input_index)" uses the same population
as the caller; make the same change to the other identical loop in this file
that uses the same indexing logic.

In `@tests/integration/scenarios/out_stdout/tests/test_out_stdout_001.py`:
- Around line 214-223: The test stops the service immediately after waiting for
"[0] topic1:" which can arrive earlier than other expected lines; change it to
wait for all required log lines before calling service.stop(): call
service.wait_for_log_contains for each of the remaining expected strings ("no
matching route for input chunk" and "tag 'firstdummy'") with appropriate
timeouts (or use a helper that waits for all expected substrings), then stop the
service and finally collect log_text for assertions (use the existing
service.wait_for_log_contains/service.get_logs helpers and the log_text
variable). Ensure you reference the existing service.wait_for_log_contains calls
and keep the same assertions.

---

Nitpick comments:
In `@tests/internal/router_config.c`:
- Around line 1793-1797: The test only asserts the fan-out count for
input_three.routes_direct but not that the two direct routes target the expected
outputs; update the assertion after flb_router_apply_config to iterate
input_three.routes_direct and verify that one route points to output_one and the
other to output_two (e.g., inspect each route's destination/output pointer or
identifier on the route entries stored in input_three.routes_direct and assert
equality to output_one and output_two), keeping the existing count check to
ensure exactly two entries; use the same list/traversal helpers already used in
tests to find and assert the presence of both outputs.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 9bbc8c3a-5f60-46ed-aaa5-b0b1c154aea0

📥 Commits

Reviewing files that changed from the base of the PR and between 63ed88e and 65439c7.

📒 Files selected for processing (5)
  • src/flb_router_config.c
  • tests/integration/scenarios/out_stdout/config/out_stdout_routing_no_alias.yaml
  • tests/integration/scenarios/out_stdout/config/out_stdout_routing_with_alias.yaml
  • tests/integration/scenarios/out_stdout/tests/test_out_stdout_001.py
  • tests/internal/router_config.c

Comment thread src/flb_router_config.c
Comment on lines +214 to +223
log_text = service.wait_for_log_contains("[0] topic1:", timeout=10)
service.stop()

assert "connected input 'dummy.2' route 'topic1' to output 'stdout1'" in log_text
assert "[0] topic1:" in log_text
assert "\"topic\"=>\"topic1\"" in log_text
assert "\"message\"=>\"custom dummy\"" in log_text
assert "no matching route for input chunk" in log_text
assert "tag 'firstdummy'" in log_text

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Wait for all asserted log lines before stopping the service.

This returns as soon as "[0] topic1:" appears, but the test also requires "no matching route for input chunk" and "tag 'firstdummy'". Those lines can arrive later, so this is prone to flakes in slower runs.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/integration/scenarios/out_stdout/tests/test_out_stdout_001.py` around
lines 214 - 223, The test stops the service immediately after waiting for "[0]
topic1:" which can arrive earlier than other expected lines; change it to wait
for all required log lines before calling service.stop(): call
service.wait_for_log_contains for each of the remaining expected strings ("no
matching route for input chunk" and "tag 'firstdummy'") with appropriate
timeouts (or use a helper that waits for all expected substrings), then stop the
service and finally collect log_text for assertions (use the existing
service.wait_for_log_contains/service.get_logs helpers and the log_text
variable). Ensure you reference the existing service.wait_for_log_contains calls
and keep the same assertions.

edsiper added 3 commits April 16, 2026 08:11
Signed-off-by: Eduardo Silva <eduardo@chronosphere.io>
Signed-off-by: Eduardo Silva <eduardo@chronosphere.io>
Signed-off-by: Eduardo Silva <eduardo@chronosphere.io>
@edsiper
Copy link
Copy Markdown
Member Author

edsiper commented Apr 16, 2026

CI issue: related to macos issue in a http client runtime test, being fixed in #11717

@edsiper edsiper merged commit 136f2cd into master Apr 16, 2026
50 of 53 checks passed
@edsiper edsiper deleted the routing-issue branch April 16, 2026 17:15
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