diff --git a/lib/fluent/config/yaml_parser/parser.rb b/lib/fluent/config/yaml_parser/parser.rb index 862f774802..2d9410bce2 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 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') @@ -164,6 +168,10 @@ def section_build(name, config, indent: 0, arg: nil) SectionBuilder.new(name, sb, indent, arg) end + + def section?(value) + value.is_a?(Array) or value.is_a?(Hash) + end end end end 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')