circuitbox 1.1.0 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +5 -2
- data/Rakefile +23 -11
- data/lib/circuitbox.rb +1 -4
- data/lib/circuitbox/circuit_breaker.rb +5 -9
- data/lib/circuitbox/version.rb +1 -1
- data/test/circuit_breaker_test.rb +8 -0
- metadata +3 -4
- data/lib/circuitbox/memcache_store.rb +0 -31
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6b50bdb4f6ad77ee69e5f67bc61f9ae5e70e32b4
|
4
|
+
data.tar.gz: 86c89e7e0e10bd67349f76e3fee069218b5bb01a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fb6c0076a6689dc2fcc153f11f5060347a544a678b2a74304fa53a1659fa5456037d9642b34d90ce862f48edbc8215dcc0187549d91cface993757afc8413594
|
7
|
+
data.tar.gz: 6cdecb23e5598ae81f621099d5329fc1d133f9acf5f9163a168ba8645615d777441b15045c51e0d16c1c24df56e9210d4bc235fcc6c158bb1ededaced99c1fdb
|
data/README.md
CHANGED
@@ -53,8 +53,11 @@ class ExampleServiceClient
|
|
53
53
|
|
54
54
|
# seconds the circuit stays open once it has passed the error threshold
|
55
55
|
sleep_window: 300,
|
56
|
+
|
57
|
+
# length of interval (in seconds) over which it calculates the error rate
|
58
|
+
time_window: 60,
|
56
59
|
|
57
|
-
# number of requests within
|
60
|
+
# number of requests within `time_window` seconds before it calculates error rates
|
58
61
|
volume_threshold: 10,
|
59
62
|
|
60
63
|
# the store you want to use to save the circuit state so it can be
|
@@ -263,7 +266,7 @@ c.use Circuitbox::FaradayMiddleware, exceptions: [Faraday::Error::TimeoutError]
|
|
263
266
|
with either
|
264
267
|
* a static value
|
265
268
|
* a `lambda` which is passed the `original_response` and `original_error`.
|
266
|
-
`original_response` will be populated if Faraday
|
269
|
+
`original_response` will be populated if Faraday returns an error response,
|
267
270
|
`original_error` will be populated if an error was thrown before Faraday
|
268
271
|
returned a response. (It will also accept a lambda with arity 1 that is
|
269
272
|
only passed `original_response`. This use is deprecated and will be removed
|
data/Rakefile
CHANGED
@@ -1,18 +1,30 @@
|
|
1
|
-
require
|
1
|
+
require "rake/testtask"
|
2
2
|
require "bundler/gem_version_tasks"
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
4
|
+
namespace :test do
|
5
|
+
desc "Run complete test suite"
|
6
|
+
task :all => [:unit, :integration]
|
7
|
+
|
8
|
+
desc "Run unit tests"
|
9
|
+
Rake::TestTask.new(:unit) do |t|
|
10
|
+
t.libs << "test"
|
11
|
+
t.test_files = FileList["test/*_test.rb"]
|
12
|
+
end
|
13
|
+
|
14
|
+
desc "Run integration tests"
|
15
|
+
Rake::TestTask.new(:integration) do |t|
|
16
|
+
t.libs << "test"
|
17
|
+
t.test_files = FileList["test/integration/*_test.rb"]
|
18
|
+
end
|
8
19
|
|
9
|
-
desc "
|
10
|
-
task :benchmark do
|
11
|
-
|
12
|
-
|
13
|
-
|
20
|
+
desc "Run the circuitbox benchmarks"
|
21
|
+
task :benchmark do
|
22
|
+
benchmark_scripts = FileList.new("./benchmark/*_benchmark.rb")
|
23
|
+
benchmark_scripts.each do |script|
|
24
|
+
system "bundle exec ruby #{script}"
|
25
|
+
end
|
14
26
|
end
|
15
27
|
end
|
16
28
|
|
17
29
|
desc "Run tests"
|
18
|
-
task :default => :
|
30
|
+
task :default => ["test:all"]
|
data/lib/circuitbox.rb
CHANGED
@@ -1,15 +1,12 @@
|
|
1
1
|
require 'uri'
|
2
|
-
require 'singleton'
|
3
|
-
require 'active_support'
|
4
2
|
require 'logger'
|
5
3
|
require 'timeout'
|
6
4
|
require 'moneta'
|
5
|
+
require 'active_support/all'
|
7
6
|
|
8
7
|
require 'circuitbox/version'
|
9
|
-
require 'circuitbox/memcache_store'
|
10
8
|
require 'circuitbox/circuit_breaker'
|
11
9
|
require 'circuitbox/notifier'
|
12
|
-
|
13
10
|
require 'circuitbox/errors/error'
|
14
11
|
require 'circuitbox/errors/open_circuit_error'
|
15
12
|
require 'circuitbox/errors/service_failure_error'
|
@@ -47,6 +47,7 @@ class Circuitbox
|
|
47
47
|
if open?
|
48
48
|
logger.debug "[CIRCUIT] open: skipping #{service}"
|
49
49
|
open! unless open_flag?
|
50
|
+
skipped!
|
50
51
|
raise Circuitbox::OpenCircuitError.new(service)
|
51
52
|
else
|
52
53
|
close! if was_open?
|
@@ -170,6 +171,10 @@ class Circuitbox
|
|
170
171
|
log_event :failure
|
171
172
|
end
|
172
173
|
|
174
|
+
def skipped!
|
175
|
+
log_event :skipped
|
176
|
+
end
|
177
|
+
|
173
178
|
# Store success/failure/open/close data in memcache
|
174
179
|
def log_event(event)
|
175
180
|
notifier.new(service,partition).notify(event)
|
@@ -208,15 +213,6 @@ class Circuitbox
|
|
208
213
|
end
|
209
214
|
end
|
210
215
|
|
211
|
-
# Logs to Memcache.
|
212
|
-
def log_event_to_stat_store(key)
|
213
|
-
if stat_store.read(key, raw: true)
|
214
|
-
stat_store.increment(key)
|
215
|
-
else
|
216
|
-
stat_store.store(key, 1)
|
217
|
-
end
|
218
|
-
end
|
219
|
-
|
220
216
|
# For returning stale responses when the circuit is open
|
221
217
|
def response_key(args)
|
222
218
|
Digest::SHA1.hexdigest(storage_key(:cache, args.inspect.to_s))
|
data/lib/circuitbox/version.rb
CHANGED
@@ -231,6 +231,14 @@ class CircuitBreakerTest < Minitest::Test
|
|
231
231
|
emulate_circuit_run(circuit, :failure, Timeout::Error)
|
232
232
|
end
|
233
233
|
|
234
|
+
def test_records_response_skipped
|
235
|
+
circuit = Circuitbox::CircuitBreaker.new(:yammer)
|
236
|
+
circuit.stubs(:open? => true)
|
237
|
+
circuit.stubs(:log_event)
|
238
|
+
circuit.expects(:log_event).with(:skipped)
|
239
|
+
emulate_circuit_run(circuit, :failure, Timeout::Error)
|
240
|
+
end
|
241
|
+
|
234
242
|
def test_records_response_success
|
235
243
|
circuit = Circuitbox::CircuitBreaker.new(:yammer)
|
236
244
|
circuit.expects(:log_event).with(:success)
|
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: 1.1.
|
4
|
+
version: 1.1.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:
|
11
|
+
date: 2017-03-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -257,7 +257,6 @@ files:
|
|
257
257
|
- lib/circuitbox/errors/service_failure_error.rb
|
258
258
|
- lib/circuitbox/excon_middleware.rb
|
259
259
|
- lib/circuitbox/faraday_middleware.rb
|
260
|
-
- lib/circuitbox/memcache_store.rb
|
261
260
|
- lib/circuitbox/notifier.rb
|
262
261
|
- lib/circuitbox/version.rb
|
263
262
|
- test/circuit_breaker_test.rb
|
@@ -290,7 +289,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
290
289
|
version: '0'
|
291
290
|
requirements: []
|
292
291
|
rubyforge_project:
|
293
|
-
rubygems_version: 2.
|
292
|
+
rubygems_version: 2.5.2
|
294
293
|
signing_key:
|
295
294
|
specification_version: 4
|
296
295
|
summary: A robust circuit breaker that manages failing external services.
|
@@ -1,31 +0,0 @@
|
|
1
|
-
module ActiveSupport
|
2
|
-
module Cache
|
3
|
-
class MemcacheStore
|
4
|
-
def initialize(cache)
|
5
|
-
@cache = cache
|
6
|
-
end
|
7
|
-
|
8
|
-
def read(key, options = {})
|
9
|
-
@cache.get(key, options)
|
10
|
-
rescue Memcached::NotFound
|
11
|
-
nil
|
12
|
-
end
|
13
|
-
|
14
|
-
def increment(key)
|
15
|
-
@cache.incr(key)
|
16
|
-
end
|
17
|
-
|
18
|
-
def write(key, value, options = {})
|
19
|
-
if expires_in = options.delete(:expires_in)
|
20
|
-
options[:expiry] = expires_in.to_i
|
21
|
-
end
|
22
|
-
|
23
|
-
@cache.set(key, value, options)
|
24
|
-
end
|
25
|
-
|
26
|
-
def delete(key)
|
27
|
-
@cache.delete(key)
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|