gruf-circuit-breaker 0.1.3 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +4 -4
- data/lib/gruf/circuit_breaker.rb +7 -2
- data/lib/gruf/circuit_breaker/{hook.rb → interceptor.rb} +13 -29
- data/lib/gruf/circuit_breaker/version.rb +1 -2
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b812cddba85e6ed5a9a2efa6624b33c71b87b97d
|
4
|
+
data.tar.gz: c841e828ceefd724ca89fb7faeb4f218e7c5e850
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3849d1ebcc7fd3569c18a836f2e1ccf25e8c4f0fc0ef95ba14ce375047a1aa4f36b9f387dc1c01b6ecdf9d23628083bbf1ccc82c5aba4b887dc2ed138d8f10f0
|
7
|
+
data.tar.gz: e4a2f4d405356141ec6c96c17a3839931a161b2e0ba23a566626b5c6f137d132c01bfe00caf193c035b96f37339da6c63b51f1b1b4da4b4d2ab31f1fabde2ce2
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
# gruf-circuit-breaker - Circuit Breaker for gruf
|
2
2
|
|
3
|
-
[![Build Status](https://travis-ci.org/bigcommerce/gruf-circuit-breaker.svg?branch=master)](https://travis-ci.org/bigcommerce/gruf-circuit-breaker)
|
3
|
+
[![Build Status](https://travis-ci.org/bigcommerce/gruf-circuit-breaker.svg?branch=master)](https://travis-ci.org/bigcommerce/gruf-circuit-breaker) [![Gem Version](https://badge.fury.io/rb/gruf-circuit-breaker.svg)](https://badge.fury.io/rb/gruf-circuit-breaker) [![Inline docs](http://inch-ci.org/github/bigcommerce/gruf-circuit-breaker.svg?branch=master)](http://inch-ci.org/github/bigcommerce/gruf-circuit-breaker)
|
4
4
|
|
5
|
-
Adds circuit breaker support for [gruf](https://github.com/bigcommerce/gruf)
|
5
|
+
Adds circuit breaker support for [gruf](https://github.com/bigcommerce/gruf) 2.0.0 or later.
|
6
6
|
|
7
7
|
This uses the wonderful [stoplight](https://github.com/orgsync/stoplight) gem for handling
|
8
8
|
the internals of circuit breaking.
|
@@ -26,7 +26,7 @@ You can further customize the tracing of gruf services via the configuration:
|
|
26
26
|
|
27
27
|
```ruby
|
28
28
|
Gruf.configure do |c|
|
29
|
-
c.
|
29
|
+
c.interceptors.use(Gruf::CircuitBreaker::Interceptor, {
|
30
30
|
# set cool-off time in seconds (defaults to 60)
|
31
31
|
cool_off_time: 15,
|
32
32
|
# set threshold count to 2
|
@@ -35,7 +35,7 @@ Gruf.configure do |c|
|
|
35
35
|
failure_statuses: [GRPC::Internal, GRPC::Unknown, GRPC::Aborted],
|
36
36
|
# use a redis instance for the stoplight data storage
|
37
37
|
redis: Redis.new
|
38
|
-
}
|
38
|
+
})
|
39
39
|
end
|
40
40
|
```
|
41
41
|
|
data/lib/gruf/circuit_breaker.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
# coding: utf-8
|
2
1
|
# Copyright (c) 2017-present, BigCommerce Pty. Ltd. All rights reserved
|
3
2
|
#
|
4
3
|
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
|
@@ -16,9 +15,15 @@
|
|
16
15
|
#
|
17
16
|
require 'stoplight'
|
18
17
|
require_relative 'circuit_breaker/version'
|
19
|
-
require_relative 'circuit_breaker/
|
18
|
+
require_relative 'circuit_breaker/interceptor'
|
20
19
|
|
20
|
+
##
|
21
|
+
# Base gruf module
|
22
|
+
#
|
21
23
|
module Gruf
|
24
|
+
##
|
25
|
+
# Base CircuitBreaker module
|
26
|
+
#
|
22
27
|
module CircuitBreaker
|
23
28
|
end
|
24
29
|
end
|
@@ -1,4 +1,3 @@
|
|
1
|
-
# coding: utf-8
|
2
1
|
# Copyright (c) 2017-present, BigCommerce Pty. Ltd. All rights reserved
|
3
2
|
#
|
4
3
|
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
|
@@ -16,26 +15,25 @@
|
|
16
15
|
#
|
17
16
|
module Gruf
|
18
17
|
module CircuitBreaker
|
19
|
-
|
20
|
-
|
18
|
+
##
|
19
|
+
# Intercepts gruf requests and adds a circuit breaker implementation
|
20
|
+
#
|
21
|
+
class Interceptor < Gruf::Interceptors::ServerInterceptor
|
21
22
|
##
|
22
23
|
# Sets up the stoplight gem
|
23
24
|
#
|
24
|
-
def
|
25
|
+
def initialize(request, error, options = {})
|
25
26
|
redis = options.fetch(:redis, nil)
|
26
27
|
Stoplight::Light.default_data_store = Stoplight::DataStore::Redis.new(redis) if redis && redis.is_a?(Redis)
|
28
|
+
super(request, error, options)
|
27
29
|
end
|
28
30
|
|
29
31
|
##
|
30
32
|
# Handle the gruf around hook
|
31
33
|
#
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
#
|
36
|
-
def around(call_signature, request, active_call, &block)
|
37
|
-
light = Stoplight(method_key(call_signature)) do
|
38
|
-
block.call(call_signature, request, active_call)
|
34
|
+
def call
|
35
|
+
light = Stoplight(request.method_key) do
|
36
|
+
yield
|
39
37
|
end
|
40
38
|
light.with_cool_off_time(options.fetch(:cool_off_time, 60))
|
41
39
|
light.with_error_handler do |error, handle|
|
@@ -45,24 +43,17 @@ module Gruf
|
|
45
43
|
raise error unless failure_statuses.include?(error.class)
|
46
44
|
handle.call(error)
|
47
45
|
end
|
48
|
-
light.with_threshold(
|
46
|
+
light.with_threshold(threshold) if threshold > 0
|
49
47
|
light.run
|
50
48
|
end
|
51
49
|
|
52
50
|
private
|
53
51
|
|
54
52
|
##
|
55
|
-
# @return [
|
56
|
-
#
|
57
|
-
def method_key(call_signature)
|
58
|
-
"#{service_key}.#{call_signature.to_s.gsub('_without_intercept', '')}"
|
59
|
-
end
|
60
|
-
|
61
|
-
##
|
62
|
-
# @return [String]
|
53
|
+
# @return [Integer]
|
63
54
|
#
|
64
|
-
def
|
65
|
-
|
55
|
+
def threshold
|
56
|
+
options.fetch(:threshold, 0).to_i
|
66
57
|
end
|
67
58
|
|
68
59
|
##
|
@@ -71,13 +62,6 @@ module Gruf
|
|
71
62
|
def failure_statuses
|
72
63
|
options.fetch(:failure_statuses, [GRPC::Internal, GRPC::Unknown])
|
73
64
|
end
|
74
|
-
|
75
|
-
##
|
76
|
-
# @return [Hash]
|
77
|
-
#
|
78
|
-
def options
|
79
|
-
@options.fetch(:circuit_breaker, {})
|
80
|
-
end
|
81
65
|
end
|
82
66
|
end
|
83
67
|
end
|
@@ -1,4 +1,3 @@
|
|
1
|
-
# coding: utf-8
|
2
1
|
# Copyright (c) 2017-present, BigCommerce Pty. Ltd. All rights reserved
|
3
2
|
#
|
4
3
|
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
|
@@ -16,6 +15,6 @@
|
|
16
15
|
#
|
17
16
|
module Gruf
|
18
17
|
module CircuitBreaker
|
19
|
-
VERSION = '0.
|
18
|
+
VERSION = '1.0.0'.freeze
|
20
19
|
end
|
21
20
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gruf-circuit-breaker
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shaun McCormick
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-10-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -92,7 +92,7 @@ files:
|
|
92
92
|
- README.md
|
93
93
|
- gruf-circuit-breaker.gemspec
|
94
94
|
- lib/gruf/circuit_breaker.rb
|
95
|
-
- lib/gruf/circuit_breaker/
|
95
|
+
- lib/gruf/circuit_breaker/interceptor.rb
|
96
96
|
- lib/gruf/circuit_breaker/version.rb
|
97
97
|
homepage: https://github.com/bigcommerce/gruf-circuit-breaker
|
98
98
|
licenses:
|
@@ -114,7 +114,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
114
114
|
version: '0'
|
115
115
|
requirements: []
|
116
116
|
rubyforge_project:
|
117
|
-
rubygems_version: 2.6.
|
117
|
+
rubygems_version: 2.6.13
|
118
118
|
signing_key:
|
119
119
|
specification_version: 4
|
120
120
|
summary: Plugin for implementing the circuit breaker pattern for gruf gRPC requests
|