|
29 | 29 | #include <ctraces/ctraces.h> |
30 | 30 | #include <ctraces/ctr_decode_msgpack.h> |
31 | 31 |
|
| 32 | +#include <cprofiles/cprofiles.h> |
| 33 | +#include <cprofiles/cprof_encode_text.h> |
| 34 | +#include <cprofiles/cprof_decode_msgpack.h> |
| 35 | + |
32 | 36 | #include <msgpack.h> |
33 | 37 | #include "stdout.h" |
34 | 38 |
|
@@ -165,6 +169,45 @@ static void print_traces_text(struct flb_output_instance *ins, |
165 | 169 | } |
166 | 170 | } |
167 | 171 |
|
| 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 | + |
168 | 211 | static void cb_stdout_flush(struct flb_event_chunk *event_chunk, |
169 | 212 | struct flb_output_flush *out_flush, |
170 | 213 | struct flb_input_instance *i_ins, |
@@ -201,6 +244,13 @@ static void cb_stdout_flush(struct flb_event_chunk *event_chunk, |
201 | 244 | FLB_OUTPUT_RETURN(FLB_OK); |
202 | 245 | } |
203 | 246 |
|
| 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 | + |
204 | 254 | /* Assuming data is a log entry...*/ |
205 | 255 | if (ctx->out_format != FLB_PACK_JSON_FORMAT_NONE) { |
206 | 256 | json = flb_pack_msgpack_to_json_format(event_chunk->data, |
@@ -305,6 +355,7 @@ struct flb_output_plugin out_stdout_plugin = { |
305 | 355 | .cb_exit = cb_stdout_exit, |
306 | 356 | .flags = 0, |
307 | 357 | .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, |
309 | 360 | .config_map = config_map |
310 | 361 | }; |
0 commit comments