waterdrop 2.8.9 → 2.8.11

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: 6d6b4d4ba3d3fe608324d53cf91c1d07278e810369ec9cf140520d9b065a30c1
4
- data.tar.gz: b661659c9aa6facfe8eaf2b29eecd809937dbaf2b15557673c257e09f9a0f357
3
+ metadata.gz: 3dc4cc4d1928a447c4e6c3ab9d268a87c0d3a462b1b9d62685fe51168842c0e1
4
+ data.tar.gz: b82300c02b3d774aba5a2a354f7b9d0d11f2d08738ccf66348185f1a4bbd1605
5
5
  SHA512:
6
- metadata.gz: 6d4f5323e204d8c9d8ae2f0d1eea282b1096ed1c28554bb8e46038b08679c554ebae21b9a1c7546a8c2ad5db0ca1876a882318b04aab2b671973a012364e3276
7
- data.tar.gz: 2a6b018f76dd052016352af3878d29522ea5a0d1c8fba1edfa453bfd084bdfa2a7e9e20ec57fd0bc8e6de0ea3117b200fd5450bde022a7e233dc5b5461da4455
6
+ metadata.gz: a2f0d2befaa70b25bf756fdee15757328cfa0d2a642243100ae89421c0b0d65ce7b3b3d94d630f90cf040b7bb3ce2218aaee8200edfdfc96164038fee6d79e9b
7
+ data.tar.gz: 2b5a2fae3f060435c697024aab1c064342d9919b03304b8c29a1ee25c0d85533a0b43af5184c4dd8ceb5d49377178536ca6b0306af473ed4876dc98f712bf7c1
data/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # WaterDrop changelog
2
2
 
3
+ ## 2.8.11 (2025-09-27)
4
+ - [Enhancement] Provide fast-track for middleware-less flows (20% faster) for single message, 5000x faster for batches.
5
+ - [Enhancement] Optimize middlewares application by around 20%.
6
+ - [Change] Remove Ruby `3.1` according to the EOL schedule.
7
+ - [Fix] Connection pool timeout parameter now accepts milliseconds instead of seconds for consistency with other WaterDrop timeouts. The default timeout has been changed from `5` seconds to `5000` milliseconds (equivalent value).
8
+
9
+ ## 2.8.10 (2025-09-25)
10
+ - [Enhancement] Add `#close` alias for `WaterDrop::ConnectionPool#shutdown` to align with producer API for consistent interface across both individual producers and connection pools.
11
+ - [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.
12
+
3
13
  ## 2.8.9 (2025-09-23)
4
14
  - [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
15
  - [Enhancement] Add default connection pool transactional direct API.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- waterdrop (2.8.9)
4
+ waterdrop (2.8.11)
5
5
  karafka-core (>= 2.4.9, < 3.0.0)
6
6
  karafka-rdkafka (>= 0.20.0)
7
7
  zeitwerk (~> 2.3)
@@ -47,7 +47,7 @@ module WaterDrop
47
47
  # Sets up a global connection pool
48
48
  #
49
49
  # @param size [Integer] Pool size (default: 5)
50
- # @param timeout [Numeric] Connection timeout in seconds (default: 5)
50
+ # @param timeout [Numeric] Connection timeout in milliseconds (default: 5000)
51
51
  # @param producer_config [Proc] Block to configure each producer in the pool
52
52
  # @yield [config, index] Block to configure each producer in the pool, receives config and
53
53
  # pool index
@@ -66,7 +66,7 @@ module WaterDrop
66
66
  # 'transactional.id': "my-app-#{index}"
67
67
  # }
68
68
  # end
69
- def setup(size: 5, timeout: 5, &producer_config)
69
+ def setup(size: 5, timeout: 5000, &producer_config)
70
70
  ensure_connection_pool_gem!
71
71
 
72
72
  @default_pool = new(size: size, timeout: timeout, &producer_config)
@@ -126,6 +126,11 @@ module WaterDrop
126
126
  )
127
127
  end
128
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
+
129
134
  # Reload the global connection pool
130
135
  def reload
131
136
  return unless @default_pool
@@ -189,18 +194,18 @@ module WaterDrop
189
194
  # Creates a new WaterDrop connection pool
190
195
  #
191
196
  # @param size [Integer] Pool size (default: 5)
192
- # @param timeout [Numeric] Connection timeout in seconds (default: 5)
197
+ # @param timeout [Numeric] Connection timeout in milliseconds (default: 5000)
193
198
  # @param producer_config [Proc] Block to configure each producer in the pool
194
199
  # @yield [config, index] Block to configure each producer in the pool, receives config and
195
200
  # pool index
196
- def initialize(size: 5, timeout: 5, &producer_config)
201
+ def initialize(size: 5, timeout: 5000, &producer_config)
197
202
  self.class.send(:ensure_connection_pool_gem!)
198
203
 
199
204
  @producer_config = producer_config
200
205
  @pool_index = 0
201
206
  @pool_mutex = Mutex.new
202
207
 
203
- @pool = ::ConnectionPool.new(size: size, timeout: timeout) do
208
+ @pool = ::ConnectionPool.new(size: size, timeout: timeout / 1000.0) do
204
209
  producer_index = @pool_mutex.synchronize { @pool_index += 1 }
205
210
 
206
211
  WaterDrop::Producer.new do |config|
@@ -244,6 +249,11 @@ module WaterDrop
244
249
  )
