karafka-core 2.6.6 → 2.6.8
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/CODEOWNERS +4 -1
- data/.github/workflows/ci.yml +59 -6
- data/.github/workflows/push.yml +1 -1
- data/.github/workflows/verify-action-pins.yml +8 -1
- data/.ruby-version +1 -1
- data/CHANGELOG.md +18 -5
- data/Gemfile +2 -0
- data/Gemfile.lock +9 -8
- data/lib/karafka/core/contractable/contract.rb +36 -4
- data/lib/karafka/core/contractable/result.rb +5 -0
- data/lib/karafka/core/helpers/kafka/config.rb +27 -0
- data/lib/karafka/core/taggable/tags.rb +10 -0
- data/lib/karafka/core/version.rb +1 -1
- data/lib/karafka-core.rb +1 -0
- data/package-lock.json +3 -3
- data/renovate.json +18 -1
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 4cbf9ee706d087b7dcaea80dd337de6cfb7378af2566c7c91d3f92f603241542
|
|
4
|
+
data.tar.gz: 9a925d25b8cd28b65c6cfccc063470d0f11d9daddcd101cbcf4f5950d0f7ba14
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 4ac3047a2c035c012d255ea0dfd400963eee75db432e3d9af8d40079de9bff63ea04187d3dbfde5e30310c974257d260293293ebe8a1a5f3ddf6012f55518470
|
|
7
|
+
data.tar.gz: 0f49c0c21bc54c9ac20785666056da63b3566a2d8a6382d8d1a627e7439cf1f0635b6bea1504701b29943c435f7cc5b38e3464e83c573b5e5b033d910d1d2f28
|
data/.github/CODEOWNERS
CHANGED
data/.github/workflows/ci.yml
CHANGED
|
@@ -14,9 +14,52 @@ permissions:
|
|
|
14
14
|
contents: read
|
|
15
15
|
|
|
16
16
|
jobs:
|
|
17
|
+
# Decides whether the change touches anything but docs. Docs-only pull requests skip the jobs
|
|
18
|
+
# below; CI Success still runs and reports success, so the required check does not stay pending
|
|
19
|
+
changes:
|
|
20
|
+
timeout-minutes: 5
|
|
21
|
+
runs-on: ubuntu-latest
|
|
22
|
+
outputs:
|
|
23
|
+
code: ${{ steps.filter.outputs.code }}
|
|
24
|
+
steps:
|
|
25
|
+
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
|
26
|
+
with:
|
|
27
|
+
fetch-depth: 2
|
|
28
|
+
|
|
29
|
+
- name: Detect code changes
|
|
30
|
+
id: filter
|
|
31
|
+
env:
|
|
32
|
+
EVENT_NAME: ${{ github.event_name }}
|
|
33
|
+
run: |
|
|
34
|
+
# Only pull requests can skip; scheduled and any other runs always test everything
|
|
35
|
+
if [ "$EVENT_NAME" != "pull_request" ]; then
|
|
36
|
+
echo "code=true" >> "$GITHUB_OUTPUT"
|
|
37
|
+
exit 0
|
|
38
|
+
fi
|
|
39
|
+
|
|
40
|
+
# HEAD is the PR merge commit, so HEAD^1..HEAD is what the PR changes in master
|
|
41
|
+
changed="$(git diff --name-only --no-renames HEAD^1 HEAD)"
|
|
42
|
+
|
|
43
|
+
# Anything not on the docs list counts as code (an empty diff too)
|
|
44
|
+
code=false
|
|
45
|
+
while IFS= read -r file; do
|
|
46
|
+
case "$file" in
|
|
47
|
+
lib/*|spec/*|test/*|ext/*|bin/*) code=true ;;
|
|
48
|
+
*.md|LICENSE*|MIT-LICENSE|.github/ISSUE_TEMPLATE/*|.github/FUNDING.yml) ;;
|
|
49
|
+
*.png|*.jpg|*.jpeg|*.svg|*.gif) ;;
|
|
50
|
+
*) code=true ;;
|
|
51
|
+
esac
|
|
52
|
+
done <<< "$changed"
|
|
53
|
+
|
|
54
|
+
echo "Changed files:"
|
|
55
|
+
echo "$changed"
|
|
56
|
+
echo "code=$code" >> "$GITHUB_OUTPUT"
|
|
57
|
+
|
|
17
58
|
tests:
|
|
18
59
|
timeout-minutes: 15
|
|
19
60
|
runs-on: ubuntu-latest
|
|
61
|
+
needs: changes
|
|
62
|
+
if: needs.changes.outputs.code == 'true'
|
|
20
63
|
strategy:
|
|
21
64
|
fail-fast: false
|
|
22
65
|
matrix:
|
|
@@ -24,6 +67,7 @@ jobs:
|
|
|
24
67
|
- '4.0'
|
|
25
68
|
- '3.4'
|
|
26
69
|
- '3.3'
|
|
70
|
+
- 'jruby-10.0'
|
|
27
71
|
include:
|
|
28
72
|
- ruby: '4.0'
|
|
29
73
|
coverage: 'true'
|
|
@@ -36,7 +80,7 @@ jobs:
|
|
|
36
80
|
run: "[ -e $APT_DEPS ] || sudo apt-get install -y --no-install-recommends $APT_DEPS"
|
|
37
81
|
|
|
38
82
|
- name: Set up Ruby
|
|
39
|
-
uses: ruby/setup-ruby@
|
|
83
|
+
uses: ruby/setup-ruby@de492cf36cbab201753d720ce4f4e336cd688c94 # v1.336.0
|
|
40
84
|
with:
|
|
41
85
|
ruby-version: ${{matrix.ruby}}
|
|
42
86
|
bundler: 'latest'
|
|
@@ -61,6 +105,8 @@ jobs:
|
|
|
61
105
|
rubocop:
|
|
62
106
|
timeout-minutes: 5
|
|
63
107
|
runs-on: ubuntu-latest
|
|
108
|
+
needs: changes
|
|
109
|
+
if: needs.changes.outputs.code == 'true'
|
|
64
110
|
env:
|
|
65
111
|
BUNDLE_GEMFILE: Gemfile.lint
|
|
66
112
|
steps:
|
|
@@ -68,9 +114,9 @@ jobs:
|
|
|
68
114
|
with:
|
|
69
115
|
fetch-depth: 0
|
|
70
116
|
- name: Set up Ruby
|
|
71
|
-
uses: ruby/setup-ruby@
|
|
117
|
+
uses: ruby/setup-ruby@de492cf36cbab201753d720ce4f4e336cd688c94 # v1.336.0
|
|
72
118
|
with:
|
|
73
|
-
ruby-version: '4.0.
|
|
119
|
+
ruby-version: '4.0.9'
|
|
74
120
|
bundler-cache: true
|
|
75
121
|
- name: Run rubocop
|
|
76
122
|
run: bundle exec rubocop
|
|
@@ -78,6 +124,8 @@ jobs:
|
|
|
78
124
|
yard-lint:
|
|
79
125
|
timeout-minutes: 5
|
|
80
126
|
runs-on: ubuntu-latest
|
|
127
|
+
needs: changes
|
|
128
|
+
if: needs.changes.outputs.code == 'true'
|
|
81
129
|
env:
|
|
82
130
|
BUNDLE_GEMFILE: Gemfile.lint
|
|
83
131
|
steps:
|
|
@@ -85,9 +133,9 @@ jobs:
|
|
|
85
133
|
with:
|
|
86
134
|
fetch-depth: 0
|
|
87
135
|
- name: Set up Ruby
|
|
88
|
-
uses: ruby/setup-ruby@
|
|
136
|
+
uses: ruby/setup-ruby@de492cf36cbab201753d720ce4f4e336cd688c94 # v1.336.0
|
|
89
137
|
with:
|
|
90
|
-
ruby-version: '4.0.
|
|
138
|
+
ruby-version: '4.0.9'
|
|
91
139
|
bundler-cache: true
|
|
92
140
|
- name: Run yard-lint
|
|
93
141
|
run: bundle exec yard-lint lib/
|
|
@@ -95,6 +143,8 @@ jobs:
|
|
|
95
143
|
lostconf:
|
|
96
144
|
timeout-minutes: 5
|
|
97
145
|
runs-on: ubuntu-latest
|
|
146
|
+
needs: changes
|
|
147
|
+
if: needs.changes.outputs.code == 'true'
|
|
98
148
|
steps:
|
|
99
149
|
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
|
100
150
|
with:
|
|
@@ -114,15 +164,18 @@ jobs:
|
|
|
114
164
|
runs-on: ubuntu-latest
|
|
115
165
|
if: always()
|
|
116
166
|
needs:
|
|
167
|
+
- changes
|
|
117
168
|
- rubocop
|
|
118
169
|
- tests
|
|
119
170
|
- yard-lint
|
|
120
171
|
- lostconf
|
|
121
172
|
steps:
|
|
173
|
+
# Skipped jobs are fine only when the change is docs-only
|
|
122
174
|
- name: Check all jobs passed
|
|
123
175
|
if: |
|
|
176
|
+
needs.changes.result != 'success' ||
|
|
124
177
|
contains(needs.*.result, 'failure') ||
|
|
125
178
|
contains(needs.*.result, 'cancelled') ||
|
|
126
|
-
contains(needs.*.result, 'skipped')
|
|
179
|
+
(needs.changes.outputs.code != 'false' && contains(needs.*.result, 'skipped'))
|
|
127
180
|
run: exit 1
|
|
128
181
|
- run: echo "All CI checks passed!"
|
data/.github/workflows/push.yml
CHANGED
|
@@ -10,7 +10,14 @@ jobs:
|
|
|
10
10
|
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
|
11
11
|
- name: Check SHA pins
|
|
12
12
|
run: |
|
|
13
|
-
|
|
13
|
+
# Every remote action must be pinned to a full 40-character commit SHA. Local actions
|
|
14
|
+
# (./) and docker:// images are not checked.
|
|
15
|
+
unpinned=$(grep -E -rn --include="*.yml" --include="*.yaml" \
|
|
16
|
+
"^[[:space:]]*(-[[:space:]]+)?uses:[[:space:]]*['\"]?[^.'\"[:space:]]" .github/workflows/ \
|
|
17
|
+
| grep -Ev "uses:[[:space:]]*['\"]?docker://" \
|
|
18
|
+
| grep -Ev "@[0-9a-f]{40}['\"]?([[:space:]]|$)" || true)
|
|
19
|
+
if [ -n "$unpinned" ]; then
|
|
20
|
+
echo "$unpinned"
|
|
14
21
|
echo "::error::Actions should use SHA pins, not tags or branch names"
|
|
15
22
|
exit 1
|
|
16
23
|
fi
|
data/.ruby-version
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
4.0.
|
|
1
|
+
4.0.9
|
data/CHANGELOG.md
CHANGED
|
@@ -1,9 +1,22 @@
|
|
|
1
1
|
# Karafka Core Changelog
|
|
2
2
|
|
|
3
|
+
## 2.6.8 (2026-11-12)
|
|
4
|
+
- [Feature] Add `Helpers::Kafka::Config.enabled?` that treats a librdkafka boolean setting as on only when it is `true` or `"true"`.
|
|
5
|
+
- [Change] Make `Contractable::Contract.virtual` raise `ArgumentError` when called inside `nested`. Such a rule ignored the nesting and got the root data.
|
|
6
|
+
|
|
7
|
+
## 2.6.7 (2026-11-10)
|
|
8
|
+
- [Maintenance] Declare `rake` in the `Gemfile`. It came only through `karafka-rdkafka`, which will stop depending on it for precompiled platform gems.
|
|
9
|
+
- [Enhancement] Make `Taggable::Tags#add` with the value a tag already has and `#delete` of a missing tag about 6x faster on MRI and JRuby.
|
|
10
|
+
- [Fix] Make `Contractable::Result#errors` keep the first error when one path has more than one, instead of the last.
|
|
11
|
+
- [Fix] Make `Contractable::Contract#call` return a successful result for a contract with no rules of its own, instead of raising `NoMethodError`.
|
|
12
|
+
- [Fix] Make `Contractable::Contract.rules` return an empty Array for a contract with no rules, instead of `nil`.
|
|
13
|
+
|
|
3
14
|
## 2.6.6 (2026-10-25)
|
|
15
|
+
- [Maintenance] Drop unused `byebug` from the test bundle.
|
|
16
|
+
- [Maintenance] Close the producer in `bindings_test.rb` so the suite exits at once; on JRuby suite exit time dropped from ~315 s to 13–15 s.
|
|
4
17
|
- [Fix] Make `Taggable::Tags` safe to read while another thread adds or removes tags. On JRuby a concurrent read could raise `NullPointerException`.
|
|
5
18
|
- [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
|
|
19
|
+
- [Fix] Make `Notifications#register_event` safe while other threads call `#instrument`. On JRuby a registered event could look unregistered or be dispatched without its method.
|
|
7
20
|
- [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
21
|
|
|
9
22
|
## 2.6.5 (2026-10-19)
|
|
@@ -18,8 +31,8 @@
|
|
|
18
31
|
|
|
19
32
|
## 2.6.2 (2026-06-29)
|
|
20
33
|
- [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.
|
|
22
34
|
- [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.
|
|
35
|
+
- [Fix] Require `pathname` explicitly, so `Karafka::Core.gem_root` no longer raises `NameError` when nothing else loaded it.
|
|
23
36
|
- [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.
|
|
24
37
|
- [Fix] Stop a rescued error inside `Contractable::Contract.nested` from prefixing its path onto every rule defined afterwards.
|
|
25
38
|
- [Fix] Report a missing path instead of raising `NoMethodError` when validating a non-Hash root with a 1-key or 2-key rule.
|
|
@@ -38,14 +51,14 @@
|
|
|
38
51
|
|
|
39
52
|
## 2.6.1 (2026-06-15)
|
|
40
53
|
- [Enhancement] Speed up `Contract#call` by ~1.25–1.4x, the per-message validation path in WaterDrop producers.
|
|
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.
|
|
43
54
|
- [Enhancement] Speed up `Monitor#instrument` dispatch (~1.2x) on the common no-subscribers path.
|
|
44
55
|
- [Enhancement] Speed up `Configurable::Node` settings reads (~1.4x flat, ~1.6x nested) on hot paths.
|
|
45
56
|
- [Enhancement] Reduce object shape variations of config nodes by giving each settings layout its own anonymous `Node` subclass.
|
|
46
|
-
- [
|
|
57
|
+
- [Change] Reject reserved setting names in `Configurable::Node#setting` and `#register` with an `ArgumentError`, since they could corrupt the node state.
|
|
47
58
|
- [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`.
|
|
48
59
|
- [Change] Assigning a setting on a frozen config node now raises `FrozenError` (previously the write silently mutated internal storage despite the freeze).
|
|
60
|
+
- [Fix] Report a missing path instead of raising `NoMethodError` when a 3+ key rule path meets a non-Hash intermediate value.
|
|
61
|
+
- [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.
|
|
49
62
|
|
|
50
63
|
## 2.6.0 (2026-06-10)
|
|
51
64
|
- [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.
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
karafka-core (2.6.
|
|
4
|
+
karafka-core (2.6.8)
|
|
5
5
|
karafka-rdkafka (>= 0.20.0)
|
|
6
6
|
logger (>= 1.6.0)
|
|
7
7
|
|
|
@@ -20,38 +20,38 @@ GEM
|
|
|
20
20
|
ffi (1.17.4-x86_64-darwin)
|
|
21
21
|
ffi (1.17.4-x86_64-linux-gnu)
|
|
22
22
|
ffi (1.17.4-x86_64-linux-musl)
|
|
23
|
-
json (3.0
|
|
24
|
-
karafka-rdkafka (0.
|
|
23
|
+
json (3.1.0)
|
|
24
|
+
karafka-rdkafka (0.31.0)
|
|
25
25
|
ffi (~> 1.17.1)
|
|
26
26
|
json (> 2.0)
|
|
27
27
|
logger
|
|
28
28
|
mini_portile2 (~> 2.6)
|
|
29
29
|
rake (> 12)
|
|
30
|
-
karafka-rdkafka (0.
|
|
30
|
+
karafka-rdkafka (0.31.0-aarch64-linux-gnu)
|
|
31
31
|
ffi (~> 1.17.1)
|
|
32
32
|
json (> 2.0)
|
|
33
33
|
logger
|
|
34
34
|
mini_portile2 (~> 2.6)
|
|
35
35
|
rake (> 12)
|
|
36
|
-
karafka-rdkafka (0.
|
|
36
|
+
karafka-rdkafka (0.31.0-aarch64-linux-musl)
|
|
37
37
|
ffi (~> 1.17.1)
|
|
38
38
|
json (> 2.0)
|
|
39
39
|
logger
|
|
40
40
|
mini_portile2 (~> 2.6)
|
|
41
41
|
rake (> 12)
|
|
42
|
-
karafka-rdkafka (0.
|
|
42
|
+
karafka-rdkafka (0.31.0-arm64-darwin)
|
|
43
43
|
ffi (~> 1.17.1)
|
|
44
44
|
json (> 2.0)
|
|
45
45
|
logger
|
|
46
46
|
mini_portile2 (~> 2.6)
|
|
47
47
|
rake (> 12)
|
|
48
|
-
karafka-rdkafka (0.
|
|
48
|
+
karafka-rdkafka (0.31.0-x86_64-linux-gnu)
|
|
49
49
|
ffi (~> 1.17.1)
|
|
50
50
|
json (> 2.0)
|
|
51
51
|
logger
|
|
52
52
|
mini_portile2 (~> 2.6)
|
|
53
53
|
rake (> 12)
|
|
54
|
-
karafka-rdkafka (0.
|
|
54
|
+
karafka-rdkafka (0.31.0-x86_64-linux-musl)
|
|
55
55
|
ffi (~> 1.17.1)
|
|
56
56
|
json (> 2.0)
|
|
57
57
|
logger
|
|
@@ -83,6 +83,7 @@ PLATFORMS
|
|
|
83
83
|
DEPENDENCIES
|
|
84
84
|
karafka-core!
|
|
85
85
|
minitest
|
|
86
|
+
rake
|
|
86
87
|
simplecov
|
|
87
88
|
warning
|
|
88
89
|
|
|
@@ -29,6 +29,15 @@ module Karafka
|
|
|
29
29
|
# @return [Array<Rule>] all the validation rules defined for a given contract
|
|
30
30
|
attr_reader :rules
|
|
31
31
|
|
|
32
|
+
# Gives each contract its own rules accumulator, so {.rules} is an Array also for a
|
|
33
|
+
# contract that defines no rules and `#call` needs no fallback
|
|
34
|
+
#
|
|
35
|
+
# @param subclass [Class] new contract class
|
|
36
|
+
def inherited(subclass)
|
|
37
|
+
super
|
|
38
|
+
subclass.init_accu
|
|
39
|
+
end
|
|
40
|
+
|
|
32
41
|
# Allows for definition of a scope/namespace for nested validations
|
|
33
42
|
#
|
|
34
43
|
# @param path [Symbol] path in the hash for nesting
|
|
@@ -54,14 +63,25 @@ module Karafka
|
|
|
54
63
|
# error if missing)
|
|
55
64
|
#
|
|
56
65
|
# @param keys [Array<Symbol>] single or full path
|
|
57
|
-
# @param block [Proc] validation rule
|
|
66
|
+
# @param block [Proc] validation rule, called with `(value, data, errors, contract)`.
|
|
67
|
+
# It returns `true` when the value is valid. A String is used as the error message.
|
|
68
|
+
# `false` or `nil` reports the `:format` error key. Any other value (e.g. a Symbol) is
|
|
69
|
+
# used as the error key to look up in the error messages.
|
|
70
|
+
#
|
|
71
|
+
# @note Only `true` means valid. Any other truthy value is an error key, so a block
|
|
72
|
+
# ending with e.g. `value =~ regexp` (which returns `0` on a match) reports an error,
|
|
73
|
+
# and building its message raises `KeyError` when no such key is defined.
|
|
58
74
|
def required(*keys, &block)
|
|
59
75
|
init_accu
|
|
60
76
|
@rules << Rule.new(@nested + keys, :required, block).freeze
|
|
61
77
|
end
|
|
62
78
|
|
|
79
|
+
# Defines a rule for an optional field. A missing key is not an error, but a present
|
|
80
|
+
# key is validated, also when its value is `nil`.
|
|
81
|
+
#
|
|
63
82
|
# @param keys [Array<Symbol>] single or full path
|
|
64
|
-
# @param block [Proc] validation rule
|
|
83
|
+
# @param block [Proc] validation rule, with the same arguments and return values as in
|
|
84
|
+
# {.required}
|
|
65
85
|
def optional(*keys, &block)
|
|
66
86
|
init_accu
|
|
67
87
|
@rules << Rule.new(@nested + keys, :optional, block).freeze
|
|
@@ -80,12 +100,22 @@ module Karafka
|
|
|
80
100
|
# supported -- in-place scoping would accumulate the prefix across validations (or
|
|
81
101
|
# raise `FrozenError`). Build the result in the block (e.g. `[[%i[id], :invalid]]`)
|
|
82
102
|
# rather than returning a constant.
|
|
103
|
+
#
|
|
104
|
+
# @note A virtual rule cannot be defined inside `nested`: its block receives the root
|
|
105
|
+
# data (also when it is not a Hash) and its error paths start at the root. Define
|
|
106
|
+
# virtual rules outside of `nested` and use full paths in the returned errors.
|
|
107
|
+
#
|
|
108
|
+
# @raise [ArgumentError] when called inside a `nested` block, with the nested path as the
|
|
109
|
+
# message
|
|
83
110
|
def virtual(&block)
|
|
84
111
|
init_accu
|
|
112
|
+
|
|
113
|
+
raise ArgumentError, @nested.join(".") unless @nested.empty?
|
|
114
|
+
|
|
85
115
|
@rules << Rule.new([], :virtual, block).freeze
|
|
86
116
|
end
|
|
87
117
|
|
|
88
|
-
|
|
118
|
+
protected
|
|
89
119
|
|
|
90
120
|
# Initializes nestings and rules building accumulator
|
|
91
121
|
def init_accu
|
|
@@ -94,6 +124,8 @@ module Karafka
|
|
|
94
124
|
end
|
|
95
125
|
end
|
|
96
126
|
|
|
127
|
+
init_accu
|
|
128
|
+
|
|
97
129
|
# Runs the validation
|
|
98
130
|
#
|
|
99
131
|
# The per-rule handling is inlined instead of dispatching to per-type methods because
|
|
@@ -126,7 +158,7 @@ module Karafka
|
|
|
126
158
|
|
|
127
159
|
# Apply the scope prefix in place on the rule's returned pairs and collect them
|
|
128
160
|
# directly. Per the `virtual` contract the rule hands back a freshly built Array
|
|
129
|
-
# each call (see `
|
|
161
|
+
# each call (see `Contract.virtual`), so mutating it here is safe and avoids allocating a
|
|
130
162
|
# new pair per error.
|
|
131
163
|
result.each do |sub_result|
|
|
132
164
|
sub_result[0] = scope + sub_result[0]
|
|
@@ -5,6 +5,9 @@ module Karafka
|
|
|
5
5
|
module Contractable
|
|
6
6
|
# Representation of a validation result with resolved error messages
|
|
7
7
|
class Result
|
|
8
|
+
# @return [Hash{Symbol => String}] error message per path. When a path has more than one
|
|
9
|
+
# error, the first one reported is kept: rules run in definition order and a virtual
|
|
10
|
+
# rule's errors keep the order it returns them in.
|
|
8
11
|
attr_reader :errors
|
|
9
12
|
|
|
10
13
|
# Empty hash that we use when no errors to save on allocations
|
|
@@ -37,6 +40,8 @@ module Karafka
|
|
|
37
40
|
errors.each do |error|
|
|
38
41
|
scope = error.first.map(&:to_s).join(".").to_sym
|
|
39
42
|
|
|
43
|
+
next if hashed.key?(scope)
|
|
44
|
+
|
|
40
45
|
# This will allow for usage of custom messages instead of yaml keys if needed
|
|
41
46
|
hashed[scope] = if error.last.is_a?(String)
|
|
42
47
|
error.last
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Karafka
|
|
4
|
+
module Core
|
|
5
|
+
module Helpers
|
|
6
|
+
# Kafka related helpers
|
|
7
|
+
module Kafka
|
|
8
|
+
# Reads librdkafka configuration values the way the ecosystem acts on them
|
|
9
|
+
module Config
|
|
10
|
+
# Values that turn a librdkafka boolean setting on
|
|
11
|
+
ENABLED_VALUES = [true, "true"].freeze
|
|
12
|
+
|
|
13
|
+
private_constant :ENABLED_VALUES
|
|
14
|
+
|
|
15
|
+
class << self
|
|
16
|
+
# @param value [Object] librdkafka boolean setting value (e.g. from a `kafka` hash)
|
|
17
|
+
# @return [Boolean] true only when the value is `true` or `"true"`
|
|
18
|
+
# @note Any other value, including `nil` (setting not provided) and `"false"`, is false
|
|
19
|
+
def enabled?(value)
|
|
20
|
+
ENABLED_VALUES.include?(value)
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
@@ -18,6 +18,11 @@ module Karafka
|
|
|
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
20
|
value = tag.to_s
|
|
21
|
+
snapshot = @snapshot
|
|
22
|
+
|
|
23
|
+
# The snapshot is frozen and replaced in one assignment, so one read of it is consistent
|
|
24
|
+
# on any engine without the lock
|
|
25
|
+
return snapshot if snapshot.tags[name] == value
|
|
21
26
|
|
|
22
27
|
@mutex.synchronize { publish(@snapshot.tags.merge(name => value)) }
|
|
23
28
|
end
|
|
@@ -30,6 +35,11 @@ module Karafka
|
|
|
30
35
|
# Removes a tag with a given name
|
|
31
36
|
# @param name [Symbol] name of the tag
|
|
32
37
|
def delete(name)
|
|
38
|
+
snapshot = @snapshot
|
|
39
|
+
|
|
40
|
+
# Safe without the lock for the same reason as in #add
|
|
41
|
+
return snapshot unless snapshot.tags.key?(name)
|
|
42
|
+
|
|
33
43
|
@mutex.synchronize { publish(@snapshot.tags.except(name)) }
|
|
34
44
|
end
|
|
35
45
|
|
data/lib/karafka/core/version.rb
CHANGED
data/lib/karafka-core.rb
CHANGED
|
@@ -7,6 +7,7 @@ require "rdkafka"
|
|
|
7
7
|
require "karafka/core"
|
|
8
8
|
require "karafka/core/version"
|
|
9
9
|
require "karafka/core/helpers/time"
|
|
10
|
+
require "karafka/core/helpers/kafka/config"
|
|
10
11
|
require "karafka/core/monitoring"
|
|
11
12
|
require "karafka/core/monitoring/event"
|
|
12
13
|
require "karafka/core/monitoring/monitor"
|
data/package-lock.json
CHANGED
|
@@ -286,9 +286,9 @@
|
|
|
286
286
|
}
|
|
287
287
|
},
|
|
288
288
|
"node_modules/smol-toml": {
|
|
289
|
-
"version": "1.9.
|
|
290
|
-
"resolved": "https://registry.npmjs.org/smol-toml/-/smol-toml-1.9.
|
|
291
|
-
"integrity": "sha512-
|
|
289
|
+
"version": "1.9.1",
|
|
290
|
+
"resolved": "https://registry.npmjs.org/smol-toml/-/smol-toml-1.9.1.tgz",
|
|
291
|
+
"integrity": "sha512-j7WyPdf0CJoutMzMoPLF/bVXHtKZIT9Rb4eGeEbWw8X2t5oirjPgpL+OpaENZrILYaXqYwnVH+qgUwVbl+pUJQ==",
|
|
292
292
|
"dev": true,
|
|
293
293
|
"license": "BSD-3-Clause",
|
|
294
294
|
"engines": {
|
data/renovate.json
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"bundler": {
|
|
3
|
-
"managerFilePatterns": [
|
|
3
|
+
"managerFilePatterns": [
|
|
4
|
+
"/(^|/)Gemfile\\.lint$/"
|
|
5
|
+
]
|
|
4
6
|
},
|
|
5
7
|
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
|
|
6
8
|
"extends": [
|
|
@@ -42,6 +44,13 @@
|
|
|
42
44
|
"ruby/setup-ruby"
|
|
43
45
|
],
|
|
44
46
|
"minimumReleaseAge": "5 days"
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
"description": "Major updates stay manual",
|
|
50
|
+
"matchUpdateTypes": [
|
|
51
|
+
"major"
|
|
52
|
+
],
|
|
53
|
+
"automerge": false
|
|
45
54
|
}
|
|
46
55
|
],
|
|
47
56
|
"labels": [
|
|
@@ -53,5 +62,13 @@
|
|
|
53
62
|
"schedule": [
|
|
54
63
|
"before 4am on the first day of the month"
|
|
55
64
|
]
|
|
65
|
+
},
|
|
66
|
+
"automerge": true,
|
|
67
|
+
"platformAutomerge": true,
|
|
68
|
+
"osvVulnerabilityAlerts": true,
|
|
69
|
+
"vulnerabilityAlerts": {
|
|
70
|
+
"labels": [
|
|
71
|
+
"security"
|
|
72
|
+
]
|
|
56
73
|
}
|
|
57
74
|
}
|
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.8
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Maciej Mensfeld
|
|
@@ -80,6 +80,7 @@ files:
|
|
|
80
80
|
- lib/karafka/core/contractable/contract.rb
|
|
81
81
|
- lib/karafka/core/contractable/result.rb
|
|
82
82
|
- lib/karafka/core/contractable/rule.rb
|
|
83
|
+
- lib/karafka/core/helpers/kafka/config.rb
|
|
83
84
|
- lib/karafka/core/helpers/minitest_locator.rb
|
|
84
85
|
- lib/karafka/core/helpers/rspec_locator.rb
|
|
85
86
|
- lib/karafka/core/helpers/time.rb
|