Skip to content

Commit

Permalink
config: reload: Save and increment the count of hot-reloaded times
Browse files Browse the repository at this point in the history
Signed-off-by: Hiroshi Hatake <[email protected]>
  • Loading branch information
cosmo0920 committed Sep 6, 2023
1 parent 1a41f49 commit 2aed767
Show file tree
Hide file tree
Showing 3 changed files with 11 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 @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/flb_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
9 changes: 9 additions & 0 deletions src/flb_reload.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -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;
}

0 comments on commit 2aed767

Please sign in to comment.