Skip to content

Conversation

pwhelan
Copy link
Contributor

@pwhelan pwhelan commented Mar 18, 2025

Summary

This PR seeks to avoid data loss when using the optional ring_buffer on emitters when using filter_rewrite_tag. To do so two new functions were added for the ring buffer API: peek and seek.

Description

During my work on #9919 I noticed that in_emitter had code to enable a ring buffer:

static int in_emitter_ingest_ring_buffer(struct flb_input_instance *in,
. This code has several problems:

  • if an error occurs but not at the end of the loop it will be ignored.
  • if a transient error occurs while ingesting the buffer it will be silently dropped.
  • there is no way to activate the ring buffer at all.

This PR seeks to solve it by:

  1. adding the option emitter_ring_buffer_size to filter_rewrite_tag to enable and set the size of the ring buffer for it's in_emitter.
  2. adding flb_ring_buffer_peek and flb_ring_buffer_seek to the flb_ring_buffer API so buffers can be read then absorbed only once they have been successfully submitted.

I changed the use of flb_ring_buffer_read to flb_ring_buffer_peek and flb_ring_buffer_seek so that when the buffer is ingested it first calls peek to read the buffer then submit it and only seeks the buffer only if the buffer has been successfully ingested by flb_input_log_append, ie: it returns a non-error value.

The work adding the flb_ring_buffer APIs could and should be applied to the main ring buffer as well. If this is required now I can split out that part of the work into a separate PR and leave just the fixes for the emitter and filter_rewrite_tag here.


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.

@pwhelan pwhelan changed the title Pwhelan fix in emitter data loss filter_rewrite_tag: fix in_emitter data loss when using ring buffers. Mar 18, 2025
pwhelan added 7 commits March 20, 2025 10:23
Signed-off-by: Phillip Adair Stewart Whelan <[email protected]>
…add missing skip_count argument.

Signed-off-by: Phillip Adair Stewart Whelan <[email protected]>
…mbers and skip the size check.

Signed-off-by: Phillip Adair Stewart Whelan <[email protected]>
@pwhelan pwhelan requested a review from niedbalski June 3, 2025 20:28
@pwhelan
Copy link
Contributor Author

pwhelan commented Jun 17, 2025

Is this functionality actually used? It might be best to actually drop it since it can cause a lot of corner cases and is actually redundant with the base ring buffer functionality.

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.

3 participants