Skip to content

Commit

Permalink
output: plugin_proxy: Migrate initialization of Golang output as cb_i…
Browse files Browse the repository at this point in the history
…nit based

Signed-off-by: Hiroshi Hatake <[email protected]>
  • Loading branch information
cosmo0920 committed Oct 3, 2023
1 parent bb9ff31 commit 8fe9412
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 32 deletions.
2 changes: 2 additions & 0 deletions include/fluent-bit/flb_output.h
Original file line number Diff line number Diff line change
Expand Up @@ -1075,6 +1075,8 @@ void *flb_output_get_cmt_instance(struct flb_output_instance *ins);
#endif
void flb_output_net_default(const char *host, int port,
struct flb_output_instance *ins);
int flb_output_enable_multi_threading(struct flb_output_instance *ins,
struct flb_config *config);
const char *flb_output_name(struct flb_output_instance *ins);
void flb_output_pre_run(struct flb_config *config);
void flb_output_exit(struct flb_config *config);
Expand Down
4 changes: 0 additions & 4 deletions include/fluent-bit/flb_plugin_proxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,6 @@ struct flb_plugin_input_proxy_context {
void *flb_plugin_proxy_symbol(struct flb_plugin_proxy *proxy,
const char *symbol);

int flb_plugin_proxy_output_init(struct flb_plugin_proxy *proxy,
struct flb_output_instance *o_ins,
struct flb_config *config);

int flb_plugin_proxy_register(struct flb_plugin_proxy *proxy,
struct flb_config *config);

Expand Down
21 changes: 0 additions & 21 deletions src/flb_output.c
Original file line number Diff line number Diff line change
Expand Up @@ -1220,27 +1220,6 @@ int flb_output_init_all(struct flb_config *config)
}
#endif

#ifdef FLB_HAVE_PROXY_GO
/* Proxy plugins have their own initialization */
if (p->type == FLB_OUTPUT_PLUGIN_PROXY) {
ret = flb_plugin_proxy_output_init(p->proxy, ins, config);
if (ret == -1) {
flb_output_instance_destroy(ins);
return -1;
}

/* Multi-threading enabled if configured */
ret = flb_output_enable_multi_threading(ins, config);
if (ret == -1) {
flb_error("[output] could not start thread pool for '%s' plugin",
p->name);
return -1;
}

continue;
}
#endif

#ifdef FLB_HAVE_TLS
if (ins->use_tls == FLB_TRUE) {
ins->tls = flb_tls_create(FLB_TLS_CLIENT_MODE,
Expand Down
29 changes: 22 additions & 7 deletions src/flb_plugin_proxy.c
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,9 @@ static int flb_proxy_output_cb_pre_run(void *out_context, struct flb_config *con
return ret;
}

int flb_proxy_output_cb_init(struct flb_output_instance *o_ins,
struct flb_config *config, void *data);

static int flb_proxy_register_output(struct flb_plugin_proxy *proxy,
struct flb_plugin_proxy_def *def,
struct flb_config *config)
Expand All @@ -363,6 +366,7 @@ static int flb_proxy_register_output(struct flb_plugin_proxy *proxy,
* the core plugins specs, have a different callback approach, so
* we put our proxy-middle callbacks to do the translation properly.
*/
out->cb_init = flb_proxy_output_cb_init;
out->cb_flush = proxy_cb_flush;
out->cb_pre_run = flb_proxy_output_cb_pre_run;
out->cb_exit = flb_proxy_output_cb_exit;
Expand Down Expand Up @@ -490,24 +494,35 @@ int flb_plugin_proxy_register(struct flb_plugin_proxy *proxy,
return 0;
}

int flb_plugin_proxy_output_init(struct flb_plugin_proxy *proxy,
struct flb_output_instance *o_ins,
struct flb_config *config)
int flb_proxy_output_cb_init(struct flb_output_instance *o_ins,
struct flb_config *config, void *data)
{
int ret = -1;
struct flb_plugin_proxy_context *pc;

/* Before to initialize for proxy, set the proxy instance reference */
pc = (struct flb_plugin_proxy_context *)(o_ins->context);

/* Before to initialize, set the instance reference */
proxy->instance = o_ins;
pc->proxy->instance = o_ins;

/* Based on 'proxy', use the proper handler */
if (proxy->def->proxy == FLB_PROXY_GOLANG) {
if (pc->proxy->def->proxy == FLB_PROXY_GOLANG) {
#ifdef FLB_HAVE_PROXY_GO
ret = proxy_go_output_init(proxy);
ret = proxy_go_output_init(pc->proxy);
#endif
}
else {
flb_error("[proxy] unrecognized proxy handler %i",
proxy->def->proxy);
pc->proxy->def->proxy);
}

/* Multi-threading enabled if configured */
ret = flb_output_enable_multi_threading(o_ins, config);
if (ret == -1) {
flb_error("[output] could not start thread pool for '%s' plugin",
o_ins->p->name);
return -1;
}

return ret;
Expand Down

0 comments on commit 8fe9412

Please sign in to comment.