Skip to content
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

Conversation

andsel
Copy link
Contributor

@andsel andsel commented Mar 5, 2021

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

Fixes #60

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
@andsel andsel force-pushed the fix/extracted_common_code_in_template_method branch from b59dad2 to 7f05acf Compare March 8, 2021 12:06
@elasticsearch-bot elasticsearch-bot self-assigned this Mar 8, 2021
@kares kares self-requested a review March 8, 2021 15:49
Copy link
Contributor

@kares kares left a 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

Comment on lines 84 to 88
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
Copy link
Contributor

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.

Copy link
Contributor Author

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
@andsel andsel requested a review from kares March 10, 2021 16:55
Copy link
Contributor

@kares kares left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 nice refactoring

@andsel andsel merged commit 418a5b9 into logstash-plugins:master Mar 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Remove duplicated methods in LogStash::Filters::Jdbc::Lookup
3 participants