Skip to content

es_out: support Upstream Servers with configuration overriding - #12659

Closed
mabrarov wants to merge 2 commits into
fluent:masterfrom
mabrarov:feature/out_es_upstream_support_extended
Closed

mabrarov wants to merge 2 commits into
fluent:masterfrom
mabrarov:feature/out_es_upstream_support_extended

Conversation

@mabrarov

Copy link
Copy Markdown
Contributor

Copy of closed #7608.

Implementation of Upstream feature for the Elasticsearch output plugin.

This pull request is based on pull request #1560 and Forward output plugin.

It was tested in a local setup with:

  1. Fluent Bit without Upstream feature connected to a single node of Elasticsearch cluster consisting of 3 master-eligible/data and 1 coordinating nodes.

    Refer to elastic-cluster directory of mabrarov/elastic-stack repository for Docker Compose project used to create target Elasticsearch cluster and Kibana.

    fluent-bit.conf Fluent Bit configuration file used for the test - refer to fluent-bit-es/fluent-bit.conf and (same in YAML format) fluent-bit-es/fluent-bit.yaml in mabrarov/elastic-stack repository.

    Debug log is available at flb_es.log.

  2. Fluent Bit with Upstream feature connected to all Elasticsearch data nodes of Elasticsearch cluster consisting of 3 master-eligible/data and 1 coordinating nodes.

    Refer to elastic-cluster directory of mabrarov/elastic-stack repository for Docker Compose project used to create target Elasticsearch cluster and Kibana.

    fluent-bit.conf Fluent Bit configuration file used for the test - refer to fluent-bit-es-cluster/fluent-bit.conf and (same in YAML format) fluent-bit-es-cluster/fluent-bit.yaml in mabrarov/elastic-stack repository.

    Debug log is available at flb_es_upstream.log.


Testing

  • Example configuration files for the change can be found in mabrarov/elastic-stack repository under fluent-bit-es-cluster directory.
  • Debug log output from testing the change - see above.
  • Attached Valgrind output that shows no leaks or memory corruption was found - refer to flb_run_code_analysis.log for the output of command
    TEST_PRESET=valgrind ./run_code_analysis.sh
  • [N/A] Run local packaging test showing all targets (including any new ones) build.
  • [N/A] Set ok-package-test label to test for all targets (requires maintainer to do).

Documentation

Backporting

  • [N/A] 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.

Signed-off-by: Marat Abrarov <abrarov@gmail.com>
Signed-off-by: Marat Abrarov <abrarov@gmail.com>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 25, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-25T13:02:50.236846Z 018bbec PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@coderabbitai

coderabbitai Bot commented Oct 25, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Caution

Review failed

The pull request is closed.

Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

@mabrarov

Copy link
Copy Markdown
Contributor Author

Ooops, wrong target repository.

@mabrarov mabrarov closed this Oct 25, 2026

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

Copy link
Copy Markdown

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.

Reviewed commit: 018bbec334

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread plugins/out_es/es.c
memcpy(logstash_index, logstash_prefix, len);
logstash_index[len] = '\0';
if (ec->logstash_format == FLB_TRUE) {
strncpy(logstash_index, ec->logstash_prefix.value, sizeof(logstash_index));

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Normalize an empty Logstash prefix before formatting

With Logstash_Format On and an explicitly empty output-level Logstash_Prefix (for example, together with an empty separator for a date-only index), config-map assignment suppresses the default and leaves logstash_prefix.value NULL. This strncpy dereferences that NULL pointer on the first record; the previous formatter normalized a missing prefix to "", so retain that normalization or reject the configuration during initialization.

Useful? React with 👍 / 👎.

Comment thread plugins/out_es/es_conf.c
static int config_validate(struct flb_elasticsearch_config* ec,
struct flb_elasticsearch* ctx)
{
if (ec->index.value == NULL && ec->logstash_format == FLB_FALSE && ec->generate_id == FLB_FALSE) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Require an index even when generating document IDs

When Index is explicitly empty, config-map assignment leaves ec->index.value NULL, but Generate_ID On makes this validation accept the configuration even though that option only creates a document _id. The formatter later uses the NULL value as the bulk action's _index, which can produce invalid metadata or invoke undefined %s formatting behavior; only Logstash_Format can supply an index without this field.

Useful? React with 👍 / 👎.

Comment thread plugins/out_es/es.c
Comment on lines +1159 to +1160
if (ec->http_user && ec->http_passwd) {
flb_http_basic_auth(c, ec->http_user, ec->http_passwd);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Treat an empty node username as unset

When an upstream node sets http_user to an empty string to disable inherited basic authentication, the upstream property table returns a non-NULL empty value and http_passwd is still non-NULL (it has an empty default or is inherited). This condition therefore sends a Basic header with an empty username instead of falling through to the node's API key, cloud credentials, or no authentication, whereas the previous check required http_user[0] != '\0'.

Useful? React with 👍 / 👎.

Comment thread plugins/out_es/es.c
Comment on lines +1162 to +1165
else if (ec->cloud_user.value && ec->cloud_passwd.value) {
flb_http_basic_auth(c, ec->cloud_user.value, ec->cloud_passwd.value);
}
else if (http_api_key != NULL && http_api_key[0] != '\0') {
else if (ec->http_api_key) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Honor node API keys over inherited cloud credentials

When output-level Cloud_Auth supplies default credentials and an upstream node overrides authentication with HTTP_API_Key, the node configuration still contains the inherited cloud user/password, so this branch fires before the API-key branch and the explicit node key is never sent. Preserve the prior API-key-before-cloud precedence or clear conflicting inherited credentials when a node selects another authentication scheme.

Useful? React with 👍 / 👎.

Comment thread plugins/out_es/es.c
goto retry;
}
header_line = tmp_sds;
header_line = flb_sds_printf(&header_line, "ApiKey %s", ec->http_api_key);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Check the API-key header formatting result

Under memory pressure, flb_sds_printf can return NULL while formatting an API-key header, but assigning its result directly discards the surviving SDS pointer and the following flb_sds_len(header_line) dereferences NULL. The removed temporary-result check previously turned this allocation failure into the retry path, so validate the return before adding the header.

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