Skip to content

filter_rewrite_tag: add opt-in input processor batching and supporting fixes - #12697

Open
edsiper wants to merge 7 commits into
masterfrom
rewrite-tag-input-batching
Open

edsiper wants to merge 7 commits into
masterfrom
rewrite-tag-input-batching

Conversation

@edsiper

@edsiper edsiper commented Oct 31, 2026 •

Copy link
Copy Markdown
Member

Using rewrite_tag as an input processor appends rewritten records individually, repeatedly invoking downstream stages even when records share a destination tag. This adds opt-in batching by destination tag so each batch continues at the next processor stage through the original input append/storage path.

For example, batch_size: 4096 batches eligible callbacks of up to 4096 records; the default 0 retains the existing path. Callbacks above the count limit or 256 KiB payload bound fall back to per-record processing. Regular filter placement retains its emitter path. Ordering is preserved within each destination tag and among retained originals; cross-tag interleaving can change, which matters for stateful downstream processors.

The series also fixes issues exposed by validation:

  • Avoid duplicate initialization of private emitter inputs and free empty filter result buffers.
  • Generate distinct emitter names across input processor instances and reject output processor placement.
  • Preserve originals when destination tag expansion fails or is empty.
  • Drain pending emitter records during shutdown, including reverse-order emitter chains, and guard recursive publication.
  • Return an error when allocating an emitter sender reference fails.

Regression coverage exercises processor stage continuation, KEEP modes, invalid destinations, per-tag order, two-output fan-out, group context, multiple inputs, and EOF shutdown chains. Components, integration tests, and benchmark evidence are kept in separate DCO-signed commits.

The included benchmark report records 36–45% lower CPU cost for repeated destination tags compared with the baseline input processor. High-cardinality tags can regress; batching remains disabled by default. Measurements are from the recorded baseline and environment in benchmarks/rewrite-tag/, not a new benchmark run for this PR.

Validation from the branch checkout:

cmake -S . -B build-bench-otel -DFLB_TESTS_RUNTIME=On -DFLB_TESTS_INTERNAL=On -DFLB_BENCHMARKS=On -DCMAKE_BUILD_TYPE=Release
cmake --build build-bench-otel --target fluent-bit-bin flb-rt-filter_rewrite_tag flb-it-processor flb-it-processor_conditional flb-it-input_chunk flb-it-input_chunk_routes flb-it-input_pause flb-it-engine_dispatch flb-it-engine_adaptive_flush flb-it-input_rate_gate flb-it-mp_chunk_cobj flb-rt-processor_content_modifier -j8

FLUENT_BIT_BINARY=$PWD/build-bench-otel/bin/fluent-bit tests/integration/.venv/bin/python -m pytest tests/integration/scenarios/filter_rewrite_tag tests/integration/scenarios/filter_multiline tests/integration/scenarios/filter_log_to_metrics -q

FLUENT_BIT_BINARY=$PWD/build-bench-otel/bin/fluent-bit VALGRIND=1 VALGRIND_STRICT=1 tests/integration/.venv/bin/python -m pytest tests/integration/scenarios/filter_rewrite_tag tests/integration/scenarios/filter_multiline tests/integration/scenarios/filter_log_to_metrics -q

ctest --test-dir build-bench-otel -R '^(flb-rt-filter_rewrite_tag|flb-rt-processor_content_modifier|flb-it-(processor|processor_conditional|input_chunk|input_chunk_routes|input_pause|engine_dispatch|engine_adaptive_flush|input_rate_gate|mp_chunk_cobj))$' --output-on-failure

GITHUB_EVENT_NAME=pull_request GITHUB_BASE_REF=master tests/integration/.venv/bin/python .github/scripts/commit_prefix_check.py
git diff --check refs/remotes/origin/master...HEAD

Results: 39 integration cases passed normally (117.99 s), and 39 passed under strict Valgrind; all 39 Valgrind logs report zero errors and zero definitely, indirectly, or possibly lost bytes. All 11 focused CTest executables passed (107.32 s). Full PR-range commit-prefix lint and whitespace checks passed.

Summary by CodeRabbit

  • New Features
    • rewrite_tag can now batch records in input processors. Configure a batch size up to 4096; batching is disabled by default, and unsupported batch sizes fall back to individual processing.
    • Added benchmark documentation covering performance, memory use, limits, and reproduction steps.
  • Bug Fixes
    • Improved delivery of records emitted during shutdown and when inputs reach end-of-file.
    • Fixed handling of empty or failed destination-tag translations.

