waterdrop 2.8.8 → 2.8.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d646a05ccb9842fdd341c1fe114eeb1e98e091056f4f3a9d8cf02da0e6d166cd
4
- data.tar.gz: 7f0f8df74fe994d1747e7ef64508d7c62635b1401b4aa34b69b63c4e41c76fad
3
+ metadata.gz: 8ed8d57d7b79987870f918e97b3ffeee07c6c68b75a506bd11f29abe8778f21f
4
+ data.tar.gz: 86fe1bdb3d1963ef3783a254dbf0c7ae3ad61dc5608eeca5a41dcc2bbd454c1b
5
5
  SHA512:
6
- metadata.gz: dc5e3653a4fba7c1e5e3c8cf4325449210cd692a646d14b44dd6c01203515f0aa58aa9c1ad5fd86e9df3e6b881f2157dd0cdfd5db7b48f4b28a200f9013f5f98
7
- data.tar.gz: dcd0b58e6019ea7fdef647f43339bf68148d1255011145e3e23f1f4ccc91d9cbbc4ba89087fa515a7b9d32dfb9a2ad947e5d0771d2bf8cb645bad6f8456d44f0
6
+ metadata.gz: 22949a9ec65e4e6c0532ad469747989c4971de5320c705cf704371440b2d21b6edd83504eb77e56192ec0043c04334c91892813f3b1d01418e88d1f996064949
7
+ data.tar.gz: 9cecd0e2e56209d14eac2c896d9f2086973874de78e478e758404eb31d17e1b9abcf66e54011a1e9341dad215bac5de8fdafcc29ef38e0a6c8f43ca8eb82a301
data/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # WaterDrop changelog
2
2
 
3
+ ## 2.8.10 (2025-09-25)
4
+ - [Enhancement] Add `#close` alias for `WaterDrop::ConnectionPool#shutdown` to align with producer API for consistent interface across both individual producers and connection pools.
5
+ - [Enhancement] Add `WaterDrop.monitor` method as the preferred alias for `WaterDrop.instrumentation` to align with per-producer API naming convention. The `instrumentation` method remains available as a deprecated alias for backward compatibility.
6
+
7
+ ## 2.8.9 (2025-09-23)
8
+ - [Enhancement] Add connection pool lifecycle events to global instrumentation for improved observability. Events include `connection_pool.created`, `connection_pool.setup`, `connection_pool.shutdown`, `connection_pool.reload`, and `connection_pool.reloaded`.
9
+ - [Enhancement] Add default connection pool transactional direct API.
10
+
3
11
  ## 2.8.8 (2025-09-23)
4
12
  - [Feature] Add `WaterDrop::ConnectionPool` for efficient connection pooling using the proven `connection_pool` gem.
5
13
  - [Feature] Add `WaterDrop.instrumentation` class-level instrumentation for producer lifecycle events. This allows external libraries to subscribe to `producer.created` and `producer.configured` events without needing producer instance references, enabling middleware injection and configuration by libraries like Datadog tracing.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- waterdrop (2.8.8)
4
+ waterdrop (2.8.10)
5
5
  karafka-core (>= 2.4.9, < 3.0.0)
6
6
  karafka-rdkafka (>= 0.20.0)
7
7
  zeitwerk (~> 2.3)
@@ -70,6 +70,16 @@ module WaterDrop
70
70
  ensure_connection_pool_gem!
71
71
 
72
72
  @default_pool = new(size: size, timeout: timeout, &producer_config)
73
+
74
+ # Emit global event for pool setup
75
+ WaterDrop.instrumentation.instrument(
76
+ 'connection_pool.setup',
77
+ pool: @default_pool,
78
+ size: size,
79
+ timeout: timeout
80
+ )
81
+
82
+ @default_pool
73
83
  end
74
84
 
75
85
  # Executes a block with a producer from the global pool
@@ -105,13 +115,33 @@ module WaterDrop
105
115
  def shutdown
106
116
  return unless @default_pool
107
117
 
118
+ pool = @default_pool
108
119
  @default_pool.shutdown
109
120
  @default_pool = nil
121
+
122
+ # Emit global event for pool shutdown
123
+ WaterDrop.instrumentation.instrument(
124
+ 'connection_pool.shutdown',
125
+ pool: pool
126
+ )
110
127
  end
111
128
 
129
+ # Alias for shutdown to align with producer API
130
+ # WaterDrop producers use #close, so we alias connection pool #shutdown to #close
131
+ # for API consistency across both individual producers and connection pools
132
+ alias close shutdown
133
+
112
134
  # Reload the global connection pool
113
135
  def reload
114
- @default_pool&.reload
136
+ return unless @default_pool
137
+
138
+ @default_pool.reload
139
+
140
+ # Emit global event for pool reload
141
+ WaterDrop.instrumentation.instrument(
142
+ 'connection_pool.reload',
143
+ pool: @default_pool
144
+ )
115
145
  end
116
146
 
117
147
  # Check if the global connection pool is active (configured)
@@ -121,6 +151,25 @@ module WaterDrop
121
151
  !@default_pool.nil?
122
152
  end
123
153
 
154
+ # Execute a transaction with a producer from the global connection pool
155
+ # Only available when connection pool is configured
156
+ #
157
+ # @param block [Proc] Block to execute within a transaction
158
+ # @yield [producer] Producer from the global pool with an active transaction
159
+ # @return [Object] Result of the block
160
+ # @raise [RuntimeError] If no global pool is configured
161
+ #
162
+ # @example
163
+ # WaterDrop::ConnectionPool.transaction do |producer|
164
+ # producer.produce(topic: 'events', payload: 'data1')
165
+ # producer.produce(topic: 'events', payload: 'data2')
166
+ # end
167
+ def transaction(&block)
168
+ raise 'No global connection pool configured. Call setup first.' unless @default_pool
169
+
170
+ @default_pool.transaction(&block)
171
+ end
172
+
124
173
  private
