Skip to content

Commit 49f544d

Browse files
committed
system_config: support built-in config files
In the previous versions, if you want to manage multiple configuration files, you must use @include directive. In this commit, add an option to specify the directory (e.g. /etc/fluent/conf.d) which stores additional configuration files. If there are such files under specified directory, they are loaded by default without @include directive. If you want to disable this feature, set empty string for config_include_dir "". Signed-off-by: Kentaro Hayashi <[email protected]>
1 parent 3a6826a commit 49f544d

File tree

4 files changed

+31
-1
lines changed

4 files changed

+31
-1
lines changed

lib/fluent/config/element.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,12 @@ def add_element(name, arg = '')
7171
e
7272
end
7373

74+
def merge_elements(elements)
75+
elements.each do |e|
76+
@elements << e
77+
end
78+
end
79+
7480
def inspect
7581
attrs = super
7682
"name:#{@name}, arg:#{@arg}, " + attrs + ", " + @elements.inspect

lib/fluent/env.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ module Fluent
2424
DEFAULT_PLUGIN_DIR = ENV['FLUENT_PLUGIN'] || '/etc/fluent/plugin'
2525
DEFAULT_SOCKET_PATH = ENV['FLUENT_SOCKET'] || '/var/run/fluent/fluent.sock'
2626
DEFAULT_BACKUP_DIR = ENV['FLUENT_BACKUP_DIR'] || '/tmp/fluent'
27+
DEFAULT_CONFIG_DIR = ENV['FLUENT_CONF_DIR'] || '/etc/fluent/conf.d'
2728
DEFAULT_OJ_OPTIONS = Fluent::OjOptions.load_env
2829
DEFAULT_DIR_PERMISSION = 0755
2930
DEFAULT_FILE_PERMISSION = 0644

lib/fluent/supervisor.rb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
require 'fileutils'
1818
require 'open3'
1919
require 'pathname'
20+
require 'find'
2021

2122
require 'fluent/config'
2223
require 'fluent/counter'
@@ -806,6 +807,26 @@ def configure(supervisor: false)
806807

807808
$log.info :supervisor, 'parsing config file is succeeded', path: @config_path
808809

810+
# merge additional configuration
811+
config_type = if File.extname(@config_path) == '.yaml' || File.extname(@config_path) == '.yml'
812+
:yaml
813+
else
814+
nil
815+
end
816+
Find.find(@system_config.config_include_dir) do |path|
817+
next if File.directory?(path)
818+
if config_type == :yaml
819+
next if File.extname(path) != '.yaml' || File.extname(path) != '.yml'
820+
else
821+
next if File.extname(path) == '.yaml' || File.extname(path) == '.yml'
822+
end
823+
elements = Fluent::Config.build(config_path: path,
824+
encoding: @conf_encoding,
825+
use_v1_config: @use_v1_config,
826+
type: config_type).elements
827+
@conf.merge_elements(elements)
828+
end
829+
809830
@libs.each do |lib|
810831
require lib
811832
end

lib/fluent/system_config.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ class SystemConfig
2828
:without_source, :with_source_only, :rpc_endpoint, :enable_get_dump, :process_name,
2929
:file_permission, :dir_permission, :counter_server, :counter_client,
3030
:strict_config_value, :enable_msgpack_time_support, :disable_shared_socket,
31-
:metrics, :enable_input_metrics, :enable_size_metrics, :enable_jit, :source_only_buffer
31+
:metrics, :enable_input_metrics, :enable_size_metrics, :enable_jit, :source_only_buffer,
32+
:config_include_dir
3233
]
3334

3435
config_param :workers, :integer, default: 1
@@ -58,6 +59,7 @@ class SystemConfig
5859
config_param :dir_permission, default: nil do |v|
5960
v.to_i(8)
6061
end
62+
config_param :config_include_dir, default: ENV["FLUENT_CONF_DIR"] || '/etc/fluent/conf.d'
6163
config_section :log, required: false, init: true, multi: false do
6264
config_param :path, :string, default: nil
6365
config_param :format, :enum, list: [:text, :json], default: :text

0 commit comments

Comments
 (0)