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 +4 -4
- data/.github/workflows/ci.yml +6 -7
- data/.github/workflows/push.yml +1 -1
- data/.gitignore +1 -0
- data/.rubocop.yml +1 -1
- data/.ruby-version +1 -1
- data/CHANGELOG.md +40 -30
- data/Gemfile +0 -1
- data/Gemfile.lock +9 -15
- data/README.md +4 -4
- data/karafka-core.gemspec +1 -1
- data/lib/karafka/core/configurable/importer.rb +1 -4
- data/lib/karafka/core/configurable/node.rb +2 -2
- data/lib/karafka/core/contractable/contract.rb +4 -2
- data/lib/karafka/core/contractable/result.rb +1 -1
- data/lib/karafka/core/helpers/minitest_locator.rb +3 -3
- data/lib/karafka/core/helpers/rspec_locator.rb +3 -3
- data/lib/karafka/core/helpers/time.rb +3 -10
- data/lib/karafka/core/monitoring/monitor.rb +21 -2
- data/lib/karafka/core/monitoring/notifications.rb +26 -15
- data/lib/karafka/core/patches/rdkafka/bindings.rb +1 -1
- data/lib/karafka/core/taggable/tags/snapshot.rb +13 -0
- data/lib/karafka/core/taggable/tags.rb +19 -9
- data/lib/karafka/core/taggable.rb +23 -1
- data/lib/karafka/core/version.rb +1 -1
- data/lib/karafka-core.rb +1 -0
- data/package-lock.json +9 -9
- data/renovate.json +3 -0
- metadata +4 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 69c1a45639ef9a5f60dfe01427637a68be3a284a1d3cc6645f35c7f1bc4db60a
|
|
4
|
+
data.tar.gz: af342b72f3862e8264fbc09e4e6ba473ff13a0b2615ea78738071f5b366e9c48
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 0ed70ee79bf6cb77ec89df3e68d30829b70c79dadc699b491006c3ac536009230fdd188996a7386c1cce0140625c04002a00575b7c5fda6b7d82a172b241e6e4
|
|
7
|
+
data.tar.gz: c7d33f57867534c8afa1ab28a00f63b4d806fc2286c61bdb31a0111b8a81048e8a1ce654b8ff5dbc0dd7736d70ad8db92738b264c7ed6d3124ba0fc6da96105e
|
data/.github/workflows/ci.yml
CHANGED
|
@@ -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@
|
|
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@
|
|
71
|
+
uses: ruby/setup-ruby@824c0e29fdfc7d689c191c27acc969d2d04b7dd8 # v1.331.0
|
|
73
72
|
with:
|
|
74
|
-
ruby-version: '4.0.
|
|
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@
|
|
88
|
+
uses: ruby/setup-ruby@824c0e29fdfc7d689c191c27acc969d2d04b7dd8 # v1.331.0
|
|
90
89
|
with:
|
|
91
|
-
ruby-version: '4.0.
|
|
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@
|
|
103
|
+
uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
|
|
105
104
|
with:
|
|
106
105
|
node-version: '20'
|
|
107
106
|
cache: 'npm'
|
data/.github/workflows/push.yml
CHANGED
data/.gitignore
CHANGED
data/.rubocop.yml
CHANGED
data/.ruby-version
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
4.0.
|
|
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
|
|
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
|
|
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
|
|
11
|
-
- [Fix] `
|
|
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`
|
|
15
|
-
- [Fix]
|
|
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`
|
|
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
|
|
23
|
-
- [Fix] Report a freeze duration (`_fd`) of `0` for statistics keys that first appear mid-stream
|
|
24
|
-
- [Fix]
|
|
25
|
-
- [Fix] `Configurable::Node#to_h`
|
|
26
|
-
- [Fix] Honor `excluded_keys`
|
|
27
|
-
- [Fix]
|
|
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]
|
|
32
|
-
- [Change] Reject reserved setting names
|
|
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]
|
|
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
|
|
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
|
|
42
|
-
- [Enhancement]
|
|
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]
|
|
54
|
-
- [Enhancement]
|
|
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]
|
|
57
|
-
- [Enhancement]
|
|
58
|
-
- [Enhancement]
|
|
59
|
-
- [Enhancement]
|
|
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
|
|
62
|
-
- [Enhancement] Cache `Tags#to_a`
|
|
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]
|
|
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
|
|
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
|
|
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
data/Gemfile.lock
CHANGED
|
@@ -1,15 +1,13 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
karafka-core (2.6.
|
|
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
|
-
|
|
26
|
-
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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
|
-
|
|
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
|
[](https://github.com/karafka/karafka-core/actions/workflows/ci.yml)
|
|
2
|
-
[](
|
|
4
|
+
[](https://badge.fury.io/rb/karafka-core)
|
|
3
5
|
[](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
|
|
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.
|
|
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,
|
|
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,
|
|
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]
|
|
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
|
|
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
|
|
@@ -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,
|
|
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
|
|
96
|
-
raise NameError,
|
|
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,
|
|
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
|
|
99
|
-
raise NameError,
|
|
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
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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
|
|
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]
|
|
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
|
-
|
|
42
|
-
|
|
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
|
|
52
|
-
#
|
|
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
|
|
65
|
+
@listeners = @listeners.merge(event_id => [])
|
|
60
66
|
return
|
|
61
67
|
end
|
|
62
68
|
|
|
63
|
-
raise(EventNotRegistered,
|
|
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
|
|
89
|
-
# dispatch may be
|
|
90
|
-
@listeners[event_id]
|
|
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.
|
|
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
|
-
|
|
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
|
|
113
|
-
# so a dispatch iterating a previously captured array still sees
|
|
114
|
-
|
|
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
|
|
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
|
-
@
|
|
13
|
-
@
|
|
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
|
-
|
|
21
|
-
|
|
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
|
-
@
|
|
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
|
-
@
|
|
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
|
-
@
|
|
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
|
|
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
|
data/lib/karafka/core/version.rb
CHANGED
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.
|
|
107
|
-
"resolved": "https://registry.npmjs.org/fastq/-/fastq-1.20.
|
|
108
|
-
"integrity": "sha512-
|
|
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.
|
|
290
|
-
"resolved": "https://registry.npmjs.org/smol-toml/-/smol-toml-1.
|
|
291
|
-
"integrity": "sha512-
|
|
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.
|
|
316
|
-
"resolved": "https://registry.npmjs.org/yaml/-/yaml-2.9.
|
|
317
|
-
"integrity": "sha512-
|
|
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
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
|
+
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.
|
|
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.
|
|
126
|
+
rubygems_version: 4.0.20
|
|
126
127
|
specification_version: 4
|
|
127
128
|
summary: Karafka ecosystem core modules
|
|
128
129
|
test_files: []
|