Skip to content

input: add thread.ring_buffer.retry_limit option#11394

Open
jinyongchoi wants to merge 2 commits intofluent:masterfrom
jinyongchoi:feature/input-ring-buffer-retry-limit
Open

input: add thread.ring_buffer.retry_limit option#11394
jinyongchoi wants to merge 2 commits intofluent:masterfrom
jinyongchoi:feature/input-ring-buffer-retry-limit

Conversation

@jinyongchoi
Copy link
Copy Markdown
Contributor

@jinyongchoi jinyongchoi commented Jan 24, 2026

When a threaded input plugin's ring buffer is full, the input thread retries writing to the buffer before dropping data. Previously, this retry limit was hardcoded to 10 (1 second total with 100ms sleep between retries).

This patch makes the retry limit configurable via the new 'thread.ring_buffer.retry_limit' option. The default value remains 10 for backward compatibility. Increasing this value allows the system to handle temporary backpressure situations without dropping data.

Fixes #11393


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 1
    grace 600
    log_level info

    storage.path /tmp/storage
    storage.metrics on
    storage.max_chunks_up 512
    storage.sync full
    storage.checksum off
    storage.backlog.mem_limit 100M

[INPUT]
    Name tail
    Path /var/log/app/*.log
    Tag app_logs
    Key message

    Read_from_Head true
    Refresh_Interval 3

    Buffer_Chunk_Size 1MB
    Buffer_Max_Size 16MB

    Mem_Buf_Limit 256MB
    storage.type memory
    storage.pause_on_chunks_overlimit true

    DB /tmp/storage/tail.db
    DB.sync normal

    Threaded true
    thread.ring_buffer.capacity  128
    thread.ring_buffer.retry_limit  1000

[OUTPUT]
    Name kafka
    Match app_logs
    Brokers kafka:9092
    Topics logs
    timestamp_format iso8601

    rdkafka.compression.codec gzip
    rdkafka.compression.level 7
    rdkafka.queue.buffering.max.messages 200000
    rdkafka.batch.size 1000000
    rdkafka.linger.ms 100

    workers 4
  • [N/A] Debug log output from testing the change
  • [N/A] 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.

  • [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

  • Documentation required for this feature

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.

Summary by CodeRabbit

  • New Features

    • Threaded input ring-buffer writes now support a per-input configurable retry limit via thread.ring_buffer.retry_limit (default: 10).
  • Bug Fixes / Observability

    • The retry value is validated (>0) and enqueue failures now increment a failure metric for improved observability.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Jan 24, 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

Adds a per-input configurable retry limit for threaded input ring buffer writes: new ring_buffer_retry_limit field on flb_input_instance, a default macro and config property, parsing/validation during input setup, and use of the instance field in enqueue retry logic.

Changes

Cohort / File(s) Summary
Input struct definition
include/fluent-bit/flb_input.h
Added int ring_buffer_retry_limit field to struct flb_input_instance.
Configuration & initialization
src/flb_input.c
Added FLB_INPUT_RING_BUFFER_RETRY_LIMIT (default 10); registered thread.ring_buffer.retry_limit in input properties; initialize ins->ring_buffer_retry_limit to default; parse and validate property (>0) in flb_input_set_property.
Ring buffer retry logic
src/flb_input_chunk.c
Replaced local hardcoded retry limit with ins->ring_buffer_retry_limit in enqueue retry loop; removed local retry variable and incremented ring buffer retry failure metric on enqueue failure.

Sequence Diagram(s)

sequenceDiagram
    participant InputThread as Input Thread
    participant RingBuffer as Ring Buffer
    participant Metrics as Metrics/Logger
    rect rgba(200,200,255,0.5)
    InputThread->>RingBuffer: try enqueue(record)
    alt enqueue succeeds
        RingBuffer-->>InputThread: ack
    else ring full
        RingBuffer-->>InputThread: reject
        InputThread->>InputThread: sleep(100ms) and retry up to ins.ring_buffer_retry_limit
        opt retries exhausted
            InputThread->>Metrics: increment ring_buffer_retry_failures
            InputThread->>Metrics: log error "could not enqueue records"
            InputThread-->>RingBuffer: drop record
        end
    end
    end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Suggested reviewers

  • edsiper
  • koleini

Poem

🐇 I poked a knob, a tiny tune,
Threads hop gently, retry by moon.
Rings wait patient, limits set kind,
Fewer lost crumbs for logs to find. 🥕

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% 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 clearly and specifically describes the main change: adding a new configuration option thread.ring_buffer.retry_limit for input plugins.
Linked Issues check ✅ Passed The PR fully implements the requirements from #11393: adds thread.ring_buffer.retry_limit configuration option [#11393], defaults to 10 for backward compatibility [#11393], applies to threaded input plugins [#11393], and includes validation [#11393].
Out of Scope Changes check ✅ Passed All changes are directly related to implementing the thread.ring_buffer.retry_limit feature: header field addition, macro definition, config property parsing, initialization, and per-instance application in retry logic.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds a configurable retry limit for threaded input plugins' ring buffer writes. Previously, the retry limit was hardcoded to 10 attempts (1 second total with 100ms sleep between retries). This caused data loss during temporary backpressure situations that lasted longer than 1 second.

Changes:

  • Added thread.ring_buffer.retry_limit configuration option with default value of 10 to maintain backward compatibility
  • Modified ring buffer write logic to use the configurable retry limit instead of hardcoded value
  • Updated documentation to explain the new configuration option

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
include/fluent-bit/flb_input.h Added ring_buffer_retry_limit field to flb_input_instance struct
src/flb_input.c Added configuration map entry, initialization, and property parsing for the new retry limit option
src/flb_input_chunk.c Removed hardcoded retry limit and updated to use instance-level configurable value

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@jinyongchoi
Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector
Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 👍

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

@jinyongchoi
Copy link
Copy Markdown
Contributor Author

@cosmo0920 @edsiper
Hello,
This PR is ready for review. It adds a new thread.ring_buffer.retry_limit configuration option for threaded input plugins, replacing the hardcoded retry limit (10) with a user-configurable value. This allows users to tune retry attempts for handling temporary backpressure situations without dropping data.
Thanks!

Add a new configuration option 'thread.ring_buffer.retry_limit' for
threaded input plugins. This option controls the maximum number of
retry attempts when the ring buffer is full before dropping data.

The default value is 10 (maintaining backward compatibility).

Fixes fluent#11393

Signed-off-by: jinyong.choi <inimax801@gmail.com>
Replace the hardcoded retry limit (10) with the configurable
'ring_buffer_retry_limit' value from the input instance.

This allows users to increase retry attempts for handling temporary
backpressure situations without dropping data.

Fixes fluent#11393

Signed-off-by: jinyong.choi <inimax801@gmail.com>
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)
include/fluent-bit/flb_input.h (1)

386-386: Consider unsigned int (or uint32_t) to reflect the non-negative constraint at the type level.

The field is validated to be > 0 in flb_input.c, but its type is int, allowing negative values to compile silently if the validation path is ever bypassed or the field is set directly. The neighbouring ring buffer fields already use distinct types (size_t, uint8_t) to encode their semantics.

♻️ Optional type adjustment
-    int ring_buffer_retry_limit;       /* ring buffer write retry limit */
+    unsigned int ring_buffer_retry_limit; /* ring buffer write retry limit */

