karafka-core 2.6.4 → 2.6.6

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: b7064756fbbf13ddd1048da55f30969b2ae10d58442b9a4ec8c8b5250a260473
4
- data.tar.gz: 9d6fbe9c4257ce42e03017333602354265c6fa408e585099c6c515d3523c368d
3
+ metadata.gz: 69c1a45639ef9a5f60dfe01427637a68be3a284a1d3cc6645f35c7f1bc4db60a
4
+ data.tar.gz: af342b72f3862e8264fbc09e4e6ba473ff13a0b2615ea78738071f5b366e9c48
5
5
  SHA512:
6
- metadata.gz: 4889fd25e48a9f06adfe9797862aa7d52dd6f363cb95839bf31e4bf66b499db9210331d1d5302f9bdf8d221c9895e68dcc58b8aec07b52004c21e7796779ed48
7
- data.tar.gz: b154d18d6feeefac2e715d21c0f63c7e5841c145f5f13dbd588386d7dbd54cc0187c2640a1034679b806db66dc6e19ffb8bf5007ca44c914a0e69abb8758f356
6
+ metadata.gz: 0ed70ee79bf6cb77ec89df3e68d30829b70c79dadc699b491006c3ac536009230fdd188996a7386c1cce0140625c04002a00575b7c5fda6b7d82a172b241e6e4
7
+ data.tar.gz: c7d33f57867534c8afa1ab28a00f63b4d806fc2286c61bdb31a0111b8a81048e8a1ce654b8ff5dbc0dd7736d70ad8db92738b264c7ed6d3124ba0fc6da96105e
@@ -24,7 +24,6 @@ jobs:
24
24
  - '4.0'
25
25
  - '3.4'
26
26
  - '3.3'
27
- - '3.2'
28
27
  include:
29
28
  - ruby: '4.0'
30
29
  coverage: 'true'
@@ -37,7 +36,7 @@ jobs:
37
36
  run: "[ -e $APT_DEPS ] || sudo apt-get install -y --no-install-recommends $APT_DEPS"
38
37
 
39
38
  - name: Set up Ruby
40
- uses: ruby/setup-ruby@95ef2b042f9d7a56d8268cba8559e2842e2ad01b # v1.321.0
39
+ uses: ruby/setup-ruby@824c0e29fdfc7d689c191c27acc969d2d04b7dd8 # v1.331.0
41
40
  with:
42
41
  ruby-version: ${{matrix.ruby}}
43
42
  bundler: 'latest'
@@ -69,9 +68,9 @@ jobs:
69
68
  with:
70
69
  fetch-depth: 0
71
70
  - name: Set up Ruby
72
- uses: ruby/setup-ruby@95ef2b042f9d7a56d8268cba8559e2842e2ad01b # v1.321.0
71
+ uses: ruby/setup-ruby@824c0e29fdfc7d689c191c27acc969d2d04b7dd8 # v1.331.0
73
72
  with:
74
- ruby-version: '4.0.6'
73
+ ruby-version: '4.0.7'
75
74
  bundler-cache: true
76
75
  - name: Run rubocop
77
76
  run: bundle exec rubocop
@@ -86,9 +85,9 @@ jobs:
86
85
  with:
87
86
  fetch-depth: 0
88
87
  - name: Set up Ruby
89
- uses: ruby/setup-ruby@95ef2b042f9d7a56d8268cba8559e2842e2ad01b # v1.321.0
88
+ uses: ruby/setup-ruby@824c0e29fdfc7d689c191c27acc969d2d04b7dd8 # v1.331.0
90
89
  with:
91
- ruby-version: '4.0.6'
90
+ ruby-version: '4.0.7'
92
91
  bundler-cache: true
93
92
  - name: Run yard-lint
94
93
  run: bundle exec yard-lint lib/
@@ -101,7 +100,7 @@ jobs:
101
100
  with:
102
101
  fetch-depth: 0
103
102
  - name: Set up Node.js
104
- uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0
103
+ uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
105
104
  with:
106
105
  node-version: '20'
107
106
  cache: 'npm'
@@ -24,7 +24,7 @@ jobs:
24
24
  fetch-depth: 0
25
25
 
26
26
  - name: Set up Ruby
27
- uses: ruby/setup-ruby@95ef2b042f9d7a56d8268cba8559e2842e2ad01b # v1.321.0
27
+ uses: ruby/setup-ruby@824c0e29fdfc7d689c191c27acc969d2d04b7dd8 # v1.331.0
28
28
  with:
29
29
  bundler-cache: false
30
30
 
data/.gitignore CHANGED
@@ -40,6 +40,7 @@ db/*.sqlite3
40
40
  /specifications
41
41
  rerun.txt
42
42
  pickle-email-*.html
43
+ .codex
43
44
 
44
45
  # If you find yourself ignoring temporary files generated by your text editor
45
46
  # or operating system, you probably want to add a global ignore instead:
data/.rubocop.yml CHANGED
@@ -11,7 +11,7 @@ inherit_gem:
11
11
 
12
12
  AllCops:
13
13
  NewCops: enable
14
- TargetRubyVersion: 3.2
14
+ TargetRubyVersion: 3.3
15
15
  Include:
16
16
  - "**/*.rb"
17
17
  - "**/*.gemspec"
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 4.0.6
1
+ 4.0.7
data/CHANGELOG.md CHANGED
@@ -1,45 +1,55 @@
1
1
  # Karafka Core Changelog
2
2
 
3
+ ## 2.6.6 (2026-10-25)
4
+ - [Fix] Make `Taggable::Tags` safe to read while another thread adds or removes tags. On JRuby a concurrent read could raise `NullPointerException`.
5
+ - [Fix] Make `Taggable#tags` return one `Tags` per object when several threads call it first. On JRuby each thread could get its own `Tags`, and tags were lost.
6
+ - [Fix] Make `Notifications#register_event` safe while other threads call `#instrument`. On JRuby a concurrent registration could make a registered event look unregistered or dispatch it without its method.
7
+ - [Fix] Make the `Monitor` event name cache thread-safe for a namespace or Symbol event ids, so on JRuby concurrent `#instrument` calls no longer corrupt it.
8
+
9
+ ## 2.6.5 (2026-10-19)
10
+ - **[EOL]** Drop Ruby 3.2 support due to EOL; require Ruby 3.3+.
11
+ - [Change] Use the offending value (event id, setting name, class or constant name) as the message of errors raised by `Notifications`, `Configurable::Node`, `Configurable::Importer` and the spec locators.
12
+
3
13
  ## 2.6.4 (2026-09-11)
