Skip to content

conditionals: resolve TAG record accessor in processor and filter conditions#12090

Open
zshuang0316 wants to merge 5 commits into
fluent:masterfrom
zshuang0316:conditionals-tag-accessor
Open

conditionals: resolve TAG record accessor in processor and filter conditions#12090
zshuang0316 wants to merge 5 commits into
fluent:masterfrom
zshuang0316:conditionals-tag-accessor

Conversation

@zshuang0316

Copy link
Copy Markdown
Contributor

Summary

Condition rules used by processors and filters could not match on the record
tag. The record accessor already parses $TAG / $TAG[n], but the condition
evaluator called flb_cfl_ra_translate() with a NULL tag, so any rule
referencing $TAG silently never resolved.

This PR threads the chunk tag through the condition-evaluation path:

  • flb_condition_evaluate() / flb_condition_evaluate_ex() and evaluate_rule()
    gain tag/tag_len arguments and forward them to flb_cfl_ra_translate().
  • struct flb_mp_chunk_cobj carries the chunk tag/tag_len; flb_processor
    sets them around the processor callback and clears them afterwards.
  • The record-next path (flb_mp) and the filter path pass the chunk tag; the
    router passes NULL since it already routes by tag natively.

This enables conditions such as:

    processors:
      logs:
        - name: content_modifier
          action: insert
          key: matched_tag
          value: "true"
          condition:
            op: and
            rules:
              - field: "$TAG"
                op: regex
                value: "^app\.frontend\..*$"

so a processor or filter can select records by tag.

The change is split into per-subsystem commits (conditionals:, mp:,
processor:, router_condition:, tests:) to satisfy the commit-prefix
convention; the tree builds as a whole.


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 (see above)
  • Debug log output from testing the change
  • Attached Valgrind output that shows no leaks or memory corruption was found

Unit coverage is added in tests/internal/conditionals.c (tag_accessor):
exact-match, regex, non-matching tag, and the no-tag case. I'll follow up with
runtime debug/Valgrind logs.

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

zshuang0316 and others added 5 commits July 13, 2026 17:29
The record accessor already parses TAG / TAG[n], but evaluate_rule()
passed NULL for the tag to flb_cfl_ra_translate(), so rules referencing
$TAG never resolved and silently failed to match.

Add tag/tag_len parameters to flb_condition_evaluate() and
flb_condition_evaluate_ex() and forward them to the record accessor.
Carry the chunk tag on struct flb_mp_chunk_cobj so callers can supply it.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Signed-off-by: zshuang0316 <zshuang0316@163.com>
flb_mp_chunk_cobj_record_next() now forwards chunk_cobj->tag/tag_len to
flb_condition_evaluate() so $TAG rules resolve during record iteration.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Signed-off-by: zshuang0316 <zshuang0316@163.com>
Set chunk_cobj->tag/tag_len around the processor callback and thread the
tag into evaluate_condition_for_log_event(), so processor and filter
conditions can match on $TAG. The tag is cleared after processing.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Signed-off-by: zshuang0316 <zshuang0316@163.com>
The router matches by tag natively, so pass NULL/0 for the new tag
arguments of flb_condition_evaluate_ex().

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Signed-off-by: zshuang0316 <zshuang0316@163.com>
Update the existing call sites for the new tag arguments and add positive
and negative coverage for $TAG conditions (exact match, regex, a
non-matching tag, and the no-tag case).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Signed-off-by: zshuang0316 <zshuang0316@163.com>
@coderabbitai

coderabbitai Bot commented Jul 13, 2026

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

An error occurred during the review process. Please try again later.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@zshuang0316 zshuang0316 force-pushed the conditionals-tag-accessor branch from e925bf2 to 6142006 Compare July 13, 2026 09:30
@zshuang0316 zshuang0316 changed the title conditionals: resolve $TAG in processor and filter condition rules conditionals: resolve TAG record accessor in processor and filter conditions Jul 13, 2026
@zshuang0316

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep it up!

Reviewed commit: 61420063b3

ℹ️ 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".

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