faulty 0.8.6 → 0.8.7

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ae75506209beb5e9490a5f2a939519060340e22022c0f0d0be07bbd8c32bd34a
4
- data.tar.gz: d08fbe083462251ac184ed0578dda3dcfdab624e48cef270662ed04bab0b337b
3
+ metadata.gz: 3148a3eb0ec2e45213ddb40bef524a3b0fa83e83b467101982d7ced65cbac71a
4
+ data.tar.gz: fd9584532fde4f3409720ca1884f825fc4d6eabb4ebe133c80e969bc0131ab9f
5
5
  SHA512:
6
- metadata.gz: 182af6be2df0089e41be78ceed0d3b866f9b6db43f2423fe1c4bd788b196c76fa206055f9ca07b558676afad7a3544c39c0215990a43fe2b8bdec593ea259d95
7
- data.tar.gz: cf3726daff78ed12b39313aab5188c53a804ac68e9e0810faf1abf4e5d11e96c85168b46b4b814334bad5d922e6188c8a9b6ed5f0b499961c3e33fde434bb5c0
6
+ metadata.gz: 330476d53d625bb22dbd2f5855dd40f4f4849135b1407df72e9ff3849504341f9e67cf6ce5bb0606bd62100a9d11dda2f7d7754be081b40b8c81784d1e25265d
7
+ data.tar.gz: 9f8023dbd90ea1d9fb55a1a5c7a9c96a9344b0db43e0735113545406734e0f02ea14bcc1550b8d2b335e1b59bd63591812ed2426f66f097789185531f6d2db51
data/CHANGELOG.md CHANGED
@@ -1,12 +1,46 @@
1
- ## Release v0.8.6
1
+ Changelog
2
+ ===================
3
+
4
+ All notable changes to this project will be documented in this file.
5
+
6
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
7
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
8
+
9
+ [Unreleased]
10
+ -------------------
11
+
12
+ [0.8.7] - 2022-08-11
13
+ -------------------
14
+
15
+ ### Added
16
+
17
+ * Add a Faulty#clear method to reset all circuits #55 justinhoward
18
+
19
+ ### Fixed
20
+
21
+ * Update rubocop cleanup gemspec #56 justinhoward
22
+
23
+ [0.8.6] - 2022-02-24
24
+ -------------------
25
+
26
+ ### Added
2
27
 
3
28
  * Define an inspect method that represent circuit #50 JuanitoFatas
4
29
 
5
- ## Release v0.8.5
30
+ [0.8.5] - 2022-02-17
31
+ -------------------
32
+
33
+ ### Added
34
+
35
+ * Add granular errors for Elasticsearch patch #48 justinhoward
36
+
37
+ ### Fixed
6
38
 
7
39
  * Fix yard warnings #49 justinhoward
8
40
  * Fix crash in Redis storage backend if opened_at was missing #46 justinhoward
9
- * Add granular errors for Elasticsearch patch #48 justinhoward
41
+
42
+ ### Changed
43
+
10
44
  * Return status conditionally for Storage::Interface#entry #45 justinhoward
11
45
 
12
46
  ### Deprecations
@@ -18,22 +52,35 @@
18
52
  * The error_module option is deprecated. Patches should use the error_mapper
19
53
  option instead. The option will be removed in 0.9
20
54
 
55
+ [0.8.4] - 2022-01-28
56
+ -------------------
21
57
 
22
- ## Release v0.8.4
58
+ ### Added
23
59
 
24
60
  * Add Elasticsearch client patch #44 justinhoward
25
61
 
26
- ## Release v0.8.2
62
+ [0.8.2] - 2021-10-18
63
+ -------------------
64
+
65
+ ### Fixed
27
66
 
28
67
  * Fix crash for older versions of concurrent-ruby #42 justinhoward
29
68
 
30
- ## Release v0.8.1
69
+ [0.8.1] - 2021-09-22
70
+ -------------------
71
+
72
+ ### Changed
31
73
 
32
74
  * Add cause message to CircuitTrippedError #40 justinhoward
75
+
76
+ ### Fixed
77
+
33
78
  * Record failures for cache hits #41 justinhoward
34
79
 
80
+ [0.8.0] - 2021-09-14
81
+ -------------------
35
82
 
36
- ## Release v0.8.0
83
+ ### Added
37
84
 
