network_resiliency 0.6.2 → 0.6.3

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: 5a2741f43768bd43985efdbf000fc82075d8fb2757e6af19a7ab0aeeae2f3a87
4
- data.tar.gz: 713af5ee87ca4a8149a3ce3f5d9416eb2fa03cc0bdea7aca1828e18a59595003
3
+ metadata.gz: 8052be9b61b7e5b4a1106fb70275a788ad70ac19369064863ba9e14a266f7271
4
+ data.tar.gz: 71c787616cd4d2da2e33cb49b9a41891940215afd978bb33d1efdeb6be6e0d88
5
5
  SHA512:
6
- metadata.gz: 6d80cac5009c100449adec47f70636dc015b069dbd6e3901545f6378841de9ad8970b2156d948c4e9ff4deb1cb579141167078032af6faa88270d88566f592e0
7
- data.tar.gz: 7a9f01e6967657f61a40d80755d95f1c67387f598bfa73efb6d3d6f38661a7e17e5ccdf058834e3e8b09ba89bdb0d286019a4c3832b4d54908d044f5db9565e9
6
+ metadata.gz: 5140b18fff31f7dd33da2cdc158b89c1e7e573f85ada027fea92adfe9f7a43cf2ac64889269cae102409e7d62aa89183ef11ba803e9c1e91d2d00478e0d9d7fd
7
+ data.tar.gz: 4bcba60c3a1d0737f5765f8043939f9a6557bd0946afc18b266d418749abf7f8b3f7cb3b9bbc68b7dc92ff8d28b21750927a91331d882f1b1afefc967ddfaa48
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ ### v0.6.3 (2023-11-27)
2
+ - custom request normalization
3
+
1
4
  ### v0.6.2 (2023-11-26)
2
5
  - syncer
3
6
  - redis without_reconnect
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- network_resiliency (0.6.2)
4
+ network_resiliency (0.6.3)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -17,15 +17,16 @@ module NetworkResiliency
17
17
 
18
18
  ID_REGEX = %r{/[0-9]+(?=/|$)}.freeze
19
19
  UUID_REGEX = %r`/\h{8}-\h{4}-(\h{4})-\h{4}-\h{12}(?=/|$)`.freeze
20
+
20
21
  refine Net::HTTP do
21
22
  def normalize_path(path)
22
- path.gsub(
23
+ NetworkResiliency.normalize_request(:http, path).gsub(
23
24
  Regexp.union(
24
25
  NetworkResiliency::Adapter::HTTP::ID_REGEX,
25
26
  NetworkResiliency::Adapter::HTTP::UUID_REGEX,
26
27
  ),
27
28
  '/x',
28
- )
29
+ ).gsub(%r{//+}, "/")
29
30
  end
30
31
 
31
32
  def with_resilience(action, destination, idempotent, &block)
@@ -1,3 +1,3 @@
1
1
  module NetworkResiliency
2
- VERSION = "0.6.2"
2
+ VERSION = "0.6.3"
3
3
  end
@@ -15,6 +15,7 @@ module NetworkResiliency
15
15
  autoload :Postgres, "network_resiliency/adapter/postgres"
16
16
  end
17
17
 
18
+ ADAPTERS = [ :http, :faraday, :redis, :mysql, :postgres ].freeze
18
19
  MODE = [ :observe, :resilient ].freeze
19
20
  RESILIENCY_SIZE_THRESHOLD = 1_000
20
21
 
@@ -103,6 +104,28 @@ module NetworkResiliency
103
104
  @mode = mode
104
105
  end
105
106
 
107
+ def normalize_request(adapter, request = nil, &block)
108
+ unless ADAPTERS.include?(adapter)
109
+ raise ArgumentError, "invalid adapter: #{adapter}"
110
+ end
111
+
112
+ if request && block_given?
113
+ raise ArgumentError, "specify request or block, but not both"
114
+ end
115
+
116
+ @normalize_request ||= {}
117
+ @normalize_request[adapter] ||= []
118
+ @normalize_request[adapter] << block if block_given?
119
+
120
+ if request
121
+ @normalize_request[adapter].reduce(request) do |req, block|
122
+ block.call(req)
123
+ end
124
+ else
125
+ @normalize_request[adapter]
126
+ end
127
+ end
128
+
106
129
  # private
107
130
 
108
131
  def record(adapter:, action:, destination:, duration:, error:, timeout:, attempts: 1)
@@ -291,6 +314,7 @@ module NetworkResiliency
291
314
  def reset
292
315
  @enabled = nil
293
316
  @mode = nil
317
+ @normalize_request = nil
294
318
  Thread.current["network_resiliency"] = nil
295
319
  StatsEngine.reset
296
320
  Syncer.stop
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: network_resiliency
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.2
4
+ version: 0.6.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Pepper