karafka 2.1.9 → 2.1.11

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: 65296040c91ec5646620f047567c9229b7d9044d41d37e690f9f6685d1199e36
4
- data.tar.gz: dedea921e5bc3b9b985861d9b6bcf6c5b5de1a148ef2c1aa72b0d96de44fb623
3
+ metadata.gz: 8d1e3000ced82b96afc7c4588d20170e0908d3b41305eead2e5e0a850c9a70c4
4
+ data.tar.gz: 1b16fc0a06f1bfd9bdb1207dd1faac04d3a7f956ccb42edd45ada76fed6dcf09
5
5
  SHA512:
6
- metadata.gz: 781e45af707a9818e9166d6c37d8be214e9334703ee598f4ce8924c99ec71283cc4364de6662fbd1bb7454600b94b71e2e32750b58630e3631235e5bf593c3f9
7
- data.tar.gz: b86b74c4d7909d504e0b60ae536360412622451a7a9868034dca63fbc3c5e962ba122967aeb8a1491196ce6b879b25eef11497798d861fcf85d3acca40fc8163
6
+ metadata.gz: 7e018450fae0ad666bff80ca9875750303946746c20e527200ee569a1a182c3d81bb71b64a0b2bd94b4a35c8cf204326b26752b1d5c0425a1f544ff9b4572323
7
+ data.tar.gz: 6025b3583179592313540231dd9d00354c30d8af3d49f482fc6c7dbd96359dbc7bbccee8cfa4cf1d14a2f5dfb3a9999b141317c782ec33af7503c4a8e26c616c
checksums.yaml.gz.sig CHANGED
Binary file
data/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # Karafka framework changelog
2
2
 
3
+ ## 2.1.11 (2023-08-23)
4
+ - [Enhancement] Expand the error handling for offset related queries with timeout error retries.
5
+ - [Enhancement] Allow for connection proxy timeouts configuration.
6
+
7
+ ## 2.1.10 (2023-08-21)
8
+ - [Enhancement] Introduce `connection.client.rebalance_callback` event for instrumentation of rebalances.
9
+ - [Refactor] Introduce low level commands proxy to handle deviation in how we want to run certain commands and how rdkafka-ruby runs that by design.
10
+ - [Fix] Do not report lags in the DD listener for cases where the assignment is not workable.
11
+ - [Fix] Do not report negative lags in the DD listener.
12
+ - [Fix] Extremely fast shutdown after boot in specs can cause process not to stop.
13
+ - [Fix] Disable `allow.auto.create.topics` for admin by default to prevent accidental topics creation on topics metadata lookups.
14
+ - [Fix] Improve the `query_watermark_offsets` operations by increasing too low timeout.
15
+ - [Fix] Increase `TplBuilder` timeouts to compensate for remote clusters.
16
+ - [Fix] Always try to unsubscribe short-lived consumers used throughout the system, especially in the admin APIs.
17
+ - [Fix] Add missing `connection.client.poll.error` error type reference.
18
+
3
19
  ## 2.1.9 (2023-08-06)
4
20
  - **[Feature]** Introduce ability to customize pause strategy on a per topic basis (Pro).
5
21
  - [Improvement] Disable the extensive messages logging in the default `karafka.rb` template.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- karafka (2.1.9)
4
+ karafka (2.1.11)
5
5
  karafka-core (>= 2.1.1, < 2.2.0)
6
6
  thor (>= 0.20)
7
7
  waterdrop (>= 2.6.6, < 3.0.0)
@@ -10,10 +10,10 @@ PATH
10
10
  GEM
11
11
  remote: https://rubygems.org/
12
12
  specs:
13
- activejob (7.0.6)
14
- activesupport (= 7.0.6)
13
+ activejob (7.0.7)
14
+ activesupport (= 7.0.7)
15
15
  globalid (>= 0.3.6)
16
- activesupport (7.0.6)
16
+ activesupport (7.0.7)
17
17
  concurrent-ruby (~> 1.0, >= 1.0.2)
