circuitbox 0.10.0 → 0.10.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +8 -4
- data/lib/circuitbox/faraday_middleware.rb +1 -8
- data/lib/circuitbox/version.rb +1 -1
- data/test/faraday_middleware_test.rb +4 -5
- data/test/integration/faraday_middleware_test.rb +21 -12
- data/test/integration_helper.rb +8 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7d3753a1304b550e062e4956cb9c4ddd366a1916
|
4
|
+
data.tar.gz: 837d1d4e71f5ddaa3b9434d6333d846043d73303
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e12e4b470624fc64ca42ada7b624c4233b0d8f80d6ac98d244833a0de261ef3d0e09b11205e6740a3a24514cccad03a959780dc9cae75f56a6ac83ee26435186
|
7
|
+
data.tar.gz: 5a81d87b4a22644b5ea2bacf5a3ee2193ddbd896b15991f41ca9a21ae446fc74a844938cc9b761e2afe38b273cea4be184b84e43d892761d5c6d185e34478f58
|
data/README.md
CHANGED
@@ -94,7 +94,7 @@ class CircuitOpenException < StandardError ; end
|
|
94
94
|
|
95
95
|
ActiveSupport::Notifications.subscribe('circuit_open') do |name, start, finish, id, payload|
|
96
96
|
circuit_name = payload[:circuit]
|
97
|
-
Rails.logger.
|
97
|
+
Rails.logger.warn("Open circuit for: #{circuit_name}")
|
98
98
|
end
|
99
99
|
ActiveSupport::Notifications.subscribe('circuit_close') do |name, start, finish, id, payload|
|
100
100
|
circuit_name = payload[:circuit]
|
@@ -196,17 +196,21 @@ conn.get("/api", circuit_breaker_run_options: {})
|
|
196
196
|
c.use Circuitbox::FaradayMiddleware, circuit_breaker_options: {}
|
197
197
|
```
|
198
198
|
|
199
|
-
|
200
|
-
* `open_circuit` lambda determining what response is considered a failure,
|
199
|
+
* `open_circuit` lambda determining what response is considered a failure,
|
201
200
|
counting towards the opening of the circuit
|
202
201
|
|
203
202
|
```ruby
|
204
203
|
c.use Circuitbox::FaradayMiddleware, open_circuit: lambda { |response| response.status >= 500 }
|
205
204
|
```
|
205
|
+
|
206
206
|
## CHANGELOG
|
207
|
-
|
207
|
+
|
208
208
|
### version next
|
209
209
|
|
210
|
+
### v0.10.1
|
211
|
+
- [Documentation fix](https://github.com/yammer/circuitbox/pull/29) [chiefcll](https://github.com/chiefcll)
|
212
|
+
- [Faraday middleware fix](https://github.com/yammer/circuitbox/pull/30) [chiefcll](https://github.com/chiefcll)
|
213
|
+
|
210
214
|
### v0.10
|
211
215
|
- configuration option for faraday middleware for what should be considered to open the circuit [enrico-scalavio](https://github.com/enrico-scalavino)
|
212
216
|
- fix for issue 16, support of in_parallel requests in faraday middlware which were opening the circuit.
|
@@ -29,7 +29,6 @@ class Circuitbox
|
|
29
29
|
|
30
30
|
def call(request_env)
|
31
31
|
service_response = nil
|
32
|
-
check_circuit_open!(request_env)
|
33
32
|
circuit(request_env).run!(run_options(request_env)) do
|
34
33
|
@app.call(request_env).on_complete do |env|
|
35
34
|
service_response = Faraday::Response.new(env)
|
@@ -50,11 +49,6 @@ class Circuitbox
|
|
50
49
|
|
51
50
|
private
|
52
51
|
|
53
|
-
def check_circuit_open!(env)
|
54
|
-
# raises if the circuit is open
|
55
|
-
circuit(env).run!(run_options(env)) { :noop }
|
56
|
-
end
|
57
|
-
|
58
52
|
def run_options(env)
|
59
53
|
env[:circuit_breaker_run_options] || {}
|
60
54
|
end
|
@@ -64,8 +58,7 @@ class Circuitbox
|
|
64
58
|
|
65
59
|
@circuit_breaker_options = opts.fetch(:circuit_breaker_options, {})
|
66
60
|
@circuit_breaker_options.merge!(
|
67
|
-
exceptions: opts.fetch(:exceptions, DEFAULT_EXCEPTIONS)
|
68
|
-
volume_threshold: 10
|
61
|
+
exceptions: opts.fetch(:exceptions, DEFAULT_EXCEPTIONS)
|
69
62
|
)
|
70
63
|
end
|
71
64
|
|
data/lib/circuitbox/version.rb
CHANGED
@@ -7,7 +7,7 @@ class Circuitbox
|
|
7
7
|
class FaradayMiddlewareTest < Minitest::Test
|
8
8
|
|
9
9
|
attr_reader :app
|
10
|
-
|
10
|
+
|
11
11
|
def setup
|
12
12
|
@app = gimme
|
13
13
|
end
|
@@ -84,7 +84,7 @@ class Circuitbox
|
|
84
84
|
env = { url: "url", circuit_breaker_run_options: :sential }
|
85
85
|
middleware = FaradayMiddleware.new(app, circuitbox: circuitbox)
|
86
86
|
middleware.call(env)
|
87
|
-
verify(circuit,
|
87
|
+
verify(circuit, 1.times).run!(:sential)
|
88
88
|
end
|
89
89
|
|
90
90
|
def test_pass_circuit_breaker_options
|
@@ -92,15 +92,14 @@ class Circuitbox
|
|
92
92
|
env = { url: "url" }
|
93
93
|
expected_circuit_breaker_options = {
|
94
94
|
sential: :sential,
|
95
|
-
exceptions: FaradayMiddleware::DEFAULT_EXCEPTIONS
|
96
|
-
volume_threshold: 10
|
95
|
+
exceptions: FaradayMiddleware::DEFAULT_EXCEPTIONS
|
97
96
|
}
|
98
97
|
give(circuitbox).circuit("url", expected_circuit_breaker_options) { circuit }
|
99
98
|
options = { circuitbox: circuitbox, circuit_breaker_options: { sential: :sential } }
|
100
99
|
middleware = FaradayMiddleware.new(app, options)
|
101
100
|
middleware.call(env)
|
102
101
|
|
103
|
-
verify(circuitbox,
|
102
|
+
verify(circuitbox, 1.times).circuit("url", expected_circuit_breaker_options)
|
104
103
|
end
|
105
104
|
|
106
105
|
def test_overwrite_circuitbreaker_default_value
|
@@ -2,7 +2,12 @@ require "integration_helper"
|
|
2
2
|
require "typhoeus/adapters/faraday"
|
3
3
|
|
4
4
|
class Circuitbox
|
5
|
+
|
5
6
|
class FaradayMiddlewareTest < Minitest::Test
|
7
|
+
include IntegrationHelpers
|
8
|
+
|
9
|
+
attr_reader :connection, :success_url, :failure_url
|
10
|
+
|
6
11
|
@@only_once = false
|
7
12
|
def setup
|
8
13
|
@connection = Faraday.new do |c|
|
@@ -22,30 +27,34 @@ class Circuitbox
|
|
22
27
|
Circuitbox.reset
|
23
28
|
end
|
24
29
|
|
30
|
+
def test_circuit_does_not_open_for_below_threshhold_failed_requests
|
31
|
+
5.times { connection.get(failure_url) }
|
32
|
+
assert_equal connection.get(success_url).status, 200
|
33
|
+
end
|
34
|
+
|
25
35
|
def test_failure_circuit_response
|
26
|
-
failure_response =
|
36
|
+
failure_response = connection.get(failure_url)
|
27
37
|
assert_equal failure_response.status, 503
|
28
38
|
assert_match failure_response.original_response.body, "Failure!"
|
29
39
|
end
|
30
40
|
|
31
41
|
def test_open_circuit_response
|
32
|
-
|
33
|
-
|
34
|
-
open_circuit_response = @connection.get(@failure_url)
|
42
|
+
open_circuit
|
43
|
+
open_circuit_response = connection.get(failure_url)
|
35
44
|
assert_equal open_circuit_response.status, 503
|
36
45
|
assert open_circuit_response.original_response.nil?
|
37
46
|
end
|
38
47
|
|
39
48
|
def test_closed_circuit_response
|
40
|
-
result =
|
49
|
+
result = connection.get(success_url)
|
41
50
|
assert result.success?
|
42
51
|
end
|
43
52
|
|
44
53
|
def test_parallel_requests_closed_circuit_response
|
45
54
|
response_1, response_2 = nil
|
46
|
-
|
47
|
-
response_1 =
|
48
|
-
response_2 =
|
55
|
+
connection.in_parallel do
|
56
|
+
response_1 = connection.get(success_url)
|
57
|
+
response_2 = connection.get(success_url)
|
49
58
|
end
|
50
59
|
|
51
60
|
assert response_1.success?
|
@@ -53,11 +62,11 @@ class Circuitbox
|
|
53
62
|
end
|
54
63
|
|
55
64
|
def test_parallel_requests_open_circuit_response
|
56
|
-
|
65
|
+
open_circuit
|
57
66
|
response_1, response_2 = nil
|
58
|
-
|
59
|
-
response_1 =
|
60
|
-
response_2 =
|
67
|
+
connection.in_parallel do
|
68
|
+
response_1 = connection.get(failure_url)
|
69
|
+
response_2 = connection.get(failure_url)
|
61
70
|
end
|
62
71
|
|
63
72
|
assert_equal response_1.status, 503
|
data/test/integration_helper.rb
CHANGED
@@ -38,3 +38,11 @@ class FakeServer
|
|
38
38
|
sleep 0.5 # wait for the server to spin up
|
39
39
|
end
|
40
40
|
end
|
41
|
+
|
42
|
+
module IntegrationHelpers
|
43
|
+
def open_circuit
|
44
|
+
volume_threshold = Circuitbox['test'].option_value(:volume_threshold)
|
45
|
+
(volume_threshold + 1).times { connection.get(failure_url) }
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: circuitbox
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.10.
|
4
|
+
version: 0.10.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Fahim Ferdous
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-05-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|