semian 0.13.3 → 0.14.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: b572c4e4fa4dee4453017187bc759a29890dca1627f8bebea6207223e58e49ba
4
- data.tar.gz: f8b7f8eda600b096242becc44cb80a10592d9a9b2490349eecb5c11a008c0fe0
3
+ metadata.gz: a7b62deafc4e8de524ae8aec32a17e3a1065d70206a5ead2ef6298da3b1c38ed
4
+ data.tar.gz: 3f6b18aa473410c0ad8d476931417fa69595328fd748a2edb75a333709b901cd
5
5
  SHA512:
6
- metadata.gz: 30c39a27e0e57ddcccc794fbe9cc04f1d84c864c1cd2786bb2e4e6e7050b51f152feeba8c66c59d1feae3c195b93a921a76aa1985dc034f00e3394d6b4cb3123
7
- data.tar.gz: 922ba4aa39b90898b84cb301ee28344e5cfe8f57b523e531db24bba2bee3731d55dda0256bf7dd923fe33175daad960a93a1090addad68a448e6fe384a6a8c42
6
+ metadata.gz: c064829103c0c4f8915f6c072d43872b9a6dc011987e6a81f5efa8931052cc84b758df9bc4dd74f4f90c0501accbaa3e09ca3212af6a8a3e7056ce1f28a28e22
7
+ data.tar.gz: 124128fc2a5791317ea5a04b32c84e9b3cd394e843a74599c5ecf044cc6c89eec656384675b88e9fd73e95038dfb1e8a35b8e613034114e264b59e754a8eec0c
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "semian/redis_client"
4
+
5
+ class Redis
6
+ BaseConnectionError.include(::Semian::AdapterError)
7
+ OutOfMemoryError.include(::Semian::AdapterError)
8
+
9
+ class SemianError < BaseConnectionError
10
+ def initialize(semian_identifier, *args)
11
+ super(*args)
12
+ @semian_identifier = semian_identifier
13
+ end
14
+ end
15
+
16
+ ResourceBusyError = Class.new(SemianError)
17
+ CircuitOpenError = Class.new(SemianError)
18
+
19
+ Client::ERROR_MAPPING.merge!(
20
+ RedisClient::CircuitOpenError => Redis::CircuitOpenError,
21
+ RedisClient::ResourceBusyError => Redis::ResourceBusyError,
22
+ )
23
+ end
24
+
25
+ module Semian
26
+ module RedisV5
27
+ def semian_resource
28
+ _client.semian_resource
29
+ end
30
+
31
+ def semian_identifier
32
+ _client.semian_identifier
33
+ end
34
+ end
35
+
36
+ module RedisV5Client
37
+ private
38
+
39
+ def translate_error!(error)
40
+ redis_error = translate_error_class(error.class)
41
+ if redis_error < ::Semian::AdapterError
42
+ redis_error = redis_error.new(error.message)
43
+ redis_error.semian_identifier = semian_identifier
44
+ end
45
+ raise redis_error, error.message, error.backtrace
46
+ end
47
+ end
48
+ end
49
+
50
+ ::Redis.prepend(Semian::RedisV5)
51
+ ::Redis::Client.prepend(Semian::RedisV5Client)
data/lib/semian/redis.rb CHANGED
@@ -3,8 +3,9 @@
3
3
  require "semian/adapter"
4
4
  require "redis"
5
5
 
6
- if Redis::VERSION >= "5.0.0"
7
- Semian.logger.warn("NOTE: Semian is not compatible with Redis 5.x")
6
+ if Redis::VERSION >= "5"
7
+ gem "redis", ">= 5.0.3"
8
+ require "semian/redis/v5"
8
9
  return
9
10
  end
10
11
 
@@ -63,7 +64,7 @@ class Redis
63
64
  end
64
65
 
65
66
  module Semian
66
- module Redis
67
+ module RedisV4
67
68
  include Semian::Adapter
68
69
 
69
70
  ResourceBusyError = ::Redis::ResourceBusyError
@@ -157,4 +158,4 @@ module Semian
157
158
  end
158
159
  end
159
160
 
160
- ::Redis::Client.include(Semian::Redis)
161
+ ::Redis::Client.include(Semian::RedisV4)
@@ -5,6 +5,14 @@ require "redis-client"
5
5
 
6
6
  class RedisClient
7
7
  ConnectionError.include(::Semian::AdapterError)
