sbmt-kafka_consumer 3.4.2 → 3.5.1

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: 46ea6a25a613913774156f44f2c81c402b647f3009e83900bdf8e46440c310fd
4
- data.tar.gz: 2ee4be3a0439595064d837023fcbcd47a96077ac3e4928599ecdf5cb93b8fb08
3
+ metadata.gz: 872a886b138e7956051e347be06915f7c9153abd50076ae2ae77e0fc83672e48
4
+ data.tar.gz: 651678b88fe6f8fde83ec4c086dc7bbfcc5edd5ff1dfd214b151bca76f8b3783
5
5
  SHA512:
6
- metadata.gz: 1069c06f8d3f8a9195c0b6405042d78131631e9dc391affb1feb1895efe6f4b95b657ca3194d852d80f0c4592cb7cf2d820dbadcd944ab21f2c26ab270c8dfa3
7
- data.tar.gz: f75958623481cd4885825e3f8bf61808adbd52ff6d22b8eb19bd049bb0d6a1e2bb4f36e093ba69db0cc657eec694f287c0843d44ae4493b1432cbbfc38fe51bb
6
+ metadata.gz: 2b60b4a2a5f84f9e3f6bc7602e352d14a373f49c9bab3d30784259e8a41e01e4d5d4324257a283cec6f3a23169ff47824fbf5c702acab891214c1ba806f2da90
7
+ data.tar.gz: 2ad55a703d2a6e264d1ceca17335d0a9a6c38250eba00d7c4b8dc4848df1a83442e6c6de1e59916be7ac0de9f3d99114b3c1b0fc0dda24501b8f05d38c867b8f
data/.rubocop.yml CHANGED
@@ -2,10 +2,12 @@ inherit_mode:
2
2
  merge:
3
3
  - Exclude
4
4
 
5
- require:
5
+ plugins:
6
6
  - rubocop-performance
7
7
  - rubocop-rails
8
8
  - rubocop-rspec
9
+
10
+ require:
9
11
  - standard
10
12
 
11
13
  inherit_gem:
@@ -22,9 +24,6 @@ AllCops:
22
24
  Exclude:
23
25
  - spec/internal/pkg/**/*
24
26
 
25
- RSpec/FilePath:
26
- Enabled: false
27
-
28
27
  RSpec/VerifiedDoubles:
29
28
  Exclude:
30
29
  - spec/**/*_spec.rb
data/CHANGELOG.md CHANGED
@@ -13,6 +13,23 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
13
13
 
14
14
  ### Fixed
15
15
 
16
+ ## [3.5.1] - 2025-04-18
17
+
18
+ ### Fixed
19
+
20
+ - Rename `yabeda_kafka_consumer_consumer_group_rebalances` gauge to `yabeda_kafka_consumer_group_rebalances`
21
+ - Change type of `yabeda_kafka_consumer_group_rebalances` from `Counter` to `Gauge`
22
+
23
+ ## [3.5.0] - 2025-04-17
24
+
25
+ ### Added
26
+
27
+ - Increase default timeout to 300 seconds for better accommodation of temporary delays.
28
+ - Make liveness probe listener thread-safe using a mutex.
29
+ - Use monotonic clock for more accurate time measurements in liveness checks.
30
+ - Simplify liveness status checking logic.
31
+ - Support Rack v3
32
+
16
33
  ## [3.4.2] - 2025-04-02
17
34
 
18
35
  ### Fixed
data/README.md CHANGED
@@ -91,7 +91,7 @@ default: &default
91
91
  liveness:
92
92
  enabled: true
93
93
  path: "/liveness"
94
- timeout: 15
94
+ timeout: 300
95
95
  max_error_count: 15 # default 10
96
96
  metrics: # optional section
97
97
  port: 9090
@@ -157,7 +157,7 @@ auth:
157
157
  The `servers` key is required and should be in rdkafka format: without `kafka://` prefix, for example: `srv1:port1,srv2:port2,...`.
158
158
 
