network_resiliency 0.4.0 → 0.5.0

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: c372873056610bf21197e55a265bdfd03e200b064c727a4713ea8725ae3d696d
4
- data.tar.gz: 5da4933543bf9a57d46ed4a3b4d94a692524e641f6c1293d8bcb99aa74c0c9d9
3
+ metadata.gz: 4eb56ca7bf0ce8610999ebfa3d51ddb42c0d1781fdbb944f305e362c03bb0f9a
4
+ data.tar.gz: 9e40b02dfd30f3d60d0983586fe09842fab43a1decc1c419bf6b3b4f640c5613
5
5
  SHA512:
6
- metadata.gz: b8e9b66cb83ff5bfda080c43935e8834228cfbd16afd0c1229be2b7edbea8469702d917ae7b6bb7383b774ebf68802e9a5572ee89357723d479d1dd8b3a91f2c
7
- data.tar.gz: 68f241f0bd9b7ef5b0b291e2e1be11aa3d2c377f6b4b70552ba32638122bff300bc1252b279a13c41e96af3ffa8843bc571b74bd9aac7f1300f27472e18001ff
6
+ metadata.gz: f872730f5fd3e25bb405b24b5cc0c0e3a807c9c582ca70d8bbc3ee172cba6126433f2a3f7d116a9df059fe08a5f4215856a7e3318d50bc160ebecfd463387aa7
7
+ data.tar.gz: 8db779e5dd4fee001e9298806510351d6d0d0748ba0760d37acc9e205b6a425ea22a1f0757d26512a63936020baf764ec266620eb9cd6cbe23745abbb4f8acba
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ ### v0.5.0 (2023-11-16)
2
+ - postgres timeout stats
3
+ - mysql timeout stats
4
+ - http resiliency
5
+
6
+ ### v0.4.1 (2023-11-14)
7
+ - timeout units
8
+
1
9
  ### v0.4.0 (2023-11-13)
2
10
  - redis resiliency
