Skip to content

Commit

Permalink
out_forward: add support to forward metrics
Browse files Browse the repository at this point in the history
Signed-off-by: Eduardo Silva <[email protected]>
  • Loading branch information
edsiper committed Aug 27, 2021
1 parent d0b1b15 commit 7cbab2c
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
3 changes: 3 additions & 0 deletions plugins/out_forward/forward.c
Original file line number Diff line number Diff line change
Expand Up @@ -1344,4 +1344,7 @@ struct flb_output_plugin out_forward_plugin = {

/* Flags */
.flags = FLB_OUTPUT_NET | FLB_IO_OPT_TLS,

/* Event types */
.event_type = FLB_OUTPUT_LOGS | FLB_OUTPUT_METRICS
};
55 changes: 55 additions & 0 deletions plugins/out_forward/forward_format.c
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,48 @@ static int flb_forward_format_message_mode(struct flb_forward *ctx,
}
#endif

static int flb_forward_format_metrics_mode(struct flb_forward *ctx,
struct flb_forward_config *fc,
struct flb_forward_flush *ff,
const char *tag, int tag_len,
const void *data, size_t bytes,
void **out_buf, size_t *out_size)
{
msgpack_packer mp_pck;
msgpack_sbuffer mp_sbuf;
struct flb_time tm;

msgpack_sbuffer_init(&mp_sbuf);
msgpack_packer_init(&mp_pck, &mp_sbuf, msgpack_sbuffer_write);

msgpack_pack_array(&mp_pck, 3);

if (fc->tag) {
msgpack_pack_str(&mp_pck, flb_sds_len(fc->tag));
msgpack_pack_str_body(&mp_pck, fc->tag, flb_sds_len(fc->tag));
}
else {
msgpack_pack_str(&mp_pck, tag_len);
msgpack_pack_str_body(&mp_pck, tag, tag_len);
}

/* timestamp */
flb_time_get(&tm);
flb_time_append_to_msgpack(&tm, &mp_pck, 0);

/* metrics */
msgpack_pack_map(&mp_pck, 1);
msgpack_pack_str(&mp_pck, 8);
msgpack_pack_str_body(&mp_pck, "cmetrics", 8);
msgpack_pack_bin(&mp_pck, bytes);
msgpack_pack_bin_body(&mp_pck, data, bytes);

*out_buf = mp_sbuf.data;
*out_size = mp_sbuf.size;

return 0;
}

/*
* Forward Protocol: Forward Mode
* ------------------------------
Expand Down Expand Up @@ -399,6 +441,19 @@ int flb_forward_format(struct flb_config *config,
return -1;
}

/* metric handling */
if (flb_input_event_type_is_metric(ins)) {
ret = flb_forward_format_metrics_mode(ctx, fc, ff,
tag, tag_len,
data, bytes,
out_buf, out_size);
if (ret != 0) {
return -1;
}

return MODE_MESSAGE;
}

#ifdef FLB_HAVE_RECORD_ACCESSOR
/*
* Based in the configuration, decide the preferred protocol mode
Expand Down

0 comments on commit 7cbab2c

Please sign in to comment.