From dc3718e21107e8aa857142997f9bca0d23cc7152 Mon Sep 17 00:00:00 2001 From: Thiago Padilha Date: Tue, 21 May 2024 14:32:53 -0300 Subject: [PATCH] output: Fix handling of metrics in output processor This patch passes an cmt_out_context pointer so that output processors can modify metrics. Signed-off-by: Thiago Padilha --- include/fluent-bit/flb_output.h | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/include/fluent-bit/flb_output.h b/include/fluent-bit/flb_output.h index 3fab2576d62..eab0c983701 100644 --- a/include/fluent-bit/flb_output.h +++ b/include/fluent-bit/flb_output.h @@ -627,6 +627,7 @@ struct flb_output_flush *flb_output_flush_create(struct flb_task *task, struct cmt *metrics_context; struct ctrace *trace_context; size_t chunk_offset; + struct cmt *cmt_out_context = NULL; /* Custom output coroutine info */ out_flush = (struct flb_output_flush *) flb_calloc(1, sizeof(struct flb_output_flush)); @@ -715,13 +716,25 @@ struct flb_output_flush *flb_output_flush_create(struct flb_task *task, flb_sds_len(evc->tag), (char *) metrics_context, 0, - NULL, + (void **)&cmt_out_context, NULL); if (ret == 0) { - ret = cmt_encode_msgpack_create(metrics_context, - &serialized_context_buffer, - &serialized_context_size); + if (cmt_out_context != NULL) { + ret = cmt_encode_msgpack_create(cmt_out_context, + &serialized_context_buffer, + &serialized_context_size); + + if (cmt_out_context != metrics_context) { + cmt_destroy(cmt_out_context); + } + + } + else { + ret = cmt_encode_msgpack_create(metrics_context, + &serialized_context_buffer, + &serialized_context_size); + } cmt_destroy(metrics_context);