network_resiliency 0.7.12 → 0.7.14

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 93c15344f1a3f02c3ef567baeb1650745b27286a92db1975368a2066e29df423
4
- data.tar.gz: '092ee5a69a9f6b3e2e299946404c83353bb142e7d6d596d7fe4d556640500c5f'
3
+ metadata.gz: 8515a542f0e3d22b8e562187dcc23325c8c89866c2e708cf540cb73894195471
4
+ data.tar.gz: 30cd44b2ad019321587b8d29f0afc28cde9070f88ded257799e1bcb1aa3dc7e1
5
5
  SHA512:
6
- metadata.gz: 9a84c796661456dd272fa052647ec99991956f5d69435a8dd046a93634de0bbfdc5100cd7cb9b8dfb54d3641d18c71cb5b0728c70448ed6de40fa2bd181eb02e
7
- data.tar.gz: d9487add703cd5c2ef71abbed8d913619338e240faceaaeac8621c58dbfe2af6203029328f37875f75315d94f91498a6283e252f3c3703fefd12b546e46745c1
6
+ metadata.gz: 0530fb98688ef75f2cccd2bbe4e75c835bbf20ca3cbdec307c26f9ed9bc04462361867f96ecbf001dc81c36675b1024dca2e09f80b0fa8e71fc623d0540849d2
7
+ data.tar.gz: 2de979e7c792a32f7993625a529d31a7b35616c51c17aedea97acd2884f0a589144ec2bbb81cf6cb0f8a50591c3bc414cff7e3253643cb46c266ecf0cb8d2458
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ ### v0.7.14 (2024-03-07)
2
+ - lower dynamic timeout
3
+ - timeout-min
4
+
5
+ ### v0.7.13 (2024-03-04)
6
+ - downsampling
7
+ - redis resiliency
8
+
1
9
  ### v0.7.12 (2024-02-23)
2
10
  - improve metric sampling
3
11
  - lower resiliency threshold
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- network_resiliency (0.7.12)
4
+ network_resiliency (0.7.14)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -50,7 +50,9 @@ module NetworkResiliency
50
50
  NetworkResiliency.redis.disconnect! if NetworkResiliency.redis.connected?
51
51
 
52
52
  until @shutdown
53
- StatsEngine.sync(NetworkResiliency.redis)
53
+ NetworkResiliency.redis.with_reconnect do
54
+ StatsEngine.sync(NetworkResiliency.redis)
55
+ end
54
56
 
55
57
  sleep(SLEEP_DURATION)
56
58
  end
@@ -1,3 +1,3 @@
1
1
  module NetworkResiliency
2
- VERSION = "0.7.12"
2
+ VERSION = "0.7.14"
3
3
  end
@@ -19,8 +19,9 @@ module NetworkResiliency
19
19
 
20
20
  ACTIONS = [ :connect, :request ].freeze
21
21
  ADAPTERS = [ :http, :faraday, :redis, :mysql, :postgres, :rails ].freeze
22
+ DEFAULT_TIMEOUT_MIN = 10 # ms
22
23
  MODE = [ :observe, :resilient ].freeze
23
- RESILIENCY_SIZE_THRESHOLD = 300
24
+ RESILIENCY_THRESHOLD = 300
24
25
  SAMPLE_RATE = {
25
26
  timeout: 0.1,
26
27
  stats: 0.1,
@@ -216,6 +217,18 @@ module NetworkResiliency
216
217
  end
217
218
  end
218
219
 
220
+ def timeout_min=(val)
221
+ unless val.nil? || val.is_a?(Numeric)
222
+ raise ArgumentError, "invalid timeout_min: #{val}"
223
+ end
224
+
225
+ @timeout_min = val
226
+ end
227
+
228
+ def timeout_min
229
+ @timeout_min || DEFAULT_TIMEOUT_MIN
230
+ end
231
+
219
232
  # private
220
233
 
221
234
  def record(adapter:, action:, destination:, duration:, error:, timeout:, attempts: 1)
@@ -257,6 +270,12 @@ module NetworkResiliency
257
270
  # record stats
258
271
  key = [ adapter, action, destination ].join(":")
259
272
  stats = StatsEngine.add(key, duration)
273
+
274
+ if stats.n > RESILIENCY_THRESHOLD * 4
275
+ # downsample to age out old stats
276
+ stats.scale!(50)
277
+ end
278
+
260
279
  tags = {
261
280
  adapter: adapter,
262
281
  destination: destination,
@@ -311,7 +330,7 @@ module NetworkResiliency
311
330
  key = [ adapter, action, destination ].join(":")
312
331
  stats = StatsEngine.get(key)
313
332
 
314
- return default unless stats.n >= RESILIENCY_SIZE_THRESHOLD
333
+ return default unless stats.n >= RESILIENCY_THRESHOLD
315
334
 
316
335
  tags = {
317
336
  adapter: adapter,
@@ -319,7 +338,9 @@ module NetworkResiliency
319
338
  destination: destination,
320
339
  }
321
340
 
322
- p99 = (stats.avg + stats.stdev * 2).order_of_magnitude(ceil: true)
341
+ # p99 = (stats.avg + stats.stdev * 2).order_of_magnitude(ceil: true)
342
+ p99 = (stats.avg + stats.stdev * 3).power_ceil
343
+ p99 = [ p99, timeout_min ].max
323
344
 
324
345
  timeouts = []
325
346
 
@@ -396,6 +417,7 @@ module NetworkResiliency
396
417
  @mode = nil
397
418
  @normalize_request = nil
398
419
  @patched = nil
420
+ @timeout_min = nil
399
421
  Thread.current["network_resiliency"] = nil
400
422
  StatsEngine.reset
401
423
  Syncer.stop
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: network_resiliency
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.12
4
+ version: 0.7.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Pepper
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-02-23 00:00:00.000000000 Z
11
+ date: 2024-03-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: byebug