159
159
  The `kafka_config` section may contain any [rdkafka option](https://github.com/confluentinc/librdkafka/blob/master/CONFIGURATION.md). Also, `kafka_options` may be redefined for each topic.
160
- Please note that the `partition.assignment.strategy` option within kafka_options is not supported for topics; instead, use the global option partition_assignment_strategy.
160
+ Please note that the `partition.assignment.strategy` option within kafka_options is not supported for topics; instead, use the global option partition_assignment_strategy.
161
161
 
162
162
  ### `consumer_groups` config section
163
163
 
@@ -275,7 +275,7 @@ To process messages in batches, you need to add the `process_batch` method in th
275
275
  # app/consumers/some_consumer.rb
276
276
  class SomeConsumer < Sbmt::KafkaConsumer::BaseConsumer
277
277
  def process_batch(messages)
278
- # some code
278
+ # some code
279
279
  end
280
280
  end
281
281
  ```
@@ -7,6 +7,6 @@ class Sbmt::KafkaConsumer::Config::Probes::LivenessProbe < Dry::Struct
7
7
  attribute :path, Sbmt::KafkaConsumer::Types::Strict::String
8
8
  .optional
9
9
  .default("/liveness")
10
- attribute :timeout, Sbmt::KafkaConsumer::Types::Coercible::Integer.optional.default(10)
10
+ attribute :timeout, Sbmt::KafkaConsumer::Types::Coercible::Integer.optional.default(300)
11
11
  attribute :max_error_count, Sbmt::KafkaConsumer::Types::Coercible::Integer.optional.default(10)
12
12
  end
@@ -9,33 +9,35 @@ module Sbmt
9
9
 
10
10
  ERROR_TYPE = "Liveness probe error"
11
11
 
12
- def initialize(timeout_sec: 10, max_error_count: 10)
13
- @consumer_groups = Karafka::App.routes.map(&:name)
14
- @timeout_sec = timeout_sec
12
+ def initialize(timeout_sec: 300, max_error_count: 10)
13
+ @timeout_sec = timeout_sec * 1000
15
14
  @max_error_count = max_error_count
16
15
  @error_count = 0
17
16
  @error_backtrace = nil
18
17
  @polls = {}
19
-
18
+ @mutex = Mutex.new
20
19
  setup_subscription
21
20
  end
22
21
 
23
22
  def probe(_env)
24
- now = current_time
25
- timed_out_polls = select_timed_out_polls(now)
23
+ now = monotonic_now
24
+ has_timed_out_polls = polls.values.any? { |tick| (now - tick) > timeout_sec }
26
25
 
27
- if timed_out_polls.empty? && @error_count < @max_error_count
28
- probe_ok groups: meta_from_polls(polls, now) if timed_out_polls.empty?
26
+ if !has_timed_out_polls && @error_count < @max_error_count
27
+ probe_ok timed_out_polls: false, errors_count: @error_count
29
28
  elsif @error_count >= @max_error_count
30
- probe_error error_type: ERROR_TYPE, failed_librdkafka: {error_count: @error_count, error_backtrace: @error_backtrace}
29
+ probe_error error_type: ERROR_TYPE, timed_out_polls: false, error_count: @error_count, error_backtrace: @error_backtrace
31
30
  else
32
- probe_error error_type: ERROR_TYPE, failed_groups: meta_from_polls(timed_out_polls, now)
31
+ probe_error error_type: ERROR_TYPE, timed_out_polls: true, errors_count: @error_count, polls: polls
33
32
  end
34
33
  end
35
34
 
36
35
  def on_connection_listener_fetch_loop(event)
37
- consumer_group = event.payload[:subscription_group].consumer_group
38
- polls[consumer_group.name] = current_time
36
+ now = monotonic_now
37
+ KafkaConsumer.logger.debug("on_connection_listener_fetch_loop: now=#{now}, thread_id=#{thread_id}")
38
+ mutex.synchronize do
39
+ polls[thread_id] = monotonic_now
40
+ end
39
41
  end
40
42
 
41
43
  def on_error_occurred(event)
@@ -50,36 +52,14 @@ module Sbmt
50
52
 
51
53
  private
52
54
 
53
- attr_reader :polls, :timeout_sec, :consumer_groups
55
+ attr_reader :polls, :timeout_sec, :mutex
54
56
 
55
- def current_time
56
- Time.now.utc
57
+ def monotonic_now
58
+ ::Process.clock_gettime(::Process::CLOCK_MONOTONIC, :float_millisecond)
57
59
  end
58
60
 
59
- def select_timed_out_polls(now)
60
- raise "consumer_groups are empty. Please set them up" if consumer_groups.empty?
61
-
62
- consumer_groups.each_with_object({}) do |group, hash|
63
- last_poll_at = polls[group]
64
- next if last_poll_at && last_poll_at + timeout_sec >= now
65
-
66
- hash[group] = last_poll_at
67
- end
68
- end
69
-
70
- def meta_from_polls(polls, now)
71
- polls.each_with_object({}) do |(group, last_poll_at), hash|
72
- if last_poll_at.nil?
73
- hash[group] = {had_poll: false}
74
- next
75
- end
76
-
77
- hash[group] = {
78
- had_poll: true,
79
- last_poll_at: last_poll_at,
80
- seconds_since_last_poll: (now - last_poll_at).to_i
81
- }
82
- end
61
+ def thread_id
62
+ Thread.current.object_id
83
63
  end
84
64
 
85
65
  def setup_subscription
@@ -150,8 +150,8 @@ module Sbmt
150
150
  state: group_stats["state"]
151
151
  }
152
152
 
153
- Yabeda.kafka_consumer.consumer_group_rebalances
154
- .increment(cg_tags, by: group_stats["rebalance_cnt"])
153
+ Yabeda.kafka_consumer.group_rebalances
154
+ .set(cg_tags, group_stats["rebalance_cnt"])
155
155
  end
156
156
 
157
157
  def report_topic_stats(group_id, topic_stats)
@@ -1,5 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "rack"
4
+ require "rackup/handler/webrick" if Gem::Version.new(::Rack.release) >= Gem::Version.new("3")
5
+
3
6
  module Sbmt
4
7
  module KafkaConsumer
5
8
  module Probes
@@ -14,6 +17,12 @@ module Sbmt
14
17
  end
15
18
  end
16
19
 
20
+ def webrick
21
+ return ::Rack::Handler::WEBrick if Gem::Version.new(::Rack.release) < Gem::Version.new("3")
22
+
23
+ ::Rackup::Handler::WEBrick
24
+ end
25
+
17
26
  private
18
27
 
19
28
  def health_check_app(config)
@@ -56,7 +65,7 @@ module Sbmt
56
65
 
57
66
  def start_webrick(app, middlewares:, port:)
58
67
  Thread.new do
59
- ::Rack::Handler::WEBrick.run(
68
+ webrick.run(
60
69
  ::Rack::Builder.new do
61
70
  middlewares.each do |middleware, options|
62
71
  use middleware, **options
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Sbmt
4
4
  module KafkaConsumer
5
- VERSION = "3.4.2"
5
+ VERSION = "3.5.1"
6
6
  end
7
7
  end
@@ -30,7 +30,7 @@ module Sbmt
30
30
  end
31
31
 
32
32
  group :kafka_consumer do
33
- counter :consumer_group_rebalances,
33
+ gauge :group_rebalances,
34
34
  tags: %i[client group_id state],
35
35
  comment: "Consumer group rebalances"
36
36
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sbmt-kafka_consumer
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.4.2
4
+ version: 3.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kuper Ruby-Platform Team
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2025-04-02 00:00:00.000000000 Z
11
+ date: 2025-04-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -565,7 +565,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
565
565
  - !ruby/object:Gem::Version
566
566
  version: '0'
567
567
  requirements: []
568
- rubygems_version: 3.3.7
568
+ rubygems_version: 3.5.21
569
569
  signing_key:
570
570
  specification_version: 4
571
571
  summary: Ruby gem for consuming Kafka messages