Skip to content

alias: output: network: handle plugin aliases#11656

Open
cosmo0920 wants to merge 4 commits intomasterfrom
comso0920-handle-plugin-aliases
Open

alias: output: network: handle plugin aliases#11656
cosmo0920 wants to merge 4 commits intomasterfrom
comso0920-handle-plugin-aliases

Conversation

@cosmo0920
Copy link
Copy Markdown
Contributor

@cosmo0920 cosmo0920 commented Apr 2, 2026

We can instantiate out_es as output elasticsearch plugin but the input of elasticsearch plugin is in_elasticsearch.
To maintain naming coherence, we need to handle plugin alias at least of out_es as out_elasticsearch.

With this patch, we can instantiate out_elasticsearch as out_es.

Closes #9261.


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
[SERVICE]
    Flush               10

[INPUT]
    Name                dummy
    Dummy               { "message" : "this is dummy data" }
    Rate                10

[OUTPUT]
    Workers             4
    Name                elasticsearch
    Host                localhost
    Port                9201
    TLS                 On
    tls.verify_hostname On
    tls.ca_file         <your_cert>
    tls.vhost           your-elasticsearch-host
    Retry_Limit         6
    Replace_Dots        On
    Suppress_Type_Name  On
    HTTP_User           elastic
    HTTP_Passwd         elastic
    Index               fluent-bit
  • Debug log output from testing the change
Fluent Bit v5.0.2
* Copyright (C) 2015-2026 The Fluent Bit Authors
* Fluent Bit is a CNCF graduated project under the Fluent organization
* https://fluentbit.io

______ _                  _    ______ _ _           _____  _____ 
|  ___| |                | |   | ___ (_) |         |  ___||  _  |
| |_  | |_   _  ___ _ __ | |_  | |_/ /_| |_  __   _|___ \ | |/' |
|  _| | | | | |/ _ \ '_ \| __| | ___ \ | __| \ \ / /   \ \|  /| |
| |   | | |_| |  __/ | | | |_  | |_/ / | |_   \ V //\__/ /\ |_/ /
\_|   |_|\__,_|\___|_| |_|\__| \____/|_|\__|   \_/ \____(_)\___/


