waterdrop 2.4.4 → 2.4.6

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: e260fd0633bf1672fc6f84613d9cf47722d68112dbcc8575f1dca40a2628401b
4
- data.tar.gz: 9528c011ffb175a22b34d59808dee41b735a008fca09f839b4a6418c2e198a2c
3
+ metadata.gz: 2a072e6e8ee65e0ce6f5c337c3a56b043140d0a5c60a1fd93d70b329c50932c5
4
+ data.tar.gz: 3b0d853ed72939da7302a89cca314d105bf3eef7c7abebe0c37c45960c2e8a80
5
5
  SHA512:
6
- metadata.gz: d1021407b74f56a864cb06013c31303a5485b7ef85e1c7214374f679cc7a9c0a04a59e3600d56b1f36929af9870ff3997f4fac320a01e9c4a1256453142c6a8b
7
- data.tar.gz: 2bcf613fa8be571699534cdd5fb08fe3665024cb2767096d2ba343f6965ec1a5c7db50bdb45fb078931b0eff2572e0176604b667af35d2c1f87d2ce8e508e583
6
+ metadata.gz: 50b61ccd6d84ee67a7de95dde8dfc926dd77cc0ebcba6299704a897da88c55a33352a87f0bed725160dd2859e6258d683dc73fec0c92bf3370eeddf1b4490e3c
7
+ data.tar.gz: a44bdb91da44a8767a385d829eaefd86f214c1baf03b5776c9d3f3d89ac6e2106b07b0da3185208b160110f0cfc5002bb779af66a4682db7d4d96211de7964fd
checksums.yaml.gz.sig CHANGED
Binary file
data/CHANGELOG.md CHANGED
@@ -1,5 +1,28 @@
1
1
  # WaterDrop changelog
2
2
 
3
+ ## 2.4.6 (2022-12-10)
4
+ - Set `statistics.interval.ms` to 5 seconds by default, so the defaults cover all the instrumentation out of the box.
5
+
6
+ ### Upgrade notes
7
+
8
+ If you want to disable `librdkafka` statistics because you do not use them at all, update the `kafka` `statistics.interval.ms` setting and set it to `0`:
9
+
10
+ ```ruby
11
+ producer = WaterDrop::Producer.new
12
+
13
+ producer.setup do |config|
14
+ config.deliver = true
15
+ config.kafka = {
16
+ 'bootstrap.servers': 'localhost:9092',
17
+ 'statistics.interval.ms': 0
18
+ }
19
+ end
20
+ ```
21
+
22
+ ## 2.4.5 (2022-12-10)
23
+ - Fix invalid error scope visibility.
24
+ - Cache partition count to improve messages production and lower stress on Kafka when `partition_key` is on.
25
+
3
26
  ## 2.4.4 (2022-12-09)
4
27
  - Add temporary patch on top of `rdkafka-ruby` to mitigate metadata fetch timeout failures.
5
28
 
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- waterdrop (2.4.4)
4
+ waterdrop (2.4.6)
5
5
  karafka-core (>= 2.0.6, < 3.0.0)
6
6
  zeitwerk (~> 2.3)
7
7
 
data/README.md CHANGED
@@ -301,9 +301,9 @@ See the `WaterDrop::Instrumentation::Monitor::EVENTS` for the list of all the su
301
301
 
302
302
  ### Usage statistics
303
303
 
304
- WaterDrop may be configured to emit internal metrics at a fixed interval by setting the `kafka` `statistics.interval.ms` configuration property to a value > `0`. Once that is done, emitted statistics are available after subscribing to the `statistics.emitted` publisher event.
304
+ WaterDrop is configured to emit internal `librdkafka` metrics every five seconds. You can change this by setting the `kafka` `statistics.interval.ms` configuration property to a value greater of equal `0`. Emitted statistics are available after subscribing to the `statistics.emitted` publisher event. If set to `0`, metrics will not be published.
305
305
 
306
- The statistics include all of the metrics from `librdkafka` (full list [here](https://github.com/edenhill/librdkafka/blob/master/STATISTICS.md)) as well as the diff of those against the previously emitted values.
306
+ The statistics include all of the metrics from `librdkafka` (complete list [here](https://github.com/edenhill/librdkafka/blob/master/STATISTICS.md)) as well as the diff of those against the previously emitted values.
307
307
 
308
308
  For several attributes like `txmsgs`, `librdkafka` publishes only the totals. In order to make it easier to track the progress (for example number of messages sent between statistics emitted events), WaterDrop diffs all the numeric values against previously available numbers. All of those metrics are available under the same key as the metric but with additional `_d` postfix:
309
309
 
@@ -9,7 +9,10 @@ module WaterDrop
9
9
 
10
10
  # Defaults for kafka settings, that will be overwritten only if not present already
11
11
  KAFKA_DEFAULTS = {
12
- 'client.id': 'waterdrop'
12
+ 'client.id': 'waterdrop',
13
+ # emit librdkafka statistics every five seconds. This is used in instrumentation.
14
+ # When disabled, part of metrics will not be published and available.
15
+ 'statistics.interval.ms': 5_000
13
16
  }.freeze
14
17
 
15
18
  private_constant :KAFKA_DEFAULTS
@@ -18,7 +18,7 @@ module WaterDrop
18
18
  attempt += 1
19
19
 
20
20
  super(*args)
21
- rescue Rdkafka::RdkafkaError => e
21
+ rescue ::Rdkafka::RdkafkaError => e
22
22
  raise unless e.code == :timed_out
23
23
  raise if attempt > 10
24
24
 
@@ -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.4'
6
+ VERSION = '2.4.6'
7
7
  end
data.tar.gz.sig CHANGED
Binary file
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.4
4
+ version: 2.4.6
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-09 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
metadata.gz.sig CHANGED
Binary file