4
- - [Enhancement] Add `Configurable::Importer`, a subclassable base for injecting memoized config readers into a class. A subclass names the config root once by overriding `.root`, and each use site then names only the attributes it wants. Supports both `include` and `extend`.
14
+ - [Enhancement] Add `Configurable::Importer`, a subclassable base for injecting memoized config readers into a class via `include` or `extend`.
5
15
 
6
16
  ## 2.6.3 (2026-08-31)
7
- - [Enhancement] Add `Configurable::Injector`, a reusable base for injecting default values into a config hash without overwriting user-provided settings, with support for layering extra defaults on top.
17
+ - [Enhancement] Add `Configurable::Injector`, a reusable base for injecting default values into a config hash without overwriting user settings.
8
18
 
9
19
  ## 2.6.2 (2026-06-29)
10
- - [Enhancement] Document that a leaf's `default` value is shared by reference across all config instances, so a mutable default (e.g. `default: []`) mutated in place is visible everywhere. Assign it inside a `configure` block if you need a per-instance copy.
11
- - [Fix] `require "pathname"` explicitly in `lib/karafka-core.rb`. `Karafka::Core.gem_root` returns a `Pathname` but the gem never required it, so `gem_root` raised `NameError` wherever nothing else happened to load it first.
20
+ - [Enhancement] Document that a setting default is shared across all config instances, so a mutable default such as `[]` must not be changed in place.
21
+ - [Fix] Require `pathname` explicitly, so `Karafka::Core.gem_root` no longer raises `NameError` when nothing else loaded it.
12
22
  - [Enhancement] Document that a `virtual` rule must return a freshly built `Array` of `[path, message]` error pairs on each call; a memoized, shared or frozen array is unsupported.
13
23
  - [Fix] `Configurable::Node#register` now raises the documented "already registered" `ArgumentError` for a name used by an unread lazy-with-constructor setting, which it previously overwrote silently.
14
- - [Fix] `Contractable::Contract.nested` now pops its path in an `ensure`. If the block raised while the contract was being defined and the caller rescued it, the path stayed on the nesting stack and was prefixed onto every rule defined afterwards.
15
- - [Fix] `Contract#call` no longer raises `NoMethodError` when validating a non-Hash root with a 1-key or 2-key rule path; it reports the path as missing, consistent with the 3+-key path (and the non-Hash intermediate handling added in 2.6.1).
24
+ - [Fix] Stop a rescued error inside `Contractable::Contract.nested` from prefixing its path onto every rule defined afterwards.
25
+ - [Fix] Report a missing path instead of raising `NoMethodError` when validating a non-Hash root with a 1-key or 2-key rule.
16
26
  - [Fix] Honor `excluded_keys` containing `"cgrp"` in `StatisticsDecorator` `only_keys` mode; the `cgrp` branch lacked the exclusion guard its `brokers` and `topics` siblings have.
17
27
  - [Fix] Guard the patched rdkafka error callback against a null client pointer, which librdkafka can pass early in client construction and which could segfault the process.
18
28
  - [Fix] Resolve fatal errors in the patched rdkafka error callback via `RdkafkaError.build_fatal`, so the real underlying error is reported instead of the generic `ERR__FATAL` marker.
19
29
  - [Fix] A lazy setting declared without a constructor (`setting(:x, lazy: true)`) no longer raises when read; it now behaves like a regular setting backed by its default.
20
- - [Fix] `Contract#call` no longer raises `NoMethodError` when a virtual rule returns `false`. A virtual rule now signals "no errors" with any non-Array result; only an `Array` of error pairs is collected.
30
+ - [Fix] Stop `Contract#call` from raising `NoMethodError` when a virtual rule returns `false`.
21
31
  - [Fix] Make `CallbacksManager` thread-safe under concurrent `add`/`delete` during dispatch, so a callback registered or removed while callbacks were firing is no longer lost.
22
- - [Fix] Make `Notifications` subscriptions thread-safe: a listener that unsubscribes itself (or another) from within its own handler no longer causes the next listener to be skipped, and concurrent subscribe/unsubscribe during dispatch is now safe.
23
- - [Fix] Report a freeze duration (`_fd`) of `0` for statistics keys that first appear mid-stream (e.g. a new broker or partition) instead of the time since the previous emission, which was incorrect and made the related spec flaky.
24
- - [Fix] Make assigning a setting on a frozen `Configurable::Node` atomic; it previously mutated the canonical store before raising `FrozenError`, leaving the store and the reader permanently out of sync.
25
- - [Fix] `Configurable::Node#to_h` no longer raises for a setting using the `->(default) { ... }` constructor form when its value has not been set yet (e.g. `#to_h` on an unconfigured instance or an unread lazy setting).
26
- - [Fix] Honor `excluded_keys` inside `StatisticsDecorator` `only_keys` decoration. A key listed in both `only_keys` and `excluded_keys` was still decorated because the direct-access decoration loop never consulted `excluded_keys`; exclusion now wins, matching the full-decoration path.
27
- - [Fix] Strip the tests/specs root directory as an anchored prefix instead of a global `gsub` in `MinitestLocator` and `RSpecLocator`, which corrupted the derived subject path when the root string recurred later in it.
32
+ - [Fix] Make `Notifications` subscriptions thread-safe, so a listener unsubscribing during dispatch no longer causes the next listener to be skipped.
33
+ - [Fix] Report a freeze duration (`_fd`) of `0` for statistics keys that first appear mid-stream.
34
+ - [Fix] Stop an assignment on a frozen `Configurable::Node` from leaving the setting in an inconsistent state.
35
+ - [Fix] Stop `Configurable::Node#to_h` from raising for an unset setting that uses the `->(default) { ... }` constructor form.
36
+ - [Fix] Honor `excluded_keys` when combined with `only_keys` in `StatisticsDecorator`.
37
+ - [Fix] Fix subject path detection in `MinitestLocator` and `RSpecLocator` when the tests root name repeats later in the path.
28
38
 
