karafka-core 2.6.3 → 2.6.5

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: 70aa3940193aebd6b4f232950a2b765ee57025aea6b3d3d7c72234429f904de4
4
- data.tar.gz: e4a550006b517eea864370ef12534dacdb6fddae40f3adf7308981fa99a1e7a1
3
+ metadata.gz: 236e0814cbc0a24dc6758f75c71057e7744c0827f1c9cb4b5be5f305bceefc46
4
+ data.tar.gz: b3d9b8d7b42e9af2aaa2609bd929dab513375aa86ebf49d198c94e11cb81427c
5
5
  SHA512:
6
- metadata.gz: '05908e99fd999ee007bcb3efd46a6a3b949d88e40d980c5ca4e8aa90a3c312755717dc8feef7a7de42c5c7c235e3ac623e26b91e9a3456568e4d552a2d8782ea'
7
- data.tar.gz: 61456523b5822db6c78ad36c839ed6e3bdcbd9bc18d56cebfb95947443296aad94b917b3bef7798f093b471d703ae9d5a7f43d1b09d726ea655e0b2a0b091a3c
6
+ metadata.gz: e6cabe34dc4bb8449ba87cec2d1dc7d120277fecc771ee7a90509f34454e28705a7ab3e883a68799ac128badd9e5f8ad3d5d6898e2e4d1565568dad3b98f0bb9
7
+ data.tar.gz: 80072d69c0ae0eb59b933c83d530e3099bf16f16c596b34bdf16c70f0986938c599dbb65c13331c69e7881119cde8c200fc51713729e84a085c15dd6d989fdba
@@ -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@651ff0d62c5c79bed6d53ec518387aae20e72c1a # v1.329.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@651ff0d62c5c79bed6d53ec518387aae20e72c1a # v1.329.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@651ff0d62c5c79bed6d53ec518387aae20e72c1a # v1.329.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@651ff0d62c5c79bed6d53ec518387aae20e72c1a # v1.329.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,42 +1,49 @@
1
1
  # Karafka Core Changelog
2
2
 
