Skip to content

Commit 37624bd

Browse files
committed
output: Handle plugin aliases
Signed-off-by: Hiroshi Hatake <hiroshi@chronosphere.io>
1 parent b501fed commit 37624bd

1 file changed

Lines changed: 34 additions & 6 deletions

File tree

src/flb_output.c

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include <fluent-bit/flb_macros.h>
3636
#include <fluent-bit/flb_utils.h>
3737
#include <fluent-bit/flb_plugin.h>
38+
#include <fluent-bit/flb_plugin_alias.h>
3839
#include <fluent-bit/flb_plugin_proxy.h>
3940
#include <fluent-bit/flb_http_client_debug.h>
4041
#include <fluent-bit/flb_output_thread.h>
@@ -128,6 +129,7 @@ static int check_protocol(const char *prot, const char *output)
128129
{
129130
int len;
130131
char *p;
132+
const char *alias_target;
131133

132134
p = strstr(output, "://");
133135
if (p && p != output) {
@@ -137,12 +139,16 @@ static int check_protocol(const char *prot, const char *output)
137139
len = strlen(output);
138140
}
139141

140-
if (strlen(prot) != len) {
141-
return 0;
142+
/* Output plugin match */
143+
if (strlen(prot) == (size_t) len &&
144+
strncasecmp(prot, output, len) == 0) {
145+
return 1;
142146
}
143147

144-
/* Output plugin match */
145-
if (strncasecmp(prot, output, len) == 0) {
148+
alias_target = flb_plugin_alias_get(FLB_PLUGIN_OUTPUT, output, len);
149+
if (alias_target != NULL &&
150+
strlen(alias_target) == strlen(prot) &&
151+
strcasecmp(prot, alias_target) == 0) {
146152
return 1;
147153
}
148154

@@ -676,6 +682,8 @@ struct flb_output_instance *flb_output_new(struct flb_config *config,
676682
{
677683
int ret = -1;
678684
int flags = 0;
685+
const char *output_name;
686+
char *output_uri;
679687
struct mk_list *head;
680688
struct flb_output_plugin *plugin;
681689
struct flb_output_instance *instance = NULL;
@@ -684,9 +692,12 @@ struct flb_output_instance *flb_output_new(struct flb_config *config,
684692
return NULL;
685693
}
686694

695+
output_name = output;
696+
output_uri = NULL;
697+
687698
mk_list_foreach(head, &config->out_plugins) {
688699
plugin = mk_list_entry(head, struct flb_output_plugin, _head);
689-
if (!check_protocol(plugin->name, output)) {
700+
if (!check_protocol(plugin->name, output_name)) {
690701
plugin = NULL;
691702
continue;
692703
}
@@ -818,7 +829,24 @@ struct flb_output_instance *flb_output_new(struct flb_config *config,
818829
#endif
819830

820831
if (plugin->flags & FLB_OUTPUT_NET) {
821-
ret = flb_net_host_set(plugin->name, &instance->host, output);
832+
output_uri = flb_plugin_alias_rewrite(FLB_PLUGIN_OUTPUT, output_name);
833+
if (output_uri == FLB_PLUGIN_ALIAS_ERR) {
834+
if (instance->flags & FLB_OUTPUT_SYNCHRONOUS) {
835+
flb_task_queue_destroy(instance->singleplex_queue);
836+
}
837+
flb_free(instance->http_server_config);
838+
flb_free(instance);
839+
return NULL;
840+
}
841+
else if (output_uri != NULL) {
842+
output_name = output_uri;
843+
}
844+
845+
ret = flb_net_host_set(plugin->name, &instance->host, output_name);
846+
if (output_uri != NULL) {
847+
flb_free(output_uri);
848+
}
849+
822850
if (ret != 0) {
823851
if (instance->flags & FLB_OUTPUT_SYNCHRONOUS) {
824852
flb_task_queue_destroy(instance->singleplex_queue);

0 commit comments

Comments
 (0)