18
18
  i18n (>= 1.6, < 2)
19
19
  minitest (>= 5.1)
@@ -33,7 +33,7 @@ GEM
33
33
  karafka-core (2.1.1)
34
34
  concurrent-ruby (>= 1.1)
35
35
  karafka-rdkafka (>= 0.13.1, < 0.14.0)
36
- karafka-rdkafka (0.13.3)
36
+ karafka-rdkafka (0.13.4)
37
37
  ffi (~> 1.15)
38
38
  mini_portile2 (~> 2.6)
39
39
  rake (> 12)
@@ -44,10 +44,10 @@ GEM
44
44
  roda (~> 3.68, >= 3.68)
45
45
  tilt (~> 2.0)
46
46
  mini_portile2 (2.8.4)
47
- minitest (5.18.1)
47
+ minitest (5.19.0)
48
48
  rack (3.0.8)
49
49
  rake (13.0.6)
50
- roda (3.70.0)
50
+ roda (3.71.0)
51
51
  rack
52
52
  rspec (3.12.0)
53
53
  rspec-core (~> 3.12.0)
@@ -75,7 +75,7 @@ GEM
75
75
  waterdrop (2.6.6)
76
76
  karafka-core (>= 2.1.1, < 3.0.0)
77
77
  zeitwerk (~> 2.3)
78
- zeitwerk (2.6.8)
78
+ zeitwerk (2.6.11)
79
79
 
80
80
  PLATFORMS
81
81
  x86_64-linux
data/certs/cert_chain.pem CHANGED
@@ -1,26 +1,26 @@
1
1
  -----BEGIN CERTIFICATE-----
2
2
  MIIEcDCCAtigAwIBAgIBATANBgkqhkiG9w0BAQsFADA/MRAwDgYDVQQDDAdjb250
3
3
  YWN0MRcwFQYKCZImiZPyLGQBGRYHa2FyYWZrYTESMBAGCgmSJomT8ixkARkWAmlv
4
- MB4XDTIyMDgxOTE3MjEzN1oXDTIzMDgxOTE3MjEzN1owPzEQMA4GA1UEAwwHY29u
4
+ MB4XDTIzMDgyMTA3MjU1NFoXDTI0MDgyMDA3MjU1NFowPzEQMA4GA1UEAwwHY29u
5
5
  dGFjdDEXMBUGCgmSJomT8ixkARkWB2thcmFma2ExEjAQBgoJkiaJk/IsZAEZFgJp
6
- bzCCAaIwDQYJKoZIhvcNAQEBBQADggGPADCCAYoCggGBAODzeO3L6lxdATzMHKNW
7
- jFA/GGunoPuylO/BMzy8RiQHh7VIvysAKs0tHhTx3g2D0STDpF+hcQcPELFikiT2
8
- F+1wOHj/SsrK7VKqfA8+gq04hKc5sQoX2Egf9k3V0YJ3eZ6R/koHkQ8A0TVt0w6F
9
- ZQckoV4MqnEAx0g/FZN3mnHTlJ3VFLSBqJEIe+S6FZMl92mSv+hTrlUG8VaYxSfN
10
- lTCvnKk284F6QZq5XIENLRmcDd/3aPBLnLwNnyMyhB+6gK8cUO+CFlDO5tjo/aBA
11
- rUnl++wGG0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pDXzFSPMG7YQFLzwYz1zZZvOU7/UCpQsHpID/YxqDp4+Dgb+Y
23
+ qma0whX8UG/gXFV2pYWpYOfpatvahwi+A1TwPQsuZwkkhi1OyF1At3RY+hjSXyav
24
+ AnG1dJU+yL2BK7vaVytLTstJME5mepSZ46qqIJXMuWob/YPDmVaBF39TDSG9e34s
25
+ msG3BiCqgOgHAnL23+CN3Rt8MsuRfEtoTKpJVcCfoEoNHOkc
26
26
  -----END CERTIFICATE-----