38
85
  * Store circuit options in the backend when run #34 justinhoward
39
86
 
@@ -52,16 +99,28 @@
52
99
  instances, so likely this will not be a breaking change for most
53
100
  cases.
54
101
 
55
- ## Release v0.7.2
102
+ [0.7.2] - 2021-09-02
103
+ -------------------
104
+
105
+ ### Added
56
106
 
57
107
  * Add Faulty.disable! for disabling globally #38 justinhoward
108
+
109
+ ### Changed
110
+
58
111
  * Suppress circuit_success for proxy circuits #39 justinhoward
59
112
 
60
- ## Release v0.7.1
113
+ [0.7.1] - 2021-09-02
114
+ -------------------
115
+
116
+ ### Fixed
61
117
 
62
118
  * Fix success event crash in log listener #37 justinhoward
63
119
 
64
- ## Release v0.7.0
120
+ [0.7.0] - 2021-09-02
121
+ -------------------
122
+
123
+ ### Added
65
124
 
66
125
  * Add initial benchmarks and performance improvements #36 justinhoward
67
126
 
@@ -70,22 +129,37 @@
70
129
  The `circuit_success` event no longer contains the status value. Computing this
71
130
  value was causing performance problems.
72
131
 
73
- ## Release v0.6.0
132
+ [0.6.0] - 2021-06-10
133
+ -------------------
134
+
135
+ ### Added
136
+
137
+ * Capture an error for BUSY redis backend when patched #30 justinhoward
138
+ * Add a patch for mysql2 #28 justinhoward
139
+
140
+ ### Fixed
74
141
 
75
142
  * docs, use correct state in description for skipped event #27 senny
76
143
  * Fix CI to set REDIS_VERSION correctly #31 justinhoward
77
144
  * Fix a potential memory leak in patches #32 justinhoward
78
- * Capture an error for BUSY redis backend when patched #30 justinhoward
79
- * Add a patch for mysql2 #28 justinhoward
80
145
 
81
- ## Release v0.5.1
146
+ [0.5.1] - 2021-05-28
147
+ -------------------
148
+
149
+ ### Fixed
82
150
 
83
151
  * Fix Storage::FaultTolerantProxy to return empty history on entries fail #26 justinhoward
84
152
 
85
- ## Release v0.5.0
153
+ [0.5.0] - 2021-05-28
154
+ -------------------
155
+
156
+ ### Added
86
157
 
87
158
  * Allow creating a new Faulty instance in Faulty#register #24 justinhoward
88
159
  * Add support for patches to core dependencies starting with redis #14 justinhoward
160
+
161
+ ### Fixed
162
+
89
163
  * Improve storage #entries performance by returning entries #23 justinhoward
90
164
 
91
165
  ### Breaking Changes
@@ -95,23 +169,35 @@ value was causing performance problems.
95
169
  * Faulty::Storage::Interface must now return a history array instead of a
96
170
  circuit status object. Custom storage backends must be updated.
97
171
 
98
- ## Release v0.4.0
172
+ [0.4.0] - 2021-02-19
173
+ -------------------
174
+
175
+ ### Added
99
176
 
100
- * Switch from Travis CI to GitHub actions #11 justinhoward
101
- * Only run rubocop for Ruby 2.7 in CI #12 justinhoward
102
177
  * Explicitly add support for Redis 3 and 4 #15 justinhoward
103
178
  * Allow setting default circuit options on Faulty instances #16 justinhoward
179
+
180
+ ### Changed
181
+
182
+ * Switch from Travis CI to GitHub actions #11 justinhoward
183
+ * Only run rubocop for Ruby 2.7 in CI #12 justinhoward
104
184
  * Switch to codacy for quality metrics #17 justinhoward
185
+ * Allow passing custom circuit to AutoWire #22 justinhoward
186
+
187
+ ### Fixed
188
+
105
189
  * Small logic fix to README #19 silasb
106
190
  * Fix Redis storage dependency on ConnectionPool #21 justinhoward
107
- * Allow passing custom circuit to AutoWire #22 justinhoward
108
191
 
109
192
  ### Breaking Changes
110
193
 
111
194
  AutoWire.new is replaced with AutoWire.wrap and no longer creates an instance
112
195
  of AutoWire.
113
196
 
114
- ## Release v0.3.0
197
+ [0.3.0] - 2020-10-24
198
+ -------------------
199
+
200
+ ### Added
115
201
 
