-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Port parser filter from fluent-plugin-parser. fix #1189 #1191
Conversation
8824827
to
ebd5cf5
Compare
@tagomoris We can't set |
Reaming task is replacing |
Don't set |
Fluent::Test.setup | ||
@tag = 'test' | ||
@default_time = Time.parse('2010-05-04 03:02:01 UTC') | ||
Timecop.freeze(@default_time) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we restore Time with Timecop.return
in #teardown
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
right
self | ||
end | ||
|
||
def filter_stream(tag, es) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is just a comment. Feel free to ignore this.
I think that we can use #filter_with_time
instead of #filter_stream
here.
Adopting to filter pipeline should be next task?
config_param :inject_key_prefix, :string, default: nil | ||
config_param :replace_invalid_sequence, :bool, default: false | ||
config_param :hash_value_field, :string, default: nil | ||
config_param :suppress_parse_error_log, :bool, default: false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's no need to use, but to use error stream instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems good. I will rewrite it.
Default filter_stream implementation catches exceptions and exceptions are routed to error stream. So warning tests are changed to log check way.
The drawback is parser tries to parse time field even if users don't need parsed time. If this is a critical, we should revive time_parse option.
Several tests are executed by new and compat configurations for checking backward compatibility
030dfd8
to
5ffcb87
Compare
Rebased and apply reviews. |
@tagomoris Could you check this patch again? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added review comments.
config_param :replace_invalid_sequence, :bool, default: false | ||
config_param :hash_value_field, :string, default: nil | ||
|
||
config_section :parse do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's this blank config_section
for?
r = handle_parsed(tag, record, t, values) | ||
return t, r | ||
else | ||
router.emit_error_event(tag, time, record, Fluent::Plugin::Parser::ParserError.new("pattern not match with data '#{raw_value}'")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are there any cases NOT to return values without ParserError?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure but we can't say all existing parsers don't return nil for time and value.
So keeping this behaviour is better for users.
router.emit_error_event(tag, time, record, e) | ||
return FAILED_RESULT | ||
rescue ArgumentError => e | ||
if @replace_invalid_sequence |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's better to do raise unless @replace_invalid_sequence
to reduce nest levels.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good point. I will rewrite these lines.
r | ||
end | ||
|
||
def replace_invalid_byte(string) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can use String#scrub
now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
right.
raise | ||
end | ||
replaced_string = replace_invalid_byte(raw_value) | ||
@parser.parse(replaced_string) do |t, values| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should use retry
with scrubbed string to dedup code.
end | ||
end | ||
|
||
def test_nothing_raised |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto.
INVALID_MESSAGE = 'foo bar' | ||
VALID_MESSAGE = 'col1=foo col2=bar' | ||
|
||
def test_parser_error_warning |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are no assertions about warning.
@d = create_driver(CONFIG_DISABELED_SUPPRESS_PARSE_ERROR_LOG) | ||
end | ||
|
||
def test_raise_exception |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto.
end | ||
end | ||
|
||
def test_nothing_raised |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto.
</parse> | ||
] | ||
|
||
class EnabledSuppressParseErrorLogTest < self |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Migrated plugin code doesn't have suppress_parse_error_log
option.
This test code is outdated, right?
Parser plugin helper can instantiate two or more parsers. So we can add "secondary" parser for the values which don't match the first parser. It's nice to have to replace <parse>
@type json
</parse>
<parse 1>
@type regexp
expression ...
</parse>
<parse 2>
@type regexp
expression ...
</parse>
# snip |
- Use proper assertion - Add data to EventTime and Integer time tests - Extract some assertions for better test cases
Applied reviews. |
@tagomoris It is a good idea > secondary parsers. |
This patch is not the cause of test failure. |
@tagomoris check again. |
invalid_utf8 = "\xff".force_encoding('UTF-8') | ||
|
||
d = create_driver(CONFIG_NOT_REPLACE) | ||
d.run(shutdown: false) do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are there any reason to specify shutdown: false
?
flexmock(d.instance.router).should_receive(:emit_error_event). | ||
with(String, Integer, Hash, ArgumentError.new("data does not exist")).once | ||
assert_nothing_raised { | ||
d.run(shutdown: false) do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
I commented about just one point (twice). Others look good to me. |
Applied all reviews. After test passed, I will merge this PR. |
Changes from original code: