network_resiliency 0.4.1 → 0.5.1

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: 8949456e392f5198caa080238dff62a567114a9386d3a6f575fdb855fd5b5e98
4
- data.tar.gz: 95d58f753ccb7f4aa5ffe1093d98d0f5e33016bb7e06caa111a181d29c8ac5fb
3
+ metadata.gz: 6bf447ec73846d8911df202dc4a2ba576879a2768cd2a2e817ae9119a0e40506
4
+ data.tar.gz: d38481d92461272cbcefd34ea81f2c82d38381e135a06daed527210cdce6a178
5
5
  SHA512:
6
- metadata.gz: d1544a231ebcdd48c6838a8b398f3d4463c9cae2e18182c8e28fda3c4cfeba51b75b6e355342f98a16a51979da035d65040dffdd83e1bcd0273c636f14332236
7
- data.tar.gz: a90be5d5152dee3ce23ef7d682ce62dd495293e429d06494e5dcc91eb9cf3bf4a0bcf26b1cece0665815ab181394feff48016c9781e81b69408de3dca1572ec1
6
+ metadata.gz: 73b6e3fa940f4f8b91e26cc039b2bdfb37f7879a2a4c60ac1cc29e0572e79fd427c4984dfd8a139695e1225a370e295330833d81e250c6b3f922f467fb5f0b00
7
+ data.tar.gz: 00a8fe95736393d1e9133ca4d2d0c9873d859a93c53ef487503ad00762eadcaba18bad6c99138910a9bbf4916cc7eae5a464d8324657321b68eaaca076a5a10f
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ ### v0.5.1 (2023-11-17)
2
+ - support nil timeouts
3
+
4
+ ### v0.5.0 (2023-11-16)
5
+ - postgres timeout stats
6
+ - mysql timeout stats
7
+ - http resiliency
8
+
1
9
  ### v0.4.1 (2023-11-14)
2
10
  - timeout units
3
11
 
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- network_resiliency (0.4.1)
4
+ network_resiliency (0.5.1)
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.to_f * 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].to_f * 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
@@ -78,7 +78,7 @@ module NetworkResiliency
78
78
  destination: host,
79
79
  duration: ts,
80
80
  error: error,
81
- timeout: @options[:connect_timeout] * 1_000,
81
+ timeout: @options[:connect_timeout].to_f * 1_000,
82
82
  attempts: attempts,
83
83
  )
84
84
  end
@@ -1,3 +1,3 @@
1
1
  module NetworkResiliency
2
- VERSION = "0.4.1"
2
+ VERSION = "0.5.1"
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(
@@ -135,7 +135,7 @@ module NetworkResiliency
135
135
  adapter: adapter,
136
136
  destination: destination,
137
137
  },
138
- )
138
+ ) if timeout && timeout > 0
139
139
 
140
140
  if error
141
141
  NetworkResiliency.statsd&.distribution(
@@ -145,7 +145,7 @@ module NetworkResiliency
145
145
  adapter: adapter,
146
146
  destination: destination,
147
147
  },
148
- ) if timeout
148
+ ) if timeout && timeout > 0
149
149
  else
150
150
  # track successful retries
151
151
  NetworkResiliency.statsd&.increment(
@@ -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
 
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.1
4
+ version: 0.5.1
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-14 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