29
39
  ## 2.6.1 (2026-06-15)
30
40
  - [Enhancement] Speed up `Contract#call` by ~1.25–1.4x, the per-message validation path in WaterDrop producers.
31
- - [Fix] `Contract#call` with rule paths of 3+ keys no longer raises `NoMethodError` when an intermediate value is not a `Hash` and reports the path as missing instead, consistent with the 2-key path behavior.
32
- - [Change] Reject reserved setting names with an `ArgumentError` in `Configurable::Node#setting` and `#register` (internal state names and the node public API names). Such names previously shadowed the node's own accessors and could corrupt its internal state.
41
+ - [Fix] Report a missing path instead of raising `NoMethodError` when a 3+ key rule path meets a non-Hash intermediate value.
42
+ - [Change] Reject reserved setting names in `Configurable::Node#setting` and `#register` with an `ArgumentError`, since they could corrupt the node state.
33
43
  - [Enhancement] Speed up `Monitor#instrument` dispatch (~1.2x) on the common no-subscribers path.
34
44
  - [Enhancement] Speed up `Configurable::Node` settings reads (~1.4x flat, ~1.6x nested) on hot paths.
35
- - [Enhancement] Instantiate each `Configurable::Node` through a per-layout anonymous subclass so ivar-backed settings do not grow object shape variations on the shared `Node` class. `deep_dup` reuses the template's subclass.
45
+ - [Enhancement] Reduce object shape variations of config nodes by giving each settings layout its own anonymous `Node` subclass.
36
46
  - [Fix] Symbolize setting names at definition time and on config store writes, so `String` setting names work end to end and cannot corrupt node internal state when they match reserved internal names.
37
- - [Change] Config nodes are now instances of anonymous `Node` subclasses: `is_a?(Karafka::Core::Configurable::Node)` still holds, but `instance_of?(Node)` is now `false` and `node.class.name` is `nil`.
47
+ - [Change] Config nodes are instances of anonymous `Node` subclasses: `is_a?(Karafka::Core::Configurable::Node)` still holds, but `instance_of?(Node)` is `false` and `node.class.name` is `nil`.
38
48
  - [Change] Assigning a setting on a frozen config node now raises `FrozenError` (previously the write silently mutated internal storage despite the freeze).
39
49
 
40
50
  ## 2.6.0 (2026-06-10)
41
- - [Enhancement] Add `Node#register` to allow runtime key-value registration on compiled nodes without going through the static `setting` DSL. Useful for dynamic registries (e.g. named clusters) where setting names are not known at class-load time.
42
- - [Enhancement] Replace version-gated `Warning[:performance]` with a `Warning.categories`-based loop that enables all opt-in Ruby warning categories automatically, picking up new categories (e.g. `strict_unused_block` in Ruby 3.4+) without future patches.
51
+ - [Enhancement] Add `Node#register` to register keys at runtime on compiled nodes, for dynamic registries (e.g. named clusters) whose setting names are not known at class-load time.
52
+ - [Enhancement] Enable all opt-in Ruby warning categories via `Warning.categories`, so new ones (e.g. `strict_unused_block` in Ruby 3.4+) are picked up automatically.
43
53
 
44
54
  ## 2.5.13 (2026-04-08)
45
55
  - [Enhancement] Extract `decorate_partitions` method from `StatisticsDecorator` to allow subclasses to filter which partitions are decorated (e.g. skip unassigned partitions in a consumer context).
@@ -50,24 +60,24 @@
50
60
  ## 2.5.11 (2026-04-02)
51
61
  - [Enhancement] Specialize `Contract#dig` for common 1-key and 2-key paths to avoid iterator overhead, yielding ~1.5x faster single-key lookups and ~1.45x faster two-key nested lookups.
52
62
  - [Enhancement] Replace `Node#build_accessors` `@local_defs` Array with Hash for O(1) membership checks instead of O(n) `Array#include?`, yielding up to ~5x faster accessor lookups at 50 settings.
53
- - [Enhancement] Use frozen `EMPTY_ARRAY` constant for `Contract#call` and `#validate!` default `scope` parameter to avoid allocating a new Array on every invocation, yielding ~1.36x faster call dispatch and saving 1 Array allocation per call.
54
- - [Enhancement] Pre-resolve `@events_methods_map` method name before the listener notification loop in `Notifications#instrument` to avoid repeated Hash lookup per listener, yielding ~1.12x faster event dispatch with multiple listeners.
63
+ - [Enhancement] Stop allocating an Array on every `Contract#call` and `#validate!` call (~1.36x faster dispatch).
64
+ - [Enhancement] Speed up `Notifications#instrument` with multiple listeners (~1.12x faster event dispatch).
55
65
  - [Enhancement] Cache a frozen success `Result` singleton via `Result.success` to eliminate 1 object allocation per successful `Contract#call` on the happy path.
56
- - [Enhancement] Skip nestings block re-evaluation in `Node#deep_dup` to avoid recreating children that are immediately overwritten, yielding ~14x faster deep_dup and reducing allocations from ~620 to ~66 objects for large configs.
57
- - [Enhancement] Cache `CallbacksManager#call` values snapshot and invalidate on `add`/`delete` to avoid allocating a new Array on every invocation while preserving thread-safety snapshot semantics, saving 1 Array allocation per call.
58
- - [Enhancement] Store execution time separately in `Event` and build the merged payload hash lazily on `#payload` access, eliminating 1 Hash allocation per `Notifications#instrument` call when listeners use `#[]` access (the common pattern), yielding ~1.7x faster event dispatch.
59
- - [Enhancement] Replace `StatisticsDecorator#diff` pending-writes buffer with `keys.each` direct-write iteration, eliminating the buffer and write-back loop for ~13% faster decoration at scale (10 brokers, 20 topics, 2000 partitions).
66
+ - [Enhancement] Speed up `Node#deep_dup` ~14x and cut its allocations from ~620 to ~66 objects for large configs.
67
+ - [Enhancement] Stop allocating an Array on every `CallbacksManager#call` call.
68
+ - [Enhancement] Build the `Event` payload hash lazily on `#payload` access, saving one Hash allocation per `Notifications#instrument` call with `#[]` access, for ~1.7x faster event dispatch.
69
+ - [Enhancement] Speed up `StatisticsDecorator#diff` by ~13% at scale (10 brokers, 20 topics, 2000 partitions).
60
70
  - [Enhancement] Reorder `StatisticsDecorator#diff` type checks to test `Numeric` before `Hash`, matching the ~80% numeric value distribution in librdkafka statistics.
