1818require 'open3'
1919require 'pathname'
2020require 'find'
21+ require 'set'
2122
2223require 'fluent/config'
2324require 'fluent/counter'
@@ -796,18 +797,20 @@ def configure(supervisor: false)
796797 $log. warn ( 'the value "-" for `inline_config` is deprecated. See https://github.com/fluent/fluentd/issues/2711' )
797798 @inline_config = STDIN . read
798799 end
800+ parsed_files = Set . new
799801 @conf = Fluent ::Config . build (
800802 config_path : @config_path ,
801803 encoding : @conf_encoding ,
802804 additional_config : @inline_config ,
803805 use_v1_config : @use_v1_config ,
804806 type : @config_file_type ,
807+ on_file_parsed : -> ( path ) { parsed_files << path } ,
805808 )
806809 @system_config = build_system_config ( @conf )
807810
808811 $log. info :supervisor , 'parsing config file is succeeded' , path : @config_path
809812
810- build_additional_configurations do |additional_conf |
813+ build_additional_configurations ( parsed_files ) do |additional_conf |
811814 @conf += additional_conf
812815 end
813816
@@ -854,6 +857,7 @@ def setup_global_logger(supervisor: false)
854857 additional_config : @inline_config ,
855858 use_v1_config : @use_v1_config ,
856859 type : @config_file_type ,
860+ on_file_parsed : nil ,
857861 )
858862 system_config = build_system_config ( conf )
859863
@@ -1088,15 +1092,17 @@ def reload_config
10881092 $log. debug ( 'worker got SIGUSR2' )
10891093
10901094 begin
1095+ parsed_files = Set . new
10911096 conf = Fluent ::Config . build (
10921097 config_path : @config_path ,
10931098 encoding : @conf_encoding ,
10941099 additional_config : @inline_config ,
10951100 use_v1_config : @use_v1_config ,
10961101 type : @config_file_type ,
1102+ on_file_parsed : -> ( path ) { parsed_files << path } ,
10971103 )
10981104
1099- build_additional_configurations do |additional_conf |
1105+ build_additional_configurations ( parsed_files ) do |additional_conf |
11001106 conf += additional_conf
11011107 end
11021108
@@ -1206,7 +1212,7 @@ def build_system_config(conf)
12061212 system_config
12071213 end
12081214
1209- def build_additional_configurations
1215+ def build_additional_configurations ( parsed_files )
12101216 if @system_config . config_include_dir &.empty?
12111217 $log. info :supervisor , 'configuration include directory is disabled'
12121218 return
@@ -1218,11 +1224,17 @@ def build_additional_configurations
12181224 next unless supported_suffixes . include? ( File . extname ( path ) )
12191225 # NOTE: both types of normal config (.conf) and YAML will be loaded.
12201226 # Thus, it does not care whether @config_path is .conf or .yml.
1227+ if parsed_files . include? ( path )
1228+ $log. info :supervisor , 'skip auto loading, it was already loaded' , path : path
1229+ next
1230+ end
1231+
12211232 $log. info :supervisor , 'loading additional configuration file' , path : path
12221233 yield Fluent ::Config . build ( config_path : path ,
12231234 encoding : @conf_encoding ,
12241235 use_v1_config : @use_v1_config ,
1225- type : :guess )
1236+ type : :guess ,
1237+ on_file_parsed : nil )
12261238 end
12271239 rescue Errno ::ENOENT
12281240 $log. info :supervisor , 'inaccessible include directory was specified' , path : @system_config . config_include_dir
0 commit comments