Skip to content

Commit

Permalink
Merge pull request #3302 from ashie/fix-conflict-parser-type
Browse files Browse the repository at this point in the history
parser_csv, parser_syslog: Fix a naming conflict on parser_type
  • Loading branch information
cosmo0920 committed Mar 31, 2021
2 parents d895383 + 5c84037 commit 98600df
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 4 deletions.
4 changes: 2 additions & 2 deletions lib/fluent/plugin/parser_csv.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ class CSVParser < Parser
desc 'The delimiter character (or string) of CSV values'
config_param :delimiter, :string, default: ','
desc 'The parser type used to parse CSV line'
config_param :parser_type, :enum, list: [:normal, :fast], default: :normal
config_param :parser_engine, :enum, list: [:normal, :fast], default: :normal, alias: :parser_type

def configure(conf)
super


if @parser_type == :fast
if @parser_engine == :fast
@quote_char = '"'
@escape_pattern = Regexp.compile(@quote_char * 2)

Expand Down
4 changes: 2 additions & 2 deletions lib/fluent/plugin/parser_syslog.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class SyslogParser < Parser
desc 'Specify time format for event time for rfc5424 protocol'
config_param :rfc5424_time_format, :string, default: "%Y-%m-%dT%H:%M:%S.%L%z"
desc 'The parser type used to parse syslog message'
config_param :parser_type, :enum, list: [:regexp, :string], default: :regexp
config_param :parser_engine, :enum, list: [:regexp, :string], default: :regexp, alias: :parser_type
desc 'support colonless ident in string parser'
config_param :support_colonless_ident, :bool, default: true

Expand All @@ -79,7 +79,7 @@ def initialize
def configure(conf)
super

@regexp_parser = @parser_type == :regexp
@regexp_parser = @parser_engine == :regexp
@regexp = case @message_format
when :rfc3164
if @regexp_parser
Expand Down
14 changes: 14 additions & 0 deletions test/plugin/test_parser_csv.rb
Original file line number Diff line number Diff line change
Expand Up @@ -183,4 +183,18 @@ def test_incompatibility_between_normal_and_fast_parser
# And more...
end
end

# "parser_type" config shouldn't hide Fluent::Plugin::Parser#plugin_type
# https://github.com/fluent/fluentd/issues/3296
data('normal' => :normal, 'fast' => :fast)
def test_parser_type_method(engine)
d = create_driver('keys' => '["time"]','time_key' => 'time', 'parser_type' => engine.to_s)
assert_equal(:text_per_line, d.instance.parser_type)
end

data('normal' => :normal, 'fast' => :fast)
def test_parser_engine(engine)
d = create_driver('keys' => '["time"]', 'time_key' => 'time', 'parser_engine' => engine.to_s)
assert_equal(engine, d.instance.parser_engine)
end
end
14 changes: 14 additions & 0 deletions test/plugin/test_parser_syslog.rb
Original file line number Diff line number Diff line change
Expand Up @@ -633,4 +633,18 @@ def test_parse_with_both_message_type_and_priority(param)
end
end
end

# "parser_type" config shouldn't hide Fluent::Plugin::Parser#plugin_type
# https://github.com/fluent/fluentd/issues/3296
data('regexp' => :regexp, 'fast' => :string)
def test_parser_type_method(engine)
@parser.configure({'parser_type' => engine.to_s})
assert_equal(:text_per_line, @parser.instance.parser_type)
end

data('regexp' => :regexp, 'string' => :string)
def test_parser_engine(engine)
d = @parser.configure({'parser_engine' => engine.to_s})
assert_equal(engine, @parser.instance.parser_engine)
end
end

0 comments on commit 98600df

Please sign in to comment.