3
+ ## 2.6.5 (2026-10-19)
4
+ - **[EOL]** Drop Ruby 3.2 support due to EOL; require Ruby 3.3+.
5
+ - [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.
6
+
7
+ ## 2.6.4 (2026-09-11)
8
+ - [Enhancement] Add `Configurable::Importer`, a subclassable base for injecting memoized config readers into a class via `include` or `extend`.
9
+
3
10
  ## 2.6.3 (2026-08-31)
4
- - [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.
11
+ - [Enhancement] Add `Configurable::Injector`, a reusable base for injecting default values into a config hash without overwriting user settings.
5
12
 
6
13
  ## 2.6.2 (2026-06-29)
7
- - [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.
8
- - [Fix] `require "pathname"` explicitly in `lib/karafka-core.rb` (with the other top-level requires). `Karafka::Core.gem_root` returns a `Pathname`, but the gem never required `pathname` -- it only worked because Bundler (or another gem) happened to load it first. In an environment where nothing else loads it, `gem_root` raised `NameError: uninitialized constant Pathname`.
14
+ - [Enhancement] Document that a setting default is shared across all config instances, so a mutable default such as `[]` must not be changed in place.
15
+ - [Fix] Require `pathname` explicitly, so `Karafka::Core.gem_root` no longer raises `NameError` when nothing else loaded it.
9
16
  - [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.
10
- - [Fix] `Configurable::Node#register` raises the documented "already registered" `ArgumentError` for a name already used by an unread lazy-with-constructor setting. The duplicate guard only checked `@configs_refs`, but a lazy setting with a constructor is absent from it until first read, so `register` silently overwrote it; it now checks the defined children.
11
- - [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.
12
- - [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).
13
- - [Fix] Honor `excluded_keys` containing `"cgrp"` in `StatisticsDecorator` `only_keys` mode. The `cgrp` branch of the structure-aware fast path lacked the exclusion guard that the `brokers` and `topics` branches have, so excluding the consumer-group subtree still decorated it (inconsistent with the full-decoration path).
14
- - [Fix] Guard the patched rdkafka error callback against a null client pointer. librdkafka can invoke the error callback with a NULL `rd_kafka_t` (e.g. very early in client construction); calling `rd_kafka_name` on it dereferenced the null pointer and could segfault the process. Mirrors the upstream `ErrorCallback`.
15
- - [Fix] Resolve fatal errors in the patched rdkafka error callback. `ERR__FATAL` is only a generic marker, so the callback now fetches the real underlying error code and description via `RdkafkaError.build_fatal` (`rd_kafka_fatal_error`) instead of reporting the generic fatal code. Mirrors the upstream `ErrorCallback`.
17
+ - [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.
18
+ - [Fix] Stop a rescued error inside `Contractable::Contract.nested` from prefixing its path onto every rule defined afterwards.
19
+ - [Fix] Report a missing path instead of raising `NoMethodError` when validating a non-Hash root with a 1-key or 2-key rule.
20
+ - [Fix] Honor `excluded_keys` containing `"cgrp"` in `StatisticsDecorator` `only_keys` mode; the `cgrp` branch lacked the exclusion guard its `brokers` and `topics` siblings have.
21
+ - [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.
22
+ - [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.
16
23
  - [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.
17
- - [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 (`true`/`false`/`nil`); only an `Array` of error pairs is collected. Previously a `false` return reached `false.each` (a `nil` return was already tolerated).
18
- - [Fix] Make `CallbacksManager` thread-safe under concurrent `add`/`delete` during dispatch. A callback registered or removed while callbacks were firing could be lost — kept firing after removal, or never fired after being added. librdkafka fires these from a background thread, so it was reachable in practice.
19
- - [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.
20
- - [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.
21
- - [Fix] Make assigning a setting on a frozen `Configurable::Node` atomic. The ivar-backed writer evaluated `@configs_refs[name] = value` before `instance_variable_set`, so a frozen node mutated the canonical store and only then raised `FrozenError`, leaving the store and the ivar-backed reader permanently out of sync. It now raises before touching any state.
22
- - [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).
23
- - [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.
24
- - [Fix] Strip the tests/specs root directory as an anchored prefix (`sub(/\A.../)`) instead of a global `gsub` in `MinitestLocator` and `RSpecLocator`. When the root directory string recurred later in a test/spec file path, the global replace removed every occurrence and corrupted the derived subject class path; only the leading prefix is now removed.
24
+ - [Fix] Stop `Contract#call` from raising `NoMethodError` when a virtual rule returns `false`.
25
+ - [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.
26
+ - [Fix] Make `Notifications` subscriptions thread-safe, so a listener unsubscribing during dispatch no longer causes the next listener to be skipped.
27
+ - [Fix] Report a freeze duration (`_fd`) of `0` for statistics keys that first appear mid-stream.
28
+ - [Fix] Stop an assignment on a frozen `Configurable::Node` from leaving the setting in an inconsistent state.
29
+ - [Fix] Stop `Configurable::Node#to_h` from raising for an unset setting that uses the `->(default) { ... }` constructor form.
30
+ - [Fix] Honor `excluded_keys` when combined with `only_keys` in `StatisticsDecorator`.
31
+ - [Fix] Fix subject path detection in `MinitestLocator` and `RSpecLocator` when the tests root name repeats later in the path.
25
32
 
26
33
  ## 2.6.1 (2026-06-15)
27
34
  - [Enhancement] Speed up `Contract#call` by ~1.25–1.4x, the per-message validation path in WaterDrop producers.
28
- - [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.
29
- - [Change] Reject reserved setting names with an `ArgumentError` in `Configurable::Node#setting` and `#register`: internal state names (`node_name`, `children`, `nestings`, `compiled`, `configs_refs`, `local_defs`) and the node public API names (`setting`, `configure`, `to_h`, `deep_dup`, `register`, `compile`). Previously such names silently shadowed the node own accessors, breaking `deep_dup` or `to_h`, and assignments like `config.children = value` corrupted the node internal state.
35
+ - [Fix] Report a missing path instead of raising `NoMethodError` when a 3+ key rule path meets a non-Hash intermediate value.
36
+ - [Change] Reject reserved setting names in `Configurable::Node#setting` and `#register` with an `ArgumentError`, since they could corrupt the node state.
30
37
  - [Enhancement] Speed up `Monitor#instrument` dispatch (~1.2x) on the common no-subscribers path.
31
38
  - [Enhancement] Speed up `Configurable::Node` settings reads (~1.4x flat, ~1.6x nested) on hot paths.
32
- - [Enhancement] Instantiate each `Configurable::Node` through a per-layout anonymous subclass so the ivar-backed settings do not grow object shape variations on the shared `Node` class (which would degrade ivar access and trigger Ruby performance warnings). `deep_dup` reuses the template's subclass, so duplicated configs share object shapes.
33
- - [Fix] Symbolize setting names at definition time (`setting`, same as `register`) and on config store writes so `String` setting names work end to end (accessors, `#to_h`, recompilation state) and cannot corrupt node internal state when matching reserved internal names (previously string-named settings were quietly broken as accessors and the store disagreed on the key type).
34
- - [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`.
39
+ - [Enhancement] Reduce object shape variations of config nodes by giving each settings layout its own anonymous `Node` subclass.
40
+ - [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.
41
+ - [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`.
35
42
  - [Change] Assigning a setting on a frozen config node now raises `FrozenError` (previously the write silently mutated internal storage despite the freeze).
36
43
 
37
44
  ## 2.6.0 (2026-06-10)
38
45
  - [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.
39
- - [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.
46
+ - [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.
40
47
 
41
48
  ## 2.5.13 (2026-04-08)
42
49
  - [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).
@@ -52,10 +59,10 @@
52
59
  - [Enhancement] Cache a frozen success `Result` singleton via `Result.success` to eliminate 1 object allocation per successful `Contract#call` on the happy path.
53
60
  - [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.
54
61
  - [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.
55
- - [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.
62
+ - [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.
56
63
  - [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).
57
64
  - [Enhancement] Reorder `StatisticsDecorator#diff` type checks to test `Numeric` before `Hash`, matching the ~80% numeric value distribution in librdkafka statistics.
58
- - [Enhancement] Support `only_keys` option in `StatisticsDecorator` to decorate only specified numeric keys (e.g. `consumer_lag`, `committed_offset`). When combined with `excluded_keys`, reduces decoration cost from ~80ms to ~8.5ms per call on large clusters (10 brokers, 20 topics, 2000 partitions) by using structure-aware navigation of the librdkafka statistics tree and direct key access instead of full-hash iteration.
65
+ - [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.
59
66
  - [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.
60
67
 
61
68
  ## 2.5.10 (2026-03-02)
@@ -177,7 +184,7 @@
177
184
 
178
185
  ## 2.2.1 (2023-09-10)
179
186
  - Optimize statistics decorator by minimizing number of new objects created.
180
- - 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.
187
+ - 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.
181
188
 
182
189
  ## 2.2.0 (2023-09-01)
183
190
  - [Maintenance] Update the signing cert (old expired)
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- karafka-core (2.6.3)
4
+ karafka-core (2.6.5)
5
5
  karafka-rdkafka (>= 0.20.0)
6
6
  logger (>= 1.6.0)
7
7
 
@@ -22,39 +22,39 @@ GEM
22
22
  ffi (1.17.4-x86_64-darwin)
23
23
  ffi (1.17.4-x86_64-linux-gnu)
24
24
  ffi (1.17.4-x86_64-linux-musl)
25
- io-console (0.8.2)
26
- json (2.21.2)
27
- karafka-rdkafka (0.28.0)
25
+ io-console (0.9.4)
26
+ json (3.0.2)
27
+ karafka-rdkafka (0.30.2)
28
28
  ffi (~> 1.17.1)
29
29
  json (> 2.0)
30
30
  logger
31
31
  mini_portile2 (~> 2.6)
32
32
  rake (> 12)
33
- karafka-rdkafka (0.28.0-aarch64-linux-gnu)
33
+ karafka-rdkafka (0.30.2-aarch64-linux-gnu)
34
34
  ffi (~> 1.17.1)
35
35
  json (> 2.0)
36
36
  logger
37
37
  mini_portile2 (~> 2.6)
38
38
  rake (> 12)
39
- karafka-rdkafka (0.28.0-aarch64-linux-musl)
39
+ karafka-rdkafka (0.30.2-aarch64-linux-musl)
40
40
  ffi (~> 1.17.1)
41
41
  json (> 2.0)
42
42
  logger
43
43
  mini_portile2 (~> 2.6)
44
44
  rake (> 12)
45
- karafka-rdkafka (0.28.0-arm64-darwin)
45
+ karafka-rdkafka (0.30.2-arm64-darwin)
46
46
  ffi (~> 1.17.1)
47
47
  json (> 2.0)
48
48
  logger
49
49
  mini_portile2 (~> 2.6)
50
50
  rake (> 12)
51
- karafka-rdkafka (0.28.0-x86_64-linux-gnu)
51
+ karafka-rdkafka (0.30.2-x86_64-linux-gnu)
52
52
  ffi (~> 1.17.1)
53
53
  json (> 2.0)
54
54
  logger
55
55
  mini_portile2 (~> 2.6)
56
56
  rake (> 12)
57
- karafka-rdkafka (0.28.0-x86_64-linux-musl)
57
+ karafka-rdkafka (0.30.2-x86_64-linux-musl)
58
58
  ffi (~> 1.17.1)
59
59
  json (> 2.0)
60
60
  logger
@@ -67,9 +67,9 @@ GEM
67
67
  prism (~> 1.5)
68
68
  prism (1.9.0)
69
69
  rake (13.4.2)
70
- reline (0.6.3)
70
+ reline (0.7.0)
71
71
  io-console (~> 0.5)
72
- simplecov (1.1.1)
72
+ simplecov (1.3.2)
73
73
  warning (1.6.0)
74
74
 
75
75
  PLATFORMS
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:
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]
@@ -0,0 +1,145 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Karafka
4
+ module Core
5
+ module Configurable
6
+ # Base class for config importers.
7
+ #
8
+ # An importer builds memoized config readers on a target, so a class can read a few config
9
+ # values under short, local names instead of spelling out the full config path at every
10
+ # call site.
11
+ #
12
+ # The config root is not hardcoded and is not passed per use site: it is defined once, by
13
+ # overriding {root} in a subclass. Each consumer therefore ships one importer subclass
14
+ # pointing at its own config tree (e.g. `Karafka::App.config` or `Karafka::Web.config`),
15
+ # and every use site only names the attributes it wants.
16
+ #
17
+ # {root} is a method rather than a stored config object, so it is resolved lazily, on the
18
+ # first read of a given attribute. That matters because importers are typically built while
19
+ # a class body is being loaded, which is usually before the config itself has been set up.
20
+ #
21
+ # Each attribute is memoized per target, so the path is walked only once and every later
22
+ # read is a plain instance variable lookup. Memoization is `||=`-based, so an attribute
23
+ # whose configured value is `nil` or `false` is re-read on each call.
24
+ #
25
+ # @example Define the importer once, with the root
26
+ # module Karafka
27
+ # module Web
28
+ # module Helpers
29
+ # class ConfigImporter < Karafka::Core::Configurable::Importer
30
+ # class << self
31
+ # def root
32
+ # Karafka::Web.config
33
+ # end
34
+ # end
35
+ # end
36
+ # end
37
+ # end
38
+ # end
39
+ #
40
+ # @example Import instance-level readers
41
+ # class LagStats
42
+ # include Karafka::Web::Helpers::ConfigImporter.new(
43
+ # skew_threshold: %i[ui health lags skew_threshold]
44
+ # )
45
+ #
46
+ # def skewed?(lag)
47
+ # lag > skew_threshold
48
+ # end
49
+ # end
50
+ #
51
+ # @example Import class-level readers
52
+ # class Message
53
+ # extend Karafka::Web::Helpers::ConfigImporter.new(per_page: %i[ui per_page])
54
+ # end
55
+ #
56
+ # Message.per_page
57
+ #
58
+ # @example Import the whole config root under `#config` (the default)
59
+ # class Consumer
60
+ # include Karafka::Web::Helpers::ConfigImporter.new
61
+ # end
62
+ #
63
+ # @note The base class defines no root of its own; it is not useful directly and is expected
64
+ # to be subclassed. Reading an attribute off an importer whose class defines no {root}
65
+ # raises `NotImplementedError`.
66
+ #
67
+ # @note The readers are defined directly on the target, so an attribute name that collides
68
+ # with an existing method silently replaces it.
69
+ class Importer < Module
70
+ # Default attributes map, exposing the whole config root under `#config`.
71
+ DEFAULT_ATTRIBUTES = { config: %i[itself] }.freeze
72
+
73
+ private_constant :DEFAULT_ATTRIBUTES
74
+
75
+ class << self
76
+ # @return [Object] config root the attribute paths are resolved against. Override in
77
+ # subclasses; the base class defines none. Called on each memoization miss rather
78
+ # than when the importer is built, so it may safely reference a config that does not
79
+ # exist yet at load time.
80
+ # @raise [NotImplementedError] when called on a class that does not define a root
81
+ def root
82
+ raise(NotImplementedError, self)
83
+ end
84
+ end
85
+
86
+ # @param attributes [Hash{Symbol => Array<Symbol>}] map defining what to import. The key
87
+ # is the name the reader will be available under and the value is the path to the
88
+ # attribute, relative to the root, as an array of message names.
89
+ def initialize(attributes = DEFAULT_ATTRIBUTES)
90
+ super()
91
+ @attributes = attributes
92
+ end
93
+
94
+ # @return [Object] config root this importer resolves against, as defined by its class
95
+ def root
96
+ self.class.root
97
+ end
98
+
99
+ # Defines the readers as instance methods on the target.
100
+ #
101
+ # @param model [Object] object to which we want to add the config fetchers
102
+ # @return [void]
103
+ def included(model)
104
+ super
105
+
106
+ define_readers(model, :define_method)
107
+ end
108
+
109
+ # Defines the readers as class-level methods on the target.
110
+ #
111
+ # @param model [Object] object to which we want to add the config fetchers on a class
112
+ # level
113
+ # @return [void]
114
+ def extended(model)
115
+ super
116
+
117
+ define_readers(model, :define_singleton_method)
118
+ end
119
+
120
+ private
121
+
122
+ # Defines one memoized reader per configured attribute on the target.
123
+ #
124
+ # @param model [Object] object the readers are defined on
125
+ # @param definer [Symbol] method used to define them, either `:define_method` for
126
+ # instance-level readers or `:define_singleton_method` for class-level ones
127
+ # @return [void]
128
+ def define_readers(model, definer)
129
+ importer = self
130
+
131
+ @attributes.each do |name, path|
132
+ ivar = :"@#{name}"
133
+
134
+ model.public_send(definer, name) do
135
+ instance_variable_get(ivar) || instance_variable_set(
136
+ ivar,
137
+ path.reduce(importer.root) { |node, part| node.public_send(part) }
138
+ )
139
+ end
140
+ end
141
+ end
142
+ end
143
+ end
144
+ end
145
+ end
@@ -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
@@ -60,7 +60,7 @@ module Karafka
60
60
  return
61
61
  end
62
62
 
63
- raise(EventNotRegistered, "#{event_id} not registered!")
63
+ raise(EventNotRegistered, event_id)
64
64
  end
65
65
  end
66
66
 
@@ -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)
@@ -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.3"
6
+ VERSION = "2.6.5"
7
7
  end
8
8
  end
data/lib/karafka-core.rb CHANGED
@@ -16,6 +16,7 @@ require "karafka/core/configurable"
16
16
  require "karafka/core/configurable/leaf"
17
17
  require "karafka/core/configurable/node"
18
18
  require "karafka/core/configurable/injector"
19
+ require "karafka/core/configurable/importer"
19
20
  require "karafka/core/contractable/contract"
20
21
  require "karafka/core/contractable/result"
21
22
  require "karafka/core/contractable/rule"
data/package-lock.json CHANGED
@@ -103,9 +103,9 @@
103
103
  }
104
104
  },
105
105
  "node_modules/fastq": {
106
- "version": "1.20.1",
107
- "resolved": "https://registry.npmjs.org/fastq/-/fastq-1.20.1.tgz",
108
- "integrity": "sha512-GGToxJ/w1x32s/D2EKND7kTil4n8OVk/9mycTc4VDza13lOvpUZTGX3mFSCtV9ksdGBVzvsyAVLM6mHFThxXxw==",
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.7.1",
290
- "resolved": "https://registry.npmjs.org/smol-toml/-/smol-toml-1.7.1.tgz",
291
- "integrity": "sha512-PPlsspAZ4jbMBu5DMFhfUGDQLu/vrL4SyBROVS37x8ynnVmFIs1VPBz1Co8Xks3TvpIaZXmU85y4DrQ+UyVFoQ==",
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.3
4
+ version: 2.6.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Maciej Mensfeld
@@ -72,6 +72,7 @@ files:
72
72
  - lib/karafka-core.rb
73
73
  - lib/karafka/core.rb
74
74
  - lib/karafka/core/configurable.rb
75
+ - lib/karafka/core/configurable/importer.rb
75
76
  - lib/karafka/core/configurable/injector.rb
76
77
  - lib/karafka/core/configurable/leaf.rb
77
78
  - lib/karafka/core/configurable/node.rb
@@ -114,14 +115,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
114
115
  requirements:
115
116
  - - ">="
116
117
  - !ruby/object:Gem::Version
117
- version: 3.2.0
118
+ version: 3.3.0
118
119
  required_rubygems_version: !ruby/object:Gem::Requirement
119
120
  requirements:
120
121
  - - ">="
121
122
  - !ruby/object:Gem::Version
122
123
  version: '0'
123
124
  requirements: []
124
- rubygems_version: 4.0.16
125
+ rubygems_version: 4.0.20
125
126
  specification_version: 4
126
127
  summary: Karafka ecosystem core modules
127
128
  test_files: []