From 1a571a9146f1c63998c7cdf4630081bf2e4914e9 Mon Sep 17 00:00:00 2001 From: Hiroshi Hatake Date: Thu, 25 Jul 2024 08:00:01 +0900 Subject: [PATCH] out_stdout: consume entire metrics type of buffers (#9118) Like as ctraces events, there is possibilities to have multiple concatenated cmetrics buffers case. For instance, calling flb_input_metrics_append more than one per a cycle, msgpack payload of cmetrics have multiply concatenated contexts of cmetrics. Signed-off-by: Hiroshi Hatake --- plugins/out_stdout/stdout.c | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/plugins/out_stdout/stdout.c b/plugins/out_stdout/stdout.c index e2a7f29430b..5c126fa075b 100644 --- a/plugins/out_stdout/stdout.c +++ b/plugins/out_stdout/stdout.c @@ -107,24 +107,32 @@ static void print_metrics_text(struct flb_output_instance *ins, size_t off = 0; cfl_sds_t text; struct cmt *cmt = NULL; + int ok = CMT_DECODE_MSGPACK_SUCCESS; /* get cmetrics context */ - ret = cmt_decode_msgpack_create(&cmt, (char *) data, bytes, &off); - if (ret != 0) { - flb_plg_error(ins, "could not process metrics payload"); - return; - } + while((ret = cmt_decode_msgpack_create(&cmt, + (char *) data, + bytes, &off)) == ok) { + if (ret != 0) { + flb_plg_error(ins, "could not process metrics payload"); + return; + } - /* convert to text representation */ - text = cmt_encode_text_create(cmt); + /* convert to text representation */ + text = cmt_encode_text_create(cmt); - /* destroy cmt context */ - cmt_destroy(cmt); + /* destroy cmt context */ + cmt_destroy(cmt); - printf("%s", text); - fflush(stdout); + printf("%s", text); + fflush(stdout); + + cmt_encode_text_destroy(text); + } - cmt_encode_text_destroy(text); + if (ret != ok) { + flb_plg_debug(ins, "cmt decode msgpack returned : %d", ret); + } } #endif