Skip to content

Commit 0200a2f

Browse files
Leonardo Alminanaedsiper
authored andcommitted
out_stdout: added profile event support
Signed-off-by: Leonardo Alminana <[email protected]>
1 parent 51b0390 commit 0200a2f

File tree

1 file changed

+52
-1
lines changed

1 file changed

+52
-1
lines changed

plugins/out_stdout/stdout.c

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@
2929
#include <ctraces/ctraces.h>
3030
#include <ctraces/ctr_decode_msgpack.h>
3131

32+
#include <cprofiles/cprofiles.h>
33+
#include <cprofiles/cprof_encode_text.h>
34+
#include <cprofiles/cprof_decode_msgpack.h>
35+
3236
#include <msgpack.h>
3337
#include "stdout.h"
3438

@@ -165,6 +169,45 @@ static void print_traces_text(struct flb_output_instance *ins,
165169
}
166170
}
167171

172+
static void print_profiles_text(struct flb_output_instance *ins,
173+
const void *data, size_t bytes)
174+
{
175+
int ret;
176+
size_t off;
177+
cfl_sds_t text;
178+
struct cprof *profiles_context;
179+
180+
profiles_context = NULL;
181+
off = 0;
182+
183+
/* Decode each profiles context */
184+
while ((ret = cprof_decode_msgpack_create(&profiles_context,
185+
(unsigned char *) data,
186+
bytes, &off)) ==
187+
CPROF_DECODE_MSGPACK_SUCCESS) {
188+
/* convert to text representation */
189+
ret = cprof_encode_text_create(&text, profiles_context);
190+
191+
if (ret != CPROF_ENCODE_TEXT_SUCCESS) {
192+
flb_plg_debug(ins, "cprofiles text encoder returned : %d", ret);
193+
194+
continue;
195+
}
196+
197+
/* destroy ctr context */
198+
cprof_decode_msgpack_destroy(profiles_context);
199+
200+
printf("%s", text);
201+
fflush(stdout);
202+
203+
cprof_encode_text_destroy(text);
204+
}
205+
206+
if (ret != CPROF_DECODE_MSGPACK_SUCCESS) {
207+
flb_plg_debug(ins, "cprofiles msgpack decoder returned : %d", ret);
208+
}
209+
}
210+
168211
static void cb_stdout_flush(struct flb_event_chunk *event_chunk,
169212
struct flb_output_flush *out_flush,
170213
struct flb_input_instance *i_ins,
@@ -201,6 +244,13 @@ static void cb_stdout_flush(struct flb_event_chunk *event_chunk,
201244
FLB_OUTPUT_RETURN(FLB_OK);
202245
}
203246

247+
if (event_chunk->type == FLB_EVENT_TYPE_PROFILES) {
248+
print_profiles_text(ctx->ins, (char *)
249+
event_chunk->data,
250+
event_chunk->size);
251+
FLB_OUTPUT_RETURN(FLB_OK);
252+
}
253+
204254
/* Assuming data is a log entry...*/
205255
if (ctx->out_format != FLB_PACK_JSON_FORMAT_NONE) {
206256
json = flb_pack_msgpack_to_json_format(event_chunk->data,
@@ -305,6 +355,7 @@ struct flb_output_plugin out_stdout_plugin = {
305355
.cb_exit = cb_stdout_exit,
306356
.flags = 0,
307357
.workers = 1,
308-
.event_type = FLB_OUTPUT_LOGS | FLB_OUTPUT_METRICS | FLB_OUTPUT_TRACES | FLB_OUTPUT_BLOBS,
358+
.event_type = FLB_OUTPUT_LOGS | FLB_OUTPUT_METRICS | FLB_OUTPUT_TRACES |
359+
FLB_OUTPUT_PROFILES | FLB_OUTPUT_BLOBS,
309360
.config_map = config_map
310361
};

0 commit comments

Comments
 (0)