waterdrop 2.4.3 → 2.4.5

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: 065c53c0e711cfe49e718a321ce64740b68a45bd6ac477c9eaf2a79876de8df7
4
- data.tar.gz: e77179ca5162c4862369838197a62063b5127b4d3a72b7ab08f85f930cee6ea6
3
+ metadata.gz: e1cabe8225d1038bc9fab5c41efaf5822b3d6a633dac233f92058874be8cb5ae
4
+ data.tar.gz: ac830393a2c6ed2d50042a08fbd59a6d2ebbd0de505a53953c67b3d50ac1dd22
5
5
  SHA512:
6
- metadata.gz: 76af1a5f87a5f31bda8b9f5f111173e1992f6d5ddc85fa2b43d5e1fbd45b93e67601691cbf13b3b2a2e8eb49bc04196b84c5eb81c5b0bd6e11bbe014220fe821
7
- data.tar.gz: 27c667d0c93f6948a85d9411fd1dfa46bd38ebb36f7c6907785658bb58ae3001b8d2b81bcb1a9faac64acc5248bc1300a3530736cdd7193b155e01eca4eefbbe
6
+ metadata.gz: d757751cb8a62fee91c5aff7ac30260e3b45d62d17db71eedcd23b77881b4564b8dc0bef534eb060049a65b5d99610c09c86eeb13913a999d864dffc3adee5e3
7
+ data.tar.gz: 51cb53cc3a4f168b3157ad840157f2df8a9479381972fe0d8cc13b445449099373acd76d37cf0206ec35d625fb75723b3ab4a3e0c193413de9844c54106209c5
checksums.yaml.gz.sig CHANGED
Binary file
data/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # WaterDrop changelog
2
2
 
3
+ ## 2.4.5 (2022-12-10)
4
+ - Fix invalid error scope visibility.
5
+ - Cache partition count to improve messages production and lower stress on Kafka when `partition_key` is on.
6
+
7
+ ## 2.4.4 (2022-12-09)
8
+ - Add temporary patch on top of `rdkafka-ruby` to mitigate metadata fetch timeout failures.
9
+
3
10
  ## 2.4.3 (2022-12-07)
4
11
  - Support for librdkafka 0.13
5
12
  - Update Github Actions
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- waterdrop (2.4.3)
4
+ waterdrop (2.4.5)
5
5
  karafka-core (>= 2.0.6, < 3.0.0)
6
6
  zeitwerk (~> 2.3)
7
7
 
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ module WaterDrop
4
+ # Patches to external components
5
+ module Patches
6
+ # Rdkafka related patches
7
+ module Rdkafka
8
+ # Rdkafka::Metadata patches
9
+ module Metadata
10
+ # We overwrite this method because there were reports of metadata operation timing out
11
+ # when Kafka was under stress. While the messages dispatch will be retried, metadata
12
+ # fetch happens prior to that, effectively crashing the process. Metadata fetch was not
13
+ # being retried at all.
14
+ #
15
+ # @param args [Array<Object>] all the metadata original arguments
16
+ def initialize(*args)
17
+ attempt ||= 0
18
+ attempt += 1
19
+
20
+ super(*args)
21
+ rescue ::Rdkafka::RdkafkaError => e
22
+ raise unless e.code == :timed_out
23
+ raise if attempt > 10
24
+
25
+ backoff_factor = 2**attempt
26
+ timeout = backoff_factor * 0.1
27
+
28
+ sleep(timeout)
29
+
30
+ retry
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
36
+
37
+ ::Rdkafka::Metadata.prepend ::WaterDrop::Patches::Rdkafka::Metadata
@@ -7,6 +7,25 @@ module WaterDrop
7
7
  module Rdkafka
8
8
  # Rdkafka::Producer patches
9
9
  module Producer
10
+ # Cache partitions count for 30 seconds
11
+ PARTITIONS_COUNT_TTL = 30_000
12
+
13
+ private_constant :PARTITIONS_COUNT_TTL
14
+
15
+ # @param args [Object] arguments accepted by the original rdkafka producer
16
+ def initialize(*args)
17
+ super
18
+
19
+ @_partitions_count_cache = Concurrent::Hash.new do |cache, topic|
20
+ topic_metadata = ::Rdkafka::Metadata.new(inner_kafka, topic).topics&.first
21
+
22
+ cache[topic] = [
23
+ now,
24
+ topic_metadata ? topic_metadata[:partition_count] : nil
25
+ ]
26
+ end
27
+ end
28
+
10
29
  # Adds a method that allows us to get the native kafka producer name
11
30
  #
12
31
  # In between rdkafka versions, there are internal changes that force us to add some extra
@@ -14,23 +33,49 @@ module WaterDrop
14
33
  #
