Skip to content

config_format: yaml: handle configuration metadata on yaml conf#11690

Open
cosmo0920 wants to merge 2 commits into
masterfrom
cosmo0920-handle-configuration-metadata-on-yaml-conf
Open

config_format: yaml: handle configuration metadata on yaml conf#11690
cosmo0920 wants to merge 2 commits into
masterfrom
cosmo0920-handle-configuration-metadata-on-yaml-conf

Conversation

@cosmo0920
Copy link
Copy Markdown
Contributor

@cosmo0920 cosmo0920 commented Apr 9, 2026

Closes #11683.


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

Release Notes

  • New Features
    • Added support for a new ignorable section in YAML configuration files
    • Added probabilistic sampling processor with configurable sampling percentage
    • Enhanced YAML configuration parser to support nested mappings and OTLP connection settings

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 9, 2026

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

The pull request introduces a new ignorable YAML configuration section that allows users to include custom metadata, version numbers, and annotations within Fluent Bit's configuration files. These values are parsed and validated as legal YAML but are not processed operationally by Fluent Bit itself.

Changes

Cohort / File(s) Summary
YAML Parser Core
src/config_format/flb_cf_yaml.c
Adds SECTION_IGNORABLE and STATE_IGNORABLE to parser state machine; enables parsing of scalar and container variants within the ignorable section; routes variants into section properties via flb_cf_section_property_add_variant with proper error handling; tightens container value validation to restrict mappings/sequences to only ignorable and env sections.
Test Suite
tests/internal/config_format_yaml.c
Extends existing YAML processor test to verify sampling configuration with nested sampling_settings and sampling_percentage; adds new test cases validating ignorable section parsing with record_metadata.enabled and otlp materialization; adds rejection test for nested maps in non-ignorable sections.
Test Fixtures
tests/internal/data/config_format/yaml/ignorable.yaml, tests/internal/data/config_format/yaml/other_with_nested_map.yaml, tests/internal/data/config_format/yaml/processors.yaml
New fixture files: ignorable.yaml defines service and ignorable sections with record metadata and OTLP settings; other_with_nested_map.yaml defines invalid nested map structure for rejection testing; processors.yaml adds probabilistic sampling processor configuration.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~30 minutes

Suggested reviewers

  • edsiper

Poem

🐰 A rabbit hops through YAML fields so bright,
Where ignorable sections rest in sight,
Metadata and notes now safely stay,
Parsed but never in the processing way,
Config annotations find their place—hooray! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 14.29% 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 accurately describes the main change: implementing handling of configuration metadata (ignorable section) in YAML configuration files.
Linked Issues check ✅ Passed The PR implements the core requirement from #11683: a reserved top-level YAML section ('ignorable') that accepts and validates metadata attributes while ensuring they have no operational impact on Fluent Bit.
Out of Scope Changes check ✅ Passed All changes are directly related to implementing the ignorable section feature for configuration metadata. No unrelated modifications were introduced.

✏️ 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 cosmo0920-handle-configuration-metadata-on-yaml-conf

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/config_format_yaml.c (1)

840-887: Please assert the config still loads with metadata present.

This verifies parse-time retention, but the feature contract is “accept and ignore operationally.” Adding a flb_config_load_config_format() success check here would catch any later regression where cf->others starts affecting runtime config loading.

