Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

output: allow records size 0 on flb event type logs processor #9554

Merged
merged 1 commit into from
Nov 5, 2024

Conversation

niedbalski
Copy link
Collaborator

@niedbalski niedbalski commented Nov 4, 2024

Description.

For full context, refer to #9553.

A chunk with no records is a valid scenario for logs (e.g., when all are dropped) and should either be added to the flush list or released immediately. However, the chunk should not attempt to flush.

This patch allows for the record size to be zero for FLB_EVENT_TYPE_LOGS.

I created a basic processor that calls flb_mp_chunk_cobj_record_destroy on each record, resulting in a chunk with no records (size = 0). When this happens, coroutine tasks do not run, and fluentbit_storage_mem_chunks continues to grow, causing a memory leak (refer to the issue report).

#include <fluent-bit/flb_processor_plugin.h>

static int cb_init(struct flb_processor_instance *ins,
                   void *source_plugin_instance,
                   int source_plugin_type,
                   struct flb_config *config)
{
    return FLB_PROCESSOR_SUCCESS;
}

static int cb_exit(struct flb_processor_instance *ins, void *data)
{
    return FLB_PROCESSOR_SUCCESS;
}

static int cb_process_logs(struct flb_processor_instance *ins,
                           void *chunk_data, const char *tag, int tag_len){
    struct flb_mp_chunk_cobj *chunk_cobj = (struct flb_mp_chunk_cobj *) chunk_data;
    struct flb_mp_chunk_record *record;
    while (flb_mp_chunk_cobj_record_next(chunk_cobj, &record) == FLB_MP_CHUNK_RECORD_OK) {
        flb_mp_chunk_cobj_record_destroy(chunk_cobj, record);  
    }
    return FLB_PROCESSOR_SUCCESS;
}


static struct flb_config_map config_map[] = {
    {0}
};

struct flb_processor_plugin processor_template_plugin = {
    .name               = "chunk_leaks",
    .description        = "chunk_leaks processor",
    .cb_init            = cb_init,
    .cb_process_logs    = cb_process_logs,
    .cb_process_metrics = NULL,
    .cb_process_traces  = NULL,
    .cb_exit            = cb_exit,
    .config_map         = NULL,
    .flags              = 0
};

With this configuration

service:
  http_server: on
pipeline:
  inputs:
    - name: dummy
      rate: 1000
      dummy: '{"message": "a message", "event_cluster": "raptor"}'
  outputs:
    - name: stdout
      match: '*'
      processors:
        logs:
            - name: chunk_leaks

Without this patch heap allocation graphs show continuous growth in heap memory allocations not being returned, with the chunk counter also incrementing in metrics.

image

With this patch enabled, chunks are released

image

Testing

  • 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

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.

include/fluent-bit/flb_output.h Outdated Show resolved Hide resolved
A chunk with no records is a valid case for logs (dropped all, etc)
and must be processed in flush list.

This patch allow record size to be == 0 in the case of FLB_EVENT_TYPE_LOGS

Signed-off-by: Jorge Niedbalski <[email protected]>
@niedbalski
Copy link
Collaborator Author

@edsiper / @cosmo0920 seems stable / no chunk leaks for 15m or so. Appreciated suggestions on testing if required.
image

Copy link
Contributor

@cosmo0920 cosmo0920 left a comment

Choose a reason for hiding this comment

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

Looks good and I have never imagined and though as not returned chunks cause memory leaks. This could be interesting behavior and we need to return when the size of chunks are zero. It won't be caused without processors but now we have processors. So, we need to change this behavior.

@cosmo0920 cosmo0920 added this to the Fluent Bit v3.2.0 milestone Nov 5, 2024
@niedbalski niedbalski merged commit 4532ef4 into master Nov 5, 2024
53 checks passed
@niedbalski niedbalski deleted the fix-9553 branch November 5, 2024 10:01
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