@@ -26,6 +26,12 @@ en:
26
26
  internal.process_format: needs to be present
27
27
  internal.routing.builder_format: needs to be present
28
28
  internal.routing.subscription_groups_builder_format: needs to be present
29
+ internal.connection.proxy.query_watermark_offsets.timeout_format: needs to be an integer bigger than 0
30
+ internal.connection.proxy.query_watermark_offsets.max_attempts_format: needs to be an integer bigger than 0
31
+ internal.connection.proxy.query_watermark_offsets.wait_time_format: needs to be an integer bigger than 0
32
+ internal.connection.proxy.offsets_for_times.timeout_format: needs to be an integer bigger than 0
33
+ internal.connection.proxy.offsets_for_times.max_attempts_format: needs to be an integer bigger than 0
34
+ internal.connection.proxy.offsets_for_times.wait_time_format: needs to be an integer bigger than 0
29
35
  key_must_be_a_symbol: All keys under the kafka settings scope need to be symbols
30
36
  max_timeout_vs_pause_max_timeout: pause_timeout must be less or equal to pause_max_timeout
31
37
  shutdown_timeout_vs_max_wait_time: shutdown_timeout must be more than max_wait_time
data/lib/karafka/admin.rb CHANGED
@@ -13,9 +13,6 @@ module Karafka
13
13
  # retry after checking that the operation was finished or failed using external factor.
14
14
  MAX_WAIT_TIMEOUT = 1
15
15
 
16
- # Max time for a TPL request. We increase it to compensate for remote clusters latency
17
- TPL_REQUEST_TIMEOUT = 2_000
18
-
19
16
  # How many times should be try. 1 x 60 => 60 seconds wait in total
20
17
  MAX_ATTEMPTS = 60
21
18
 
@@ -29,11 +26,12 @@ module Karafka
29
26
  'fetch.message.max.bytes': 5 * 1_048_576,
30
27
  # Do not commit offset automatically, this prevents offset tracking for operations involving
31
28
  # a consumer instance
32
- 'enable.auto.commit': false
29
+ 'enable.auto.commit': false,
30
+ # Make sure that topic metadata lookups do not create topics accidentally
31
+ 'allow.auto.create.topics': false
33
32
  }.freeze
34
33
 
35
- private_constant :CONFIG_DEFAULTS, :MAX_WAIT_TIMEOUT, :TPL_REQUEST_TIMEOUT,
36
- :MAX_ATTEMPTS
34
+ private_constant :CONFIG_DEFAULTS, :MAX_WAIT_TIMEOUT, :MAX_ATTEMPTS
37
35
 
38
36
  class << self
39
37
  # Allows us to read messages from the topic
@@ -184,10 +182,24 @@ module Karafka
184
182
  # This API can be used in other pieces of code and allows for low-level consumer usage
185
183
  #
186
184
  # @param settings [Hash] extra settings to customize consumer
185
+ #
186
+ # @note We always ship and yield a proxied consumer because admin API performance is not
187
+ # that relevant. That is, there are no high frequency calls that would have to be delegated
187
188
  def with_consumer(settings = {})
188
189
  consumer = config(:consumer, settings).consumer
189
- yield(consumer)
190
+ proxy = ::Karafka::Connection::Proxy.new(consumer)
191
+ yield(proxy)
190
192
  ensure
193
+ # Always unsubscribe consumer just to be sure, that no metadata requests are running
194
+ # when we close the consumer. This in theory should prevent from some race-conditions
195
+ # that originate from librdkafka
196
+ begin
197
+ consumer&.unsubscribe
198
+ # Ignore any errors and continue to close consumer despite them
199
+ rescue Rdkafka::RdkafkaError
200
+ nil
201
+ end
202
+
191
203
  consumer&.close
192
204
  end
193
205
 
@@ -261,7 +273,7 @@ module Karafka
261
273
  name, partition => offset
262
274
  )
263
275
 
264
- real_offsets = consumer.offsets_for_times(tpl, TPL_REQUEST_TIMEOUT)
276
+ real_offsets = consumer.offsets_for_times(tpl)
265
277
  detected_offset = real_offsets.to_h.dig(name, partition)
266
278
 
267
279
  detected_offset&.offset || raise(Errors::InvalidTimeBasedOffsetError)
data/lib/karafka/app.rb CHANGED
@@ -53,6 +53,12 @@ module Karafka
53
53
  RUBY
54
54
  end
55
55
 
56
+ # @return [Boolean] true if we should be done in general with processing anything
57
+ # @note It is a meta status from the status object
58
+ def done?
59
+ App.config.internal.status.done?
60
+ end
61
+
56
62
  # Methods that should be delegated to Karafka module
57
63
  %i[
58
64
  root
@@ -70,9 +70,9 @@ module Karafka
70
70
 
71
71
  # Executes the default consumer flow.
72
72
  #
73
- # @return [Boolean] true if there was no exception, otherwise false.
74
- #
75
73
  # @private
74
+ #
75
+ # @return [Boolean] true if there was no exception, otherwise false.
76
76
  # @note We keep the seek offset tracking, and use it to compensate for async offset flushing
77
77
  # that may not yet kick in when error occurs. That way we pause always on the last processed
78
78
  # message.
@@ -20,9 +20,6 @@ module Karafka
20
20
  # How many times should we retry polling in case of a failure
21
21
  MAX_POLL_RETRIES = 20
22
22
 
23
- # Max time for a TPL request. We increase it to compensate for remote clusters latency
24
- TPL_REQUEST_TIMEOUT = 2_000
25
-
26
23
  # 1 minute of max wait for the first rebalance before a forceful attempt
27
24
  # This applies only to a case when a short-lived Karafka instance with a client would be
28
25
  # closed before first rebalance. Mitigates a librdkafka bug.
@@ -32,8 +29,7 @@ module Karafka
32
29
  # potential race conditions and other issues
33
30
  SHUTDOWN_MUTEX = Mutex.new
34
31
 
35
- private_constant :MAX_POLL_RETRIES, :SHUTDOWN_MUTEX, :TPL_REQUEST_TIMEOUT,
36
- :COOPERATIVE_STICKY_MAX_WAIT
32
+ private_constant :MAX_POLL_RETRIES, :SHUTDOWN_MUTEX, :COOPERATIVE_STICKY_MAX_WAIT
37
33
 
38
34
  # Creates a new consumer instance.
39
35
  #
@@ -350,10 +346,12 @@ module Karafka
350
346
  message.partition => message.offset
351
347
  )
352
348
 
349
+ proxy = Proxy.new(@kafka)
350
+
353
351
  # Now we can overwrite the seek message offset with our resolved offset and we can
354
352
  # then seek to the appropriate message
355
353
  # We set the timeout to 2_000 to make sure that remote clusters handle this well
356
- real_offsets = @kafka.offsets_for_times(tpl, TPL_REQUEST_TIMEOUT)
354
+ real_offsets = proxy.offsets_for_times(tpl)
357
355
  detected_partition = real_offsets.to_h.dig(message.topic, message.partition)
358
356
 
359
357
  # There always needs to be an offset. In case we seek into the future, where there
@@ -387,6 +385,21 @@ module Karafka
387
385
  end
388
386
  end
389
387
 
388
+ # Unsubscribes from all the subscriptions
389
+ # @note This is a private API to be used only on shutdown
390
+ # @note We do not re-raise since this is supposed to be only used on close and can be safely
391
+ # ignored. We do however want to instrument on it
392
+ def unsubscribe
393
+ @kafka.unsubscribe
394
+ rescue ::Rdkafka::RdkafkaError => e
395
+ Karafka.monitor.instrument(
396
+ 'error.occurred',
397
+ caller: self,
398
+ error: e,
399
+ type: 'connection.client.unsubscribe.error'
400
+ )
401
+ end
402
+
390
403
  # @param topic [String]
391
404
  # @param partition [Integer]
392
405
  # @return [Rdkafka::Consumer::TopicPartitionList]
@@ -85,7 +85,7 @@ module Karafka
85
85
  # propagate this far.
86
86
  def fetch_loop
87
87
  # Run the main loop as long as we are not stopping or moving into quiet mode
88
- until Karafka::App.stopping? || Karafka::App.quieting? || Karafka::App.quiet?
88
+ until Karafka::App.done?
89
89
  Karafka.monitor.instrument(
90
90
  'connection.listener.fetch_loop',
91
91
  caller: self,
@@ -0,0 +1,98 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Karafka
4
+ module Connection
5
+ # Usually it is ok to use the `Rdkafka::Consumer` directly because we need 1:1 its
6
+ # functionality. There are however cases where we want to have extra recoveries or other
7
+ # handling of errors and settings. This is where this module comes in handy.
8
+ #
9
+ # We do not want to wrap and delegate all via a proxy object for performance reasons, but we
10
+ # do still want to be able to alter some functionalities. This wrapper helps us do it when
11
+ # it would be needed
12
+ class Proxy < SimpleDelegator
13
+ # Errors on which we want to retry
14
+ RETRYABLE_ERRORS = %i[
15
+ all_brokers_down
16
+ timed_out
17
+ ].freeze
18
+
19
+ private_constant :RETRYABLE_ERRORS
20
+
21
+ attr_accessor :wrapped
22
+
23
+ alias __getobj__ wrapped
24
+
25
+ # @param obj [Rdkafka::Consumer, Proxy] rdkafka consumer or consumer wrapped with proxy
26
+ def initialize(obj)
27
+ super
28
+ # Do not allow for wrapping proxy with a proxy. This will prevent a case where we might
29
+ # wrap an already wrapped object with another proxy level. Simplifies passing consumers
30
+ # and makes it safe to wrap without type checking
31
+ @wrapped = obj.is_a?(self.class) ? obj.wrapped : obj
32
+ @config = ::Karafka::App.config.internal.connection.proxy
33
+ end
34
+
35
+ # Proxies the `#query_watermark_offsets` with extra recovery from timeout problems.
36
+ # We impose our own custom timeout to make sure, that high-latency clusters and overloaded
37
+ # clusters can handle our requests.
38
+ #
39
+ # @param topic [String] topic name
40
+ # @param partition [Partition]
41
+ # @return [Array<Integer, Integer>] watermark offsets
42
+ def query_watermark_offsets(topic, partition)
43
+ l_config = @config.query_watermark_offsets
44
+
45
+ with_broker_errors_retry(
46
+ # required to be in seconds, not ms
47
+ wait_time: l_config.wait_time / 1_000.to_f,
48
+ max_attempts: l_config.max_attempts
49
+ ) do
50
+ @wrapped.query_watermark_offsets(topic, partition, l_config.timeout)
51
+ end
52
+ end
53
+
54
+ # Similar to `#query_watermark_offsets`, this method can be sensitive to latency. We handle
55
+ # this the same way
56
+ #
57
+ # @param tpl [Rdkafka::Consumer::TopicPartitionList] tpl to get time offsets
58
+ # @return [Rdkafka::Consumer::TopicPartitionList] tpl with time offsets
59
+ def offsets_for_times(tpl)
60
+ l_config = @config.offsets_for_times
61
+
62
+ with_broker_errors_retry(
63
+ # required to be in seconds, not ms
64
+ wait_time: l_config.wait_time / 1_000.to_f,
65
+ max_attempts: l_config.max_attempts
66
+ ) do
67
+ @wrapped.offsets_for_times(tpl, l_config.timeout)
68
+ end
69
+ end
70
+
71
+ private
72
+
73
+ # Runs expected block of code with few retries on all_brokers_down
74
+ # librdkafka can return `all_brokers_down` for scenarios when broker is overloaded or not
75
+ # reachable due to latency.
76
+ # @param max_attempts [Integer] how many attempts (not retries) should we take before failing
77
+ # completely.
78
+ # @param wait_time [Integer, Float] how many seconds should we wait. It uses `#sleep` of Ruby
79
+ # so it needs time in seconds.
80
+ def with_broker_errors_retry(max_attempts:, wait_time: 1)
81
+ attempt ||= 0
82
+ attempt += 1
83
+
84
+ yield
85
+ rescue Rdkafka::RdkafkaError => e
86
+ raise unless RETRYABLE_ERRORS.include?(e.code)
87
+
88
+ if attempt <= max_attempts
89
+ sleep(wait_time)
90
+
91
+ retry
92
+ end
93
+
94
+ raise
95
+ end
96
+ end
97
+ end
98
+ end
@@ -39,6 +39,22 @@ module Karafka
39
39
  required(:status) { |val| !val.nil? }
40
40
  required(:process) { |val| !val.nil? }
41
41
 
42
+ nested(:connection) do
43
+ nested(:proxy) do
44
+ nested(:query_watermark_offsets) do
45
+ required(:timeout) { |val| val.is_a?(Integer) && val.positive? }
46
+ required(:max_attempts) { |val| val.is_a?(Integer) && val.positive? }
47
+ required(:wait_time) { |val| val.is_a?(Integer) && val.positive? }
48
+ end
49
+
50
+ nested(:offsets_for_times) do
51
+ required(:timeout) { |val| val.is_a?(Integer) && val.positive? }
52
+ required(:max_attempts) { |val| val.is_a?(Integer) && val.positive? }
53
+ required(:wait_time) { |val| val.is_a?(Integer) && val.positive? }
54
+ end
55
+ end
56
+ end
57
+
42
58
  nested(:routing) do
43
59
  required(:builder) { |val| !val.nil? }
44
60
  required(:subscription_groups_builder) { |val| !val.nil? }
@@ -280,6 +280,9 @@ module Karafka
280
280
  when 'connection.client.rebalance_callback.error'
281
281
  error "Rebalance callback error occurred: #{error}"
282
282
  error details
283
+ when 'connection.client.unsubscribe.error'
284
+ error "Client unsubscribe error occurred: #{error}"
285
+ error details
283
286
  else
284
287
  # This should never happen. Please contact the maintainers
285
288
  raise Errors::UnsupportedCaseError, event
@@ -35,6 +35,10 @@ module Karafka
35
35
  connection.listener.fetch_loop
36
36
  connection.listener.fetch_loop.received
37
37
 
38
+ connection.client.rebalance_callback
39
+ connection.client.poll.error
40
+ connection.client.unsubscribe.error
41
+
38
42
  consumer.consume
39
43
  consumer.consumed
40
44
  consumer.consuming.pause
@@ -220,6 +220,11 @@ module Karafka
220
220
  next if partition_name == '-1'
221
221
  # Skip until lag info is available
222
222
  next if partition_statistics['consumer_lag'] == -1
223
+ next if partition_statistics['consumer_lag_stored'] == -1
224
+
225
+ # Skip if we do not own the fetch assignment
226
+ next if partition_statistics['fetch_state'] == 'stopped'
227
+ next if partition_statistics['fetch_state'] == 'none'
223
228
 
224
229
  public_send(
225
230
  metric.type,
@@ -1,7 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Karafka
4
+ # Namespace for third-party libraries patches
4
5
  module Patches
6
+ # Rdkafka patches specific to Karafka
5
7
  module Rdkafka
6
8
  # Binding patches that slightly change how rdkafka operates in certain places
7
9
  module Bindings
@@ -51,11 +53,18 @@ module Karafka
51
53
  # @param opaque [Rdkafka::Opaque]
52
54
  # @param tpl [Rdkafka::Consumer::TopicPartitionList]
53
55
  def trigger_callbacks(code, opaque, tpl)
54
- case code
55
- when RB::RD_KAFKA_RESP_ERR__ASSIGN_PARTITIONS
56
- opaque.call_on_partitions_assigned(tpl)
57
- when RB::RD_KAFKA_RESP_ERR__REVOKE_PARTITIONS
58
- opaque.call_on_partitions_revoked(tpl)
56
+ Karafka.monitor.instrument(
57
+ 'connection.client.rebalance_callback',
58
+ caller: self,
59
+ code: code,
60
+ tpl: tpl
61
+ ) do
62
+ case code
63
+ when RB::RD_KAFKA_RESP_ERR__ASSIGN_PARTITIONS
64
+ opaque.call_on_partitions_assigned(tpl)
65
+ when RB::RD_KAFKA_RESP_ERR__REVOKE_PARTITIONS
66
+ opaque.call_on_partitions_revoked(tpl)
67
+ end
59
68
  end
60
69
  rescue StandardError => e
61
70
  Karafka.monitor.instrument(
@@ -14,11 +14,6 @@
14
14
  module Karafka
15
15
  module Pro
16
16
  class Iterator
17
- # Max time for a TPL request. We increase it to compensate for remote clusters latency
18
- TPL_REQUEST_TIMEOUT = 2_000
19
-
20
- private_constant :TPL_REQUEST_TIMEOUT
21
-
22
17
  # Because we have various formats in which we can provide the offsets, before we can
23
18
  # subscribe to them, there needs to be a bit of normalization.
24
19
  #
@@ -30,7 +25,7 @@ module Karafka
30
25
  # @param consumer [::Rdkafka::Consumer] consumer instance needed to talk with Kafka
31
26
  # @param expanded_topics [Hash] hash with expanded and normalized topics data
32
27
  def initialize(consumer, expanded_topics)
33
- @consumer = consumer
28
+ @consumer = Connection::Proxy.new(consumer)
34
29
  @expanded_topics = expanded_topics
35
30
  @mapped_topics = Hash.new { |h, k| h[k] = {} }
36
31
  end
@@ -144,7 +139,7 @@ module Karafka
144
139
  # If there were no time-based, no need to query Kafka
145
140
  return if time_tpl.empty?
146
141
 
147
- real_offsets = @consumer.offsets_for_times(time_tpl, TPL_REQUEST_TIMEOUT)
142
+ real_offsets = @consumer.offsets_for_times(time_tpl)
148
143
 
149
144
  real_offsets.to_h.each do |name, results|
150
145
  results.each do |result|
@@ -126,6 +126,32 @@ module Karafka
126
126
  setting :activity_manager, default: Routing::ActivityManager.new
127
127
  end
128
128
 
129
+ # Namespace for internal connection related settings
130
+ setting :connection do
131
+ # Settings that are altered by our client proxy layer
132
+ setting :proxy do
133
+ # Watermark offsets request settings
134
+ setting :query_watermark_offsets do
135
+ # timeout for this request. For busy or remote clusters, this should be high enough
136
+ setting :timeout, default: 5_000
137
+ # How many times should we try to run this call before raising an error
138
+ setting :max_attempts, default: 3
139
+ # How long should we wait before next attempt in case of a failure
140
+ setting :wait_time, default: 1_000
141
+ end
142
+
143
+ # Offsets for times request settings
144
+ setting :offsets_for_times do
145
+ # timeout for this request. For busy or remote clusters, this should be high enough
146
+ setting :timeout, default: 5_000
147
+ # How many times should we try to run this call before raising an error
148
+ setting :max_attempts, default: 3
149
+ # How long should we wait before next attempt in case of a failure
150
+ setting :wait_time, default: 1_000
151
+ end
152
+ end
153
+ end
154
+
129
155
  setting :processing do
130
156
  # option scheduler [Object] scheduler we will be using
131
157
  setting :scheduler, default: Processing::Scheduler.new
@@ -62,5 +62,15 @@ module Karafka
62
62
  end
63
63
  end
64
64
  end
65
+
66
+ # @return [Boolean] true if we are in any of the status that would indicate we should no longer
67
+ # process incoming data. It is a meta status built from others and not a separate state in
68
+ # the sense of a state machine
69
+ def done?
70
+ # Short-track for the most common case not to invoke all others on normal execution
71
+ return false if running?
72
+
73
+ stopping? || stopped? || quieting? || quiet? || terminated?
74
+ end
65
75
  end
66
76
  end
@@ -3,5 +3,5 @@
3
3
  # Main module namespace
4
4
  module Karafka
5
5
  # Current Karafka version
6
- VERSION = '2.1.9'
6
+ VERSION = '2.1.11'
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: karafka
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.9
4
+ version: 2.1.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Maciej Mensfeld
@@ -12,30 +12,30 @@ cert_chain:
12
12
  -----BEGIN CERTIFICATE-----
13
13
  MIIEcDCCAtigAwIBAgIBATANBgkqhkiG9w0BAQsFADA/MRAwDgYDVQQDDAdjb250
14
14
  YWN0MRcwFQYKCZImiZPyLGQBGRYHa2FyYWZrYTESMBAGCgmSJomT8ixkARkWAmlv
15
- MB4XDTIyMDgxOTE3MjEzN1oXDTIzMDgxOTE3MjEzN1owPzEQMA4GA1UEAwwHY29u
15
+ MB4XDTIzMDgyMTA3MjU1NFoXDTI0MDgyMDA3MjU1NFowPzEQMA4GA1UEAwwHY29u
16
16
  dGFjdDEXMBUGCgmSJomT8ixkARkWB2thcmFma2ExEjAQBgoJkiaJk/IsZAEZFgJp
17
- bzCCAaIwDQYJKoZIhvcNAQEBBQADggGPADCCAYoCggGBAODzeO3L6lxdATzMHKNW
18
- jFA/GGunoPuylO/BMzy8RiQHh7VIvysAKs0tHhTx3g2D0STDpF+hcQcPELFikiT2
19
- F+1wOHj/SsrK7VKqfA8+gq04hKc5sQoX2Egf9k3V0YJ3eZ6R/koHkQ8A0TVt0w6F
20
- ZQckoV4MqnEAx0g/FZN3mnHTlJ3VFLSBqJEIe+S6FZMl92mSv+hTrlUG8VaYxSfN
21
- lTCvnKk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PW6nGSYKgRhkfpmquXSNKZRIQ4V6bFrufa+DzD0bt2ZA3ah
33
+ fMmJguyb5L2Gf1zpDXzFSPMG7YQFLzwYz1zZZvOU7/UCpQsHpID/YxqDp4+Dgb+Y
34
+ qma0whX8UG/gXFV2pYWpYOfpatvahwi+A1TwPQsuZwkkhi1OyF1At3RY+hjSXyav
35
+ AnG1dJU+yL2BK7vaVytLTstJME5mepSZ46qqIJXMuWob/YPDmVaBF39TDSG9e34s
36
+ msG3BiCqgOgHAnL23+CN3Rt8MsuRfEtoTKpJVcCfoEoNHOkc
37
37
  -----END CERTIFICATE-----
38
- date: 2023-08-06 00:00:00.000000000 Z
38
+ date: 2023-08-23 00:00:00.000000000 Z
39
39
  dependencies:
40
40
  - !ruby/object:Gem::Dependency
41
41
  name: karafka-core
@@ -178,6 +178,7 @@ files:
178
178
  - lib/karafka/connection/listeners_batch.rb
179
179
  - lib/karafka/connection/messages_buffer.rb
180
180
  - lib/karafka/connection/pauses_manager.rb
181
+ - lib/karafka/connection/proxy.rb
181
182
  - lib/karafka/connection/raw_messages_buffer.rb
182
183
  - lib/karafka/connection/rebalance_manager.rb
183
184
  - lib/karafka/contracts.rb
metadata.gz.sig CHANGED
Binary file