245
250
  end
246
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
+
247
257
  # Reload all connections in the pool
248
258
  # Useful for configuration changes or error recovery
249
259
  def reload
@@ -6,6 +6,7 @@ module WaterDrop
6
6
  def initialize
7
7
  @mutex = Mutex.new
8
8
  @steps = []
9
+ @count = 0
9
10
  end
10
11
 
11
12
  # Runs middleware on a single message prior to validation
@@ -16,6 +17,8 @@ module WaterDrop
16
17
  # @note You need to decide yourself whether you don't use the message hash data anywhere else
17
18
  # and you want to save on memory by modifying it in place or do you want to do a deep copy
18
19
  def run(message)
20
+ return message if @count.zero?
21
+
19
22
  @steps.each do |step|
20
23
  message = step.call(message)
21
24
  end
@@ -24,10 +27,18 @@ module WaterDrop
24
27
  end
25
28
 
26
29
  # @param messages [Array<Hash>] messages on which we want to run middlewares
27
- # @return [Array<Hash>] transformed messages
30
+ # @return [Array<Hash>] transformed messages or same messages if no transformation
28
31
  def run_many(messages)
29
- messages.map do |message|
30
- run(message)
32
+ # Skip middleware processing entirely if no middleware steps are configured
33
+ return messages if @count.zero?
34
+
35
+ # Use each_with_object to avoid creating intermediate arrays for large batches
36
+ messages.each_with_object([]) do |message, result|
37
+ @steps.each do |step|
38
+ message = step.call(message)
39
+ end
40
+
41
+ result << message
31
42
  end
32
43
  end
33
44
 
@@ -36,6 +47,7 @@ module WaterDrop
36
47
  def prepend(step)
37
48
  @mutex.synchronize do
38
49
  @steps.prepend step
50
+ @count = @steps.size
39
51
  end
40
52
  end
41
53
 
@@ -44,6 +56,7 @@ module WaterDrop
44
56
  def append(step)
45
57
  @mutex.synchronize do
46
58
  @steps.append step
59
+ @count = @steps.size
47
60
  end
48
61
  end
49
62
  end
@@ -3,5 +3,5 @@
3
3
  # WaterDrop library
4
4
  module WaterDrop
5
5
  # Current WaterDrop version
6
- VERSION = '2.8.9'
6
+ VERSION = '2.8.11'
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
 
data/waterdrop.gemspec CHANGED
@@ -20,7 +20,7 @@ Gem::Specification.new do |spec|
20
20
  spec.add_dependency 'karafka-rdkafka', '>= 0.20.0'
21
21
  spec.add_dependency 'zeitwerk', '~> 2.3'
22
22
 
23
- spec.required_ruby_version = '>= 3.1.0'
23
+ spec.required_ruby_version = '>= 3.2.0'
24
24
 
25
25
  spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(spec)/}) }
26
26
  spec.executables = []
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.9
4
+ version: 2.8.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Maciej Mensfeld
@@ -146,7 +146,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
146
146
  requirements:
147
147
  - - ">="
148
148
  - !ruby/object:Gem::Version
149
- version: 3.1.0
149
+ version: 3.2.0
150
150
  required_rubygems_version: !ruby/object:Gem::Requirement
151
151
  requirements:
152
152
  - - ">="