Skip to content

Commit 48f74e6

Browse files
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 <richard.treu@sap.com>
1 parent 12a9de5 commit 48f74e6

2 files changed

Lines changed: 36 additions & 1 deletion

File tree

src/config_format/flb_config_format.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -752,6 +752,10 @@ static void dump_section(struct flb_cf_section *s)
752752
struct cfl_kvpair *kv;
753753
struct flb_cf_group *g;
754754

755+
if (!s) {
756+
return;
757+
}
758+
755759
printf("> section:\n name: %s\n type: %s\n",
756760
s->name, section_type_str(s->type));
757761

@@ -793,6 +797,10 @@ static void dump_env(struct mk_list *list)
793797
struct mk_list *head;
794798
struct flb_kv *kv;
795799

800+
if (!list) {
801+
return;
802+
}
803+
796804
if (mk_list_size(list) == 0) {
797805
return;
798806
}
@@ -810,6 +818,10 @@ static void dump_metas(struct mk_list *list)
810818
struct mk_list *head;
811819
struct flb_kv *kv;
812820

821+
if (!list) {
822+
return;
823+
}
824+
813825
if (mk_list_size(list) == 0) {
814826
return;
815827
}
@@ -827,6 +839,10 @@ static void dump_section_list(struct mk_list *list)
827839
struct mk_list *head;
828840
struct flb_cf_section *s;
829841

842+
if (!list) {
843+
return;
844+
}
845+
830846
mk_list_foreach(head, list) {
831847
s = mk_list_entry(head, struct flb_cf_section, _head);
832848
dump_section(s);

src/fluent-bit.c

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ static void flb_help(int rc, struct flb_config *config)
165165
print_opt("-q, --quiet", "quiet mode");
166166
print_opt("-S, --sosreport", "support report for Enterprise customers");
167167
print_opt("-Y, --enable-hot-reload", "enable for hot reloading");
168+
print_opt("-a, --dump-config", "print configuration on startup");
168169
print_opt("-W, --disable-thread-safety-on-hot-reloading", "disable thread safety on hot reloading");
169170
print_opt("-V, --version", "show version number");
170171
print_opt("-h, --help", "print this help");
@@ -948,13 +949,17 @@ int flb_main(int argc, char **argv)
948949
int opt;
949950
int ret;
950951
flb_sds_t json;
952+
int dump_cfg;
951953

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

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

960+
/* do not dump config file on default */
961+
dump_cfg = FLB_FALSE;
962+
958963
/* config format context */
959964
struct flb_cf *cf;
960965
struct flb_cf *tmp;
@@ -1024,6 +1029,7 @@ int flb_main(int argc, char **argv)
10241029
{ "http_listen", required_argument, NULL, 'L' },
10251030
{ "http_port", required_argument, NULL, 'P' },
10261031
#endif
1032+
{ "dump-config", no_argument , NULL, 'a' },
10271033
{ "enable-hot-reload", no_argument, NULL, 'Y' },
10281034
#ifdef FLB_HAVE_CHUNK_TRACE
10291035
{ "enable-chunk-trace", no_argument, NULL, 'Z' },
@@ -1063,7 +1069,7 @@ int flb_main(int argc, char **argv)
10631069
/* Parse the command line options */
10641070
while ((opt = getopt_long(argc, argv,
10651071
"b:c:dDf:C:i:m:o:R:F:p:e:"
1066-
"t:T:l:vw:qVhJL:HP:s:SWYZ",
1072+
"t:T:l:vw:qVhJL:HP:s:SWaYZ",
10671073
long_opts, NULL)) != -1) {
10681074

10691075
switch (opt) {
@@ -1221,6 +1227,9 @@ int flb_main(int argc, char **argv)
12211227
case 'Y':
12221228
flb_cf_section_property_add(cf_opts, service->properties, FLB_CONF_STR_HOT_RELOAD, 0, "on", 0);
12231229
break;
1230+
case 'a':
1231+
dump_cfg = FLB_TRUE;
1232+
break;
12241233
case 'W':
12251234
flb_cf_section_property_add(cf_opts, service->properties,
12261235
FLB_CONF_STR_HOT_RELOAD_ENSURE_THREAD_SAFETY, 0, "off", 0);
@@ -1314,6 +1323,16 @@ int flb_main(int argc, char **argv)
13141323
cf = tmp;
13151324
#endif
13161325

1326+
/* Print read config for debugging purposes */
1327+
if(dump_cfg) {
1328+
if (cf) {
1329+
fprintf(stderr, "[debug] read configuration:\n");
1330+
flb_cf_dump(cf);
1331+
fflush(stdout);
1332+
fflush(stderr);
1333+
}
1334+
}
1335+
13171336
/* Check co-routine stack size */
13181337
if (config->coro_stack_size < getpagesize()) {
13191338
flb_cf_destroy(cf_opts);

0 commit comments

Comments
 (0)