Skip to content

Commit

Permalink
Add option -a, --dump-config to print read configuration on startup
Browse files Browse the repository at this point in the history
This can be useful for debugging purposes when e.g. a lot of includes are used.

Signed-off-by: Richard Treu <[email protected]>
  • Loading branch information
drbugfinder-work committed Sep 17, 2024
1 parent 12a9de5 commit 48f74e6
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
16 changes: 16 additions & 0 deletions src/config_format/flb_config_format.c
Original file line number Diff line number Diff line change
Expand Up @@ -752,6 +752,10 @@ static void dump_section(struct flb_cf_section *s)
struct cfl_kvpair *kv;
struct flb_cf_group *g;

if (!s) {
return;
}

printf("> section:\n name: %s\n type: %s\n",
s->name, section_type_str(s->type));

Expand Down Expand Up @@ -793,6 +797,10 @@ static void dump_env(struct mk_list *list)
struct mk_list *head;
struct flb_kv *kv;

if (!list) {
return;
}

if (mk_list_size(list) == 0) {
return;
}
Expand All @@ -810,6 +818,10 @@ static void dump_metas(struct mk_list *list)
struct mk_list *head;
struct flb_kv *kv;

if (!list) {
return;
}

if (mk_list_size(list) == 0) {
return;
}
Expand All @@ -827,6 +839,10 @@ static void dump_section_list(struct mk_list *list)
struct mk_list *head;
struct flb_cf_section *s;

if (!list) {
return;
}

mk_list_foreach(head, list) {
s = mk_list_entry(head, struct flb_cf_section, _head);
dump_section(s);
Expand Down
21 changes: 20 additions & 1 deletion src/fluent-bit.c
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ static void flb_help(int rc, struct flb_config *config)
print_opt("-q, --quiet", "quiet mode");
print_opt("-S, --sosreport", "support report for Enterprise customers");
print_opt("-Y, --enable-hot-reload", "enable for hot reloading");
print_opt("-a, --dump-config", "print configuration on startup");
print_opt("-W, --disable-thread-safety-on-hot-reloading", "disable thread safety on hot reloading");
print_opt("-V, --version", "show version number");
print_opt("-h, --help", "print this help");
Expand Down Expand Up @@ -948,13 +949,17 @@ int flb_main(int argc, char **argv)
int opt;
int ret;
flb_sds_t json;
int dump_cfg;

/* handle plugin properties: -1 = none, 0 = input, 1 = output */
int last_plugin = -1;

/* local variables to handle config options */
char *cfg_file = NULL;

/* do not dump config file on default */
dump_cfg = FLB_FALSE;

/* config format context */
struct flb_cf *cf;
struct flb_cf *tmp;
Expand Down Expand Up @@ -1024,6 +1029,7 @@ int flb_main(int argc, char **argv)
{ "http_listen", required_argument, NULL, 'L' },
{ "http_port", required_argument, NULL, 'P' },
#endif
{ "dump-config", no_argument , NULL, 'a' },
{ "enable-hot-reload", no_argument, NULL, 'Y' },
#ifdef FLB_HAVE_CHUNK_TRACE
{ "enable-chunk-trace", no_argument, NULL, 'Z' },
Expand Down Expand Up @@ -1063,7 +1069,7 @@ int flb_main(int argc, char **argv)
/* Parse the command line options */
while ((opt = getopt_long(argc, argv,
"b:c:dDf:C:i:m:o:R:F:p:e:"
"t:T:l:vw:qVhJL:HP:s:SWYZ",
"t:T:l:vw:qVhJL:HP:s:SWaYZ",
long_opts, NULL)) != -1) {

switch (opt) {
Expand Down Expand Up @@ -1221,6 +1227,9 @@ int flb_main(int argc, char **argv)
case 'Y':
flb_cf_section_property_add(cf_opts, service->properties, FLB_CONF_STR_HOT_RELOAD, 0, "on", 0);
break;
case 'a':
dump_cfg = FLB_TRUE;
break;
case 'W':
flb_cf_section_property_add(cf_opts, service->properties,
FLB_CONF_STR_HOT_RELOAD_ENSURE_THREAD_SAFETY, 0, "off", 0);
Expand Down Expand Up @@ -1314,6 +1323,16 @@ int flb_main(int argc, char **argv)
cf = tmp;
#endif

/* Print read config for debugging purposes */
if(dump_cfg) {
if (cf) {
fprintf(stderr, "[debug] read configuration:\n");
flb_cf_dump(cf);
fflush(stdout);
fflush(stderr);
}
}

/* Check co-routine stack size */
if (config->coro_stack_size < getpagesize()) {
flb_cf_destroy(cf_opts);
Expand Down

0 comments on commit 48f74e6

Please sign in to comment.