From c4f067e0d11af13bb68fd1e391badad457610fa1 Mon Sep 17 00:00:00 2001 From: Hiroshi Hatake Date: Wed, 18 Oct 2023 16:28:03 +0900 Subject: [PATCH] in_forward: Handle non log types of compressed events Signed-off-by: Hiroshi Hatake --- plugins/in_forward/fw_prot.c | 54 ++++++++++++++++++++++++++++++++---- 1 file changed, 49 insertions(+), 5 deletions(-) diff --git a/plugins/in_forward/fw_prot.c b/plugins/in_forward/fw_prot.c index b656a100321..e065e3d61ca 100644 --- a/plugins/in_forward/fw_prot.c +++ b/plugins/in_forward/fw_prot.c @@ -752,11 +752,55 @@ int fw_prot_process(struct flb_input_instance *ins, struct fw_conn *conn) return -1; } - /* Append uncompressed data */ - flb_input_log_append(conn->in, - out_tag, flb_sds_len(out_tag), - gz_data, gz_size); - flb_free(gz_data); + event_type = FLB_EVENT_TYPE_LOGS; + if (contain_options) { + ret = get_chunk_event_type(ins, root.via.array.ptr[2]); + if (ret == -1) { + msgpack_unpacked_destroy(&result); + msgpack_unpacker_free(unp); + flb_sds_destroy(out_tag); + return -1; + } + event_type = ret; + } + + if (event_type == FLB_EVENT_TYPE_LOGS) { + /* Append uncompressed data */ + flb_input_log_append(conn->in, + out_tag, flb_sds_len(out_tag), + gz_data, gz_size); + flb_free(gz_data); + } + else if (event_type == FLB_EVENT_TYPE_METRICS) { + ret = cmt_decode_msgpack_create(&cmt, (char *) gz_data, gz_size, &off); + if (ret != CMT_DECODE_MSGPACK_SUCCESS) { + flb_error("cmt_decode_msgpack_create failed. ret=%d", ret); + msgpack_unpacked_destroy(&result); + msgpack_unpacker_free(unp); + flb_sds_destroy(out_tag); + return -1; + } + flb_input_metrics_append(conn->in, + out_tag, flb_sds_len(out_tag), + cmt); + flb_free(gz_data); + } + else if (event_type == FLB_EVENT_TYPE_TRACES) { + off = 0; + ret = ctr_decode_msgpack_create(&ctr, (char *) gz_data, gz_size, &off); + if (ret == -1) { + msgpack_unpacked_destroy(&result); + msgpack_unpacker_free(unp); + flb_sds_destroy(out_tag); + return -1; + } + + flb_input_trace_append(ins, + out_tag, flb_sds_len(out_tag), + ctr); + + flb_free(gz_data); + } } else { event_type = FLB_EVENT_TYPE_LOGS;