Skip to content

Commit

Permalink
config: plugin_proxy: Pass whether hot-reloading state or not into Go…
Browse files Browse the repository at this point in the history
…lan plugins on pre_exit callbacks

Signed-off-by: Hiroshi Hatake <[email protected]>
  • Loading branch information
cosmo0920 committed Oct 2, 2023
1 parent 50b35a8 commit 3f43ed9
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions include/fluent-bit/flb_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ struct flb_config {
int enable_hot_reload;
int ensure_thread_safety_on_hot_reloading;
unsigned int hot_reloaded_count;
int shutdown_by_hot_reloading;

/* Co-routines */
unsigned int coro_stack_size;
Expand Down
1 change: 1 addition & 0 deletions src/flb_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ struct flb_config *flb_config_init()
/* reload */
config->ensure_thread_safety_on_hot_reloading = FLB_TRUE;
config->hot_reloaded_count = 0;
config->shutdown_by_hot_reloading = FLB_FALSE;

#ifdef FLB_HAVE_SQLDB
mk_list_init(&config->sqldb_list);
Expand Down
14 changes: 14 additions & 0 deletions src/flb_plugin_proxy.c
Original file line number Diff line number Diff line change
Expand Up @@ -208,11 +208,18 @@ static int flb_proxy_output_cb_exit(void *out_context, struct flb_config *config
{
struct flb_plugin_proxy_context *ctx = out_context;
struct flb_plugin_proxy *proxy = (ctx->proxy);
/* pre_exit (Golang plugin only) */
void (*cb_pre_exit)(int);

if (!out_context) {
return 0;
}

cb_pre_exit = flb_plugin_proxy_symbol(proxy, "FLBPluginOutputPreExit");
if (cb_pre_exit != NULL) {
cb_pre_exit(config->shutdown_by_hot_reloading);
}

if (proxy->def->proxy == FLB_PROXY_GOLANG) {
#ifdef FLB_HAVE_PROXY_GO
proxy_go_output_destroy(ctx);
Expand Down Expand Up @@ -247,11 +254,18 @@ static int flb_proxy_input_cb_exit(void *in_context, struct flb_config *config)
{
struct flb_plugin_input_proxy_context *ctx = in_context;
struct flb_plugin_proxy *proxy = (ctx->proxy);
/* pre_exit (Golang plugin only) */
void (*cb_pre_exit)(int);

if (!in_context) {
return 0;
}

cb_pre_exit = flb_plugin_proxy_symbol(proxy, "FLBPluginInputPreExit");
if (cb_pre_exit != NULL) {
cb_pre_exit(config->shutdown_by_hot_reloading);
}

if (proxy->def->proxy == FLB_PROXY_GOLANG) {
#ifdef FLB_HAVE_PROXY_GO
proxy_go_input_destroy(ctx);
Expand Down
2 changes: 2 additions & 0 deletions src/flb_reload.c
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,8 @@ int flb_reload(flb_ctx_t *ctx, struct flb_cf *cf_opts)
new_config->verbose = verbose;
/* Increment and store the number of hot reloaded times */
reloaded_count = ctx->config->hot_reloaded_count + 1;
/* Mark shutdown reason as hot_reloading */
ctx->config->shutdown_by_hot_reloading = FLB_TRUE;

#ifdef FLB_HAVE_STREAM_PROCESSOR
/* Inherit stream processor definitions from command line */
Expand Down

0 comments on commit 3f43ed9

Please sign in to comment.