-
Notifications
You must be signed in to change notification settings - Fork 54
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
Extracted template method for static filter #59
Extracted template method for static filter #59
Conversation
In class LogStash::Filters::Jdbc::Lookup the methods fetch(local, event), call_prepared(local, event) shared a lot of logic. Extracted common part in template method name 'retrieve_local_data(local, event, load_method_ref)' and separated the differiation logic in methods: - load_data_from_prepared, used to load data from prepared statement rows - load_data_from_local, used to load data from normal statement rows
b59dad2
to
7f05acf
Compare
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 refactoring.
feel like we should take it a bit further to avoid method lookup on plugin.filter
lib/logstash/filters/jdbc/lookup.rb
Outdated
if @prepared_statement | ||
result = call_prepared(local, event) | ||
load_method_ref = method(:load_data_from_prepared) | ||
else | ||
result = fetch(local, event) # should return a LookupResult | ||
load_method_ref = method(:load_data_from_local) | ||
end |
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.
could we move this whole block to happen during LookupProcessor#initialize
?
enhance
is called on plugin.filter
so we end up doing the method lookup every time.
we should be able to keep the looked up method in an instance field as @prepared_statement
is known ahead.
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.
Thanks @kares to have pointed it out, now the Lookup.initialize
sets by default to load_data_from_local
but when the method Lookup.prepare
is called we switch to load_data_from_prepared
, so essentially we removed the "if"
…a eager way, when the Lookup is configured, so avoid the method selection for every event
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.
👍 nice refactoring
In class LogStash::Filters::Jdbc::Lookup the methods fetch(local, event), call_prepared(local, event) shared a lot of logic.
Extracted common part in template method name 'retrieve_local_data(local, event, load_method_ref)' and separated
the differiation logic in methods:
load_data_from_prepared
, used to load data from prepared statement rowsload_data_from_local
, used to load data from normal statement rowsFixes #60