gruf-circuit-breaker 0.1.3

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b16d5d48832a9bb1a168222fdac0de751f517556
4
+ data.tar.gz: a055a5833e82e781f0f9654325d6ca61bc74fb2e
5
+ SHA512:
6
+ metadata.gz: 3e85e39daa737aa178b120d3a36f8393f3ac2082422399d73d0ea469af99a903f0bdac1bc2b9e1d5bddaa678979fec3f10ede2c1a351a3952517e2b24da7544d
7
+ data.tar.gz: c9ba632395b6fc61cfd7374910c8a4902e115e02cb7b37a3435417db4eb795cc2abe22d4216c65d51668bb26a01f58623dff45cee685903abc375fca43a8b276
@@ -0,0 +1,19 @@
1
+ Changelog for the gruf-circuit-breaker gem.
2
+
3
+ h3. 0.1.3
4
+
5
+ - Add rubocop to test suite
6
+ - Add bundler-audit to test suite
7
+ - Various cleanups to pass rubocop suite
8
+
9
+ h3. 0.1.2
10
+
11
+ - Updated to MIT license
12
+
13
+ h3. 0.1.1
14
+
15
+ - Fix to grpc error catching
16
+
17
+ h3. 0.1.0
18
+
19
+ - Initial public release
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at splittingred@gmail.com. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
@@ -0,0 +1,57 @@
1
+ # gruf-circuit-breaker - Circuit Breaker for gruf
2
+
3
+ [![Build Status](https://travis-ci.org/bigcommerce/gruf-circuit-breaker.svg?branch=master)](https://travis-ci.org/bigcommerce/gruf-circuit-breaker)
4
+
5
+ Adds circuit breaker support for [gruf](https://github.com/bigcommerce/gruf) 1.0.0 or later.
6
+
7
+ This uses the wonderful [stoplight](https://github.com/orgsync/stoplight) gem for handling
8
+ the internals of circuit breaking.
9
+
10
+ ## Installation
11
+
12
+ ```ruby
13
+ gem 'gruf-circuit-breaker'
14
+ ```
15
+
16
+ Then in an initializer or before use, after loading gruf:
17
+
18
+ ```ruby
19
+ require 'gruf/circuit_breaker'
20
+ Gruf::Hooks::Registry.add(:circuit_breaker, Gruf::CircuitBreaker::Hook)
21
+ ```
22
+
23
+ ## Configuration
24
+
25
+ You can further customize the tracing of gruf services via the configuration:
26
+
27
+ ```ruby
28
+ Gruf.configure do |c|
29
+ c.hook_options[:circuit_breaker] = {
30
+ # set cool-off time in seconds (defaults to 60)
31
+ cool_off_time: 15,
32
+ # set threshold count to 2
33
+ threshold: 2,
34
+ # set the gRPC failure statuses that will cause a circuit to trip
35
+ failure_statuses: [GRPC::Internal, GRPC::Unknown, GRPC::Aborted],
36
+ # use a redis instance for the stoplight data storage
37
+ redis: Redis.new
38
+ }
39
+ end
40
+ ```
41
+
42
+ ## License
43
+
44
+ Copyright (c) 2017-present, BigCommerce Pty. Ltd. All rights reserved
45
+
46
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
47
+ documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
48
+ rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
49
+ persons to whom the Software is furnished to do so, subject to the following conditions:
50
+
51
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
52
+ Software.
53
+
54
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
55
+ WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
56
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
57
+ OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,40 @@
1
+ # coding: utf-8
2
+ # Copyright (c) 2017-present, BigCommerce Pty. Ltd. All rights reserved
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
5
+ # documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
6
+ # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
7
+ # persons to whom the Software is furnished to do so, subject to the following conditions:
8
+ #
9
+ # The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
10
+ # Software.
11
+ #
12
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
13
+ # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
14
+ # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
15
+ # OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
16
+ #
17
+ $:.push File.expand_path("../lib", __FILE__)
18
+ require 'gruf/circuit_breaker/version'
19
+
20
+ Gem::Specification.new do |spec|
21
+ spec.name = 'gruf-circuit-breaker'
22
+ spec.version = Gruf::CircuitBreaker::VERSION
23
+ spec.authors = ['Shaun McCormick']
24
+ spec.email = ['shaun.mccormick@bigcommerce.com']
25
+
26
+ spec.summary = %q{Plugin for implementing the circuit breaker pattern for gruf gRPC requests}
27
+ spec.description = spec.summary
28
+ spec.homepage = 'https://github.com/bigcommerce/gruf-circuit-breaker'
29
+ spec.license = 'MIT'
30
+
31
+ spec.files = Dir['README.md', 'CHANGELOG.md', 'CODE_OF_CONDUCT.md', 'lib/**/*', 'gruf-circuit-breaker.gemspec']
32
+ spec.require_paths = ['lib']
33
+
34
+ spec.add_development_dependency 'bundler', '~> 1.11'
35
+ spec.add_development_dependency 'rake', '~> 10.0'
36
+ spec.add_development_dependency 'rspec', '~> 3.6'
37
+ spec.add_development_dependency 'pry', '~> 0'
38
+
39
+ spec.add_runtime_dependency 'stoplight', '~> 2.1'
40
+ end
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ # Copyright (c) 2017-present, BigCommerce Pty. Ltd. All rights reserved
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
5
+ # documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
6
+ # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
7
+ # persons to whom the Software is furnished to do so, subject to the following conditions:
8
+ #
9
+ # The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
10
+ # Software.
11
+ #
12
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
13
+ # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
14
+ # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
15
+ # OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
16
+ #
17
+ require 'stoplight'
18
+ require_relative 'circuit_breaker/version'
19
+ require_relative 'circuit_breaker/hook'
20
+
21
+ module Gruf
22
+ module CircuitBreaker
23
+ end
24
+ end
@@ -0,0 +1,83 @@
1
+ # coding: utf-8
2
+ # Copyright (c) 2017-present, BigCommerce Pty. Ltd. All rights reserved
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
5
+ # documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
6
+ # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
7
+ # persons to whom the Software is furnished to do so, subject to the following conditions:
8
+ #
9
+ # The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
10
+ # Software.
11
+ #
12
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
13
+ # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
14
+ # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
15
+ # OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
16
+ #
17
+ module Gruf
18
+ module CircuitBreaker
19
+ class Hook < Gruf::Hooks::Base
20
+
21
+ ##
22
+ # Sets up the stoplight gem
23
+ #
24
+ def setup
25
+ redis = options.fetch(:redis, nil)
26
+ Stoplight::Light.default_data_store = Stoplight::DataStore::Redis.new(redis) if redis && redis.is_a?(Redis)
27
+ end
28
+
29
+ ##
30
+ # Handle the gruf around hook
31
+ #
32
+ # @param [Symbol] call_signature
33
+ # @param [Object] request
34
+ # @param [GRPC::ActiveCall] active_call
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)
39
+ end
40
+ light.with_cool_off_time(options.fetch(:cool_off_time, 60))
41
+ light.with_error_handler do |error, handle|
42
+ # if it's not a gRPC::BadStatus, pass it through
43
+ raise error unless error.is_a?(GRPC::BadStatus)
44
+ # only special handling for GRPC error statuses. We want to pass-through any normal exceptions
45
+ raise error unless failure_statuses.include?(error.class)
46
+ handle.call(error)
47
+ end
48
+ light.with_threshold(options.fetch(:threshold, 1)) if options.fetch(:threshold, false)
49
+ light.run
50
+ end
51
+
52
+ private
53
+
54
+ ##
55
+ # @return [String]
56
+ #
57
+ def method_key(call_signature)
58
+ "#{service_key}.#{call_signature.to_s.gsub('_without_intercept', '')}"
59
+ end
60
+
61
+ ##
62
+ # @return [String]
63
+ #
64
+ def service_key
65
+ service.class.name.underscore.tr('/', '.')
66
+ end
67
+
68
+ ##
69
+ # @return [Array<Class>]
70
+ #
71
+ def failure_statuses
72
+ options.fetch(:failure_statuses, [GRPC::Internal, GRPC::Unknown])
73
+ end
74
+
75
+ ##
76
+ # @return [Hash]
77
+ #
78
+ def options
79
+ @options.fetch(:circuit_breaker, {})
80
+ end
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,21 @@
1
+ # coding: utf-8
2
+ # Copyright (c) 2017-present, BigCommerce Pty. Ltd. All rights reserved
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
5
+ # documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
6
+ # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
7
+ # persons to whom the Software is furnished to do so, subject to the following conditions:
8
+ #
9
+ # The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
10
+ # Software.
11
+ #
12
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
13
+ # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
14
+ # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
15
+ # OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
16
+ #
17
+ module Gruf
18
+ module CircuitBreaker
19
+ VERSION = '0.1.3'.freeze
20
+ end
21
+ end
metadata ADDED
@@ -0,0 +1,121 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gruf-circuit-breaker
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.3
5
+ platform: ruby
6
+ authors:
7
+ - Shaun McCormick
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-07-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.11'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.11'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.6'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.6'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: stoplight
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '2.1'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '2.1'
83
+ description: Plugin for implementing the circuit breaker pattern for gruf gRPC requests
84
+ email:
85
+ - shaun.mccormick@bigcommerce.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - CHANGELOG.md
91
+ - CODE_OF_CONDUCT.md
92
+ - README.md
93
+ - gruf-circuit-breaker.gemspec
94
+ - lib/gruf/circuit_breaker.rb
95
+ - lib/gruf/circuit_breaker/hook.rb
96
+ - lib/gruf/circuit_breaker/version.rb
97
+ homepage: https://github.com/bigcommerce/gruf-circuit-breaker
98
+ licenses:
99
+ - MIT
100
+ metadata: {}
101
+ post_install_message:
102
+ rdoc_options: []
103
+ require_paths:
104
+ - lib
105
+ required_ruby_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ required_rubygems_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ requirements: []
116
+ rubyforge_project:
117
+ rubygems_version: 2.6.12
118
+ signing_key:
119
+ specification_version: 4
120
+ summary: Plugin for implementing the circuit breaker pattern for gruf gRPC requests
121
+ test_files: []