61
- - [Enhancement] Support an `only_keys` option in `StatisticsDecorator` to decorate only specified numeric keys. Combined with `excluded_keys`, this cuts decoration cost from ~80ms to ~8.5ms per call on large clusters (10 brokers, 20 topics, 2000 partitions).
62
- - [Enhancement] Cache `Tags#to_a` values array and invalidate on `add`/`delete`/`clear` to avoid allocating a new Array and running `uniq` on every call, yielding ~7x faster reads at 5 tags and ~28x faster at 20 tags.
71
+ - [Enhancement] Support an `only_keys` option in `StatisticsDecorator` to decorate only the listed numeric keys. With `excluded_keys`, this cuts decoration cost from ~80ms to ~8.5ms per call on large clusters.
72
+ - [Enhancement] Cache `Tags#to_a` (~7x faster reads at 5 tags, ~28x at 20 tags).
63
73
 
64
74
  ## 2.5.10 (2026-03-02)
65
75
  - [Enhancement] Introduce `MinitestLocator` helper for minitest/spec subject class auto-discovery from test file paths.
66
76
 
67
77
  ## 2.5.9 (2026-03-02)
68
- - [Enhancement] Optimize `StatisticsDecorator` to eliminate per-hash Array allocations by using `each_pair` with a per-call pending-writes buffer instead of `current.keys.each`, reducing allocations from tens of thousands to one per call at scale.
78
+ - [Enhancement] Reduce `StatisticsDecorator` allocations from tens of thousands to one per call at scale.
69
79
  - [Enhancement] Inline `StatisticsDecorator#append` and `#suffix_keys_for` into `#diff` to reduce method call overhead by ~96% (from ~915k to ~39k calls at 6400 partitions).
70
- - [Enhancement] Support `excluded_keys` option in `StatisticsDecorator` to skip decoration of unused librdkafka statistics subtrees (e.g. broker toppars, window stats), yielding ~28% additional speedup at scale.
80
+ - [Enhancement] Support an `excluded_keys` option in `StatisticsDecorator` to skip unused librdkafka statistics subtrees (e.g. broker toppars, window stats), ~28% faster at scale.
71
81
 
72
82
  ## 2.5.8 (2025-11-23)
