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

Add transparent support for count query embargo on failure. #294

Merged
merged 2 commits into from
Aug 29, 2018

Conversation

guyboertje
Copy link
Contributor

Many folks get errors when using DB drivers that are not supported by adapters in Sequel.

This update traps any errors when doing the first count query and prevents further count queries from being executed.

@guyboertje guyboertje requested a review from jsvd August 13, 2018 11:52
@guyboertje guyboertje self-assigned this Aug 13, 2018
@guyboertje
Copy link
Contributor Author

Changelog and gemspec updates to follow.

@@ -0,0 +1,35 @@

module LogStash module PluginMixins
Copy link
Member

Choose a reason for hiding this comment

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

IMO we should not place plugin specific (or integration specific) mixins in LogStash::PluginMixins, all of these could be namespaced to LogStash::PluginMixins::Jdbc or similar

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed. This is old code but I can fix it now.

@@ -0,0 +1,35 @@

Copy link
Member

Choose a reason for hiding this comment

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

missing encoding header

begin
execute_count(query)
@count_is_supported = true
rescue Exception => e
Copy link
Member

Choose a reason for hiding this comment

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

is there a risk that the query fails here for an arbitrary reason not related to counts?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I suppose so. I'll see if I can find a more specific Exception to rescue.

return unless @in_debug
check_count_query(query) if @needs_check
if @count_is_supported
@logger.debug("Executing JDBC query", :statement => statement, :parameters => parameters, :count => query.count)
Copy link
Member

Choose a reason for hiding this comment

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

since execute_count was implemented to do query.count, maybe we use it here as well?

expect(logger).to receive(:debug).once.with("Executing JDBC query", :statement => settings["statement"], :parameters => {:sql_last_value=>"bar"})
plugin.run(queue)
event = queue.pop
expect(event.get("num")).to eq(1)
Copy link
Member

Choose a reason for hiding this comment

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

this test is about not debugging with a count key, maybe we can remove the remaining assertions and create a separate test to check the presence of things that we expect?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure. I can remove the other expectations, as this context block is a copy of the one at line 1240, those expectations have been verified already.
OTOH, it could be argued that it is important to verify that the normal event creation still occurs when the code from this PR is in the call path and when some degree of stubbing is used.

Copy link
Member

Choose a reason for hiding this comment

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

Agreed it may be desirable to test that but I'd put it into a separate it block that uses the same test setup (thus it is the same scenario we're testing)

@guyboertje
Copy link
Contributor Author

@jsvd

Changelog and gemspec updates made. Is this PR OK now?

Copy link
Member

@jsvd jsvd left a comment

Choose a reason for hiding this comment

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

LGTM

@guyboertje guyboertje merged commit 36d2279 into logstash-plugins:master Aug 29, 2018
@guyboertje guyboertje deleted the fix/287 branch August 29, 2018 08:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants