network_resiliency 0.2.1 → 0.3.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: f19f34885c2da17fa7d1d7bb5777a4d8712918281708d0e04f743260859cbd90
4
- data.tar.gz: 1ee75fdedacbb172ae51ba3c425d8808ba3ecfd4b6414cd8155195603dc49d94
3
+ metadata.gz: fb3d39476429afedf4ec8532e509dd25d0c121e21fa59f36b69bad40a0985dc6
4
+ data.tar.gz: 2ef67d94b01e34a758ae52117e1e9ac5eb9fa8901841d5bcb9ef7c1cc3011f6f
5
5
  SHA512:
6
- metadata.gz: 7e2f9eb75cddf2fee82f32a561df20180bced19639fb0326010c67e0cca4076d01114a5368648a8ce781220d0cb90db4a6c6256859d27669c7c94204ab69f628
7
- data.tar.gz: 614a9aa8a59ce1918f9b800c098a1e0c41254df096ed698c64c3ae24b2c9275a214aa1f134ae6c6f9b5308a29fdcd87f0dc92dfe7af0fafc79cd466d2823265e
6
+ metadata.gz: b3c19d756696ab7d4d0a11e13d6d99c70a27bd2414774e71eb31147e08685e74da0a4f5b56d15260cbbc0faf9e954b1976db307f116a47208697e83d2ff3f7ef
7
+ data.tar.gz: 28a018c2ad35c15e01309da7a4f0368a67f4c21aacaba8f81fbc1fb2b41435fea368b98ec84274fca03e406416f9fa6eb403e0426adb046ba9a8ea1ae826bd83
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ### v0.3.0 (2023-10-04)
2
+ - mysql adapter
3
+ - faraday version constraint
4
+
1
5
  ### v0.2.1 (2023-10-02)
2
6
  - prevent recursion
3
7
  - test coverage
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- network_resiliency (0.2.1)
4
+ network_resiliency (0.3.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -45,6 +45,7 @@ GEM
45
45
  ffi (~> 1.0)
46
46
  msgpack (1.7.2)
47
47
  multipart-post (2.3.0)
48
+ mysql2 (0.5.5)
48
49
  rack (3.0.8)
49
50
  rack-test (2.1.0)
50
51
  rack (>= 1.3)
@@ -79,6 +80,7 @@ DEPENDENCIES
79
80
  dogstatsd-ruby (<= 4.8.3)
80
81
  faraday (~> 1)
81
82
  faraday-rack
83
+ mysql2 (>= 0.5)
82
84
  network_resiliency!
83
85
  rack
84
86
  rack-test
@@ -1,3 +1,4 @@
1
+ gem "faraday", "~> 1.10"
1
2
  require "faraday"
2
3
 
3
4
  module NetworkResiliency
@@ -0,0 +1,52 @@
1
+ gem "mysql2", ">= 0.5"
2
+ require "mysql2"
3
+
4
+ module NetworkResiliency
5
+ module Adapter
6
+ module Mysql
7
+ extend self
8
+
9
+ def patch
10
+ return if patched?
11
+
12
+ Mysql2::Client.prepend(Instrumentation)
13
+ end
14
+
15
+ def patched?
16
+ Mysql2::Client.ancestors.include?(Instrumentation)
17
+ end
18
+
19
+ module Instrumentation
20
+ def connect(_, _, host, *args)
21
+ # timeout = query_options[:connect_timeout]
22
+
23
+ return super unless NetworkResiliency.enabled?(:mysql)
24
+
25
+ begin
26
+ ts = -NetworkResiliency.timestamp
27
+
28
+ super
29
+ rescue Mysql2::Error::TimeoutError => e
30
+ # capture error
31
+ raise
32
+ ensure
33
+ ts += NetworkResiliency.timestamp
34
+
35
+ NetworkResiliency.record(
36
+ adapter: "mysql",
37
+ action: "connect",
38
+ destination: host,
39
+ error: e&.class,
40
+ duration: ts,
41
+ )
42
+ end
43
+ end
44
+
45
+ # def query(sql, options = {})
46
+ # puts "query"
47
+ # super
48
+ # end
49
+ end
50
+ end
51
+ end
52
+ end
@@ -1,3 +1,3 @@
1
1
  module NetworkResiliency
2
- VERSION = "0.2.1"
2
+ VERSION = "0.3.0"
3
3
  end
@@ -5,6 +5,7 @@ module NetworkResiliency
5
5
  autoload :HTTP, "network_resiliency/adapter/http"
6
6
  autoload :Faraday, "network_resiliency/adapter/faraday"
7
7
  autoload :Redis, "network_resiliency/adapter/redis"
8
+ autoload :Mysql, "network_resiliency/adapter/mysql"
8
9
  end
9
10
 
10
11
  extend self
@@ -22,6 +23,8 @@ module NetworkResiliency
22
23
  Adapter::HTTP.patch
23
24
  when :redis
24
25
  Adapter::Redis.patch
26
+ when :mysql
27
+ Adapter::Mysql.patch
25
28
  else
26
29
  raise NotImplementedError
27
30
  end
@@ -18,6 +18,7 @@ Gem::Specification.new do |s|
18
18
  s.add_development_dependency "dogstatsd-ruby", "<= 4.8.3"
19
19
  s.add_development_dependency "faraday", "~> 1"
20
20
  s.add_development_dependency "faraday-rack"
21
+ s.add_development_dependency "mysql2", ">= 0.5"
21
22
  s.add_development_dependency "rack"
22
23
  s.add_development_dependency "rack-test"
23
24
  s.add_development_dependency "redis", "~> 4"
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.2.1
4
+ version: 0.3.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-10-02 00:00:00.000000000 Z
11
+ date: 2023-10-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: byebug
@@ -80,6 +80,20 @@ dependencies:
80
80
  - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: mysql2
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0.5'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0.5'
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: rack
85
99
  requirement: !ruby/object:Gem::Requirement
@@ -164,6 +178,7 @@ files:
164
178
  - lib/network_resiliency.rb
165
179
  - lib/network_resiliency/adapter/faraday.rb
166
180
  - lib/network_resiliency/adapter/http.rb
181
+ - lib/network_resiliency/adapter/mysql.rb
167
182
  - lib/network_resiliency/adapter/redis.rb
168
183
  - lib/network_resiliency/stats.rb
169
184
  - lib/network_resiliency/version.rb