@@ -1054,6 +1054,129 @@ def test_stop_parallel_old_supervisor_after_delay
10541054 end
10551055 end
10561056
1057+ sub_test_case "include additional configuration" do
1058+ setup do
1059+ @config_include_dir = File . join ( @tmp_dir , "conf.d" )
1060+ FileUtils . mkdir_p ( @config_include_dir )
1061+ end
1062+
1063+ test "no additional configuration" do
1064+ c = Fluent ::Config ::Element . new ( 'system' , '' , { 'config_include_dir' => '' } , [ ] )
1065+ stub ( Fluent ::Config ) . build { config_element ( 'ROOT' , '' , { } , [ c ] ) }
1066+ supervisor = Fluent ::Supervisor . new ( { } )
1067+ stub ( supervisor ) . build_spawn_command { "dummy command line" }
1068+ supervisor . configure ( supervisor : true )
1069+ assert_equal ( [ c ] , supervisor . instance_variable_get ( :@conf ) . elements )
1070+ end
1071+
1072+ data (
1073+ "single source" => [ "forward" ] ,
1074+ "multiple sources" => [ "forward" , "tcp" ] )
1075+ test "additional configuration" do |sources |
1076+ c = Fluent ::Config ::Element . new ( 'system' , '' ,
1077+ { 'config_include_dir' => @config_include_dir } , [ ] )
1078+ config_path = "#{ @config_include_dir } /dummy.conf"
1079+ stub ( Fluent ::Config ) . build ( config_path : "/etc/fluent/fluent.conf" , encoding : "utf-8" ,
1080+ additional_config : anything , use_v1_config : anything ,
1081+ type : anything ) { config_element ( 'ROOT' , '' , { } , [ c ] ) }
1082+ sources . each do |type |
1083+ config = <<~EOF
1084+ <source>
1085+ @type #{ type }
1086+ </source>
1087+ EOF
1088+ additional_config_path = "#{ @config_include_dir } /#{ type } .yml"
1089+ write_config ( additional_config_path , config )
1090+ stub ( Fluent ::Config ) . build ( config_path : additional_config_path , encoding : "utf-8" ,
1091+ use_v1_config : true , type : :guess ) {
1092+ Fluent ::Config . parse ( File . read ( additional_config_path ) , File . dirname ( config_path ) , true )
1093+ }
1094+ end
1095+ supervisor = Fluent ::Supervisor . new ( { } )
1096+ stub ( supervisor ) . build_spawn_command { "dummy command line" }
1097+ supervisor . configure ( supervisor : true )
1098+ expected = [ c ] . concat ( sources . collect { |type | { "@type" => type } } )
1099+ assert_equal ( expected , supervisor . instance_variable_get ( :@conf ) . elements )
1100+ end
1101+
1102+ data (
1103+ "single YAML source" => [ "forward" ] ,
1104+ "multiple YAML sources" => [ "forward" , "tcp" ] )
1105+ test "additional YAML configuration" do |sources |
1106+ c = Fluent ::Config ::Element . new ( 'system' , '' ,
1107+ { 'config_include_dir' => @config_include_dir } , [ ] )
1108+ config_path = "#{ @config_include_dir } /dummy.yml"
1109+ stub ( Fluent ::Config ) . build ( config_path : "/etc/fluent/fluent.conf" , encoding : "utf-8" ,
1110+ additional_config : anything , use_v1_config : anything ,
1111+ type : anything ) { config_element ( 'ROOT' , '' , { } , [ c ] ) }
1112+ sources . each do |type |
1113+ config = <<~EOF
1114+ config:
1115+ - source:
1116+ $type: #{ type }
1117+ EOF
1118+ additional_config_path = "#{ @config_include_dir } /#{ type } .yml"
1119+ write_config ( additional_config_path , config )
1120+ stub ( Fluent ::Config ) . build ( config_path : additional_config_path , encoding : "utf-8" ,
1121+ use_v1_config : true , type : :guess ) {
1122+ Fluent ::Config ::YamlParser . parse ( additional_config_path )
1123+ }
1124+ end
1125+ supervisor = Fluent ::Supervisor . new ( { } )
1126+ stub ( supervisor ) . build_spawn_command { "dummy command line" }
1127+ supervisor . configure ( supervisor : true )
1128+ expected = [ c ] . concat ( sources . collect { |type | { "@type" => type } } )
1129+ assert_equal ( expected , supervisor . instance_variable_get ( :@conf ) . elements )
1130+ end
1131+
1132+ data (
1133+ "single source" => [ false , [ "forward" ] ] ,
1134+ "multiple sources" => [ false , [ "forward" , "tcp" ] ] ,
1135+ "single YAML source" => [ true , [ "forward" ] ] ,
1136+ "multiple YAML sources" => [ true , [ "forward" , "tcp" ] ] )
1137+ test "reload with additional configuration" do |( yaml , sources ) |
1138+ c = Fluent ::Config ::Element . new ( 'system' , '' ,
1139+ { 'config_include_dir' => @config_include_dir } , [ ] )
1140+ config_path = "#{ @config_include_dir } /dummy.yml"
1141+ stub ( Fluent ::Config ) . build ( config_path : "/etc/fluent/fluent.conf" , encoding : "utf-8" ,
1142+ additional_config : anything , use_v1_config : anything ,
1143+ type : anything ) { config_element ( 'ROOT' , '' , { } , [ c ] ) }
1144+ sources . each do |type |
1145+ if yaml
1146+ config = <<~EOF
1147+ config:
1148+ - source:
1149+ $type: #{ type }
1150+ EOF
1151+ additional_config_path = "#{ @config_include_dir } /#{ type } .yml"
1152+ write_config ( additional_config_path , config )
1153+ stub ( Fluent ::Config ) . build ( config_path : additional_config_path , encoding : "utf-8" ,
1154+ use_v1_config : true , type : :guess ) {
1155+ Fluent ::Config ::YamlParser . parse ( additional_config_path )
1156+ }
1157+ else
1158+ config = <<~EOF
1159+ <source>
1160+ @type #{ type }
1161+ </source>
1162+ EOF
1163+ additional_config_path = "#{ @config_include_dir } /#{ type } .conf"
1164+ write_config ( additional_config_path , config )
1165+ stub ( Fluent ::Config ) . build ( config_path : additional_config_path , encoding : "utf-8" ,
1166+ use_v1_config : true , type : :guess ) {
1167+ Fluent ::Config . parse ( File . read ( additional_config_path ) , File . dirname ( config_path ) , true )
1168+ }
1169+ end
1170+ end
1171+ supervisor = Fluent ::Supervisor . new ( { } )
1172+ stub ( supervisor ) . build_spawn_command { "dummy command line" }
1173+ supervisor . configure ( supervisor : true )
1174+ supervisor . __send__ ( :reload_config )
1175+ expected = [ c ] . concat ( sources . collect { |type | { "@type" => type } } )
1176+ assert_equal ( expected , supervisor . instance_variable_get ( :@conf ) . elements )
1177+ end
1178+ end
1179+
10571180 def create_debug_dummy_logger
10581181 dl_opts = { }
10591182 dl_opts [ :log_level ] = ServerEngine ::DaemonLogger ::DEBUG
0 commit comments