3
11
  - timeouts_for
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- network_resiliency (0.4.0)
4
+ network_resiliency (0.5.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -18,7 +18,7 @@ NetworkResiliency.configure do |conf|
18
18
  conf.patch :redis
19
19
  end
20
20
 
21
- Redis.new.connect
21
+ Redis.new.ping
22
22
  ```
23
23
 
24
24
 
@@ -18,23 +18,45 @@ module NetworkResiliency
18
18
  module Instrumentation
19
19
  def connect
20
20
  return super unless NetworkResiliency.enabled?(:http)
21
+ original_timeout = self.open_timeout
22
+
23
+ timeouts = NetworkResiliency.timeouts_for(
24
+ adapter: "http",
25
+ action: "connect",
26
+ destination: address,
27
+ max: original_timeout,
28
+ units: :seconds,
29
+ )
30
+
31
+ attempts = 0
32
+ ts = -NetworkResiliency.timestamp
21
33
 
22
34
  begin
23
- ts = -NetworkResiliency.timestamp
35
+ attempts += 1
36
+ error = nil
37
+
38
+ self.open_timeout = timeouts.shift
24
39
 
25
40
  super
26
41
  rescue Net::OpenTimeout => e
27
42
  # capture error
43
+ error = e.class
44
+
45
+ retry if timeouts.size > 0
46
+
28
47
  raise
29
48
  ensure
30
49
  ts += NetworkResiliency.timestamp
50
+ self.open_timeout = original_timeout
31
51
 
32
52
  NetworkResiliency.record(
33
53
  adapter: "http",
34
54
  action: "connect",
35
55
  destination: address,
36
- error: e&.class,
56
+ error: error,
37
57
  duration: ts,
58
+ timeout: self.open_timeout * 1_000,
59
+ attempts: attempts,
38
60
  )
39
61
  end
40
62
  end
@@ -18,8 +18,6 @@ module NetworkResiliency
18
18
 
19
19
  module Instrumentation
20
20
  def connect(_, _, host, *args)
21
- # timeout = query_options[:connect_timeout]
22
-
23
21
  return super unless NetworkResiliency.enabled?(:mysql)
24
22
 
25
23
  begin
@@ -38,11 +36,14 @@ module NetworkResiliency
38
36
  destination: host,
39
37
  error: e&.class,
40
38
  duration: ts,
39
+ timeout: query_options[:connect_timeout] * 1_000,
41
40
  )
42
41
  end
43
42
  end
44
43
 
45
44
  # def query(sql, options = {})
45
+ # query_options[:read_timeout]
46
+ # query_options[:write_timeout]
46
47
  # puts "query"
47
48
  # super
48
49
  # end
@@ -38,6 +38,7 @@ module NetworkResiliency
38
38
  destination: host,
39
39
  error: e&.class,
40
40
  duration: ts,
41
+ timeout: opts[:connect_timeout].to_i * 1_000,
41
42
  )
42
43
  end
43
44
  end
@@ -46,6 +46,7 @@ module NetworkResiliency
46
46
  action: "connect",
47
47
  destination: host,
48
48
  max: original_timeout,
49
+ units: :seconds,
49
50
  )
50
51
 
51
52
  attempts = 0
@@ -77,7 +78,7 @@ module NetworkResiliency
77
78
  destination: host,
78
79
  duration: ts,
79
80
  error: error,
80
- timeout: @options[:connect_timeout],
81
+ timeout: @options[:connect_timeout] * 1_000,
81
82
  attempts: attempts,
82
83
  )
83
84
  end
@@ -31,7 +31,7 @@ module NetworkResiliency
31
31
 
32
32
  # select data to be synced
33
33
  data = synchronize do
34
- # ensure sync is not run concurrently
34
+ # ensure sync does not run concurrently
35
35
  return [] if @syncing
36
36
  @syncing = Thread.current
37
37
 
@@ -1,3 +1,3 @@
1
1
  module NetworkResiliency
2
- VERSION = "0.4.0"
2
+ VERSION = "0.5.0"
3
3
  end
@@ -104,7 +104,7 @@ module NetworkResiliency
104
104
 
105
105
  # private
106
106
 
107
- def record(adapter:, action:, destination:, duration:, error:, timeout: nil, attempts: 1)
107
+ def record(adapter:, action:, destination:, duration:, error:, timeout:, attempts: 1)
108
108
  return if ignore_destination?(adapter, action, destination)
109
109
 
110
110
  NetworkResiliency.statsd&.distribution(
@@ -153,6 +153,7 @@ module NetworkResiliency
153
153
  tags: {
154
154
  adapter: adapter,
155
155
  destination: destination,
156
+ attempts: attempts,
156
157
  },
157
158
  ) if attempts > 1
158
159
 
@@ -204,7 +205,7 @@ module NetworkResiliency
204
205
  IP_ADDRESS_REGEX.match?(destination)
205
206
  end
206
207
 
207
- def timeouts_for(adapter:, action:, destination:, max: nil)
208
+ def timeouts_for(adapter:, action:, destination:, max: nil, units: :ms)
208
209
  default = [ max ]
209
210
 
210
211
  return default if NetworkResiliency.mode == :observe
@@ -224,6 +225,8 @@ module NetworkResiliency
224
225
  timeouts = []
225
226
 
226
227
  if max
228
+ max *= 1_000 if units == :s || units == :seconds
229
+
227
230
  if p99 < max
228
231
  timeouts << p99
229
232
 
@@ -262,7 +265,14 @@ module NetworkResiliency
262
265
  )
263
266
  end
264
267
 
265
- timeouts
268
+ case units
269
+ when nil, :ms, :milliseconds
270
+ timeouts
271
+ when :s, :seconds
272
+ timeouts.map { |t| t.to_f / 1_000 if t }
273
+ else
274
+ raise ArgumentError, "invalid units: #{units}"
275
+ end
266
276
  rescue => e
267
277
  NetworkResiliency.statsd&.increment(
268
278
  "network_resiliency.error",
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.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Pepper
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-11-13 00:00:00.000000000 Z
11
+ date: 2023-11-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: byebug