Signed-off-by: Eduardo Silva <eduardo@chronosphere.io>
Signed-off-by: Eduardo Silva <eduardo@chronosphere.io>
Signed-off-by: Eduardo Silva <eduardo@chronosphere.io>
Signed-off-by: Eduardo Silva <eduardo@chronosphere.io>
Signed-off-by: Eduardo Silva <eduardo@chronosphere.io>
Signed-off-by: Eduardo Silva <eduardo@chronosphere.io>
Signed-off-by: Eduardo Silva <eduardo@chronosphere.io>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 31, 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-31T18:57:48.367213Z 3f22a22 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 31, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 2c44fa65-e1bb-4702-ac33-3b3c008a37e8
Commits

Reviewing files that changed from the base of the PR and between 5f98aee and 3f22a22.

Files ignored due to path filters: 4
  • benchmarks/rewrite-tag/high-cardinality.csv is excluded by !**/*.csv
  • benchmarks/rewrite-tag/keep.csv is excluded by !**/*.csv
  • benchmarks/rewrite-tag/no-match.csv is excluded by !**/*.csv
  • benchmarks/rewrite-tag/throughput.csv is excluded by !**/*.csv
Files selected for processing: 12
  • benchmarks/rewrite-tag/README.md
  • benchmarks/rewrite-tag/benchmark.py
  • benchmarks/rewrite-tag/environment.json
  • benchmarks/rewrite-tag/verification.json
  • include/fluent-bit/flb_input.h
  • plugins/filter_rewrite_tag/rewrite_tag.c
  • plugins/filter_rewrite_tag/rewrite_tag.h
  • plugins/in_emitter/emitter.c
  • src/flb_input.c
  • src/flb_processor.c
  • tests/integration/scenarios/filter_rewrite_tag/tests/test_filter_rewrite_tag_batch.py
  • tests/integration/scenarios/filter_rewrite_tag/tests/test_filter_rewrite_tag_groups.py

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

Walkthrough

The change adds optional batching for rewrite_tag input processors, updates emitter shutdown and processor lifecycle handling, and adds integration tests plus benchmark tooling and results.

Changes: rewrite_tag input processor batching

Layer / File(s) Summary
Configure and process batches
include/fluent-bit/flb_input.h, plugins/filter_rewrite_tag/*, tests/integration/scenarios/filter_rewrite_tag/tests/*
rewrite_tag adds a batch_size option, validates input-processor placement, and groups eligible records by destination tag. Unsupported or failed batch attempts use record-at-a-time processing. Integration tests cover batch sizes, keep behavior, record order and retention, output-processor rejection, and group context.

Emitter and processor lifecycle

Layer / File(s) Summary
Emitter shutdown and processor lifecycle
plugins/in_emitter/emitter.c, src/flb_input.c, src/flb_processor.c, tests/integration/scenarios/filter_rewrite_tag/tests/test_filter_rewrite_tag_batch.py
The emitter adds an ingestion guard and queues pending chunks during shutdown. Input initialization skips repeated initialization, and processor_run frees a zero-sized modified-filter buffer. An EOF test checks delivery across filter arrangements.

Benchmark tooling and results

Layer / File(s) Summary
Benchmark tooling and results
benchmarks/rewrite-tag/*
The benchmark driver runs four rewrite_tag configurations and records delivery and resource measurements. The README and JSON files document the benchmark workloads, results, validation, and reproduction commands.

Estimated code review effort: 4 (Complex) | ~45 minutes

Change: Feature

Sequence Diagram(s)

sequenceDiagram
  participant InputProcessor
  participant cb_rewrite_tag_filter
  participant rewrite_tag_batch
  participant Emitter
  InputProcessor->>cb_rewrite_tag_filter: invoke processor callback
  cb_rewrite_tag_filter->>rewrite_tag_batch: attempt eligible batch
  rewrite_tag_batch->>Emitter: ingest grouped destination records
  Emitter-->>rewrite_tag_batch: return admission result
  rewrite_tag_batch-->>InputProcessor: return retained records and result
Loading

Possibly related issues

Possibly related PRs

  • fluent/fluent-bit#12668: It changes the same rewrite_tag lifecycle paths, including placement validation, emitter naming, and shutdown handling.
  • fluent/fluent-bit#12589: It changes processor handling of empty results, which overlaps with the zero-sized output cleanup here.

Suggested reviewers: cosmo0920

Merge Risk: Minimal · up to 3f22a

No confirmed issue in the supplied evidence blocks merging; proceed with normal checks.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 21.05% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documenta… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed 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 clearly and concisely identifies the main change: opt-in batching for the rewrite_tag input processor. It also accurately notes the supporting fixes.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

Docstring coverage is 21.05% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 19 functions across 9 files. (3 skipped: 3 unsupported.)

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Finishing Touches
Generate docstrings
  • Commit to this branch
  • Create a new PR
Generate unit tests (beta)
  • Commit to this branch
  • 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

This branch was previously deployed

1 inactive deployment
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