125
174
 
126
175
  # Ensures the connection_pool gem is available (class method)
@@ -167,6 +216,14 @@ module WaterDrop
167
216
  end
168
217
  end
169
218
  end
219
+
220
+ # Emit event when a connection pool is created
221
+ WaterDrop.instrumentation.instrument(
222
+ 'connection_pool.created',
223
+ pool: self,
224
+ size: size,
225
+ timeout: timeout
226
+ )
170
227
  end
171
228
 
172
229
  # Get pool statistics
@@ -184,14 +241,49 @@ module WaterDrop
184
241
  @pool.shutdown do |producer|
185
242
  producer.close! if producer&.status&.active?
186
243
  end
244
+
245
+ # Emit event after pool is shut down
246
+ WaterDrop.instrumentation.instrument(
247
+ 'connection_pool.shutdown',
248
+ pool: self
249
+ )
187
250
  end
188
251
 
252
+ # Alias for shutdown to align with producer API
253
+ # WaterDrop producers use #close, so we alias connection pool #shutdown to #close
254
+ # for API consistency across both individual producers and connection pools
255
+ alias close shutdown
256
+
189
257
  # Reload all connections in the pool
190
258
  # Useful for configuration changes or error recovery
191
259
  def reload
192
260
  @pool.reload do |producer|
193
261
  producer.close! if producer&.status&.active?
194
262
  end
263
+
264
+ # Emit event after pool is reloaded
265
+ WaterDrop.instrumentation.instrument(
266
+ 'connection_pool.reloaded',
267
+ pool: self
268
+ )
269
+ end
270
+
271
+ # Execute a transaction with a producer from this connection pool
272
+ #
273
+ # @yield [producer] Producer from the pool with an active transaction
274
+ # @return [Object] Result of the block
275
+ #
276
+ # @example
277
+ # pool.transaction do |producer|
278
+ # producer.produce(topic: 'events', payload: 'data1')
279
+ # producer.produce(topic: 'events', payload: 'data2')
280
+ # end
281
+ def transaction
282
+ with do |producer|
283
+ producer.transaction do
284
+ yield(producer)
285
+ end
286
+ end
195
287
  end
196
288
 
197
289
  # Returns the underlying connection_pool instance
@@ -218,6 +310,22 @@ module WaterDrop
218
310
  ConnectionPool.with(&block)
219
311
  end
220
312
 
313
+ # Execute a transaction with a producer from the global connection pool
314
+ # Only available when connection pool is configured
315
+ #
316
+ # @param block [Proc] Block to execute within a transaction
317
+ # @yield [producer] Producer from the global pool with an active transaction
318
+ # @return [Object] Result of the block
319
+ #
320
+ # @example
321
+ # WaterDrop.transaction do |producer|
322
+ # producer.produce(topic: 'events', payload: 'data1')
323
+ # producer.produce(topic: 'events', payload: 'data2')
324
+ # end
325
+ def transaction(&block)
326
+ ConnectionPool.transaction(&block)
327
+ end
328
+
221
329
  # Access the global connection pool
222
330
  #
223
331
  # @return [WaterDrop::ConnectionPool] The global pool
@@ -7,9 +7,16 @@ module WaterDrop
7
7
  class ClassNotifications < ::Karafka::Core::Monitoring::Notifications
8
8
  # List of events that are available at the class level via WaterDrop.instrumentation
9
9
  # These are lifecycle events for producer creation and configuration
10
+ # and connection pool lifecycle events
10
11
  EVENTS = %w[
11
12
  producer.created
12
13
  producer.configured
14
+
15
+ connection_pool.created
16
+ connection_pool.setup
17
+ connection_pool.shutdown
18
+ connection_pool.reload
19
+ connection_pool.reloaded
13
20
  ].freeze
14
21
 
15
22
  # @return [WaterDrop::Instrumentation::ClassNotifications] class-level notification instance
@@ -3,5 +3,5 @@
3
3
  # WaterDrop library
4
4
  module WaterDrop
5
5
  # Current WaterDrop version
6
- VERSION = '2.8.8'
6
+ VERSION = '2.8.10'
7
7
  end
data/lib/waterdrop.rb CHANGED
@@ -17,7 +17,7 @@ module WaterDrop
17
17
  Pathname.new(File.expand_path('..', __dir__))
18
18
  end
19
19
 
20
- # @return [WaterDrop::Instrumentation::ClassMonitor] global instrumentation monitor for
20
+ # @return [WaterDrop::Instrumentation::ClassMonitor] global monitor for
21
21
  # class-level event subscriptions. This allows external libraries to subscribe to WaterDrop
22
22
  # lifecycle events without needing producer instance references.
23
23
  #
@@ -25,13 +25,16 @@ module WaterDrop
25
25
  # instance events
26
26
  #
27
27
  # @example Subscribe to producer creation events
28
- # WaterDrop.instrumentation.subscribe('producer.created') do |event|
28
+ # WaterDrop.monitor.subscribe('producer.created') do |event|
29
29
  # producer = event[:producer]
30
30
  # # Configure producer or add middleware
31
31
  # end
32
- def instrumentation
32
+ def monitor
33
33
  @instrumentation ||= Instrumentation::ClassMonitor.new
34
34
  end
35
+
36
+ # @deprecated Use #monitor instead. This method is provided for backward compatibility only.
37
+ alias instrumentation monitor
35
38
  end
36
39
  end
37
40
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: waterdrop
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.8.8
4
+ version: 2.8.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Maciej Mensfeld