From 3f43ed94670d860f7f61f697a6af251be70aacf5 Mon Sep 17 00:00:00 2001 From: Hiroshi Hatake Date: Wed, 27 Sep 2023 12:59:23 +0900 Subject: [PATCH] config: plugin_proxy: Pass whether hot-reloading state or not into Golan plugins on pre_exit callbacks Signed-off-by: Hiroshi Hatake --- include/fluent-bit/flb_config.h | 1 + src/flb_config.c | 1 + src/flb_plugin_proxy.c | 14 ++++++++++++++ src/flb_reload.c | 2 ++ 4 files changed, 18 insertions(+) diff --git a/include/fluent-bit/flb_config.h b/include/fluent-bit/flb_config.h index a5955908b88..85e5b77984f 100644 --- a/include/fluent-bit/flb_config.h +++ b/include/fluent-bit/flb_config.h @@ -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; diff --git a/src/flb_config.c b/src/flb_config.c index 882a93c7c1c..aa65a9eb266 100644 --- a/src/flb_config.c +++ b/src/flb_config.c @@ -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); diff --git a/src/flb_plugin_proxy.c b/src/flb_plugin_proxy.c index 5f5698bb594..05a0c6151cf 100644 --- a/src/flb_plugin_proxy.c +++ b/src/flb_plugin_proxy.c @@ -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); @@ -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); diff --git a/src/flb_reload.c b/src/flb_reload.c index 641fa4a66d0..7b113d78204 100644 --- a/src/flb_reload.c +++ b/src/flb_reload.c @@ -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 */