network_resiliency 0.3.1 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/Gemfile.lock +1 -1
- data/lib/network_resiliency/refinements.rb +6 -2
- data/lib/network_resiliency/version.rb +1 -1
- data/lib/network_resiliency.rb +35 -6
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 19102b63c5f8090d6805ac5ce1d71a25e30ab7483ef11bf5d9cee771bb4ce508
|
4
|
+
data.tar.gz: a9f37e7fafbfc1d45e0f8b24b655cf72b33300b5b6335e396d9dbffc22479799
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 27390e9651bef755a92a02218c286291971e7c77baabbddd062e3279d5a52f3a819fbbd9b0a9f91e289bd3124afdc028e42caf6b504c54bb198d959ba54dd1f6
|
7
|
+
data.tar.gz: 56763326a26679f03124a1a4f8b5dab2de10edeeebaff1a4dab8c821ee9b8a035b3b8cf285089bac944c722cc647bcb47264b7fe60295dfbf51d35c4977d2d1f
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,8 +1,12 @@
|
|
1
1
|
module NetworkResiliency
|
2
2
|
module Refinements
|
3
3
|
refine Numeric do
|
4
|
-
def order_of_magnitude
|
5
|
-
|
4
|
+
def order_of_magnitude(ceil: false)
|
5
|
+
return 0 if self <= 0
|
6
|
+
return 1 if self <= 1
|
7
|
+
|
8
|
+
log10 = Math.log10(self.round)
|
9
|
+
10 ** (ceil ? log10.ceil : log10.floor)
|
6
10
|
end
|
7
11
|
end
|
8
12
|
end
|
data/lib/network_resiliency.rb
CHANGED
@@ -89,11 +89,8 @@ module NetworkResiliency
|
|
89
89
|
|
90
90
|
# private
|
91
91
|
|
92
|
-
IP_ADDRESS_REGEX = Regexp.new(/\d{1,3}(\.\d{1,3}){3}/)
|
93
|
-
|
94
92
|
def record(adapter:, action:, destination:, duration:, error: nil)
|
95
|
-
|
96
|
-
return if IP_ADDRESS_REGEX.match?(destination)
|
93
|
+
return if ignore_destination?(adapter, action, destination)
|
97
94
|
|
98
95
|
NetworkResiliency.statsd&.distribution(
|
99
96
|
"network_resiliency.#{action}",
|
@@ -107,7 +104,7 @@ module NetworkResiliency
|
|
107
104
|
|
108
105
|
NetworkResiliency.statsd&.distribution(
|
109
106
|
"network_resiliency.#{action}.magnitude",
|
110
|
-
duration.order_of_magnitude,
|
107
|
+
duration.order_of_magnitude(ceil: true),
|
111
108
|
tags: {
|
112
109
|
adapter: adapter,
|
113
110
|
destination: destination,
|
@@ -116,11 +113,36 @@ module NetworkResiliency
|
|
116
113
|
)
|
117
114
|
|
118
115
|
key = [ adapter, action, destination ].join(":")
|
119
|
-
StatsEngine.add(key, duration)
|
116
|
+
StatsEngine.add(key, duration).tap do |stats|
|
117
|
+
tags = {
|
118
|
+
adapter: adapter,
|
119
|
+
destination: destination,
|
120
|
+
n: stats.n.order_of_magnitude,
|
121
|
+
}
|
122
|
+
|
123
|
+
NetworkResiliency.statsd&.distribution(
|
124
|
+
"network_resiliency.#{action}.stats.n",
|
125
|
+
stats.n,
|
126
|
+
tags: tags,
|
127
|
+
)
|
128
|
+
|
129
|
+
NetworkResiliency.statsd&.distribution(
|
130
|
+
"network_resiliency.#{action}.stats.avg",
|
131
|
+
stats.avg,
|
132
|
+
tags: tags,
|
133
|
+
)
|
134
|
+
|
135
|
+
NetworkResiliency.statsd&.distribution(
|
136
|
+
"network_resiliency.#{action}.stats.stdev",
|
137
|
+
stats.stdev,
|
138
|
+
tags: tags,
|
139
|
+
)
|
140
|
+
end
|
120
141
|
rescue => e
|
121
142
|
NetworkResiliency.statsd&.increment(
|
122
143
|
"network_resiliency.error",
|
123
144
|
tags: {
|
145
|
+
method: __method__,
|
124
146
|
type: e.class,
|
125
147
|
},
|
126
148
|
)
|
@@ -128,6 +150,13 @@ module NetworkResiliency
|
|
128
150
|
warn "[ERROR] NetworkResiliency: #{e.class}: #{e.message}"
|
129
151
|
end
|
130
152
|
|
153
|
+
IP_ADDRESS_REGEX = Regexp.new(/\d{1,3}(\.\d{1,3}){3}/)
|
154
|
+
|
155
|
+
def ignore_destination?(adapter, action, destination)
|
156
|
+
# filter raw IP addresses
|
157
|
+
IP_ADDRESS_REGEX.match?(destination)
|
158
|
+
end
|
159
|
+
|
131
160
|
def reset
|
132
161
|
@enabled = nil
|
133
162
|
Thread.current["network_resiliency"] = nil
|
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.3.
|
4
|
+
version: 0.3.2
|
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-
|
11
|
+
date: 2023-11-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: byebug
|