Skip to content

Commit 1a571a9

Browse files
authored
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 <[email protected]>
1 parent 574a69a commit 1a571a9

File tree

1 file changed

+20
-12
lines changed

1 file changed

+20
-12
lines changed

plugins/out_stdout/stdout.c

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -107,24 +107,32 @@ static void print_metrics_text(struct flb_output_instance *ins,
107107
size_t off = 0;
108108
cfl_sds_t text;
109109
struct cmt *cmt = NULL;
110+
int ok = CMT_DECODE_MSGPACK_SUCCESS;
110111

111112
/* get cmetrics context */
112-
ret = cmt_decode_msgpack_create(&cmt, (char *) data, bytes, &off);
113-
if (ret != 0) {
114-
flb_plg_error(ins, "could not process metrics payload");
115-
return;
116-
}
113+
while((ret = cmt_decode_msgpack_create(&cmt,
114+
(char *) data,
115+
bytes, &off)) == ok) {
116+
if (ret != 0) {
117+
flb_plg_error(ins, "could not process metrics payload");
118+
return;
119+
}
117120

118-
/* convert to text representation */
119-
text = cmt_encode_text_create(cmt);
121+
/* convert to text representation */
122+
text = cmt_encode_text_create(cmt);
120123

121-
/* destroy cmt context */
122-
cmt_destroy(cmt);
124+
/* destroy cmt context */
125+
cmt_destroy(cmt);
123126

124-
printf("%s", text);
125-
fflush(stdout);
127+
printf("%s", text);
128+
fflush(stdout);
129+
130+
cmt_encode_text_destroy(text);
131+
}
126132

127-
cmt_encode_text_destroy(text);
133+
if (ret != ok) {
134+
flb_plg_debug(ins, "cmt decode msgpack returned : %d", ret);
135+
}
128136
}
129137
#endif
130138

0 commit comments

Comments
 (0)