From 22e297de1514e0c9d51aaa832654abb2f14f8004 Mon Sep 17 00:00:00 2001 From: Fujimoto Seiji Date: Tue, 14 Jan 2020 21:51:10 +0900 Subject: [PATCH] out_forward: Add a new option 'Empty_Shared_Key' (#1874) Fluentd allows to use an empty string "" as a shared key. This means that the following configuration is perfectly valid in Fluentd. @type forward shared_key "" self_hostname foo The trouble is that Fluent Bit was being unable to connect to such a Fluentd node, because Fluent Bit's configuration syntax did not allow to specify an empty string. This adds a new boolean option 'Empty_Shared_Key' that enables us to circumvent the limitation, and should make Fluent Bit on par with Fluentd. Signed-off-by: Fujimoto Seiji --- plugins/out_forward/forward.c | 29 +++++++++++++++++++++++++++-- plugins/out_forward/forward.h | 1 + 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/plugins/out_forward/forward.c b/plugins/out_forward/forward.c index e65229657b8..a60b29fceb1 100644 --- a/plugins/out_forward/forward.c +++ b/plugins/out_forward/forward.c @@ -628,8 +628,19 @@ static int forward_config_ha(const char *upstream_file, } /* Shared key */ + tmp = flb_upstream_node_get_property("empty_shared_key", node); + if (tmp && flb_utils_bool(tmp)) { + fc->empty_shared_key = FLB_TRUE; + } + else { + fc->empty_shared_key = FLB_FALSE; + } + tmp = flb_upstream_node_get_property("shared_key", node); - if (tmp) { + if (fc->empty_shared_key == FLB_TRUE) { + fc->shared_key = flb_sds_create(""); + } + else if (tmp) { fc->shared_key = flb_sds_create(tmp); } else { @@ -755,10 +766,24 @@ static int forward_config_simple(struct flb_forward *ctx, flb_output_upstream_set(ctx->u, ins); /* Shared Key */ + tmp = flb_output_get_property("empty_shared_key", ins); + if (tmp && flb_utils_bool(tmp)) { + fc->empty_shared_key = FLB_TRUE; + } + else { + fc->empty_shared_key = FLB_FALSE; + } + tmp = flb_output_get_property("shared_key", ins); - if (tmp) { + if (fc->empty_shared_key) { + fc->shared_key = flb_sds_create(""); + } + else if (tmp) { fc->shared_key = flb_sds_create(tmp); } + else { + fc->shared_key = NULL; + } tmp = flb_output_get_property("username", ins); if (tmp) { diff --git a/plugins/out_forward/forward.h b/plugins/out_forward/forward.h index e8b5ef76084..e58d79cbbce 100644 --- a/plugins/out_forward/forward.h +++ b/plugins/out_forward/forward.h @@ -46,6 +46,7 @@ struct flb_forward_config { /* config */ flb_sds_t shared_key; /* shared key */ flb_sds_t self_hostname; /* hotname used in certificate */ + int empty_shared_key; /* use an empty string as shared key */ int require_ack_response; /* Require acknowledge for "chunk" */ int send_options; /* send options in messages */