From bb63df1b4efce6eec0f42a879bc80daff801daf6 Mon Sep 17 00:00:00 2001 From: Hear_Y Date: Mon, 20 Oct 2025 13:57:36 +0800 Subject: [PATCH 1/4] Supports parsing of basic data types when analyzing YAML configuration files. Signed-off-by: Hear_Y --- lib/fluent/config/yaml_parser/parser.rb | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/fluent/config/yaml_parser/parser.rb b/lib/fluent/config/yaml_parser/parser.rb index 862f774802..69f0806ac5 100644 --- a/lib/fluent/config/yaml_parser/parser.rb +++ b/lib/fluent/config/yaml_parser/parser.rb @@ -144,8 +144,12 @@ def section_build(name, config, indent: 0, arg: nil) config.each do |key, val| if val.is_a?(Array) - val.each do |v| - sb.add_section(section_build(key, v, indent: indent + @base_indent)) + if val.all?{ |item| basic_type?(item) } + sb.add_line(key, val) + else + val.each do |v| + sb.add_section(section_build(key, v, indent: indent + @base_indent)) + end end elsif val.is_a?(Hash) harg = val.delete('$arg') @@ -164,6 +168,9 @@ def section_build(name, config, indent: 0, arg: nil) SectionBuilder.new(name, sb, indent, arg) end + def basic_type?(value) + [Integer, Float, String, TrueClass, FalseClass, NilClass].any?{ |type| value.is_a?(type) } + end end end end From 0e23aeefc552c9b3c01758f53d9b542bbdef2aca Mon Sep 17 00:00:00 2001 From: spairy Date: Tue, 21 Oct 2025 12:27:50 +0800 Subject: [PATCH 2/4] Update lib/fluent/config/yaml_parser/parser.rb Co-authored-by: Daijiro Fukuda Signed-off-by: Hear_Y --- lib/fluent/config/yaml_parser/parser.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/fluent/config/yaml_parser/parser.rb b/lib/fluent/config/yaml_parser/parser.rb index 69f0806ac5..696bc00807 100644 --- a/lib/fluent/config/yaml_parser/parser.rb +++ b/lib/fluent/config/yaml_parser/parser.rb @@ -144,12 +144,12 @@ def section_build(name, config, indent: 0, arg: nil) config.each do |key, val| if val.is_a?(Array) - if val.all?{ |item| basic_type?(item) } - sb.add_line(key, val) - else + if section?(val.first) val.each do |v| sb.add_section(section_build(key, v, indent: indent + @base_indent)) end + else + sb.add_line(key, val) end elsif val.is_a?(Hash) harg = val.delete('$arg') From 2264e5e4bcd6d71d86696e94fd87f0b5d4c6d9b6 Mon Sep 17 00:00:00 2001 From: spairy Date: Tue, 21 Oct 2025 12:28:10 +0800 Subject: [PATCH 3/4] Update lib/fluent/config/yaml_parser/parser.rb Co-authored-by: Daijiro Fukuda Signed-off-by: Hear_Y Supports parsing array of basic data types when analyzing YAML configuration files. Signed-off-by: Hear_Y --- lib/fluent/config/yaml_parser/parser.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/fluent/config/yaml_parser/parser.rb b/lib/fluent/config/yaml_parser/parser.rb index 696bc00807..2d9410bce2 100644 --- a/lib/fluent/config/yaml_parser/parser.rb +++ b/lib/fluent/config/yaml_parser/parser.rb @@ -168,8 +168,9 @@ def section_build(name, config, indent: 0, arg: nil) SectionBuilder.new(name, sb, indent, arg) end - def basic_type?(value) - [Integer, Float, String, TrueClass, FalseClass, NilClass].any?{ |type| value.is_a?(type) } + + def section?(value) + value.is_a?(Array) or value.is_a?(Hash) end end end From 2c05c83c6e265b1c3f58d963e3098e73e5547741 Mon Sep 17 00:00:00 2001 From: Daijiro Fukuda Date: Tue, 21 Oct 2025 18:02:08 +0900 Subject: [PATCH 4/4] add tests Signed-off-by: Daijiro Fukuda --- test/test_config.rb | 149 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 149 insertions(+) diff --git a/test/test_config.rb b/test/test_config.rb index 7533e6e16b..019a534758 100644 --- a/test/test_config.rb +++ b/test/test_config.rb @@ -343,6 +343,155 @@ def test_check_not_fetchd 10.times { match_conf['type'] } assert_equal before_size, match_conf.unused.size end + + data( + "One String for $arg" => <<~CONF, + config: + - source: + $type: sample + tag: test + - match: + $type: stdout + $tag: test.** + buffer: + $arg: tag + $type: memory + flush_mode: immediate + CONF + "Comma-separated String for $arg" => <<~CONF, + config: + - source: + $type: sample + tag: test + - match: + $type: stdout + $tag: test.** + buffer: + $arg: tag, time + $type: memory + timekey: 1h + flush_mode: immediate + CONF + "One-liner Array for $arg" => <<~CONF, + config: + - source: + $type: sample + tag: test + - match: + $type: stdout + $tag: test.** + buffer: + $arg: [tag, time] + $type: memory + timekey: 1h + flush_mode: immediate + CONF + "Multi-liner Array for $arg" => <<~CONF, + config: + - source: + $type: sample + tag: test + - match: + $type: stdout + $tag: test.** + buffer: + $arg: + - tag + - time + $type: memory + timekey: 1h + flush_mode: immediate + CONF + "One String for normal Array option" => <<~CONF, + config: + - source: + $type: sample + tag: test + - match: + $type: stdout + $tag: test.** + format: + $type: csv + fields: message + CONF + "Comma-separated String for normal Array option" => <<~CONF, + config: + - source: + $type: sample + tag: test + - match: + $type: stdout + $tag: test.** + inject: + time_key: timestamp + time_type: string + format: + $type: csv + fields: timestamp, message + CONF + "One-liner Array for normal Array option" => <<~CONF, + config: + - source: + $type: sample + tag: test + - match: + $type: stdout + $tag: test.** + inject: + time_key: timestamp + time_type: string + format: + $type: csv + fields: [timestamp, message] + CONF + "Multi-liner Array for normal Array option" => <<~CONF, + config: + - source: + $type: sample + tag: test + - match: + $type: stdout + $tag: test.** + inject: + time_key: timestamp + time_type: string + format: + $type: csv + fields: + - timestamp + - message + CONF + "Multiple sections" => <<~CONF, + config: + - source: + $type: sample + tag: test + - match: + $type: copy + $tag: test.** + store: + - $type: relabel + $label: "@foo" + - $type: relabel + $label: "@bar" + - label: + $name: "@foo" + config: + - match: + $type: stdout + $tag: test.** + - label: + $name: "@bar" + config: + - match: + $type: stdout + $tag: test.** + CONF + ) + test "Can parse config without error" do |conf| + write_config "#{TMP_DIR}/config.yaml", conf + read_config("#{TMP_DIR}/config.yaml", use_yaml: true) + end end def write_config(path, data, encoding: 'utf-8')