As per coding guidelines, tests/**: "Add or update tests for behavior changes, especially protocol parsing and encoder/decoder paths" and "Validate both success and failure paths (invalid payloads, boundary sizes, null/missing fields) in tests".

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

In `@tests/internal/config_format_yaml.c` around lines 840 - 887, The test parses
a YAML config into a flb_cf (test_metadata_section via flb_cf_yaml_create) but
doesn’t assert that runtime config loading still succeeds when metadata is
present; call flb_config_load_config_format(cf) after the existing
parse/metadata assertions and add a TEST_CHECK that it returns success (e.g., 0)
to ensure cf->others/metadata is ignored at load time; finally proceed to
flb_cf_destroy(cf) as before.
🤖 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/config_format/flb_cf_yaml.c`:
- Line 1839: In the STATE_METADATA handling in flb_cf_yaml.c ensure top-level
metadata scalar nodes are routed through state_variant_parse_scalar() instead of
falling through to flb_cf_section_property_add(); update the STATE_METADATA case
(and the similar block around lines 1921-1937) to detect scalar tokens at the
top metadata level and call state_variant_parse_scalar() to create CFL_VARIANT_*
values, then add the resulting variant to the metadata section rather than
storing the raw string via flb_cf_section_property_add(), preserving type parity
with nested metadata parsing.
- Around line 2420-2423: When cfl_kvlist_insert(state->cf_section->properties,
state->key, variant) fails the newly created nested value stored in variant is
leaked; fix by destroying/freeing variant before returning (call the appropriate
cleanup function, e.g., cfl_variant_destroy(variant)) and then return
YAML_FAILURE. Update the error path in the block that checks the return of
cfl_kvlist_insert so it releases variant (and nulls it if your codebase
convention requires) to avoid the memory leak; refer to symbols
cfl_kvlist_insert, state->cf_section->properties, state->key, and variant to
locate the change.

---

Nitpick comments:
In `@tests/internal/config_format_yaml.c`:
- Around line 840-887: The test parses a YAML config into a flb_cf
(test_metadata_section via flb_cf_yaml_create) but doesn’t assert that runtime
config loading still succeeds when metadata is present; call
flb_config_load_config_format(cf) after the existing parse/metadata assertions
and add a TEST_CHECK that it returns success (e.g., 0) to ensure
cf->others/metadata is ignored at load time; finally proceed to
flb_cf_destroy(cf) as before.
🪄 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: b477964d-a275-4772-af84-5bc1479daa1c

📥 Commits

Reviewing files that changed from the base of the PR and between 40a6d4a and 89d9f20.

📒 Files selected for processing (4)
  • src/config_format/flb_cf_yaml.c
  • tests/internal/config_format_yaml.c
  • tests/internal/data/config_format/yaml/metadata.yaml
  • tests/internal/data/config_format/yaml/other_with_nested_map.yaml

Comment thread src/config_format/flb_cf_yaml.c Outdated
Comment thread src/config_format/flb_cf_yaml.c Outdated
Copy link
Copy Markdown

@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.

Reviewed commit: 89d9f20510

ℹ️ 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 thread src/config_format/flb_cf_yaml.c Outdated
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

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

Inline comments:
In `@tests/internal/config_format_yaml.c`:
- Around line 472-480: The test currently dereferences second_processor and
sampling_type immediately after TEST_CHECK, which can crash on regression;
update the assertions in tests/internal/config_format_yaml.c to first verify
second_processor != NULL and second_processor->type == CFL_VARIANT_KVLIST (from
cfl_array_fetch_by_index) before accessing second_processor->data, and similarly
verify sampling_type != NULL and sampling_type->type == CFL_VARIANT_STRING (from
cfl_kvlist_fetch) before reading sampling_type->data.as_string; implement these
guards using explicit if checks around the existing checks (or convert
TEST_CHECK to conditional TEST_SKIP/return on failure) so failures produce clean
test assertions instead of dereference crashes.
🪄 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: 2e234d49-63da-4ee4-90dc-8c49795acb02

📥 Commits

Reviewing files that changed from the base of the PR and between 89d9f20 and bc08185.

📒 Files selected for processing (2)
  • tests/internal/config_format_yaml.c
  • tests/internal/data/config_format/yaml/processors.yaml
✅ Files skipped from review due to trivial changes (1)
  • tests/internal/data/config_format/yaml/processors.yaml

Comment thread tests/internal/config_format_yaml.c
@edsiper
Copy link
Copy Markdown
Member

edsiper commented Apr 14, 2026

I think for this implementation we need a section name that is generic enough for fluent bit use cases, note that metadata can refer to record metadata, group metadata, otlp metadata an can lead to confusions. Trying to come up with something, however the section name must be able to have sub-sections so different "callers" can have their own section that Fluent Bit can ignore

Signed-off-by: Hiroshi Hatake <hiroshi@chronosphere.io>
Signed-off-by: Hiroshi Hatake <hiroshi@chronosphere.io>
@cosmo0920
Copy link
Copy Markdown
Contributor Author

cosmo0920 commented Apr 23, 2026

Trying to come up with something, however the section name must be able to have sub-sections so different "callers" can have their own section that Fluent Bit can ignore

For now, I updated as "ignorable" to show that this section can be ignored and meaning less for other configuration and only for adding metadata with structured attributes.

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.

🧹 Nitpick comments (1)
src/config_format/flb_cf_yaml.c (1)

1921-1937: Nit: redundant ENV guard in container-value rejection.

The SECTION_ENV branch and the != SECTION_IGNORABLE branch both fall through to the same yaml_error_event + return YAML_FAILURE. Since SECTION_ENV != SECTION_IGNORABLE, the second condition already covers ENV; the two checks can be collapsed into one and would read more clearly.

♻️ Proposed refactor
         case YAML_MAPPING_START_EVENT:
         case YAML_SEQUENCE_START_EVENT:
-            if (state->section == SECTION_ENV) {
-                yaml_error_event(ctx, state, event);
-                return YAML_FAILURE;
-            }
             if (state->section != SECTION_IGNORABLE) {
                 yaml_error_event(ctx, state, event);
                 return YAML_FAILURE;
             }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/config_format/flb_cf_yaml.c` around lines 1921 - 1937, Remove the
redundant SECTION_ENV guard in the
YAML_MAPPING_START_EVENT/YAML_SEQUENCE_START_EVENT branch: replace the two
checks that call yaml_error_event(ctx, state, event) and return YAML_FAILURE
with a single check that tests if state->section != SECTION_IGNORABLE, then
calls yaml_error_event(ctx, state, event) and returns YAML_FAILURE; keep the
subsequent call to state_push_variant(...) and the existing error handling
(flb_error and return YAML_FAILURE) untouched; look for the conditional block
handling YAML_MAPPING_START_EVENT and YAML_SEQUENCE_START_EVENT and update it
accordingly (symbols: YAML_MAPPING_START_EVENT, YAML_SEQUENCE_START_EVENT,
state->section, SECTION_ENV, SECTION_IGNORABLE, yaml_error_event,
state_push_variant).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@src/config_format/flb_cf_yaml.c`:
- Around line 1921-1937: Remove the redundant SECTION_ENV guard in the
YAML_MAPPING_START_EVENT/YAML_SEQUENCE_START_EVENT branch: replace the two
checks that call yaml_error_event(ctx, state, event) and return YAML_FAILURE
with a single check that tests if state->section != SECTION_IGNORABLE, then
calls yaml_error_event(ctx, state, event) and returns YAML_FAILURE; keep the
subsequent call to state_push_variant(...) and the existing error handling
(flb_error and return YAML_FAILURE) untouched; look for the conditional block
handling YAML_MAPPING_START_EVENT and YAML_SEQUENCE_START_EVENT and update it
accordingly (symbols: YAML_MAPPING_START_EVENT, YAML_SEQUENCE_START_EVENT,
state->section, SECTION_ENV, SECTION_IGNORABLE, yaml_error_event,
state_push_variant).

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 6fbb3451-b73f-4bf4-b126-a839d9871bce

📥 Commits

Reviewing files that changed from the base of the PR and between e56d7b5 and f97cead.

📒 Files selected for processing (5)
  • src/config_format/flb_cf_yaml.c
  • tests/internal/config_format_yaml.c
  • tests/internal/data/config_format/yaml/ignorable.yaml
  • tests/internal/data/config_format/yaml/other_with_nested_map.yaml
  • tests/internal/data/config_format/yaml/processors.yaml
✅ Files skipped from review due to trivial changes (2)
  • tests/internal/data/config_format/yaml/other_with_nested_map.yaml
  • tests/internal/data/config_format/yaml/ignorable.yaml
🚧 Files skipped from review as they are similar to previous changes (2)
  • tests/internal/data/config_format/yaml/processors.yaml
  • tests/internal/config_format_yaml.c

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.

YAML Config reserve attribute name for customer attributes

2 participants