Skip to content

Commit

Permalink
Fix a bug when path has tag[\d+]
Browse files Browse the repository at this point in the history
  • Loading branch information
ganmacs committed Aug 12, 2016
1 parent efa3991 commit b169908
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
6 changes: 3 additions & 3 deletions lib/fluent/plugin/out_secondary_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def extract_placeholders(str, chunk)
private

def configure_path!
matched = @path.scan(/\${([\w.@-]+)}/).flat_map { |e| e } # for suporting 2.1 or less
matched = @path.scan(/\${([\w.@-]+(\[\d+\])?)}/).flat_map(&:first) # to trim suffix [\d+]
if matched.empty? && !path_has_time_format?
if pos = @path.index('*')
@path_prefix = @path[0, pos]
Expand All @@ -121,9 +121,9 @@ def validate_path_is_comptible_with_primary_buffer?(matched)
raise "TimeFormat is not imcompatible with primary buffer's params" if !@chunk_key_time && path_has_time_format?
matched.each do |e|
case
when @chunk_key_tag && e =~ /tag\w*/
when @chunk_key_tag && e =~ /tag(\[\d+\])?/
# ok
when !@chunk_key_tag && e =~ /tag\w*/
when !@chunk_key_tag && e =~ /tag(\[\d+\])?/
raise "#{e} is not imcompatible with primary buffer's params"
when @chunk_keys.include?(e.to_sym)
# ok
Expand Down
21 changes: 19 additions & 2 deletions test/plugin/test_out_secondary_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ def create_es_chunk(metadata, es)

data(
invalid_tag: "#{TMP_DIR}/${tag}",
invalid_tag0: "#{TMP_DIR}/${tag0}",
invalid_tag0: "#{TMP_DIR}/${tag[0]}",
invalid_variable: "#{TMP_DIR}/${dummy}",
invalid_timeformat: "#{TMP_DIR}/%Y%m%d",
)
Expand Down Expand Up @@ -237,7 +237,24 @@ def create_es_chunk(metadata, es)
path = d.instance.write(c)
assert_equal "#{TMP_DIR}/out_file_test/cool_test.dummy_0.log.gz", path
end
# 複数タグ

test 'path includes /tag[\d+]/' do
primary = DummyOutput.new.tap do |e|
e.register_value('chunk_key_tag', true)
e.register_value('chunk_keys', [])
end

d = create_driver(%[
path #{TMP_DIR}/out_file_test/cool_${tag[0]}_${tag[1]}
compress gz
], primary)

c = create_es_chunk(create_metadata(nil, "test.dummy"), @es)

path = d.instance.write(c)
assert_equal "#{TMP_DIR}/out_file_test/cool_test_dummy_0.log.gz", path
end


test 'path includes time format' do
primary = DummyOutput.new.tap do |e|
Expand Down

0 comments on commit b169908

Please sign in to comment.