[2026/04/02 19:46:50.277] [ info] Configuration:
[2026/04/02 19:46:50.298] [ info]  flush time     | 10.000000 seconds
[2026/04/02 19:46:50.306] [ info]  grace          | 5 seconds
[2026/04/02 19:46:50.306] [ info]  daemon         | 0
[2026/04/02 19:46:50.306] [ info] ___________
[2026/04/02 19:46:50.307] [ info]  inputs:
[2026/04/02 19:46:50.307] [ info]      dummy
[2026/04/02 19:46:50.308] [ info] ___________
[2026/04/02 19:46:50.308] [ info]  filters:
[2026/04/02 19:46:50.308] [ info] ___________
[2026/04/02 19:46:50.309] [ info]  outputs:
[2026/04/02 19:46:50.309] [ info]      es.0
[2026/04/02 19:46:50.309] [ info] ___________
[2026/04/02 19:46:50.310] [ info]  collectors:
[2026/04/02 19:46:50.372] [ info] [fluent bit] version=5.0.2, commit=4efcaf7d0e, pid=2864687
[2026/04/02 19:46:50.380] [debug] [engine] coroutine stack size: 24576 bytes (24.0K)
[2026/04/02 19:46:50.385] [ info] [storage] ver=1.5.4, type=memory, sync=normal, checksum=off, max_chunks_up=128
[2026/04/02 19:46:50.386] [ info] [simd    ] SSE2
[2026/04/02 19:46:50.386] [ info] [cmetrics] version=2.1.1
[2026/04/02 19:46:50.386] [ info] [ctraces ] version=0.7.1
[2026/04/02 19:46:50.400] [ info] [input:dummy:dummy.0] initializing
[2026/04/02 19:46:50.401] [ info] [input:dummy:dummy.0] storage_strategy='memory' (memory only)
[2026/04/02 19:46:50.402] [debug] [dummy:dummy.0] created event channels: read=21 write=22
[2026/04/02 19:46:50.419] [debug] [es:es.0] created event channels: read=23 write=24
[2026/04/02 19:46:50.784] [debug] [output:es:es.0] host=localhost port=9201 uri=/_bulk index=fluent-bit type=_doc
[2026/04/02 19:46:50.859] [ info] [sp] stream processor started
[2026/04/02 19:46:50.861] [ info] [engine] Shutdown Grace Period=5, Shutdown Input Grace Period=2
[2026/04/02 19:46:50.899] [ info] [output:es:es.0] worker #2 started
[2026/04/02 19:46:50.900] [ info] [output:es:es.0] worker #0 started
[2026/04/02 19:46:50.899] [ info] [output:es:es.0] worker #1 started
[2026/04/02 19:46:50.902] [ info] [output:es:es.0] worker #3 started
[2026/04/02 19:47:00.017] [debug] [task] created task=0x986bcb0 id=0 OK
[2026/04/02 19:47:00.019] [debug] [output:es:es.0] task_id=0 assigned to thread #0
[2026/04/02 19:47:00.590] [debug] [upstream] KA connection #69 to localhost:9201 is connected
[2026/04/02 19:47:00.606] [debug] [out_es] converted_size is 0
[2026/04/02 19:47:00.609] [debug] [out_es] converted_size is 0
[2026/04/02 19:47:00.611] [debug] [http_client] not using http_proxy for header
[2026/04/02 19:47:00.678] [debug] [output:es:es.0] HTTP Status=200 URI=/_bulk
[2026/04/02 19:47:00.689] [debug] [output:es:es.0] Elasticsearch response
{"errors":false,"took":0,"items":[{"create":{"_index":"fluent-bit","_id":"Re7NTZ0BckMZbRRnt-0m","_version":1,"result":"created","_shards":{"total":2,"successful":2,"failed":0},"_seq_no":646,"_primary_term":1,"status":201}},{"create":{"_index":"fluent-bit","_id":"Ru7NTZ0BckMZbRRnt-0m","_version":1,"result":"created","_shards":{"total":2,"successful":2,"failed":0},"_seq_no":647,"_primary_term":1,"status":201}},{"create":{"_index":"fluent-bit","_id":"R-7NTZ0BckMZbRRnt-0m","_version":1,"result":"created","_shards":{"total":2,"successful":2,"failed":0},"_seq_no":648,"_primary_term":1,"status":201}},{"create":{"_index":"fluent-bit","_id":"SO7NTZ0BckMZbRRnt-0m","_version":1,"result":"created","_shards":{"total":2,"successful":2,"failed":0},"_seq_no":649,"_primary_term":1,"status":201}},{"create":{"_index":"fluent-bit","_id":"Se7NTZ0BckMZbRRnt-0m","_version":1,"result":"created","_shards":{"total":2,"successful":2,"failed":0},"_seq_no":650,"_primary_term":1,"status":201}},{"create":{"_index":"fluent-bit","_id":"Su7NTZ0BckMZbRRnt-0m","_version":1,"result":"created","_shards":{"total":2,"successful":2,"failed":0},"_seq_no":651,"_primary_term":1,"status":201}},{"create":{"_index":"fluent-bit","_id":"S-7NTZ0BckMZbRRnt-0m","_version":1,"result":"created","_shards":{"total":2,"successful":2,"failed":0},"_seq_no":652,"_primary_term":1,"status":201}},{"create":{"_index":"fluent-bit","_id":"TO7NTZ0BckMZbRRnt-0m","_version":1,"result":"created","_shards":{"total":2,"successful":2,"failed":0},"_seq_no":653,"_primary_term":1,"status":201}},{"create":{"_index":"fluent-bit","_id":"Te7NTZ0BckMZbRRnt-0m","_version":1,"result":"created","_shards":{"total":2,"successful":2,"failed":0},"_seq_no":654,"_primary_term":1,"status":201}},{"create":{"_index":"fluent-bit","_id":"Tu7NTZ0BckMZbRRnt-0m","_version":1,"result":"created","_shards":{"total":2,"successful":2,"failed":0},"_seq_no":655,"_primary_term":1,"status":201}},{"create":{"_index":"fluent-bit","_id":"T-7NTZ0BckMZbRRnt-0m","_version":1,"result":"created","_shards":{"total":2,"successful":2,"failed":0},"_seq_no":656,"_primary_term":1,"status":201}},{"create":{"_index":"fluent-bit","_id":"UO7NTZ0BckMZbRRnt-0m","_version":1,"result":"created","_shards":{"total":2,"successful":2,"failed":0},"_seq_no":657,"_primary_term":1,"status":201}},{"create":{"_index":"fluent-bit","_id":"Ue7NTZ0BckMZbRRnt-0m","_version":1,"result":"created","_shards":{"total":2,"successful":2,"failed":0},"_seq_no":658,"_primary_term":1,"status":201}},{"create":{"_index":"fluent-bit","_id":"Uu7NTZ0BckMZbRRnt-0m","_version":1,"result":"created","_shards":{"total":2,"successful":2,"failed":0},"_seq_no":659,"_primary_term":1,"status":201}},{"create":{"_index":"fluent-bit","_id":"U-7NTZ0BckMZbRRnt-0m","_version":1,"result":"created","_shards":{"total":2,"successful":2,"failed":0},"_seq_no":660,"_primary_term":1,"status":201}},{"create":{"_index":"fluent-bit","_id":"VO7NTZ0BckMZbRRnt-0m","_version":1,"result":"created","_shards":{"total":2,"successful":2,"failed":0},"_seq_no":661,"_primary_term":1,"status":201}},{"create":{"_index":"fluent-bit","_id":"Ve7NTZ0BckMZbRRnt-0m","_version":1,"result":"created","_shards":{"total":2,"successful":2,"failed":0},"_seq_no":662,"_primary_term":1,"status":201}},{"create":{"_index":"fluent-bit","_id":"Vu7NTZ0BckMZbRRnt-0m","_version":1,"result":"created","_shards":{"total":2,"successful":2,"failed":0},"_seq_no":663,"_primary_term":1,"status":201}},{"create":{"_index":"fluent-bit","_id":"V-7NTZ0BckMZbRRnt-0m","_version":1,"result":"created","_shards":{"total":2,"successful":2,"failed":0},"_seq_no":664,"_primary_term":1,"status":201}},{"create":{"_index":"fluent-bit","_id":"WO7NTZ0BckMZbRRnt-0m","_version":1,"result":"created","_shards":{"total":2,"successful":2,"failed":0},"_seq_no":665,"_primary_term":1,"status":201}},{"create":{"_index":"fluent-bit","_id":"We7NTZ0BckMZbRRnt-0m","_version":1,"result":"created","_shards":{"total":2,"successful":2,"failed":0},"_seq_no":666,"_primary_term":
[2026/04/02 19:47:00.693] [debug] [upstream] KA connection #69 to localhost:9201 is now available
[2026/04/02 19:47:00.695] [debug] [out flush] cb_destroy coro_id=0
[2026/04/02 19:47:00.704] [debug] [task] destroy task=0x986bcb0 (task_id=0)
^C[2026/04/02 19:47:01] [engine] caught signal (SIGINT)
[2026/04/02 19:47:01.244] [debug] [task] created task=0x9c03d10 id=0 OK
[2026/04/02 19:47:01.245] [debug] [output:es:es.0] task_id=0 assigned to thread #1
[2026/04/02 19:47:01.245] [ warn] [engine] service will shutdown in max 5 seconds
[2026/04/02 19:47:01.246] [debug] [engine] task 0 already scheduled to run, not re-scheduling it.
[2026/04/02 19:47:01.246] [ info] [engine] pausing all inputs..
[2026/04/02 19:47:01.247] [ info] [input] pausing dummy.0
[2026/04/02 19:47:01.279] [debug] [upstream] KA connection #70 to localhost:9201 is connected
[2026/04/02 19:47:01.280] [debug] [http_client] not using http_proxy for header
[2026/04/02 19:47:01.312] [debug] [output:es:es.0] HTTP Status=200 URI=/_bulk
[2026/04/02 19:47:01.313] [debug] [output:es:es.0] Elasticsearch response
{"errors":false,"took":0,"items":[{"create":{"_index":"fluent-bit","_id":"oe7NTZ0BckMZbRRnue2j","_version":1,"result":"created","_shards":{"total":2,"successful":2,"failed":0},"_seq_no":738,"_primary_term":1,"status":201}},{"create":{"_index":"fluent-bit","_id":"ou7NTZ0BckMZbRRnue2j","_version":1,"result":"created","_shards":{"total":2,"successful":2,"failed":0},"_seq_no":739,"_primary_term":1,"status":201}},{"create":{"_index":"fluent-bit","_id":"o-7NTZ0BckMZbRRnue2j","_version":1,"result":"created","_shards":{"total":2,"successful":2,"failed":0},"_seq_no":740,"_primary_term":1,"status":201}},{"create":{"_index":"fluent-bit","_id":"pO7NTZ0BckMZbRRnue2j","_version":1,"result":"created","_shards":{"total":2,"successful":2,"failed":0},"_seq_no":741,"_primary_term":1,"status":201}},{"create":{"_index":"fluent-bit","_id":"pe7NTZ0BckMZbRRnue2j","_version":1,"result":"created","_shards":{"total":2,"successful":2,"failed":0},"_seq_no":742,"_primary_term":1,"status":201}},{"create":{"_index":"fluent-bit","_id":"pu7NTZ0BckMZbRRnue2j","_version":1,"result":"created","_shards":{"total":2,"successful":2,"failed":0},"_seq_no":743,"_primary_term":1,"status":201}},{"create":{"_index":"fluent-bit","_id":"p-7NTZ0BckMZbRRnue2j","_version":1,"result":"created","_shards":{"total":2,"successful":2,"failed":0},"_seq_no":744,"_primary_term":1,"status":201}},{"create":{"_index":"fluent-bit","_id":"qO7NTZ0BckMZbRRnue2j","_version":1,"result":"created","_shards":{"total":2,"successful":2,"failed":0},"_seq_no":745,"_primary_term":1,"status":201}},{"create":{"_index":"fluent-bit","_id":"qe7NTZ0BckMZbRRnue2j","_version":1,"result":"created","_shards":{"total":2,"successful":2,"failed":0},"_seq_no":746,"_primary_term":1,"status":201}}]}
[2026/04/02 19:47:01.313] [debug] [upstream] KA connection #70 to localhost:9201 is now available
[2026/04/02 19:47:01.313] [debug] [out flush] cb_destroy coro_id=0
[2026/04/02 19:47:01.314] [debug] [task] destroy task=0x9c03d10 (task_id=0)
[2026/04/02 19:47:02.012] [ info] [engine] service has stopped (0 pending tasks)
[2026/04/02 19:47:02.013] [ info] [input] pausing dummy.0
[2026/04/02 19:47:02.016] [ info] [output:es:es.0] thread worker #0 stopping...
[2026/04/02 19:47:02.035] [ info] [output:es:es.0] thread worker #0 stopped
[2026/04/02 19:47:02.056] [ info] [output:es:es.0] thread worker #1 stopping...
[2026/04/02 19:47:02.057] [ info] [output:es:es.0] thread worker #1 stopped
[2026/04/02 19:47:02.057] [ info] [output:es:es.0] thread worker #2 stopping...
[2026/04/02 19:47:02.058] [ info] [output:es:es.0] thread worker #2 stopped
[2026/04/02 19:47:02.058] [ info] [output:es:es.0] thread worker #3 stopping...
[2026/04/02 19:47:02.058] [ info] [output:es:es.0] thread worker #3 stopped
  • Attached Valgrind output that shows no leaks or memory corruption was found
==2864687== 
==2864687== HEAP SUMMARY:
==2864687==     in use at exit: 0 bytes in 0 blocks
==2864687==   total heap usage: 20,719 allocs, 20,719 frees, 9,198,473 bytes allocated
==2864687== 
==2864687== All heap blocks were freed -- no leaks are possible
==2864687== 
==2864687== For lists of detected and suppressed errors, rerun with: -s
==2864687== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)

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

  • New Features

    • Plugin aliasing: refer to output plugins by friendly names (e.g., "elasticsearch" → "es") during selection.
    • Automatic URI rewriting: alias-style connection strings are rewritten to canonical plugin identifiers at instantiation.
  • Improvements

    • Network address parsing correctly handles URIs with scheme prefixes when extracting host/port.
  • Tests

    • Added unit tests for alias lookup, URI rewrite, address parsing, and plugin instantiation.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 2, 2026

📝 Walkthrough

Walkthrough

Adds a plugin-aliasing subsystem: new public header and implementation for alias lookup and URI rewriting, integrates alias handling into output creation and network parsing, updates build/test files, and adds unit tests for alias lookup, rewrite, parsing, and instantiation.

Changes

Cohort / File(s) Summary
Public API
include/fluent-bit/flb_plugin_alias.h
New header declaring FLB_PLUGIN_ALIAS_ERR, flb_plugin_alias_get() and flb_plugin_alias_rewrite() for alias resolution and rewrite.
Core implementation
src/flb_plugin_alias.c, src/CMakeLists.txt
New source implementing alias table, case-insensitive exact-length alias lookup, and URI rewrite logic; added flb_plugin_alias.c to build sources.
Output integration
src/flb_output.c
Use alias lookup in check_protocol() and call flb_plugin_alias_rewrite() for network outputs; handle rewrite errors with explicit cleanup and apply/free rewritten URIs; use rewritten name for flb_net_host_set().
Network parsing
src/flb_network.c
flb_net_host_set() updated to detect and skip "://" scheme delimiter when locating host/port start.
Tests & build
tests/internal/plugin_alias.c, tests/internal/CMakeLists.txt
New unit tests covering alias lookup, rewrite, network address parsing, and output instantiation; test added to internal CMake test list.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant OutputLayer as Output Layer
    participant AliasResolver as Alias Resolver
    participant NetworkLayer as Network Layer
    participant Plugin as Plugin

    User->>OutputLayer: flb_output_new(config, "elasticsearch")
    OutputLayer->>AliasResolver: flb_plugin_alias_rewrite(FLB_PLUGIN_OUTPUT, "elasticsearch://host:port")
    AliasResolver->>AliasResolver: extract scheme/alias, lookup "elasticsearch"
    AliasResolver-->>OutputLayer: "es://host:port" or FLB_PLUGIN_ALIAS_ERR or NULL
    alt rewritten URI returned
        OutputLayer->>NetworkLayer: flb_net_host_set("es://host:port")
    else no rewrite/NULL
        OutputLayer->>NetworkLayer: flb_net_host_set("elasticsearch://host:port")
    else FLB_PLUGIN_ALIAS_ERR
        OutputLayer-->>User: return error (cleanup and NULL)
    end
    NetworkLayer->>NetworkLayer: detect "://", parse host and port
    NetworkLayer-->>OutputLayer: host/port populated
    OutputLayer->>Plugin: instantiate plugin with canonical name "es"
    Plugin-->>User: plugin instance returned
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Poem

🐇 I hopped through names both near and far,

swapped "elasticsearch" back to "es" by star,
I rewrote URIs with a careful paw,
parsed hosts and ports without a flaw,
plugins now find the names they saw.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 18.18% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ 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 'alias: output: network: handle plugin aliases' accurately summarizes the main change—introducing plugin alias handling for outputs across the network and output modules.
Linked Issues check ✅ Passed The PR successfully addresses issue #9261 by implementing an alias system allowing 'elasticsearch' to map to the internal 'es' plugin, enabling standardized naming coherence between input and output plugins without breaking existing configurations.
Out of Scope Changes check ✅ Passed All changes are directly scoped to the plugin alias objective: new alias API headers/implementation, CMake build integration, output/network layer modifications for alias resolution, and comprehensive unit tests—no unrelated changes detected.

✏️ 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 comso0920-handle-plugin-aliases

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

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@include/fluent-bit/flb_plugin_alias.h`:
- Around line 25-27: flb_plugin_alias_rewrite currently returns NULL for both
“no rewrite needed” and allocation/build failures; change its API and
implementation so callers can distinguish errors: return NULL only for “no
rewrite”, return a distinct sentinel pointer (e.g. (char *)-1 or a named macro
like FLB_PLUGIN_ALIAS_ERR) to indicate allocation/build failure, and continue
returning a real allocated string on success; update callers (e.g. the code that
calls flb_plugin_alias_rewrite in flb_output.c) to check for the sentinel and
treat it as an error (fail cleanly) instead of falling back to the original
plugin_reference, and document the new return contract next to the
flb_plugin_alias_rewrite and flb_plugin_alias_get declarations.

In `@src/flb_network.c`:
- Around line 178-184: In flb_net_host_set make scheme detection strict: do not
use strstr(address, "://") which can match "://" anywhere; instead find the
first ':' with strchr(address, ':'), verify it is not at address (non-empty
scheme) and that the following two chars are '/' and '/' (i.e. separator[1]=='/'
&& separator[2]=='/'), and only then set s = separator + 3; otherwise fall back
to s = address + len. Update the code around variables separator, address, and s
in flb_net_host_set accordingly so only a proper leading "scheme://" is
accepted.
🪄 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: 5c181e7c-7d06-484f-933f-359991ea075c

📥 Commits

Reviewing files that changed from the base of the PR and between 66ffbe4 and 4efcaf7.

📒 Files selected for processing (7)
  • include/fluent-bit/flb_plugin_alias.h
  • src/CMakeLists.txt
  • src/flb_network.c
  • src/flb_output.c
  • src/flb_plugin_alias.c
  • tests/internal/CMakeLists.txt
  • tests/internal/plugin_alias.c

Signed-off-by: Hiroshi Hatake <hiroshi@chronosphere.io>
Signed-off-by: Hiroshi Hatake <hiroshi@chronosphere.io>
Signed-off-by: Hiroshi Hatake <hiroshi@chronosphere.io>
Signed-off-by: Hiroshi Hatake <hiroshi@chronosphere.io>
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: 1

♻️ Duplicate comments (1)
src/flb_network.c (1)

178-186: ⚠️ Potential issue | 🟠 Major

Keep flb_net_host_set() strict about the expected plugin prefix.

flb_net_host_set("es", ..., "http://127.0.0.1:9200") now succeeds because any leading scheme:// is stripped, not just plugin_name://. The aliased output path already canonicalizes elasticsearch://... to es://..., so this shared parser should still reject unrelated schemes instead of silently accepting them.

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

In `@src/flb_network.c` around lines 178 - 186, In flb_net_host_set ensure you
only strip a leading "plugin_name://"-style scheme: when you find separator =
strchr(address, ':'), compare the prefix (address..separator) against the
provided plugin_name and only if they match and separator[1]=='/' &&
separator[2]=='/' set s = separator + 3; otherwise leave s = address + len (do
not accept arbitrary schemes like "http://"). Use the existing variables
separator, address, s and the plugin_name parameter to perform the exact-match
check before removing the scheme.
🤖 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_output.c`:
- Around line 832-839: When flb_plugin_alias_rewrite returns
FLB_PLUGIN_ALIAS_ERR you must fully unwind the partially-initialized instance:
if instance->callback is set invoke the plugin teardown callback (using the same
callback signature used elsewhere) so the plugin can free its state, free
instance->context if non-NULL, destroy instance->singleplex_queue only if it was
created/non-NULL (and/or when instance->flags & FLB_OUTPUT_SYNCHRONOUS), then
free instance->http_server_config and finally free instance; implement this
sequence in the error branch that handles output_uri == FLB_PLUGIN_ALIAS_ERR to
avoid leaking plugin state.

---

Duplicate comments:
In `@src/flb_network.c`:
- Around line 178-186: In flb_net_host_set ensure you only strip a leading
"plugin_name://"-style scheme: when you find separator = strchr(address, ':'),
compare the prefix (address..separator) against the provided plugin_name and
only if they match and separator[1]=='/' && separator[2]=='/' set s = separator
+ 3; otherwise leave s = address + len (do not accept arbitrary schemes like
"http://"). Use the existing variables separator, address, s and the plugin_name
parameter to perform the exact-match check before removing the scheme.
🪄 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: 1375d157-6cca-4999-97d8-8c65196e634a

📥 Commits

Reviewing files that changed from the base of the PR and between dd91460 and e19cc04.

📒 Files selected for processing (7)
  • include/fluent-bit/flb_plugin_alias.h
  • src/CMakeLists.txt
  • src/flb_network.c
  • src/flb_output.c
  • src/flb_plugin_alias.c
  • tests/internal/CMakeLists.txt
  • tests/internal/plugin_alias.c
✅ Files skipped from review due to trivial changes (4)
  • tests/internal/CMakeLists.txt
  • src/CMakeLists.txt
  • include/fluent-bit/flb_plugin_alias.h
  • tests/internal/plugin_alias.c

Comment on lines +832 to +839
output_uri = flb_plugin_alias_rewrite(FLB_PLUGIN_OUTPUT, output_name);
if (output_uri == FLB_PLUGIN_ALIAS_ERR) {
if (instance->flags & FLB_OUTPUT_SYNCHRONOUS) {
flb_task_queue_destroy(instance->singleplex_queue);
}
flb_free(instance->http_server_config);
flb_free(instance);
return NULL;
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

Fully unwind instance on the new alias-rewrite error path.

By this point instance->callback is already live and non-core plugins may also have allocated instance->context. Returning here only frees the outer structs, so FLB_PLUGIN_ALIAS_ERR leaks initialized state; singleplex_queue also has not been created yet on this path.

💡 Suggested cleanup
         output_uri = flb_plugin_alias_rewrite(FLB_PLUGIN_OUTPUT, output_name);
         if (output_uri == FLB_PLUGIN_ALIAS_ERR) {
-            if (instance->flags & FLB_OUTPUT_SYNCHRONOUS) {
+            if ((instance->flags & FLB_OUTPUT_SYNCHRONOUS) &&
+                instance->singleplex_queue != NULL) {
                 flb_task_queue_destroy(instance->singleplex_queue);
             }
+            if (instance->callback != NULL) {
+                flb_callback_destroy(instance->callback);
+            }
+            if (plugin->type != FLB_OUTPUT_PLUGIN_CORE &&
+                instance->context != NULL) {
+                flb_free(instance->context);
+            }
             flb_free(instance->http_server_config);
             flb_free(instance);
             return NULL;
         }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/flb_output.c` around lines 832 - 839, When flb_plugin_alias_rewrite
returns FLB_PLUGIN_ALIAS_ERR you must fully unwind the partially-initialized
instance: if instance->callback is set invoke the plugin teardown callback
(using the same callback signature used elsewhere) so the plugin can free its
state, free instance->context if non-NULL, destroy instance->singleplex_queue
only if it was created/non-NULL (and/or when instance->flags &
FLB_OUTPUT_SYNCHRONOUS), then free instance->http_server_config and finally free
instance; implement this sequence in the error branch that handles output_uri ==
FLB_PLUGIN_ALIAS_ERR to avoid leaking plugin state.

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.

rename output plugin name from 'es' to 'elasticsearch'

1 participant