8
+ ConnectionError.class_eval do
9
+ # A Connection Reset is a fast failure and we don't want to track these errors in semian
10
+ def marks_semian_circuits?
11
+ !message.include?("Connection reset by peer")
12
+ end
13
+ end
14
+
15
+ OutOfMemoryError.include(::Semian::AdapterError)
8
16
 
9
17
  class SemianError < ConnectionError
10
18
  def initialize(semian_identifier, *args)
@@ -72,7 +80,7 @@ module Semian
72
80
  end
73
81
 
74
82
  module RedisClient
75
- EXCEPTIONS = [::RedisClient::ConnectionError]
83
+ EXCEPTIONS = [::RedisClient::ConnectionError, ::RedisClient::OutOfMemoryError]
76
84
 
77
85
  include Semian::Adapter
78
86
  include RedisClientCommon
@@ -110,4 +118,4 @@ module Semian
110
118
  end
111
119
 
112
120
  RedisClient.prepend(Semian::RedisClient)
113
- RedisClient::Pooled.prepend(Semian::RedisClient)
121
+ RedisClient::Pooled.prepend(Semian::RedisClientPool)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Semian
4
- VERSION = "0.13.3"
4
+ VERSION = "0.14.0"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: semian
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.13.3
4
+ version: 0.14.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Scott Francis
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2022-09-02 00:00:00.000000000 Z
13
+ date: 2022-09-07 00:00:00.000000000 Z
14
14
  dependencies: []
15
15
  description: |2
16
16
  A Ruby C extention that is used to control access to shared resources
@@ -21,7 +21,6 @@ extensions:
21
21
  - ext/semian/extconf.rb
22
22
  extra_rdoc_files: []
23
23
  files:
24
- - CHANGELOG.md
25
24
  - LICENSE.md
26
25
  - README.md
27
26
  - ext/semian/extconf.rb
@@ -46,6 +45,7 @@ files:
46
45
  - lib/semian/protected_resource.rb
47
46
  - lib/semian/rails.rb
48
47
  - lib/semian/redis.rb
48
+ - lib/semian/redis/v5.rb
49
49
  - lib/semian/redis_client.rb
50
50
  - lib/semian/resource.rb
51
51
  - lib/semian/simple_integer.rb
@@ -60,18 +60,10 @@ metadata:
60
60
  allowed_push_host: https://rubygems.org
61
61
  bug_tracker_uri: https://github.com/Shopify/semian/issues
62
62
  changelog_uri: https://github.com/Shopify/semian/blob/master/CHANGELOG.md
63
+ documentation_uri: https://github.com/Shopify/semian
64
+ homepage_uri: https://github.com/Shopify/semian
63
65
  source_code_uri: https://github.com/Shopify/semian
64
- post_install_message: |2+
65
-
66
- ==============================================================================
67
-
68
- semians is not compatible with redis 5.x.
69
- Update Gemfile to use older redis version:
70
-
71
- gem "redis", "~> 4.8"
72
-
73
- ==============================================================================
74
-
66
+ post_install_message:
75
67
  rdoc_options: []
76
68
  require_paths:
77
69
  - lib
