Skip to content

Commit a916014

Browse files
authored
Merge pull request #4478 from fluent/filter-parser-add-error-event-for-multiple-parsed-results
filter_parser: add error event for multiple parsed results
2 parents 8804a80 + bf7c1b8 commit a916014

File tree

1 file changed

+26
-12
lines changed

1 file changed

+26
-12
lines changed

lib/fluent/plugin/filter_parser.rb

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,13 @@ def filter_with_time(tag, time, record)
7070
end
7171
end
7272
begin
73+
# Note: https://github.com/fluent/fluentd/issues/4100
74+
# If the parser returns multiple records from one raw_value,
75+
# this returns only the first one record.
76+
# This should be fixed in the future version.
77+
result_time = nil
78+
result_record = nil
79+
7380
@parser.parse(raw_value) do |t, values|
7481
if values
7582
t = if @reserve_time
@@ -79,24 +86,31 @@ def filter_with_time(tag, time, record)
7986
end
8087
@accessor.delete(record) if @remove_key_name_field
8188
r = handle_parsed(tag, record, t, values)
82-
# Note: https://github.com/fluent/fluentd/issues/4100
83-
# If the parser returns multiple records from one raw_value,
84-
# this returns only the first one record.
85-
# This should be fixed in the future version.
86-
return t, r
89+
90+
if result_record.nil?
91+
result_time = t
92+
result_record = r
93+
else
94+
if @emit_invalid_record_to_error
95+
router.emit_error_event(tag, t, r, Fluent::Plugin::Parser::ParserError.new(
96+
"Could not emit the event. The parser returned multiple results, but currently filter_parser plugin only returns the first parsed result. Raw data: '#{raw_value}'"
97+
))
98+
end
99+
end
87100
else
88101
if @emit_invalid_record_to_error
89102
router.emit_error_event(tag, time, record, Fluent::Plugin::Parser::ParserError.new("pattern not matched with data '#{raw_value}'"))
90103
end
91-
if @reserve_data
92-
t = time
93-
r = handle_parsed(tag, record, time, {})
94-
return t, r
95-
else
96-
return FAILED_RESULT
97-
end
104+
105+
next unless @reserve_data
106+
next unless result_record.nil?
107+
108+
result_time = time
109+
result_record = handle_parsed(tag, record, time, {})
98110
end
99111
end
112+
113+
return result_time, result_record
100114
rescue Fluent::Plugin::Parser::ParserError => e
101115
if @emit_invalid_record_to_error
102116
raise e

0 commit comments

Comments
 (0)