breakers 0.2.2 → 0.5.0
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 +5 -5
- data/.rubocop.yml +10 -5
- data/breakers.gemspec +2 -1
- data/lib/breakers/service.rb +8 -0
- data/lib/breakers/uptime_middleware.rb +14 -2
- data/lib/breakers/version.rb +1 -1
- metadata +8 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: eb4f99f9230a8a77ef80b47b9c06582f7e885f0f52f52998b1c92fa61070bb0b
|
4
|
+
data.tar.gz: 78ec47202acff0af6961a7be2f8735103360bc976df6e32df3ab94eb0de79533
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 158c40c57705a319eb1683f27f5fc58fe6da8786e59faf4d7ea05c5868333e55e1885eb8eaa005bb0564ad57931a18eddc12c0278a86ee2ef382820927392b87
|
7
|
+
data.tar.gz: d5551fdb570642bb96b0cce674efed1e470454542793d5696a15eace950ed7dd73acde565ff515d790b0157936cb9b3b70f758cf6de8dfc6403aa30e4c4c17c1
|
data/.rubocop.yml
CHANGED
@@ -2,6 +2,8 @@ AllCops:
|
|
2
2
|
TargetRubyVersion: 2.3
|
3
3
|
Include:
|
4
4
|
- 'Rakefile'
|
5
|
+
Exclude:
|
6
|
+
- Gemfile
|
5
7
|
|
6
8
|
Metrics/LineLength:
|
7
9
|
Max: 140
|
@@ -22,6 +24,9 @@ Metrics/ClassLength:
|
|
22
24
|
Metrics/MethodLength:
|
23
25
|
Max: 50
|
24
26
|
|
27
|
+
Metrics/BlockLength:
|
28
|
+
Max: 500
|
29
|
+
|
25
30
|
Metrics/AbcSize:
|
26
31
|
Max: 75
|
27
32
|
|
@@ -98,7 +103,7 @@ Style/GuardClause:
|
|
98
103
|
Style/Next:
|
99
104
|
Enabled: false
|
100
105
|
|
101
|
-
|
106
|
+
Layout/IndentArray:
|
102
107
|
EnforcedStyle: consistent
|
103
108
|
|
104
109
|
# This forces you to change simple if/unless blocks to the conditional form like: `return 2 if badness`.
|
@@ -149,7 +154,7 @@ Style/WordArray:
|
|
149
154
|
|
150
155
|
# Some people really like to put lines at the beginning and end of class bodies, while other people
|
151
156
|
# really don't. It doesn't really seem to matter.
|
152
|
-
|
157
|
+
Layout/EmptyLinesAroundClassBody:
|
153
158
|
Enabled: false
|
154
159
|
|
155
160
|
# This forces you to put a comment like this at the top of every single file:
|
@@ -164,10 +169,10 @@ Style/Lambda:
|
|
164
169
|
Enabled: false
|
165
170
|
|
166
171
|
# Force indentation for milti-line expressions and method calls
|
167
|
-
|
172
|
+
Layout/MultilineOperationIndentation:
|
168
173
|
EnforcedStyle: indented
|
169
174
|
|
170
|
-
|
175
|
+
Layout/MultilineMethodCallIndentation:
|
171
176
|
EnforcedStyle: indented
|
172
177
|
|
173
178
|
# This disallows the use of $1, $2 from regular expressions, which seems to make no sense whatsoever
|
@@ -198,7 +203,7 @@ Style/ZeroLengthPredicate:
|
|
198
203
|
# ...
|
199
204
|
# end
|
200
205
|
Lint/EndAlignment:
|
201
|
-
|
206
|
+
EnforcedStyleAlignWith: variable
|
202
207
|
|
203
208
|
# This cop will require you to replace or prefix method arguments that go unused with underscores. The problem
|
204
209
|
# is that while seeming to solve no problem this could easily cause issues where someone editing the code to
|
data/breakers.gemspec
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# coding: utf-8
|
2
|
+
|
2
3
|
lib = File.expand_path('../lib', __FILE__)
|
3
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
5
|
require 'breakers/version'
|
@@ -21,7 +22,7 @@ Gem::Specification.new do |spec|
|
|
21
22
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
23
|
spec.require_paths = ['lib']
|
23
24
|
|
24
|
-
spec.add_dependency 'faraday', ['>= 0.7.4', '< 0
|
25
|
+
spec.add_dependency 'faraday', ['>= 0.7.4', '< 2.0']
|
25
26
|
spec.add_dependency 'multi_json', '~> 1.0'
|
26
27
|
|
27
28
|
spec.add_development_dependency 'bundler', '~> 1.0'
|
data/lib/breakers/service.rb
CHANGED
@@ -17,6 +17,7 @@ module Breakers
|
|
17
17
|
# @option opts [Integer] :seconds_before_retry The number of seconds to wait after an outage begins before testing with a new request
|
18
18
|
# @option opts [Integer] :error_threshold The percentage of errors over the last two minutes that indicates an outage
|
19
19
|
# @option opts [Integer] :data_retention_seconds The number of seconds to retain success and error data in Redis
|
20
|
+
# @option opts [Proc] :exception_handler A proc taking an exception and returns true if it represents an error on the service
|
20
21
|
def initialize(opts)
|
21
22
|
@configuration = DEFAULT_OPTS.merge(opts)
|
22
23
|
end
|
@@ -43,6 +44,13 @@ module Breakers
|
|
43
44
|
@configuration[:seconds_before_retry]
|
44
45
|
end
|
45
46
|
|
47
|
+
# Returns true if a given exception represents an error with the service
|
48
|
+
#
|
49
|
+
# @return [Boolean] is it an error?
|
50
|
+
def exception_represents_server_error?(exception)
|
51
|
+
@configuration[:exception_handler]&.call(exception)
|
52
|
+
end
|
53
|
+
|
46
54
|
# Indicate that an error has occurred and potentially create an outage
|
47
55
|
def add_error
|
48
56
|
increment_key(key: errors_key)
|
@@ -35,6 +35,9 @@ module Breakers
|
|
35
35
|
protected
|
36
36
|
|
37
37
|
def outage_response(outage:, service:)
|
38
|
+
Breakers.client.plugins.each do |plugin|
|
39
|
+
plugin.on_skipped_request(service) if plugin.respond_to?(:on_skipped_request)
|
40
|
+
end
|
38
41
|
if Breakers.outage_response[:type] == :status_code
|
39
42
|
Faraday::Response.new.tap do |response|
|
40
43
|
response.finish(
|
@@ -51,7 +54,7 @@ module Breakers
|
|
51
54
|
def handle_request(service:, request_env:, current_outage: nil)
|
52
55
|
start_time = Time.now
|
53
56
|
return @app.call(request_env).on_complete do |response_env|
|
54
|
-
response_env[:duration] = Time.now - start_time
|
57
|
+
response_env[:duration] = (Time.now - start_time) * 1000
|
55
58
|
if response_env.status >= 500
|
56
59
|
handle_error(
|
57
60
|
service: service,
|
@@ -69,8 +72,17 @@ module Breakers
|
|
69
72
|
end
|
70
73
|
end
|
71
74
|
end
|
75
|
+
rescue Faraday::TimeoutError, Faraday::ConnectionFailed => e
|
76
|
+
handle_error(
|
77
|
+
service: service,
|
78
|
+
request_env: request_env,
|
79
|
+
response_env: nil,
|
80
|
+
error: "#{e.class.name} - #{e.message}",
|
81
|
+
current_outage: current_outage
|
82
|
+
)
|
83
|
+
raise
|
72
84
|
rescue => e
|
73
|
-
|
85
|
+
if service.exception_represents_server_error?(e)
|
74
86
|
handle_error(
|
75
87
|
service: service,
|
76
88
|
request_env: request_env,
|
data/lib/breakers/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: breakers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aubrey Holland
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-05-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -19,7 +19,7 @@ dependencies:
|
|
19
19
|
version: 0.7.4
|
20
20
|
- - "<"
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version: '0
|
22
|
+
version: '2.0'
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -29,7 +29,7 @@ dependencies:
|
|
29
29
|
version: 0.7.4
|
30
30
|
- - "<"
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version: '0
|
32
|
+
version: '2.0'
|
33
33
|
- !ruby/object:Gem::Dependency
|
34
34
|
name: multi_json
|
35
35
|
requirement: !ruby/object:Gem::Requirement
|
@@ -200,7 +200,7 @@ homepage: https://github.com/department-of-veterans-affairs/breakers
|
|
200
200
|
licenses:
|
201
201
|
- CC0-1.0
|
202
202
|
metadata: {}
|
203
|
-
post_install_message:
|
203
|
+
post_install_message:
|
204
204
|
rdoc_options: []
|
205
205
|
require_paths:
|
206
206
|
- lib
|
@@ -215,10 +215,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
215
215
|
- !ruby/object:Gem::Version
|
216
216
|
version: '0'
|
217
217
|
requirements: []
|
218
|
-
|
219
|
-
|
220
|
-
signing_key:
|
218
|
+
rubygems_version: 3.0.8
|
219
|
+
signing_key:
|
221
220
|
specification_version: 4
|
222
221
|
summary: Handle outages to backend systems with a Faraday middleware
|
223
222
|
test_files: []
|
224
|
-
has_rdoc:
|