15
34
  # @return [String] producer instance name
16
35
  def name
17
- unless @_native
36
+ @_name ||= ::Rdkafka::Bindings.rd_kafka_name(inner_kafka)
37
+ end
38
+
39
+ # This patch makes sure we cache the partition count for a given topic for given time
40
+ # This prevents us in case someone uses `partition_key` from querying for the count with
41
+ # each message. Instead we query once every 30 seconds at most
42
+ #
43
+ # @param topic [String] topic name
44
+ # @return [Integer] partition count for a given topic
45
+ def partition_count(topic)
46
+ closed_producer_check(__method__)
47
+
48
+ @_partitions_count_cache.delete_if do |_, cached|
49
+ now - cached.first > PARTITIONS_COUNT_TTL
50
+ end
51
+
52
+ @_partitions_count_cache[topic].last
53
+ end
54
+
55
+ # @return [FFI::Pointer] pointer to the raw librdkafka
56
+ def inner_kafka
57
+ unless @_inner_kafka
18
58
  version = ::Gem::Version.new(::Rdkafka::VERSION)
19
59
 
20
60
  if version < ::Gem::Version.new('0.12.0')
21
- @native = @native_kafka
61
+ @_inner_kafka = @native_kafka
22
62
  elsif version < ::Gem::Version.new('0.13.0.beta.1')
23
- @_native = @client.native
63
+ @_inner_kafka = @client.native
24
64
  else
25
- @_native = @native_kafka.inner
65
+ @_inner_kafka = @native_kafka.inner
26
66
  end
27
67
  end
28
68
 
29
- ::Rdkafka::Bindings.rd_kafka_name(@_native)
69
+ @_inner_kafka
70
+ end
71
+
72
+ # @return [Float] current clock time
73
+ def now
74
+ ::Process.clock_gettime(::Process::CLOCK_MONOTONIC) * 1_000
30
75
  end
31
76
  end
32
77
  end
33
78
  end
34
79
  end
35
80
 
36
- ::Rdkafka::Producer.include ::WaterDrop::Patches::Rdkafka::Producer
81
+ ::Rdkafka::Producer.prepend ::WaterDrop::Patches::Rdkafka::Producer
@@ -3,5 +3,5 @@
3
3
  # WaterDrop library
4
4
  module WaterDrop
5
5
  # Current WaterDrop version
6
- VERSION = '2.4.3'
6
+ VERSION = '2.4.5'
7
7
  end
data.tar.gz.sig CHANGED
@@ -1 +1,5 @@
1
- V�i�ڈg J�Ł�J})g�������.�J�QSn̡��؊��@lG_t&A���<e{���|���=@;��@��px[( M��8��_+|���0[��$���g���t #XIw?�=X�%Ԉ�qoA�:��}��aT���`� ��K
1
+ w�9T���BSC��=Y<_ʀ����:����-+A�Y���Lo��.}VNyҙH.�mJu4����؄\Y2�� 9s]Ї�AԷ[�7JQ�� 3��]ʳ���Su}"����samB봧�^S����n���K��bN��F�Ԙ����g��m �,�4r��MB` �
2
+ �H>��Kh�*���7��
3
+ �nA�*�%gOn�z����!CWAP!SҼ8h��n���9z�'�F��j�òr@D�>�V�~�
4
+ Rj,������и]��cGv���U���2����� ��L�
5
+ �r~�3���S`���۹�?�
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.4.3
4
+ version: 2.4.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Maciej Mensfeld
@@ -35,7 +35,7 @@ cert_chain:
35
35
  Qf04B9ceLUaC4fPVEz10FyobjaFoY4i32xRto3XnrzeAgfEe4swLq8bQsR3w/EF3
36
36
  MGU0FeSV2Yj7Xc2x/7BzLK8xQn5l7Yy75iPF+KP3vVmDHnNl
37
37
  -----END CERTIFICATE-----
38
- date: 2022-12-07 00:00:00.000000000 Z
38
+ date: 2022-12-10 00:00:00.000000000 Z
39
39
  dependencies:
40
40
  - !ruby/object:Gem::Dependency
41
41
  name: karafka-core
@@ -108,6 +108,7 @@ files:
108
108
  - lib/waterdrop/instrumentation/notifications.rb
109
109
  - lib/waterdrop/instrumentation/vendors/datadog/dashboard.json
110
110
  - lib/waterdrop/instrumentation/vendors/datadog/listener.rb
111
+ - lib/waterdrop/patches/rdkafka/metadata.rb
111
112
  - lib/waterdrop/patches/rdkafka/producer.rb
112
113
  - lib/waterdrop/producer.rb
113
114
  - lib/waterdrop/producer/async.rb
metadata.gz.sig CHANGED
Binary file