From 48f74e681283137368c64648ec04926525d7b937 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/config_format/flb_config_format.c | 16 ++++++++++++++++ src/fluent-bit.c | 21 ++++++++++++++++++++- 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/src/config_format/flb_config_format.c b/src/config_format/flb_config_format.c index 2a6ab5f4601..10f72b7c3aa 100644 --- a/src/config_format/flb_config_format.c +++ b/src/config_format/flb_config_format.c @@ -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)); @@ -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; } @@ -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; } @@ -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); diff --git a/src/fluent-bit.c b/src/fluent-bit.c index d35e034ed20..1b1161310a6 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) { + 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);