This also means the validation in flb_input.c and the usage in flb_input_chunk.c should check > 0 against an unsigned type (which is naturally ≥ 0), or keep the > 0 guard as-is for clarity.

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

In `@include/fluent-bit/flb_input.h` at line 386, Change the type of the struct
field ring_buffer_retry_limit from int to an unsigned type (preferably uint32_t
or unsigned int) in flb_input.h, then update all validation/uses in flb_input.c
and flb_input_chunk.c to treat it as unsigned (keep the existing > 0 guard if
you want to preserve explicit non-zero checks, or replace checks with != 0 where
clearer) and adjust any signed-to-unsigned comparisons/casts to avoid warnings;
ensure all references (e.g., the validation logic in flb_input.c and any loops
or counters in flb_input_chunk.c) compile cleanly with the new unsigned type.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@include/fluent-bit/flb_input.h`:
- Line 386: Change the type of the struct field ring_buffer_retry_limit from int
to an unsigned type (preferably uint32_t or unsigned int) in flb_input.h, then
update all validation/uses in flb_input.c and flb_input_chunk.c to treat it as
unsigned (keep the existing > 0 guard if you want to preserve explicit non-zero
checks, or replace checks with != 0 where clearer) and adjust any
signed-to-unsigned comparisons/casts to avoid warnings; ensure all references
(e.g., the validation logic in flb_input.c and any loops or counters in
flb_input_chunk.c) compile cleanly with the new unsigned type.

ℹ️ Review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 20b9f36 and 311d857.

📒 Files selected for processing (3)
  • include/fluent-bit/flb_input.h
  • src/flb_input.c
  • src/flb_input_chunk.c
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/flb_input.c
  • src/flb_input_chunk.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.

input: add configurable retry limit for threaded input ring buffer

2 participants