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 +4 -4
- data/CHANGELOG.md +3 -0
- data/Gemfile.lock +1 -1
- data/lib/network_resiliency/adapter/http.rb +3 -2
- data/lib/network_resiliency/version.rb +1 -1
- data/lib/network_resiliency.rb +24 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8052be9b61b7e5b4a1106fb70275a788ad70ac19369064863ba9e14a266f7271
|
4
|
+
data.tar.gz: 71c787616cd4d2da2e33cb49b9a41891940215afd978bb33d1efdeb6be6e0d88
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5140b18fff31f7dd33da2cdc158b89c1e7e573f85ada027fea92adfe9f7a43cf2ac64889269cae102409e7d62aa89183ef11ba803e9c1e91d2d00478e0d9d7fd
|
7
|
+
data.tar.gz: 4bcba60c3a1d0737f5765f8043939f9a6557bd0946afc18b266d418749abf7f8b3f7cb3b9bbc68b7dc92ff8d28b21750927a91331d882f1b1afefc967ddfaa48
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
@@ -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)
|
data/lib/network_resiliency.rb
CHANGED
@@ -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
|