116
202
  * Add tools for backend fault-tolerance #10
117
203
  * CircuitProxy for wrapping storage in an internal circuit
@@ -120,7 +206,10 @@ of AutoWire.
120
206
  * AutoWire wrappers for automatically configuring storage and cache
121
207
  * Better documentation for fault-tolerance
122
208
 
123
- ## Release v0.2.0
209
+ [0.2.0] - 2020-10-18
210
+ -------------------
211
+
212
+ ### Changed
124
213
 
125
214
  * Remove Scopes and replace them with Faulty instances #9
126
215
 
@@ -129,28 +218,71 @@ of AutoWire.
129
218
  * `Faulty::Scope` has been removed. Use `Faulty.new` instead.
130
219
  * `Faulty` is now a class, not a module
131
220
 
132
- ## Release v0.1.5
221
+ [0.1.5] - 2020-10-18
222
+ -------------------
223
+
224
+ ### Fixed
133
225
 
134
226
  * Fix redis storage to expire state key when using CAS #8
135
227
 
136
- ## Release v0.1.4
228
+ [0.1.4] - 2020-10-18
229
+ -------------------
230
+
231
+ ### Fixed
137
232
 
138
233
  * Improve spec coverage for supporting classes #6
139
234
  * Fix redis bug where concurrent CAS requests could crash #7
140
235
 
141
- ## Release v0.1.3
236
+ [0.1.3] - 2020-09-29
237
+ -------------------
238
+
239
+ ### Added
142
240
 
143
- * Fix bug where memory storage would delete the newest entries #5
144
241
  * Add HoneybadgerListener for error reporting #4
145
242
 
146
- ## Release v0.1.2
243
+ ### Fixed
244
+
245
+ * Fix bug where memory storage would delete the newest entries #5
246
+
247
+ [0.1.2] - 2020-08-28
248
+ -------------------
249
+
250
+ ### Fixed
147
251
 
148
252
  * Fix Storage::FaultTolerantProxy open and reopen methods #2
149
253
 
150
- ## Release v0.1.1
254
+ [0.1.1] - 2020-08-28
255
+ -------------------
256
+
257
+ ### Fixed
151
258
 
152
259
  * Fix a crash when Storage::FaultTolerantProxy created a status stub #1
153
260
 
154
- ## Release v0.1.0
261
+ [0.1.0] - 2020-08-27
262
+ -------------------
155
263
 
156
264
  Initial public release