data/CHANGELOG.md DELETED
@@ -1,247 +0,0 @@
1
- # Unreleased
2
-
3
- # v0.13.3
4
-
5
- * Add a warning message about redis 5.x. (#386)
6
-
7
- # v0.13.2
8
-
9
- * Fix: Update AbstractAdapter patch to accomodate recent Rails changes. (#364)
10
-
11
- # v0.13.1
12
-
13
- * Fix: Raise `Redis::OutOfMemoryError` for messages that match `OOM command not allowed when used memory > 'maxmemory'` rather than checking `start_with?("OOM ")`. (#367)
14
-
15
- # v0.13.0
16
-
17
- * Refactor: Replace Time.now with CLOCK_MONOTONIC in MockServer (#318)
18
- * Fix: Circuit not open for GRPC::ActiveCall::Operation failures (#348)
19
-
20
- # v0.12.0
21
-
22
- * Feature: Add support for the `redis-client` gem (#314)
23
-
24
- # v0.11.8
25
-
26
- * Feature: Add error_threshold_timeout configuration parameter (#299)
27
-
28
- # v0.11.7
29
-
30
- * Fix: ECONNRESET won't trigger circuit open for redis (#306)
31
-
32
- # v0.11.6
33
-
34
- * Fix: pass disable flag by patching new singleton method (#303)
35
-
36
- # v0.11.5
37
-
38
- * Feature: Add disable flag to http adapter (#301)
39
-
40
- # v0.11.4
41
-
42
- * Fix: Add `extern` to global variable declarations for gcc 10 (#288)
43
-
44
- # v0.11.3
45
-
46
- * Feature: Log last error message on circuit breaker state transition (#285)
47
- * Fix: Update README and docs to resolve common misconception about error_threshold (#283)
48
-
49
- # v0.11.2
50
-
51
- * Fix: Remove `MySQL client is not connected` error from mysql2 adapter
52
-
53
- # v0.11.1
54
-
55
- * Feature: Add `Semian.namespace` to globally prefix all the semaphore names. (#280)
56
-
57
- # v0.11.0
58
-
59
- * Feature: Add `Semian.default_permissions` to globally change the default semaphore permissions. (#279)
60
-
61
- # v0.10.6
62
-
63
- * Fix: Match whitelisted SQL queries when Marginalia is prepended (#276)
64
-
65
- # v0.10.5
66
-
67
- * Fix: Compatibility with GC.compact
68
-
69
- # v0.10.4
70
-
71
- * Fix: Revert the changes in v0.10.3. (#270)
72
-
73
- # v0.10.3
74
-
75
- * Fix: Positional/Keyword arguments deprecations warning for Ruby 2.7 in the grpc adapter. (#269)
76
-
77
- # v0.10.2
78
-
79
- * Fix: Positional/Keyword arguments deprecations warning for Ruby 2.7.
80
-
81
- # v0.10.1
82
-
83
- * Fix: thread safety bug on Ruby 2.7. (#263)
84
-
85
- # v0.10.0
86
-
87
- * Feature: Support half open resource timeout for redis.
88
-
89
- # v0.9.1
90
-
91
- * Fix: Compatibility with MRI 2.3
92
-
93
- # v0.9.0
94
-
95
- * Feature: Add a LRU to garbage collect old resources. (#193)
96
-
97
- # v0.8.9
98
- * Fix: Recursion issue in MySQL2 adapter causing circuits breakers to stay open much longer than they should. (#250)
99
- * Fix: Better handle DNS resolutions exceptions in Redis adapter. (#230)
100
-
101
- # v0.8.8
102
- * Feature: Introduce the GRPC adapter (#200)
103
-
104
- # v0.8.7
105
- * Fix: Instrument success for `acquire_circuit_breaker` (#209)
106
-
107
- # v0.8.6
108
- * Feature: If an error instance responds to `#marks_semian_circuits?` don't mark the circuit if it returns false (#210)
109
-
110
- # v0.8.5
111
- * Fix: Redis adapter using hiredis is resilient to DNS resolution failures (#205)
112
-
113
- # v0.8.4
114
- * Feature: Introduce `half_open_resource_timeout` which changes the resource timeout when the circuit is in a half-open state for the Net::HTTP adapter. (#198)
115
- * Feature: Add the cause of the last error when a circuit opens (#197)
116
- * Fix: Reset successes when transitioning to the half open state (#192)
117
-
118
- # v0.8.1
119
-
120
- * Fix: Expose `half_open?` when the circuit state has not transitioned but will. This allows consumers further up the stack to know if the circuit
121
- is half open.
122
-
123
- # v0.8.0
124
-
125
- * Feature: Introduce `half_open_resource_timeout` which changes the resource timeout when the circuit is in a half-open state (#188)
126
-
127
- # v0.7.8
128
-
129
- * Feature: More informative error messages when initializing Semian with missing
130
- arguments (#182)
131
- * Fix: Redis adapter is now resilient to DNS resolution failures (#184)
132
-
133
- # v0.7.5
134
-
135
- * Fix: Repaired compatibility with dependent Redis library
136
-
137
- # v0.7.4
138
-
139
- * Fix: Protect internal semaphore when adjusting resource count (#164)
140
- * Feature: Use prepend when monkey-patching Net::HTTP. (#157)
141
- * Feature: Include time spend waiting for bulkhead in notification (#154)
142
-
143
- # v0.7.1
144
-
145
- * Feature: Add the behaviour to enable open circuiting on 5xxs conditionally (#149)
146
- * Refactor: Configurable hosts for Semian's development dependencies (#152)
147
-
148
- # v0.7.0
149
-
150
- This change introduced a series of changes to support a new "dynamic quota" ticket
151
- allocation strategy. This code primarily affects bulkheads (protected resources).
152
-
153
- Rather than statically setting a ticket count, workers (in their own process) now register
154
- themselves. By specifying 'quota' instead of 'tickets', the bulkhead threshold will now be
155
- computed dynamically as a ratio of the number of registered workers, eliminating the need to
156
- continuously readjust ticket counts, and supporting environments with non-uniform worker
157
- distribution between machines.
158
-
159
- * Feature: Support quota based allocation strategy (#120)
160
- * Feature: Add ability to manually unregister workers (#130)
161
- * Feature: Add ability to clear resources from adapters and unregister all resources (#134)
162
- * Feature: Allow sysV IPC key to be accessed in ruby (#136)
163
- * Feature: Expose registered worker count to ruby (#137)
164
- * Refactor: Allow registered worker count to be accessed through bulkhead (#138)
165
- * Bug fix: Register all workers (#128)
166
- * Bug fix: Lazy instantiate redis clien on first I/O (#132)
167
- * Bug fix: New mysql error (#131)
168
- * Bug fix: Prevent race conditions when unregistering (#141)
169
- * Refactor/Feature: Break coupling between resource and circuit breaker (#123)
170
- * Refactor: Use generic max_sem_val (#117)
171
- * Refactor: Fix header syntax (#118)
172
- * Refactor: Always acquire semaphore without_gvl (#121)
173
- * Thread-safety for circuit breakers by default (#150)
174
- * Fix bug where calling name on a protected resource without a semaphore would fail (#151)
175
-
176
- # v0.6.2
177
-
178
- * Refactor: Refactor semian ticket management into its own files (#116)
179
- * Refactor: Create sem_meta_lock and sem_meta_unlock (#115)
180
- * Refactor: Refactor semaphore operations (#114)
181
-
182
- # v0.6.1
183
-
184
- * Refactor: Generate a unique semaphore key by including size of semaphore set
185
- * Refactor: Refactor semian\_resource related C functions
186
- * Fix: Don't require sudo for travis (#110)
187
- * Refactor: Refactor semian.c includes and types into header files
188
- * Fix: Use glob instead of git for gemspec file list
189
- * Fix: Fix travis CI for ruby 2.3.0 installing rainbows
190
- * Refactor: Switch to enumerated type for tracking semaphore indices
191
- * Docs: readme: explain co-operation between cbs and bulkheads
192
- * Docs: readme: add section about server limits
193
-
194
- # v0.6.0
195
-
196
- * Feature: Load semian/rails automatically if necessary
197
- * Feature: Implement AR::AbstractAdapter#semian\_resource
198
-
199
- # v0.5.4
200
-
201
- * Fix: Also let "Too many connections" be a first class conn error
202
-
203
- # v0.5.3
204
-
205
- * Fix: mysql: protect pings
206
- * Fix: mysql: match more lost conn queries
207
-
208
- # v0.5.2
209
-
210
- * Fix: Make request\_allowed? thread safe
211
- * Fix: Fix CI connect errors on HTTP requests by using 127.0.0.1 for host
212
-
213
- # v0.5.1
214
-
215
- * Fix: Assert Resource#initialize\_semaphore contract on Resource init
216
- * Fix: Lock on older thin version for pre MRI 2.2 compatibility
217
-
218
- # v0.5.0
219
-
220
- * Fix: Only issue unsupported or disabled semaphores warnings when the first resource is instanciated
221
- * Refactor: Cleanup requires
222
- * Maintenance: Use published version of the toxiproxy gem
223
- * Fix: Fix minitest deprecation warnings
224
- * Maintenance: Update bundler on travis
225
- * Maintenance: Update supported MRI versions on travis
226
-
227
- # v0.4.3
228
-
229
- * Fix: Fix lazy aliasing of Redis#semian\_resource
230
- * Fix: Workaround rubocop parser limitations
231
-
232
- # v0.4.2
233
-
234
- * Fix: Fix for TimeoutError is deprecated in Ruby 2.3.0
235
- * Feature: Include Ruby 2.3 in Travis builds
236
-
237
- # v0.4.1
238
- * Fix: resource: cast float ticket count to fixnum #75
239
-
240
- # v0.4.0
241
-
242
- * Feature: net/http: add adapter for net/http #58
243
- * Refactor: circuit_breaker: split circuit breaker into three data structures to allow for
244
- alternative implementations in the future #62
245
- * Fix: mysql: don't prevent rollbacks on transactions #60
246
- * Fix: core: fix initialization bug when the resource is accessed before the options
247
- are set #65