Skip to content

Commit

Permalink
Merge pull request #2267 from fluent/add-parse-section-checking-in-tc…
Browse files Browse the repository at this point in the history
…p-in-udp

in_tcp: in_udp: Add <parse> section checking. Fix #2266
  • Loading branch information
repeatedly authored Jan 18, 2019
2 parents 2d05002 + 5e299b4 commit 162d20e
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
6 changes: 5 additions & 1 deletion lib/fluent/plugin/in_tcp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,15 @@ class TcpInput < Input

def configure(conf)
compat_parameters_convert(conf, :parser)
parser_config = conf.elements('parse').first
unless parser_config
raise Fluent::ConfigError, "<parse> section is required."
end
super
@_event_loop_blocking_timeout = @blocking_timeout
@source_hostname_key ||= @source_host_key if @source_host_key

@parser = parser_create
@parser = parser_create(conf: parser_config)
end

def multi_workers_ready?
Expand Down
6 changes: 5 additions & 1 deletion lib/fluent/plugin/in_udp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,16 @@ class UdpInput < Input

def configure(conf)
compat_parameters_convert(conf, :parser)
parser_config = conf.elements('parse').first
unless parser_config
raise Fluent::ConfigError, "<parse> section is required."
end
super
@_event_loop_blocking_timeout = @blocking_timeout
@source_hostname_key ||= @source_host_key if @source_host_key
@message_length_limit = @body_size_limit if @body_size_limit

@parser = parser_create
@parser = parser_create(conf: parser_config)
end

def multi_workers_ready?
Expand Down
6 changes: 6 additions & 0 deletions test/plugin/test_in_tcp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ def create_tcp_socket(host, port, &block)
assert_equal "\n", d.instance.delimiter
end

test ' configure w/o parse section' do
assert_raise(Fluent::ConfigError.new("<parse> section is required.")) {
create_driver(BASE_CONFIG)
}
end

test_case_data = {
'none' => {
'format' => 'none',
Expand Down
6 changes: 6 additions & 0 deletions test/plugin/test_in_udp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ def create_udp_socket(host, port)
assert_equal nil, d.instance.receive_buffer_size
end

test ' configure w/o parse section' do
assert_raise(Fluent::ConfigError.new("<parse> section is required.")) {
create_driver(BASE_CONFIG)
}
end

data(
'ipv4' => [CONFIG, '127.0.0.1', :ipv4],
'ipv6' => [IPv6_CONFIG, '::1', :ipv6],
Expand Down

0 comments on commit 162d20e

Please sign in to comment.