Skip to content

Commit

Permalink
input_chunk: adapted chunk filtering code to operate on a local buffer
Browse files Browse the repository at this point in the history
Signed-off-by: Leonardo Alminana <[email protected]>
  • Loading branch information
leonardo-albertovich authored and edsiper committed Nov 4, 2023
1 parent b763ad5 commit ac4ec1f
Showing 1 changed file with 39 additions and 10 deletions.
49 changes: 39 additions & 10 deletions src/flb_input_chunk.c
Original file line number Diff line number Diff line change
Expand Up @@ -1390,6 +1390,10 @@ static int input_chunk_append_raw(struct flb_input_instance *in,
size_t pre_real_size;
struct flb_input_chunk *ic;
struct flb_storage_input *si;
void *filtered_data_buffer;
size_t filtered_data_size;
void *final_data_buffer;
size_t final_data_size;

/* memory ring-buffer checker */
if (in->storage_type == FLB_STORAGE_MEMRB) {
Expand Down Expand Up @@ -1491,15 +1495,6 @@ static int input_chunk_append_raw(struct flb_input_instance *in,
pre_real_size = flb_input_chunk_get_real_size(ic);
}

/* Write the new data */
ret = flb_input_chunk_write(ic, buf, buf_size);
if (ret == -1) {
flb_error("[input chunk] error writing data from %s instance",
in->name);
cio_chunk_tx_rollback(ic->chunk);
return -1;
}

#ifdef FLB_HAVE_CHUNK_TRACE
flb_chunk_trace_do_input(ic);
#endif /* FLB_HAVE_CHUNK_TRACE */
Expand Down Expand Up @@ -1529,11 +1524,45 @@ static int input_chunk_append_raw(struct flb_input_instance *in,
}
#endif

filtered_data_buffer = NULL;
final_data_buffer = (char *) buf;
final_data_size = buf_size;

/* Apply filters */
if (event_type == FLB_INPUT_LOGS) {
flb_filter_do(ic,
buf, buf_size,
tag, tag_len, in->config);
&filtered_data_buffer,
&filtered_data_size,
tag, tag_len,
in->config);

if (filtered_data_buffer != NULL) {
final_data_buffer = filtered_data_buffer;
final_data_size = filtered_data_size;
}
}

if (final_data_size > 0){
ret = flb_input_chunk_write(ic,
final_data_buffer,
final_data_size);
}
else {
ret = 0;
}

if (filtered_data_buffer != NULL &&
filtered_data_buffer != buf) {
flb_free(filtered_data_buffer);
}

if (ret == -1) {
flb_error("[input chunk] error writing data from %s instance",
in->name);
cio_chunk_tx_rollback(ic->chunk);

return -1;
}

/* get the chunks content size */
Expand Down

0 comments on commit ac4ec1f

Please sign in to comment.