Skip to content

Commit 1ce4df5

Browse files
nokute78edsiper
authored andcommitted
out_lib: support metrics input
Signed-off-by: Takahiro Yamashita <[email protected]>
1 parent 2148b1a commit 1ce4df5

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

plugins/out_lib/out_lib.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,19 @@ static void out_lib_flush(struct flb_event_chunk *event_chunk,
149149
data_size = alloc_size;
150150
break;
151151
case FLB_OUT_LIB_FMT_JSON:
152+
#ifdef FLB_HAVE_METRICS
153+
if (event_chunk->type == FLB_EVENT_TYPE_METRIC) {
154+
alloc_size = (off - last_off) + 4096;
155+
buf = flb_msgpack_to_json_str(alloc_size, &result.data);
156+
if (buf == NULL) {
157+
msgpack_unpacked_destroy(&result);
158+
FLB_OUTPUT_RETURN(FLB_ERROR);
159+
}
160+
data_size = strlen(buf);
161+
data_for_user = buf;
162+
}
163+
else {
164+
#endif
152165
/* JSON is larger than msgpack */
153166
alloc_size = (off - last_off) + 128;
154167

@@ -174,6 +187,9 @@ static void out_lib_flush(struct flb_event_chunk *event_chunk,
174187
flb_free(buf);
175188
data_for_user = out_buf;
176189
data_size = len;
190+
#ifdef FLB_HAVE_METRICS
191+
}
192+
#endif
177193
break;
178194
}
179195

@@ -201,5 +217,6 @@ struct flb_output_plugin out_lib_plugin = {
201217
.cb_init = out_lib_init,
202218
.cb_flush = out_lib_flush,
203219
.cb_exit = out_lib_exit,
220+
.event_type = FLB_OUTPUT_LOGS | FLB_OUTPUT_METRICS,
204221
.flags = 0,
205222
};

0 commit comments

Comments
 (0)