waterdrop 2.8.8 → 2.8.9

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: 6d6b4d4ba3d3fe608324d53cf91c1d07278e810369ec9cf140520d9b065a30c1
4
+ data.tar.gz: b661659c9aa6facfe8eaf2b29eecd809937dbaf2b15557673c257e09f9a0f357
5
5
  SHA512:
6
- metadata.gz: dc5e3653a4fba7c1e5e3c8cf4325449210cd692a646d14b44dd6c01203515f0aa58aa9c1ad5fd86e9df3e6b881f2157dd0cdfd5db7b48f4b28a200f9013f5f98
7
- data.tar.gz: dcd0b58e6019ea7fdef647f43339bf68148d1255011145e3e23f1f4ccc91d9cbbc4ba89087fa515a7b9d32dfb9a2ad947e5d0771d2bf8cb645bad6f8456d44f0
6
+ metadata.gz: 6d4f5323e204d8c9d8ae2f0d1eea282b1096ed1c28554bb8e46038b08679c554ebae21b9a1c7546a8c2ad5db0ca1876a882318b04aab2b671973a012364e3276
7
+ data.tar.gz: 2a6b018f76dd052016352af3878d29522ea5a0d1c8fba1edfa453bfd084bdfa2a7e9e20ec57fd0bc8e6de0ea3117b200fd5450bde022a7e233dc5b5461da4455
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # WaterDrop changelog
2
2
 
3
+ ## 2.8.9 (2025-09-23)
4
+ - [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`.
5
+ - [Enhancement] Add default connection pool transactional direct API.
6
+
3
7
  ## 2.8.8 (2025-09-23)
4
8
  - [Feature] Add `WaterDrop::ConnectionPool` for efficient connection pooling using the proven `connection_pool` gem.
5
9
  - [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.9)
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,28 @@ 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
 
112
129
  # Reload the global connection pool
113
130
  def reload
114
- @default_pool&.reload
131
+ return unless @default_pool
132
+
133
+ @default_pool.reload
134
+
135
+ # Emit global event for pool reload
136
+ WaterDrop.instrumentation.instrument(
137
+ 'connection_pool.reload',
138
+ pool: @default_pool
139
+ )
115
140
  end
116
141
 
117
142
  # Check if the global connection pool is active (configured)
@@ -121,6 +146,25 @@ module WaterDrop
121
146
  !@default_pool.nil?
122
147
  end
123
148
 
149
+ # Execute a transaction with a producer from the global connection pool
150
+ # Only available when connection pool is configured
151
+ #
152
+ # @param block [Proc] Block to execute within a transaction
153
+ # @yield [producer] Producer from the global pool with an active transaction
154
+ # @return [Object] Result of the block
155
+ # @raise [RuntimeError] If no global pool is configured
156
+ #
157
+ # @example
158
+ # WaterDrop::ConnectionPool.transaction do |producer|
159
+ # producer.produce(topic: 'events', payload: 'data1')
160
+ # producer.produce(topic: 'events', payload: 'data2')
161
+ # end
162
+ def transaction(&block)
163
+ raise 'No global connection pool configured. Call setup first.' unless @default_pool
164
+
165
+ @default_pool.transaction(&block)
166
+ end
167
+
124
168
  private
125
169
 
126
170
  # Ensures the connection_pool gem is available (class method)
@@ -167,6 +211,14 @@ module WaterDrop
167
211
  end
168
212
  end
169
213
  end
214
+
215
+ # Emit event when a connection pool is created
216
+ WaterDrop.instrumentation.instrument(
217
+ 'connection_pool.created',
218
+ pool: self,
219
+ size: size,
220
+ timeout: timeout
221
+ )
170
222
  end
171
223
 
172
224
  # Get pool statistics
@@ -184,6 +236,12 @@ module WaterDrop
184
236
  @pool.shutdown do |producer|
185
237
  producer.close! if producer&.status&.active?
186
238
  end
239
+
240
+ # Emit event after pool is shut down
241
+ WaterDrop.instrumentation.instrument(
242
+ 'connection_pool.shutdown',
243
+ pool: self
244
+ )
187
245
  end
188
246
 
189
247
  # Reload all connections in the pool
@@ -192,6 +250,30 @@ module WaterDrop
192
250
  @pool.reload do |producer|
193
251
  producer.close! if producer&.status&.active?
194
252
  end
253
+
254
+ # Emit event after pool is reloaded
255
+ WaterDrop.instrumentation.instrument(
256
+ 'connection_pool.reloaded',
257
+ pool: self
258
+ )
259
+ end
260
+
261
+ # Execute a transaction with a producer from this connection pool
262
+ #
263
+ # @yield [producer] Producer from the pool with an active transaction
264
+ # @return [Object] Result of the block
265
+ #
266
+ # @example
267
+ # pool.transaction do |producer|
268
+ # producer.produce(topic: 'events', payload: 'data1')
269
+ # producer.produce(topic: 'events', payload: 'data2')
270
+ # end
271
+ def transaction
272
+ with do |producer|
273
+ producer.transaction do
274
+ yield(producer)
275
+ end
276
+ end
195
277
  end
196
278
 
197
279
  # Returns the underlying connection_pool instance
@@ -218,6 +300,22 @@ module WaterDrop
218
300
  ConnectionPool.with(&block)
219
301
  end
220
302
 
303
+ # Execute a transaction with a producer from the global connection pool
304
+ # Only available when connection pool is configured
305
+ #
306
+ # @param block [Proc] Block to execute within a transaction
307
+ # @yield [producer] Producer from the global pool with an active transaction
308
+ # @return [Object] Result of the block
309
+ #
310
+ # @example
311
+ # WaterDrop.transaction do |producer|
312
+ # producer.produce(topic: 'events', payload: 'data1')
313
+ # producer.produce(topic: 'events', payload: 'data2')
314
+ # end
315
+ def transaction(&block)
316
+ ConnectionPool.transaction(&block)
317
+ end
318
+
221
319
  # Access the global connection pool
222
320
  #
223
321
  # @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.9'
7
7
  end
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.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Maciej Mensfeld