265
+
266
+ [Unreleased]: https://github.com/ParentSquare/faulty/compare/v0.5.0...HEAD
267
+ [0.8.6]: https://github.com/ParentSquare/faulty/compare/v0.8.5...v0.8.6
268
+ [0.8.5]: https://github.com/ParentSquare/faulty/compare/v0.8.4...v0.8.5
269
+ [0.8.4]: https://github.com/ParentSquare/faulty/compare/v0.8.3...v0.8.4
270
+ [0.8.3]: https://github.com/ParentSquare/faulty/compare/v0.8.2...v0.8.3
271
+ [0.8.2]: https://github.com/ParentSquare/faulty/compare/v0.8.1...v0.8.2
272
+ [0.8.1]: https://github.com/ParentSquare/faulty/compare/v0.8.0...v0.8.1
273
+ [0.8.0]: https://github.com/ParentSquare/faulty/compare/v0.7.2...v0.8.0
274
+ [0.7.2]: https://github.com/ParentSquare/faulty/compare/v0.7.1...v0.7.2
275
+ [0.7.1]: https://github.com/ParentSquare/faulty/compare/v0.7.0...v0.7.1
276
+ [0.7.0]: https://github.com/ParentSquare/faulty/compare/v0.6.0...v0.7.0
277
+ [0.6.0]: https://github.com/ParentSquare/faulty/compare/v0.5.1...v0.5.0
278
+ [0.5.1]: https://github.com/ParentSquare/faulty/compare/v0.5.0...v0.5.1
279
+ [0.5.0]: https://github.com/ParentSquare/faulty/compare/v0.4.0...v0.5.0
280
+ [0.4.0]: https://github.com/ParentSquare/faulty/compare/v0.3.0...v0.4.0
281
+ [0.3.0]: https://github.com/ParentSquare/faulty/compare/v0.2.0...v0.3.0
282
+ [0.2.0]: https://github.com/ParentSquare/faulty/compare/v0.1.5...v0.2.0
283
+ [0.1.5]: https://github.com/ParentSquare/faulty/releases/tag/v0.1.4...v0.1.5
284
+ [0.1.4]: https://github.com/ParentSquare/faulty/releases/tag/v0.1.3...v0.1.4
285
+ [0.1.3]: https://github.com/ParentSquare/faulty/releases/tag/v0.1.2...v0.1.3
286
+ [0.1.2]: https://github.com/ParentSquare/faulty/releases/tag/v0.1.1...v0.1.2
287
+ [0.1.1]: https://github.com/ParentSquare/faulty/releases/tag/v0.1.0...v0.1.1
288
+ [0.1.0]: https://github.com/ParentSquare/faulty/releases/tag/v0.1.0
data/README.md CHANGED
@@ -90,6 +90,7 @@ Also see "Release It!: Design and Deploy Production-Ready Software" by
90
90
  + [Other Built-in Listeners](#other-built-in-listeners)
91
91
  + [Custom Listeners](#custom-listeners)
92
92
  * [Disabling Faulty Globally](#disabling-faulty-globally)
93
+ * [Testing with Faulty](#testing-with-faulty)
93
94
  * [How it Works](#how-it-works)
94
95
  + [Caching](#caching)
95
96
  + [Fault Tolerance](#fault-tolerance)
@@ -1173,6 +1174,24 @@ not affect the stored state of circuits.
1173
1174
  Faulty will **still use the cache** even when disabled. If you also want to
1174
1175
  disable the cache, configure Faulty to use a `Faulty::Cache::Null` cache.
1175
1176
 
1177
+ ## Testing with Faulty
1178
+
1179
+ Depending on your application, you could choose to
1180
+ [disable Faulty globally](#disabling-faulty-globally), but sometimes you may
1181
+ want to test your application's behavior in a failure scenario.
1182
+
1183
+ If you have such tests, you will want to prevent failures in one test from
1184
+ affecting other tests. To clear all circuit states between tests, use `#clear!`.
1185
+ For example, with rspec:
1186
+
1187
+ ```ruby
1188
+ RSpec.configure do |config|
1189
+ config.after do
1190
+ Faulty.clear!
1191
+ end
1192
+ end
1193
+ ```
1194
+
1176
1195
  ## How it Works
1177
1196
 
1178
1197
  Faulty implements a version of circuit breakers inspired by "Release It!: Design
@@ -23,7 +23,7 @@ class Faulty
23
23
  # write your own code to periodically check how long it has been running.
24
24
  # If you're sure you want ruby's generic Timeout, you can apply it yourself
25
25
  # inside the circuit run block.
26
- class Circuit # rubocop:disable Metrics/ClassLength
26
+ class Circuit
27
27
  CACHE_REFRESH_SUFFIX = '.faulty_refresh'
28
28
 
29
29
  attr_reader :name
@@ -462,15 +462,13 @@ class Faulty
462
462
  end
463
463
  options.notifier.notify(:circuit_failure, circuit: self, status: status, error: error)
464
464
 
465
- opened = if status.half_open?
465
+ if status.half_open?
466
466
  reopen!(error, status.opened_at)
467
467
  elsif status.fails_threshold?
468
468
  open!(error)
469
469
  else
470
470
  false
471
471
  end
472
-
473
- opened
474
472
  end
475
473
 
476
474
  def deprecated_entry?
@@ -550,7 +548,7 @@ class Faulty
550
548
  # @return [Boolean] true if the cache should be refreshed
551
549
  def cache_should_refresh?(key)
552
550
  time = options.cache.read(cache_refresh_key(key.to_s)).to_i
553
- time + (rand * 2 - 1) * options.cache_refresh_jitter < Faulty.current_time
551
+ time + (((rand * 2) - 1) * options.cache_refresh_jitter) < Faulty.current_time
554
552
  end
555
553
 
556
554
  # Get the next time to refresh the cache when writing to it
@@ -5,7 +5,7 @@ class Faulty
5
5
  module Deprecation
6
6
  class << self
7
7
  # Call to raise errors instead of logging warnings for Faulty deprecations
8
- def raise_errors!(enabled = true)
8
+ def raise_errors!(enabled = true) # rubocop:disable Style/OptionalBooleanParameter
9
9
  @raise_errors = (enabled == true)
10
10
  end
11
11
 
@@ -31,13 +31,13 @@ class Faulty
31
31
  #
32
32
  # @yield A block to run inside the circuit
33
33
  # @return The block return value
34
- def faulty_run
34
+ def faulty_run(&block)
35
35
  faulty_running_key = "faulty_running_#{object_id}"
36
36
  return yield unless @faulty_circuit
37
37
  return yield if Thread.current[faulty_running_key]
38
38
 
39
39
  Thread.current[faulty_running_key] = true
40
- @faulty_circuit.run { yield }
40
+ @faulty_circuit.run(&block)
41
41
  ensure
42
42
  Thread.current[faulty_running_key] = nil
43
43
  end
@@ -81,10 +81,8 @@ class Faulty
81
81
  return super unless @faulty_circuit
82
82
 
83
83
  reply = super
84
- if reply.is_a?(::Redis::CommandError)
85
- if reply.message.start_with?('BUSY')
86
- reply = BusyError.new(reply.message)
87
- end
84
+ if reply.is_a?(::Redis::CommandError) && reply.message.start_with?('BUSY')
85
+ reply = BusyError.new(reply.message)
88
86
  end
89
87
 
90
88
  reply
data/lib/faulty/status.rb CHANGED
@@ -38,7 +38,9 @@ class Faulty
38
38
  :sample_size,
39
39
  :options,
40
40
  :stub
41
- ) do
41
+ )
42
+
43
+ class Status
42
44
  include ImmutableOptions
43
45
 
44
46
  # The allowed state values
@@ -58,6 +58,7 @@ class Faulty
58
58
  status
59
59
  history
60
60
  list
61
+ clear
61
62
  ].each do |method|
62
63
  define_method(method) do |*args|
63
64
  options.circuit.run { @storage.public_send(method, *args) }
@@ -159,6 +159,14 @@ class Faulty
159
159
  end
160
160
  end
161
161
 
162
+ # Clears circuits in all storage backends
163
+ #
164
+ # @param (see Interface#clear)
165
+ # @return (see Interface#clear)
166
+ def clear
167
+ send_all(:clear)
168
+ end
169
+
162
170
  # This is fault tolerant if any of the available backends are fault tolerant
163
171
  #
164
172
  # @param (see Interface#fault_tolerant?)
@@ -81,7 +81,14 @@ class Faulty
81
81
  # @see Interface#list
82
82
  # @param (see Interface#list)
83
83
  # @return (see Interface#list)
84
- def_delegators :@storage, :lock, :unlock, :reset, :history, :list
84
+ #
85
+ # @!method clear
86
+ # Clear is not called in normal operation, so it doesn't capture errors
87
+ #
88
+ # @see Interface#list
89
+ # @param (see Interface#list)
90
+ # @return (see Interface#list)
91
+ def_delegators :@storage, :lock, :unlock, :reset, :history, :list, :clear
85
92
 
86
93
  # Get circuit options safely
87
94
  #
@@ -172,6 +172,17 @@ class Faulty
172
172
  raise NotImplementedError
173
173
  end
174
174
 
175
+ # Reset all circuits
176
+ #
177
+ # Some implementions may clear circuits on a best-effort basis since
178
+ # all circuits may not be known.
179
+ #
180
+ # @raise NotImplementedError If the storage backend does not support clearing.
181
+ # @return [void]
182
+ def clear
183
+ raise NotImplementedError
184
+ end
185
+
175
186
  # Can this storage backend raise an error?
176
187
  #
177
188
  # If the storage backend returns false from this method, it will be wrapped
@@ -196,6 +196,13 @@ class Faulty
196
196
  @circuits.keys
197
197
  end
198
198
 
199
+ # Clears all circuits
200
+ #
201
+ # @return [void]
202
+ def clear
203
+ @circuits.clear
204
+ end
205
+
199
206
  # Memory storage is fault-tolerant by default
200
207
  #
201
208
  # @return [true]
@@ -79,6 +79,11 @@ class Faulty
79
79
  []
80
80
  end
81
81
 
82
+ # @param (see Interface#clear)
83
+ # @return (see Interface#clear)
84
+ def clear
85
+ end
86
+
82
87
  # This backend is fault tolerant
83
88
  #
84
89
  # @param (see Interface#fault_tolerant?)