diff --git a/include/fluent-bit/flb_config.h b/include/fluent-bit/flb_config.h index 4e1912c6459..59bc3a57c8e 100644 --- a/include/fluent-bit/flb_config.h +++ b/include/fluent-bit/flb_config.h @@ -258,6 +258,7 @@ struct flb_config { int enable_hot_reload; int ensure_thread_safety_on_hot_reloading; + unsigned int hot_reloaded_count; /* Co-routines */ unsigned int coro_stack_size; diff --git a/src/flb_config.c b/src/flb_config.c index 459ff8197dd..76973be6e29 100644 --- a/src/flb_config.c +++ b/src/flb_config.c @@ -274,6 +274,7 @@ struct flb_config *flb_config_init() /* reload */ config->ensure_thread_safety_on_hot_reloading = FLB_TRUE; + config->hot_reloaded_count = 0; #ifdef FLB_HAVE_SQLDB mk_list_init(&config->sqldb_list); diff --git a/src/flb_reload.c b/src/flb_reload.c index 27c5b7f1520..641fa4a66d0 100644 --- a/src/flb_reload.c +++ b/src/flb_reload.c @@ -367,6 +367,7 @@ int flb_reload(flb_ctx_t *ctx, struct flb_cf *cf_opts) struct flb_cf *new_cf; struct flb_cf *original_cf; int verbose; + int reloaded_count = 0; if (ctx == NULL) { flb_error("[reload] given flb context is NULL"); @@ -425,6 +426,8 @@ int flb_reload(flb_ctx_t *ctx, struct flb_cf *cf_opts) /* Inherit verbose from the old ctx instance */ verbose = ctx->config->verbose; new_config->verbose = verbose; + /* Increment and store the number of hot reloaded times */ + reloaded_count = ctx->config->hot_reloaded_count + 1; #ifdef FLB_HAVE_STREAM_PROCESSOR /* Inherit stream processor definitions from command line */ @@ -504,5 +507,11 @@ int flb_reload(flb_ctx_t *ctx, struct flb_cf *cf_opts) ret = flb_start(new_ctx); + /* Store the new value of hot reloading times into the new context */ + if (ret == 0) { + new_config->hot_reloaded_count = reloaded_count; + flb_debug("[reload] hot reloaded %d time(s)", reloaded_count); + } + return 0; }