From f994e0c0788ee4b8095566d1dd6379e6e56b2bb5 Mon Sep 17 00:00:00 2001 From: Richard Treu Date: Thu, 18 Jul 2024 15:46:25 +0200 Subject: [PATCH] Add option -a, --dump-config to print read configuration on startup This can be useful for debugging purposes when e.g. a lot of includes are used. Signed-off-by: Richard Treu --- src/fluent-bit.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/fluent-bit.c b/src/fluent-bit.c index d35e034ed20..b6d4086f179 100644 --- a/src/fluent-bit.c +++ b/src/fluent-bit.c @@ -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"); @@ -948,6 +949,7 @@ 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; @@ -955,6 +957,9 @@ int flb_main(int argc, char **argv) /* 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; @@ -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' }, @@ -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) { @@ -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); @@ -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) { + printf("\nRead 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);