Skip to content

Commit 41783d2

Browse files
committed
out_forward: add new 'add_option' configuration property
Forward protocol supports metadata through the 'options' feature. This information is appended to the whole payload and normally is handled only by the Forward plugin implementation. This plugin extends Fluent Bit Forward configuration where now is possible to set arbitrary options key/value pairs (strings) for very advanced use cases. Usage: [OUTPUT] name forward match * add_option key1 val1 add_option key2 val2 Signed-off-by: Eduardo Silva <[email protected]>
1 parent e0de49c commit 41783d2

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

plugins/out_forward/forward.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -839,6 +839,13 @@ static int config_set_properties(struct flb_upstream_node *node,
839839
fc->send_options = flb_utils_bool(tmp);
840840
}
841841

842+
/* add_option -> extra_options: if the user has defined 'add_option'
843+
* we need to enable the 'send_options' flag
844+
*/
845+
if (fc->extra_options && mk_list_size(fc->extra_options) > 0) {
846+
fc->send_options = FLB_TRUE;
847+
}
848+
842849
/* require ack response (implies send_options) */
843850
tmp = config_get_property("require_ack_response", node, ctx);
844851
if (tmp) {
@@ -1785,7 +1792,14 @@ static struct flb_config_map config_map[] = {
17851792
{
17861793
FLB_CONFIG_MAP_BOOL, "fluentd_compat", "false",
17871794
0, FLB_TRUE, offsetof(struct flb_forward_config, fluentd_compat),
1788-
"Send cmetrics and ctreaces with Fluentd compatible format"
1795+
"Send metrics and traces with Fluentd compatible format"
1796+
},
1797+
1798+
{
1799+
FLB_CONFIG_MAP_SLIST_2, "add_option", NULL,
1800+
FLB_CONFIG_MAP_MULT, FLB_TRUE, offsetof(struct flb_forward_config, extra_options),
1801+
"Set an extra Forward protocol option. This is an advance feature, use it only for "
1802+
"very specific use-cases."
17891803
},
17901804

17911805
/* EOF */

plugins/out_forward/forward.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ struct flb_forward_config {
7373
int time_as_integer; /* Use backward compatible timestamp ? */
7474
int fluentd_compat; /* Use Fluentd compatible payload for
7575
* metrics and ctraces */
76+
77+
/* add extra options to the Forward payload (advanced) */
78+
struct mk_list *extra_options;
79+
7680
int fwd_retain_metadata; /* Do not drop metadata in forward mode */
7781

7882
/* config */

plugins/out_forward/forward_format.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,11 @@ static int append_options(struct flb_forward *ctx,
9393
char *chunk = NULL;
9494
uint8_t checksum[64];
9595
int result;
96+
struct mk_list *head;
97+
struct flb_config_map_val *mv;
9698
struct flb_mp_map_header mh;
99+
struct flb_slist_entry *eopt_key;
100+
struct flb_slist_entry *eopt_val;
97101

98102
/* options is map, use the dynamic map type */
99103
flb_mp_map_header_init(&mh, mp_pck);
@@ -152,6 +156,20 @@ static int append_options(struct flb_forward *ctx,
152156
msgpack_pack_str_body(mp_pck, "fluent_signal", 13);
153157
msgpack_pack_int64(mp_pck, event_type);
154158

159+
/* process 'extra_option(s)' */
160+
if (fc->extra_options) {
161+
flb_config_map_foreach(head, mv, fc->extra_options) {
162+
eopt_key = mk_list_entry_first(mv->val.list, struct flb_slist_entry, _head);
163+
eopt_val = mk_list_entry_last(mv->val.list, struct flb_slist_entry, _head);
164+
165+
flb_mp_map_header_append(&mh);
166+
msgpack_pack_str(mp_pck, flb_sds_len(eopt_key->str));
167+
msgpack_pack_str_body(mp_pck, eopt_key->str, flb_sds_len(eopt_key->str));
168+
msgpack_pack_str(mp_pck, flb_sds_len(eopt_val->str));
169+
msgpack_pack_str_body(mp_pck, eopt_val->str, flb_sds_len(eopt_val->str));
170+
}
171+
}
172+
155173
if (metadata != NULL &&
156174
metadata->type == MSGPACK_OBJECT_MAP &&
157175
metadata->via.map.size > 0) {

0 commit comments

Comments
 (0)