Skip to content

Add half_open_resource_timeout for net http#198

Merged
max611 merged 1 commit into
masterfrom
half_open_http_net
Oct 9, 2018
Merged

Add half_open_resource_timeout for net http#198
max611 merged 1 commit into
masterfrom
half_open_http_net

Conversation

@max611

@max611 max611 commented Sep 28, 2018

Copy link
Copy Markdown
Member

The half_open_resource_timeout feature was introduced here #188 but only for mysql2.

This PR adds it for the net_http adapter. Net::HTTP let us assign the timeout by using read_timeout= .

Comment thread test/net_http_test.rb
end
end

def test_changes_timeout_when_half_open_and_configured

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I'm not sure if I'm doing this right, is there a better way of half opening the circuit?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

There's half_open_circuit!

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I think I'll need help with this test, I can't seem to be able to trigger the right thing. I do hit the with_resource_timeout path but ReadTimeout does not raise.

@max611 max611 requested review from jpittis and sirupsen September 28, 2018 19:31
if half_open? && @half_open_resource_timeout && resource.respond_to?(:with_resource_timeout)
resource.with_resource_timeout(@half_open_resource_timeout) do
result = block.call
result =

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why change this? 👂

@max611 max611 Oct 1, 2018

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Small bikeshed, I can bring back the old syntax. I am used to assigning the value directly from the if, not sure which syntax you guys prefer.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Just for context: The reason this kind of thing might frowned upon is because it causes a 7 line diff that we have to review manually to ensure that a typo size bug isn't added to the library.

Comment thread lib/semian/net_http.rb
Comment thread test/net_http_test.rb
end
end

def test_changes_timeout_when_half_open_and_configured

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

There's half_open_circuit!

Comment thread test/net_http_test.rb Outdated

with_semian_configuration(options) do
with_server do
Timecop.travel(10) do

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can you use an error_timeout variable or index the proc? Makes this easier to understand!

Comment thread test/net_http_test.rb Outdated
end
end
open_circuit!
Semian.resources.values.last.mark_failed(nil)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please don't use these low-level APIs 😬 Can you trigger a real failure here like the other tests? This is very implementation specific.

@max611 max611 force-pushed the half_open_http_net branch 6 times, most recently from 8956e32 to cd7831e Compare October 2, 2018 00:11
Comment thread lib/semian/net_http.rb Outdated
@max611 max611 force-pushed the half_open_http_net branch 3 times, most recently from 42dc068 to 81601db Compare October 3, 2018 13:59
Comment thread test/net_http_test.rb

private

def half_open_cicuit!(backwards_time_travel = 10)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@sirupsen I wanted to use the CircuitBreakerHelper but the half_open_circuit! method uses a open_circuit! method with an argument and when I call half_open_circuit! from the net_http_test file, it calls the open_circuit! method inside net_http_test instead of the open_circuit! method inside the helper which raises. To make it work, I would have to change the open_circuit! method name everywhere. What do you think of simply keeping the half_open_cicuit! method in the net_http_test file?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

That's fine with me.

@max611 max611 force-pushed the half_open_http_net branch from 81601db to bfa0828 Compare October 3, 2018 14:13

@jpittis jpittis left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM.

if half_open? && @half_open_resource_timeout && resource.respond_to?(:with_resource_timeout)
resource.with_resource_timeout(@half_open_resource_timeout) do
result = block.call
result =

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Just for context: The reason this kind of thing might frowned upon is because it causes a 7 line diff that we have to review manually to ensure that a typo size bug isn't added to the library.

@max611 max611 force-pushed the half_open_http_net branch from bfa0828 to 0760dc4 Compare October 9, 2018 14:35
@max611 max611 merged commit 7a6ae68 into master Oct 9, 2018
@max611 max611 deleted the half_open_http_net branch October 9, 2018 15:08
@max611 max611 temporarily deployed to rubygems October 19, 2018 15:07 Inactive
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.

3 participants