73
83
  - [Enhancement] Memoize `StatisticsDecorator` suffix keys to reduce string allocations (#268).
@@ -180,7 +190,7 @@
180
190
 
181
191
  ## 2.2.1 (2023-09-10)
182
192
  - Optimize statistics decorator by minimizing number of new objects created.
183
- - Expand the decoration to include new value `_fd` providing freeze duration in milliseconds. This value informs us for how many consecutive ms the given value did not change. It can be useful for detecting values that should change once in a while but are stale.
193
+ - Expand the decoration with the `_fd` value: the freeze duration in milliseconds, showing how long a value has not changed. Useful to detect stale values.
184
194
 
185
195
  ## 2.2.0 (2023-09-01)
186
196
  - [Maintenance] Update the signing cert (old expired)
data/Gemfile CHANGED
@@ -5,7 +5,6 @@ source "https://rubygems.org"
5
5
  gemspec
6
6
 
7
7
  group :test do
8
- gem "byebug"
9
8
  gem "minitest"
10
9
  gem "simplecov"
11
10
  gem "warning"
data/Gemfile.lock CHANGED
@@ -1,15 +1,13 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- karafka-core (2.6.4)
4
+ karafka-core (2.6.6)
5
5
  karafka-rdkafka (>= 0.20.0)
6
6
  logger (>= 1.6.0)
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
- byebug (13.0.0)
12
- reline (>= 0.6.0)
13
11
  drb (2.2.3)
14
12
  ffi (1.17.4)
15
13
  ffi (1.17.4-aarch64-linux-gnu)
@@ -22,39 +20,38 @@ GEM
22
20
  ffi (1.17.4-x86_64-darwin)
23
21
  ffi (1.17.4-x86_64-linux-gnu)
24
22
  ffi (1.17.4-x86_64-linux-musl)
25
- io-console (0.9.2)
26
- json (2.21.2)
27
- karafka-rdkafka (0.28.0)
23
+ json (3.0.2)
24
+ karafka-rdkafka (0.30.2)
28
25
  ffi (~> 1.17.1)
29
26
  json (> 2.0)
30
27
  logger
31
28
  mini_portile2 (~> 2.6)
32
29
  rake (> 12)
33
- karafka-rdkafka (0.28.0-aarch64-linux-gnu)
30
+ karafka-rdkafka (0.30.2-aarch64-linux-gnu)
34
31
  ffi (~> 1.17.1)
35
32
  json (> 2.0)
36
33
  logger
37
34
  mini_portile2 (~> 2.6)
38
35
  rake (> 12)
39
- karafka-rdkafka (0.28.0-aarch64-linux-musl)
36
+ karafka-rdkafka (0.30.2-aarch64-linux-musl)
40
37
  ffi (~> 1.17.1)
41
38
  json (> 2.0)
42
39
  logger
43
40
  mini_portile2 (~> 2.6)
44
41
  rake (> 12)
45
- karafka-rdkafka (0.28.0-arm64-darwin)
42
+ karafka-rdkafka (0.30.2-arm64-darwin)
46
43
  ffi (~> 1.17.1)
47
44
  json (> 2.0)
48
45
  logger
49
46
  mini_portile2 (~> 2.6)
50
47
  rake (> 12)
51
- karafka-rdkafka (0.28.0-x86_64-linux-gnu)
48
+ karafka-rdkafka (0.30.2-x86_64-linux-gnu)
52
49
  ffi (~> 1.17.1)
53
50
  json (> 2.0)
54
51
  logger
55
52
  mini_portile2 (~> 2.6)
56
53
  rake (> 12)
57
- karafka-rdkafka (0.28.0-x86_64-linux-musl)
54
+ karafka-rdkafka (0.30.2-x86_64-linux-musl)
58
55
  ffi (~> 1.17.1)
59
56
  json (> 2.0)
60
57
  logger
@@ -67,9 +64,7 @@ GEM
67
64
  prism (~> 1.5)
68
65
  prism (1.9.0)
69
66
  rake (13.4.2)
70
- reline (0.7.0)
71
- io-console (~> 0.5)
72
- simplecov (1.1.1)
67
+ simplecov (1.3.2)
73
68
  warning (1.6.0)
74
69
 
75
70
  PLATFORMS
@@ -86,7 +81,6 @@ PLATFORMS
86
81
  x86_64-linux-musl
87
82
 
88
83
  DEPENDENCIES
89
- byebug
90
84
  karafka-core!
91
85
  minitest
92
86
  simplecov
data/README.md CHANGED
@@ -1,9 +1,9 @@
1
+ # Karafka-Core
2
+
1
3
  [![Build Status](https://github.com/karafka/karafka-core/actions/workflows/ci.yml/badge.svg)](https://github.com/karafka/karafka-core/actions/workflows/ci.yml)
2
- [![Gem Version](https://badge.fury.io/rb/karafka-core.svg)](http://badge.fury.io/rb/karafka-core)
4
+ [![Gem Version](https://badge.fury.io/rb/karafka-core.svg)](https://badge.fury.io/rb/karafka-core)
3
5
  [![Join the chat at https://slack.karafka.io](https://raw.githubusercontent.com/karafka/misc/master/slack.svg)](https://slack.karafka.io)
4
6
 
5
- ## Karafka-Core
6
-
7
7
  Karafka-Core contains toolset of small support modules used throughout the [Karafka](https://github.com/karafka/karafka/) ecosystem.
8
8
 
9
9
  It includes:
@@ -17,6 +17,6 @@ It includes:
17
17
 
18
18
  First, thank you for considering contributing to the Karafka ecosystem! It's people like you that make the open source community such a great community!
19
19
 
20
- Each pull request must pass all the RSpec specs, integration tests and meet our quality requirements.
20
+ Each pull request must pass all the tests and meet our quality requirements.
21
21
 
22
22
  Fork it, update and wait for the Github Actions results.
data/karafka-core.gemspec CHANGED
@@ -19,7 +19,7 @@ Gem::Specification.new do |spec|
19
19
  spec.add_dependency "karafka-rdkafka", ">= 0.20.0"
20
20
  spec.add_dependency "logger", ">= 1.6.0"
21
21
 
22
- spec.required_ruby_version = ">= 3.2.0"
22
+ spec.required_ruby_version = ">= 3.3.0"
23
23
 
24
24
  spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test)/}) }
25
25
  spec.require_paths = %w[lib]
@@ -79,10 +79,7 @@ module Karafka
79
79
  # exist yet at load time.
80
80
  # @raise [NotImplementedError] when called on a class that does not define a root
81
81
  def root
82
- raise(
83
- NotImplementedError,
84
- "Define .root in a Karafka::Core::Configurable::Importer subclass"
85
- )
82
+ raise(NotImplementedError, self)
86
83
  end
87
84
  end
88
85
 
@@ -192,7 +192,7 @@ module Karafka
192
192
  # is not written to @configs_refs until first read, so a `@configs_refs.key?` guard
193
193
  # alone would silently overwrite it instead of raising the documented error.
194
194
  if @children.any? { |child| child.node_name == name }
195
- raise ArgumentError, "#{name} is already registered"
195
+ raise ArgumentError, name
196
196
  end
197
197
 
198
198
  leaf = Leaf.new(name, value, nil, true, false)
@@ -360,7 +360,7 @@ module Karafka
360
360
  def prevent_reserved_names!(name)
361
361
  return unless RESERVED_NAMES.key?(name)
362
362
 
363
- raise ArgumentError, "#{name} is a reserved name and cannot be used as a setting name"
363
+ raise ArgumentError, name
364
364
  end
365
365
  end
366
366
  end
@@ -105,7 +105,7 @@ module Karafka
105
105
  # @param data [Hash] hash with data we want to validate
106
106
  # @param scope [Array<String>] scope of this contract (if any) or empty array if no parent
107
107
  # scope is needed if contract starts from root
108
- # @return [Result] validaton result
108
+ # @return [Result] validation result
109
109
  def call(data, scope: EMPTY_ARRAY)
110
110
  errors = []
111
111
 
@@ -153,6 +153,8 @@ module Karafka
153
153
  Result.new(errors, self)
154
154
  end
155
155
 
156
+ # Runs the validation like `#call`, but raises instead of returning a failed `Result`
157
+ #
156
158
  # @param data [Hash] data for validation
157
159
  # @param error_class [Class] error class that should be used when validation fails
158
160
  # @param scope [Array<String>] scope of this contract (if any) or empty array if no parent
@@ -182,7 +184,7 @@ module Karafka
182
184
  #
183
185
  # @param data [Hash]
184
186
  # @param keys [Array<Symbol>]
185
- # @return [DIG_MISS, Object] found element or DIGG_MISS indicating that not found
187
+ # @return [DIG_MISS, Object] found element or DIG_MISS indicating that not found
186
188
  def dig(data, keys)
187
189
  case keys.length
188
190
  when 1
@@ -3,7 +3,7 @@
3
3
  module Karafka
4
4
  module Core
5
5
  module Contractable
6
- # Representation of a validaton result with resolved error messages
6
+ # Representation of a validation result with resolved error messages
7
7
  class Result
8
8
  attr_reader :errors
9
9
 
@@ -85,15 +85,15 @@ module Karafka
85
85
 
86
86
  names.each do |name|
87
87
  # Make sure we're dealing with a valid constant name
88
- raise NameError, "#{name} is not a valid constant name!" unless name.match?(regexp)
88
+ raise NameError, name unless name.match?(regexp)
89
89
 
90
90
  # Get the constant from its parent
91
91
  constant = constant.const_get(name)
92
92
  end
93
93
 
94
94
  constant
95
- rescue NameError => e
96
- raise NameError, "Uninitialized constant #{string}: #{e.message}"
95
+ rescue NameError
96
+ raise NameError, string
97
97
  end
98
98
  end
99
99
  end
@@ -88,15 +88,15 @@ module Karafka
88
88
 
89
89
  names.each do |name|
90
90
  # Make sure we're dealing with a valid constant name
91
- raise NameError, "#{name} is not a valid constant name!" unless name.match?(regexp)
91
+ raise NameError, name unless name.match?(regexp)
92
92
 
93
93
  # Get the constant from its parent
94
94
  constant = constant.const_get(name)
95
95
  end
96
96
 
97
97
  constant
98
- rescue NameError => e
99
- raise NameError, "Uninitialized constant #{string}: #{e.message}"
98
+ rescue NameError
99
+ raise NameError, string
100
100
  end
101
101
  end
102
102
  end
@@ -6,16 +6,9 @@ module Karafka
6
6
  module Helpers
7
7
  # Time related methods used across Karafka
8
8
  module Time
9
- if RUBY_VERSION >= "3.2"
10
- # @return [Float] current monotonic time in milliseconds
11
- def monotonic_now
12
- ::Process.clock_gettime(::Process::CLOCK_MONOTONIC, :float_millisecond)
13
- end
14
- else
15
- # @return [Float] current monotonic time in milliseconds
16
- def monotonic_now
17
- ::Process.clock_gettime(::Process::CLOCK_MONOTONIC) * 1_000
18
- end
9
+ # @return [Float] current monotonic time in milliseconds
10
+ def monotonic_now
11
+ ::Process.clock_gettime(::Process::CLOCK_MONOTONIC, :float_millisecond)
19
12
  end
20
13
 
21
14
  # @return [Float] current time in float
@@ -9,7 +9,7 @@ module Karafka
9
9
  # It provides abstraction layer that allows us to use both our internal notifications as well
10
10
  # as `ActiveSupport::Notifications`.
11
11
  class Monitor
12
- # Empty has to save on objects allocation
12
+ # Empty hash to save on objects allocation
13
13
  EMPTY_HASH = {}.freeze
14
14
 
15
15
  private_constant :EMPTY_HASH
@@ -21,6 +21,7 @@ module Karafka
21
21
  @notifications_bus = notifications_bus
22
22
  @namespace = namespace
23
23
  @mapped_events = {}
24
+ @mutex = Mutex.new
24
25
  end
25
26
 
26
27
  # Passes the instrumentation block (if any) into the notifications bus
@@ -35,7 +36,7 @@ module Karafka
35
36
  full_event_name = if @namespace.nil? && event_id.is_a?(String)
36
37
  event_id
37
38
  else
38
- @mapped_events[event_id] ||= [event_id, @namespace].compact.join(".")
39
+ @mapped_events[event_id] || map_event(event_id)
39
40
  end
40
41
 
41
42
  @notifications_bus.instrument(full_event_name, payload, &)
@@ -65,6 +66,24 @@ module Karafka
65
66
  def listeners
66
67
  @notifications_bus.listeners
67
68
  end
69
+
70
+ private
71
+
72
+ # Builds and caches the full event name for an event id
73
+ #
74
+ # @param event_id [String, Symbol] event id
75
+ # @return [String] full event name
76
+ def map_event(event_id)
77
+ @mutex.synchronize do
78
+ # Copy-on-write: #instrument reads the Hash without the lock and on JRuby a Hash that
79
+ # is written by many threads at once can get corrupted, so we replace it instead.
80
+ @mapped_events[event_id] || begin
81
+ full_event_name = [event_id, @namespace].compact.join(".")
82
+ @mapped_events = @mapped_events.merge(event_id => full_event_name).freeze
83
+ full_event_name
84
+ end
85
+ end
86
+ end
68
87
  end
69
88
  end
70
89
  end
@@ -38,8 +38,13 @@ module Karafka
38
38
  # @param event_id [String] event id
39
39
  def register_event(event_id)
40
40
  @mutex.synchronize do
41
- @listeners[event_id] = []
42
- @events_methods_map[event_id] = :"on_#{event_id.to_s.tr(".", "_")}"
41
+ # Copy-on-write: #instrument reads both Hashes without the lock, and on JRuby a Hash
42
+ # that grows while another thread reads it can return nil for a registered key. The
43
+ # methods map goes first, so an event visible in @listeners always has its method.
44
+ @events_methods_map = @events_methods_map.merge(
45
+ event_id => :"on_#{event_id.to_s.tr(".", "_")}"
46
+ )
47
+ @listeners = @listeners.merge(event_id => [])
43
48
  end
44
49
  end
45
50
 
@@ -48,19 +53,20 @@ module Karafka
48
53
  # @param event_id [String] the key of the event to clear listeners for.
49
54
  def clear(event_id = nil)
50
55
  @mutex.synchronize do
51
- # Copy-on-write: replace the per-event arrays rather than mutating them in place, so a
52
- # dispatch iterating a previously captured array is unaffected (see #notify_listeners).
56
+ # Copy-on-write: replace the Hash and the per-event arrays rather than mutating them in
57
+ # place, so lock-free reads in #instrument and a dispatch iterating a previously
58
+ # captured array are unaffected (see #register_event and #notify_listeners).
53
59
  unless event_id
54
- @listeners.transform_values! { [] }
60
+ @listeners = @listeners.transform_values { [] }
55
61
  return
56
62
  end
57
63
 
58
64
  if @listeners.key?(event_id)
59
- @listeners[event_id] = []
65
+ @listeners = @listeners.merge(event_id => [])
60
66
  return
61
67
  end
62
68
 
63
- raise(EventNotRegistered, "#{event_id} not registered!")
69
+ raise(EventNotRegistered, event_id)
64
70
  end
65
71
  end
66
72
 
@@ -85,17 +91,21 @@ module Karafka
85
91
 
86
92
  raise EventNotRegistered, event_id unless @listeners.key?(event_id)
87
93
 
88
- # Copy-on-write: append by replacing the array, never mutating the one a concurrent
89
- # dispatch may be iterating (see #notify_listeners).
90
- @listeners[event_id] += [block]
94
+ # Copy-on-write: append by replacing the Hash and the array, never mutating the ones
95
+ # a concurrent #instrument or dispatch may be reading (see #notify_listeners).
96
+ @listeners = @listeners.merge(event_id => @listeners[event_id] + [block])
91
97
  else
92
98
  listener = event_id_or_listener
93
99
 
94
- @listeners.each_key do |reg_event_id|
100
+ listeners = @listeners.dup
101
+
102
+ @listeners.each do |reg_event_id, event_listeners|
95
103
  next unless listener.respond_to?(@events_methods_map[reg_event_id])
96
104
 
97
- @listeners[reg_event_id] += [listener]
105
+ listeners[reg_event_id] = event_listeners + [listener]
98
106
  end
107
+
108
+ @listeners = listeners
99
109
  end
100
110
  end
101
111
  end
@@ -109,9 +119,10 @@ module Karafka
109
119
  # unsubscribe(my_listener)
110
120
  def unsubscribe(listener_or_block)
111
121
  @mutex.synchronize do
112
- # Copy-on-write: rebuild each array without the listener instead of deleting in place,
113
- # so a dispatch iterating a previously captured array still sees the full set.
114
- @listeners.transform_values! { |event_listeners| event_listeners - [listener_or_block] }
122
+ # Copy-on-write: rebuild the Hash and each array without the listener instead of
123
+ # deleting in place, so a dispatch iterating a previously captured array still sees
124
+ # the full set.
125
+ @listeners = @listeners.transform_values { |event_listeners| event_listeners - [listener_or_block] }
115
126
  end
116
127
  end
117
128
 
@@ -13,7 +13,7 @@ module Karafka
13
13
  # Add extra methods that we need
14
14
  # @param mod [::Rdkafka::Bindings] rdkafka bindings module
15
15
  def included(mod)
16
- # Default rdkafka setup for errors doest not propagate client details, thus it always
16
+ # Default rdkafka setup for errors does not propagate client details, thus it always
17
17
  # publishes all the stuff for all rdkafka instances. We change that by providing
18
18
  # function that fetches the instance name, allowing us to have better notifications
19
19
  mod.send(:remove_const, :ErrorCallback)
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Karafka
4
+ module Core
5
+ module Taggable
6
+ class Tags
7
+ # Tags by name and their unique values, published together so a reader never sees one
8
+ # without the other
9
+ Snapshot = Struct.new(:tags, :values)
10
+ end
11
+ end
12
+ end
13
+ end
@@ -9,34 +9,33 @@ module Karafka
9
9
  class Tags
10
10
  # Creates new tags accumulator
11
11
  def initialize
12
- @accu = {}
13
- @values_cache = nil
12
+ @mutex = Mutex.new
13
+ @snapshot = Snapshot.new({}.freeze, []).freeze
14
14
  end
15
15
 
16
16
  # Adds a tag with a given name to tags
17
17
  # @param name [Symbol] name we want to use for a given tag
18
18
  # @param tag [#to_s] any object that can be converted into a string via `#to_s`
19
19
  def add(name, tag)
20
- @accu[name] = tag.to_s
21
- @values_cache = nil
20
+ value = tag.to_s
21
+
22
+ @mutex.synchronize { publish(@snapshot.tags.merge(name => value)) }
22
23
  end
23
24
 
24
25
  # Removes all the tags
25
26
  def clear
26
- @accu.clear
27
- @values_cache = nil
27
+ @mutex.synchronize { publish({}) }
28
28
  end
29
29
 
30
30
  # Removes a tag with a given name
31
31
  # @param name [Symbol] name of the tag
32
32
  def delete(name)
33
- @accu.delete(name)
34
- @values_cache = nil
33
+ @mutex.synchronize { publish(@snapshot.tags.except(name)) }
35
34
  end
36
35
 
37
36
  # @return [Array<String>] all unique tags registered
38
37
  def to_a
39
- @values_cache ||= @accu.values.uniq
38
+ @snapshot.values
40
39
  end
41
40
 
42
41
  # @param _args [Object] anything that the standard `to_json` accepts
@@ -50,6 +49,17 @@ module Karafka
50
49
  def as_json(*_args)
51
50
  to_a
52
51
  end
52
+
53
+ private
54
+
55
+ # Replaces the snapshot with one built from the given tags. Readers do not lock, so the tags
56
+ # are never changed in place: each write publishes a new snapshot in one assignment.
57
+ #
58
+ # @param tags [Hash{Symbol => String}] all the tags after the change
59
+ # @return [Snapshot] the published snapshot
60
+ def publish(tags)
61
+ @snapshot = Snapshot.new(tags.freeze, tags.values.uniq).freeze
62
+ end
53
63
  end
54
64
  end
55
65
  end
@@ -8,9 +8,31 @@ module Karafka
8
8
  #
9
9
  # Tags will be converted to strings when they are added
10
10
  module Taggable
11
+ # One lock for the first `#tags` call of every object. That call is rare, and a lock per
12
+ # object would need a safe way to create it as well. Kept off the constants, because
13
+ # constants of this module are visible in every class that includes it.
14
+ @tags_lock = Mutex.new
15
+
16
+ class << self
17
+ # @return [Mutex] lock guarding the lazy creation of tags
18
+ attr_reader :tags_lock
19
+ end
20
+
11
21
  # @return [::Karafka::Core::Taggable::Tags] tags object
12
22
  def tags
13
- @tags ||= Taggable::Tags.new
23
+ @tags || taggable_build_tags
24
+ end
25
+
26
+ private
27
+
28
+ # Do not inline this into `#tags`. A `#synchronize` block there makes every warm `#tags` call
29
+ # about 2.5x slower on JRuby, even when `@tags` is already set. A hand-written `lock` /
30
+ # `ensure unlock` keeps it fast but can leave the lock held when an async exception
31
+ # (`Thread#raise`, `Timeout`) lands between `lock` and `begin`.
32
+ #
33
+ # @return [::Karafka::Core::Taggable::Tags] tags object
34
+ def taggable_build_tags
35
+ Taggable.tags_lock.synchronize { @tags ||= Taggable::Tags.new }
14
36
  end
15
37
  end
16
38
  end
@@ -3,6 +3,6 @@
3
3
  module Karafka
4
4
  module Core
5
5
  # Current Karafka::Core version. We follow the versioning schema of given Karafka version
6
- VERSION = "2.6.4"
6
+ VERSION = "2.6.6"
7
7
  end
8
8
  end
data/lib/karafka-core.rb CHANGED
@@ -24,6 +24,7 @@ require "karafka/core/instrumentation"
24
24
  require "karafka/core/instrumentation/callbacks_manager"
25
25
  require "karafka/core/taggable"
26
26
  require "karafka/core/taggable/tags"
27
+ require "karafka/core/taggable/tags/snapshot"
27
28
  require "karafka/core/patches/rdkafka/bindings"
28
29
 
29
30
  # Karafka framework main namespace
data/package-lock.json CHANGED
@@ -103,9 +103,9 @@
103
103
  }
104
104
  },
105
105
  "node_modules/fastq": {
106
- "version": "1.20.2",
107
- "resolved": "https://registry.npmjs.org/fastq/-/fastq-1.20.2.tgz",
108
- "integrity": "sha512-UpGiiODyCGprM8EPP6JodP6jC9Rws6TCuiDOD+nn0CJhR8guI3g/ozo4ugL0vJ+Yz1UtJuuRPqvQuybVOF1VQA==",
106
+ "version": "1.20.3",
107
+ "resolved": "https://registry.npmjs.org/fastq/-/fastq-1.20.3.tgz",
108
+ "integrity": "sha512-XKv5nnLs6nLF71NgiKJLIZFLkPyIEuOselLG7ujZnGrRfQK8HpvY+WqKhAJUAdLomwVHErVS4LfxFlPq0/FTAw==",
109
109
  "dev": true,
110
110
  "license": "ISC",
111
111
  "dependencies": {
@@ -286,9 +286,9 @@
286
286
  }
287
287
  },
288
288
  "node_modules/smol-toml": {
289
- "version": "1.8.0",
290
- "resolved": "https://registry.npmjs.org/smol-toml/-/smol-toml-1.8.0.tgz",
291
- "integrity": "sha512-kCZr2V3ch9i00x8zXRhjUNVcjG9ijES5dDudkXvUVCT5QlJNQWElSJdZqyPemffHoLNUYwOcou0Fy+ojN0uHSQ==",
289
+ "version": "1.9.0",
290
+ "resolved": "https://registry.npmjs.org/smol-toml/-/smol-toml-1.9.0.tgz",
291
+ "integrity": "sha512-hpd+HLON7HdZXqYchMM/+LaTTbdK0AU3NngIJ4KVyWbY9bfQqdL9cD+4yf6dUoU2Ap4VsU0JkQi6FxAI1B2mXQ==",
292
292
  "dev": true,
293
293
  "license": "BSD-3-Clause",
294
294
  "engines": {
@@ -312,9 +312,9 @@
312
312
  }
313
313
  },
314
314
  "node_modules/yaml": {
315
- "version": "2.9.0",
316
- "resolved": "https://registry.npmjs.org/yaml/-/yaml-2.9.0.tgz",
317
- "integrity": "sha512-2AvhNX3mb8zd6Zy7INTtSpl1F15HW6Wnqj0srWlkKLcpYl/gMIMJiyuGq2KeI2YFxUPjdlB+3Lc10seMLtL4cA==",
315
+ "version": "2.9.1",
316
+ "resolved": "https://registry.npmjs.org/yaml/-/yaml-2.9.1.tgz",
317
+ "integrity": "sha512-3NxN8+78OdzbT7C/WjGsyfPAtJaN3FNDsWxv7Y7mcDsT/oOmgW8BpyQQFFBnvZE3j9Y2Sdz1ULFLezL7Eb2yFw==",
318
318
  "dev": true,
319
319
  "license": "ISC",
320
320
  "bin": {
data/renovate.json CHANGED
@@ -1,4 +1,7 @@
1
1
  {
2
+ "bundler": {
3
+ "managerFilePatterns": ["/(^|/)Gemfile\\.lint$/"]
4
+ },
2
5
  "$schema": "https://docs.renovatebot.com/renovate-schema.json",
3
6
  "extends": [
4
7
  "config:recommended"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: karafka-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.6.4
4
+ version: 2.6.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Maciej Mensfeld
@@ -93,6 +93,7 @@ files:
93
93
  - lib/karafka/core/patches/rdkafka/bindings.rb
94
94
  - lib/karafka/core/taggable.rb
95
95
  - lib/karafka/core/taggable/tags.rb
96
+ - lib/karafka/core/taggable/tags/snapshot.rb
96
97
  - lib/karafka/core/version.rb
97
98
  - log/.gitkeep
98
99
  - package-lock.json
@@ -115,14 +116,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
115
116
  requirements:
116
117
  - - ">="
117
118
  - !ruby/object:Gem::Version
118
- version: 3.2.0
119
+ version: 3.3.0
119
120
  required_rubygems_version: !ruby/object:Gem::Requirement
120
121
  requirements:
121
122
  - - ">="
122
123
  - !ruby/object:Gem::Version
123
124
  version: '0'
124
125
  requirements: []
125
- rubygems_version: 4.0.16
126
+ rubygems_version: 4.0.20
126
127
  specification_version: 4
127
128
  summary: Karafka ecosystem core modules
128
129
  test_files: []