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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a9a1103993c635cbda0e6a3ba3ef523c8179680353fa67b93842f0bdfa44b197
4
- data.tar.gz: aeb11a089950492bc6099933c137ccf79c27447a18ce6335e2a46c9982201591
3
+ metadata.gz: 19102b63c5f8090d6805ac5ce1d71a25e30ab7483ef11bf5d9cee771bb4ce508
4
+ data.tar.gz: a9f37e7fafbfc1d45e0f8b24b655cf72b33300b5b6335e396d9dbffc22479799
5
5
  SHA512:
6
- metadata.gz: 7ea2cedcf4e6044299111e69c211a92a3d7df5305e66b4d6be83d32b949425daee581af33142f73f4d618ec178bd10e19ea0599175420838f57b0b61f157a8f5
7
- data.tar.gz: 772d5749b23a32e6be7542c10d18794f1905fd64dde7da5b702bba4b4fb6ceb62fa3b971ce120c550db2fbc89ccec11670e3029ee0649ec7c21266597b0cb637
6
+ metadata.gz: 27390e9651bef755a92a02218c286291971e7c77baabbddd062e3279d5a52f3a819fbbd9b0a9f91e289bd3124afdc028e42caf6b504c54bb198d959ba54dd1f6
7
+ data.tar.gz: 56763326a26679f03124a1a4f8b5dab2de10edeeebaff1a4dab8c821ee9b8a035b3b8cf285089bac944c722cc647bcb47264b7fe60295dfbf51d35c4977d2d1f
data/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ ### v0.3.2 (2023-11-03)
2
+ - stats observability
3
+ - surface errors in specs
4
+ - destination filter
5
+ - error observability
6
+ - improve order of magnitude
7
+
1
8
  ### v0.3.1 (2023-11-02)
2
9
  - sync thread safety
3
10
  - order of magnitude stats
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- network_resiliency (0.3.1)
4
+ network_resiliency (0.3.2)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -1,8 +1,12 @@
1
1
  module NetworkResiliency
2
2
  module Refinements
3
3
  refine Numeric do
4
- def order_of_magnitude
5
- self == 0 ? 0 : 10 ** Math.log10(self).ceil
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
@@ -1,3 +1,3 @@
1
1
  module NetworkResiliency
2
- VERSION = "0.3.1"
2
+ VERSION = "0.3.2"
3
3
  end
@@ -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
- # filter raw IP addresses
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.1
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-02 00:00:00.000000000 Z
11
+ date: 2023-11-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: byebug