karafka-core 2.5.6 → 2.5.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: db92a39f948cb06229746101158aa8ada484e51a85149312ef7c30944184f7aa
4
- data.tar.gz: 751901f07f172fa98d452c677fb419e842e5cb25acff07a116a7ef8475205ce8
3
+ metadata.gz: 0566f7af7e0bc6845a4078f1a43399caffde5569134931fa2b3dd7eebff80acf
4
+ data.tar.gz: 07cc05d3d190137e9564e3e55337182642c714ab3b1a239b4197c68e45e23d8c
5
5
  SHA512:
6
- metadata.gz: 99918e4fcd414f28bf28c5acef4b47bcd971b15d6e657e69c498996de2aa6e23cb9dc8535def06e9ef0e6a08d55688bf286767e7135fe0d0910da86d4fda30d6
7
- data.tar.gz: 42fc4a7e016d2ce0c7f1bc024fe2cdb68c6bec26b9d9b4b9f613843033eec38aae5cd49cf76101f8c27a460fd987789c205e2e8a659775c85bae35fb96862478
6
+ metadata.gz: e0fa31222e15c878b2bd09e5e6b1e5c2777df35d5d2e4baff9e82fdf68aac1e9937bc01055170f7845d438f7f7763c95e6d6f60848969ff08430d3fa3ccdc8dc
7
+ data.tar.gz: 98ff20883506dbdece28f8de46f6fd67895a8bb3fcc343ca1d9d753b1e87f6acf9bc0ae31ce7799b3c6c2def15d88edd696f3f55d51eca5a88f111d1915f44be
@@ -17,21 +17,19 @@ jobs:
17
17
  specs:
18
18
  timeout-minutes: 15
19
19
  runs-on: ubuntu-latest
20
- needs: diffend
21
20
  strategy:
22
21
  fail-fast: false
23
22
  matrix:
24
23
  ruby:
25
- - '3.5.0-preview1'
24
+ - '4.0.0-preview2'
26
25
  - '3.4'
27
26
  - '3.3'
28
27
  - '3.2'
29
- - '3.1'
30
28
  include:
31
29
  - ruby: '3.4'
32
30
  coverage: 'true'
33
31
  steps:
34
- - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
32
+ - uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
35
33
  with:
36
34
  fetch-depth: 0
37
35
 
@@ -39,7 +37,7 @@ jobs:
39
37
  run: "[ -e $APT_DEPS ] || sudo apt-get install -y --no-install-recommends $APT_DEPS"
40
38
 
41
39
  - name: Set up Ruby
42
- uses: ruby/setup-ruby@efbf473cab83af4468e8606cc33eca9281bb213f # v1.256.0
40
+ uses: ruby/setup-ruby@8aeb6ff8030dd539317f8e1769a044873b56ea71 # v1.268.0
43
41
  with:
44
42
  ruby-version: ${{matrix.ruby}}
45
43
  bundler: 'latest'
@@ -61,35 +59,13 @@ jobs:
61
59
  GITHUB_COVERAGE: ${{matrix.coverage}}
62
60
  run: bundle exec rspec
63
61
 
64
- diffend:
65
- timeout-minutes: 5
66
- runs-on: ubuntu-latest
67
- strategy:
68
- fail-fast: false
69
- steps:
70
- - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
71
- with:
72
- fetch-depth: 0
73
- - name: Set up Ruby
74
- uses: ruby/setup-ruby@efbf473cab83af4468e8606cc33eca9281bb213f # v1.256.0
75
- with:
76
- ruby-version: 3.4
77
- self-hosted: false
78
-
79
- - name: Install latest bundler
80
- run: gem install bundler --no-document
81
- - name: Install Diffend plugin
82
- run: bundle plugin install diffend
83
- - name: Bundle Secure
84
- run: bundle secure
85
-
86
62
  coditsu:
87
63
  timeout-minutes: 5
88
64
  runs-on: ubuntu-latest
89
65
  strategy:
90
66
  fail-fast: false
91
67
  steps:
92
- - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
68
+ - uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
93
69
  with:
94
70
  fetch-depth: 0
95
71
  - name: Download Coditsu script
@@ -107,14 +83,29 @@ jobs:
107
83
  - name: Run Coditsu
108
84
  run: ./coditsu_script.sh
109
85
 
86
+ yard-lint:
87
+ timeout-minutes: 5
88
+ runs-on: ubuntu-latest
89
+ steps:
90
+ - uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
91
+ with:
92
+ fetch-depth: 0
93
+ - name: Set up Ruby
94
+ uses: ruby/setup-ruby@8aeb6ff8030dd539317f8e1769a044873b56ea71 # v1.268.0
95
+ with:
96
+ ruby-version: '3.4.7'
97
+ bundler-cache: true
98
+ - name: Run yard-lint
99
+ run: bundle exec yard-lint lib/
100
+
110
101
  ci-success:
111
102
  name: CI Success
112
103
  runs-on: ubuntu-latest
113
104
  if: always()
114
105
  needs:
115
- - diffend
116
106
  - coditsu
117
107
  - specs
108
+ - yard-lint
118
109
  steps:
119
110
  - name: Check all jobs passed
120
111
  if: |
@@ -19,12 +19,12 @@ jobs:
19
19
  id-token: write
20
20
 
21
21
  steps:
22
- - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
22
+ - uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
23
23
  with:
24
24
  fetch-depth: 0
25
25
 
26
26
  - name: Set up Ruby
27
- uses: ruby/setup-ruby@efbf473cab83af4468e8606cc33eca9281bb213f # v1.256.0
27
+ uses: ruby/setup-ruby@8aeb6ff8030dd539317f8e1769a044873b56ea71 # v1.268.0
28
28
  with:
29
29
  bundler-cache: false
30
30
 
@@ -32,4 +32,4 @@ jobs:
32
32
  run: |
33
33
  bundle install --jobs 4 --retry 3
34
34
 
35
- - uses: rubygems/release-gem@a25424ba2ba8b387abc8ef40807c2c85b96cbe32 # v1.1.1
35
+ - uses: rubygems/release-gem@1c162a739e8b4cb21a676e97b087e8268d8fc40b # v1.1.2
@@ -13,7 +13,7 @@ jobs:
13
13
  if: github.repository_owner == 'karafka'
14
14
  steps:
15
15
  - name: Trigger wiki refresh
16
- uses: peter-evans/repository-dispatch@ff45666b9427631e3450c54a1bcbee4d9ff4d7c0 # v3.0.0
16
+ uses: peter-evans/repository-dispatch@28959ce8df70de7be546dd1250a005dd32156697 # v4.0.1
17
17
  with:
18
18
  token: ${{ secrets.WIKI_REPO_TOKEN }}
19
19
  repository: karafka/wiki
@@ -7,7 +7,7 @@ jobs:
7
7
  verify_action_pins:
8
8
  runs-on: ubuntu-latest
9
9
  steps:
10
- - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
10
+ - uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
11
11
  - name: Check SHA pins
12
12
  run: |
13
13
  if grep -E -r "uses: .*/.*@(v[0-9]+|main|master)($|[[:space:]]|$)" --include="*.yml" --include="*.yaml" .github/workflows/ | grep -v "#"; then
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 3.4.5
1
+ 3.4.7
data/.yard-lint.yml ADDED
@@ -0,0 +1,174 @@
1
+ # YARD-Lint Configuration
2
+ # See https://github.com/mensfeld/yard-lint for documentation
3
+
4
+ # Global settings for all validators
5
+ AllValidators:
6
+ # YARD command-line options (applied to all validators by default)
7
+ YardOptions:
8
+ - --private
9
+ - --protected
10
+
11
+ # Global file exclusion patterns
12
+ Exclude:
13
+ - '\.git'
14
+ - 'vendor/**/*'
15
+ - 'node_modules/**/*'
16
+ - 'spec/**/*'
17
+ - 'test/**/*'
18
+
19
+ # Exit code behavior (error, warning, convention, never)
20
+ FailOnSeverity: error
21
+
22
+ # Minimum documentation coverage percentage (0-100)
23
+ # Fails if coverage is below this threshold
24
+ MinCoverage: 98.0
25
+
26
+ # Diff mode settings
27
+ DiffMode:
28
+ # Default base ref for --diff (auto-detects main/master if not specified)
29
+ DefaultBaseRef: ~
30
+
31
+ # Documentation validators
32
+ Documentation/UndocumentedObjects:
33
+ Description: 'Checks for classes, modules, and methods without documentation.'
34
+ Enabled: true
35
+ Severity: error
36
+ ExcludedMethods:
37
+ - 'initialize/0' # Exclude parameter-less initialize
38
+ - '/^_/' # Exclude private methods (by convention)
39
+
40
+ Documentation/UndocumentedMethodArguments:
41
+ Description: 'Checks for method parameters without @param tags.'
42
+ Enabled: true
43
+ Severity: error
44
+
45
+ Documentation/UndocumentedBooleanMethods:
46
+ Description: 'Checks that question mark methods document their boolean return.'
47
+ Enabled: true
48
+ Severity: error
49
+
50
+ Documentation/UndocumentedOptions:
51
+ Description: 'Detects methods with options hash parameters but no @option tags.'
52
+ Enabled: true
53
+ Severity: error
54
+
55
+ Documentation/MarkdownSyntax:
56
+ Description: 'Detects common markdown syntax errors in documentation.'
57
+ Enabled: true
58
+ Severity: error
59
+
60
+ # Tags validators
61
+ Tags/Order:
62
+ Description: 'Enforces consistent ordering of YARD tags.'
63
+ Enabled: true
64
+ Severity: error
65
+ EnforcedOrder:
66
+ - param
67
+ - option
68
+ - return
69
+ - raise
70
+ - example
71
+
72
+ Tags/InvalidTypes:
73
+ Description: 'Validates type definitions in @param, @return, @option tags.'
74
+ Enabled: true
75
+ Severity: error
76
+ ValidatedTags:
77
+ - param
78
+ - option
79
+ - return
80
+
81
+ Tags/TypeSyntax:
82
+ Description: 'Validates YARD type syntax using YARD parser.'
83
+ Enabled: true
84
+ Severity: error
85
+ ValidatedTags:
86
+ - param
87
+ - option
88
+ - return
89
+ - yieldreturn
90
+
91
+ Tags/MeaninglessTag:
92
+ Description: 'Detects @param/@option tags on classes, modules, or constants.'
93
+ Enabled: true
94
+ Severity: error
95
+ CheckedTags:
96
+ - param
97
+ - option
98
+ InvalidObjectTypes:
99
+ - class
100
+ - module
101
+ - constant
102
+
103
+ Tags/CollectionType:
104
+ Description: 'Validates Hash collection syntax consistency.'
105
+ Enabled: true
106
+ Severity: error
107
+ EnforcedStyle: long # 'long' for Hash{K => V} (YARD standard), 'short' for {K => V}
108
+ ValidatedTags:
109
+ - param
110
+ - option
111
+ - return
112
+ - yieldreturn
113
+
114
+ Tags/TagTypePosition:
115
+ Description: 'Validates type annotation position in tags.'
116
+ Enabled: true
117
+ Severity: error
118
+ CheckedTags:
119
+ - param
120
+ - option
121
+ # EnforcedStyle: 'type_after_name' (YARD standard: @param name [Type])
122
+ # or 'type_first' (@param [Type] name)
123
+ EnforcedStyle: type_after_name
124
+
125
+ Tags/ApiTags:
126
+ Description: 'Enforces @api tags on public objects.'
127
+ Enabled: false # Opt-in validator
128
+ Severity: error
129
+ AllowedApis:
130
+ - public
131
+ - private
132
+ - internal
133
+
134
+ Tags/OptionTags:
135
+ Description: 'Requires @option tags for methods with options parameters.'
136
+ Enabled: true
137
+ Severity: error
138
+
139
+ # Warnings validators - catches YARD parser errors
140
+ Warnings/UnknownTag:
141
+ Description: 'Detects unknown YARD tags.'
142
+ Enabled: true
143
+ Severity: error
144
+
145
+ Warnings/UnknownDirective:
146
+ Description: 'Detects unknown YARD directives.'
147
+ Enabled: true
148
+ Severity: error
149
+
150
+ Warnings/InvalidTagFormat:
151
+ Description: 'Detects malformed tag syntax.'
152
+ Enabled: true
153
+ Severity: error
154
+
155
+ Warnings/InvalidDirectiveFormat:
156
+ Description: 'Detects malformed directive syntax.'
157
+ Enabled: true
158
+ Severity: error
159
+
160
+ Warnings/DuplicatedParameterName:
161
+ Description: 'Detects duplicate @param tags.'
162
+ Enabled: true
163
+ Severity: error
164
+
165
+ Warnings/UnknownParameterName:
166
+ Description: 'Detects @param tags for non-existent parameters.'
167
+ Enabled: true
168
+ Severity: error
169
+
170
+ # Semantic validators
171
+ Semantic/AbstractMethods:
172
+ Description: 'Ensures @abstract methods do not have real implementations.'
173
+ Enabled: true
174
+ Severity: error
data/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # Karafka Core Changelog
2
2
 
3
+ ## 2.5.8 (2025-11-23)
4
+ - [Enhancement] Memoize `StatisticsDecorator` suffix keys to reduce string allocations (#268).
5
+
6
+ ## 2.5.7 (2025-09-28)
7
+ - [Enhancement] Optimize `Node#deep_dup` to reduce array allocations during configuration deep copying.
8
+ - [Enhancement] Optimize `Result#initialize` to use shared `EMPTY_HASH` constant for successful validations.
9
+ - [Enhancement] Optimize `StatisticsDecorator#append` string concatenation to reduce allocations.
10
+ - [Enhancement] Optimize `Notifications#instrument` payload handling to avoid unnecessary hash merges for empty payloads.
11
+ - **[EOL]** Remove Ruby 3.1 support due to EOL.
12
+
3
13
  ## 2.5.6 (2025-09-02)
4
14
  - [Change] Normalize how libs and dependencies are required (no functional change for the end user)
5
15
  - [Change] Set minimum `karafka-rdkafka` on `0.20.0` to support new features and allow for open range as both `waterdrop` and `karafka` manage this.
@@ -48,7 +58,7 @@
48
58
  - [Change] Allow `karafka-rdkafka` `0.18.0`.
49
59
 
50
60
  ## 2.4.5 (2024-11-19)
51
- - **[Breaking]** Drop Ruby `3.0` support according to the EOL schedule.
61
+ - **[EOL]** Drop Ruby `3.0` support according to the EOL schedule.
52
62
  - [Enhancement] Support listeners inspection via `#listeners`.
53
63
  - [Fix] Restore `#available_events` notifications bus method.
54
64
  - [Change] Set minimum `karafka-rdkafka` on `0.17.6` to support new features.
@@ -71,7 +81,7 @@
71
81
  - [Enhancement] Allow clearing one event type (dorner).
72
82
 
73
83
  ## 2.4.0 (2024-04-26)
74
- - **[Breaking]** Drop Ruby `2.7` support.
84
+ - **[EOL]** Drop Ruby `2.7` support.
75
85
  - [Enhancement] Provide necessary alterations for custom oauth token callbacks to operate.
76
86
  - [Change] Set minimum `karafka-rdkafka` on `0.15.0` to support new features.
77
87
 
@@ -86,7 +96,7 @@
86
96
  - [Enhancement] Set backtrace for errors propagated via the errors callbacks.
87
97
 
88
98
  ## 2.2.5 (2023-10-31)
89
- - [Change] Drop support for Ruby 2.6 due to incompatibilities in usage of `ObjectSpace::WeakMap`
99
+ - **[EOL]** Drop support for Ruby 2.6 due to incompatibilities in usage of `ObjectSpace::WeakMap`
90
100
  - [Change] Set minimum `karafka-rdkafka` on `0.13.8` to support consumer `#position`.
91
101
 
92
102
  ## 2.2.4 (2023-10-25)
data/Gemfile CHANGED
@@ -2,8 +2,6 @@
2
2
 
3
3
  source 'https://rubygems.org'
4
4
 
5
- plugin 'diffend'
6
-
7
5
  gemspec
8
6
 
9
7
  group :test do
@@ -11,4 +9,5 @@ group :test do
11
9
  gem 'rspec'
12
10
  gem 'simplecov'
13
11
  gem 'warning'
12
+ gem 'yard-lint'
14
13
  end
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- karafka-core (2.5.6)
4
+ karafka-core (2.5.8)
5
5
  karafka-rdkafka (>= 0.20.0)
6
6
  logger (>= 1.6.0)
7
7
 
@@ -22,32 +22,32 @@ GEM
22
22
  ffi (1.17.2-x86_64-darwin)
23
23
  ffi (1.17.2-x86_64-linux-gnu)
24
24
  ffi (1.17.2-x86_64-linux-musl)
25
- json (2.13.2)
26
- karafka-rdkafka (0.21.0)
25
+ json (2.15.1)
26
+ karafka-rdkafka (0.22.2)
27
27
  ffi (~> 1.15)
28
28
  json (> 2.0)
29
29
  logger
30
30
  mini_portile2 (~> 2.6)
31
31
  rake (> 12)
32
- karafka-rdkafka (0.21.0-aarch64-linux-gnu)
32
+ karafka-rdkafka (0.22.2-aarch64-linux-gnu)
33
33
  ffi (~> 1.15)
34
34
  json (> 2.0)
35
35
  logger
36
36
  mini_portile2 (~> 2.6)
37
37
  rake (> 12)
38
- karafka-rdkafka (0.21.0-arm64-darwin)
38
+ karafka-rdkafka (0.22.2-arm64-darwin)
39
39
  ffi (~> 1.15)
40
40
  json (> 2.0)
41
41
  logger
42
42
  mini_portile2 (~> 2.6)
43
43
  rake (> 12)
44
- karafka-rdkafka (0.21.0-x86_64-linux-gnu)
44
+ karafka-rdkafka (0.22.2-x86_64-linux-gnu)
45
45
  ffi (~> 1.15)
46
46
  json (> 2.0)
47
47
  logger
48
48
  mini_portile2 (~> 2.6)
49
49
  rake (> 12)
50
- karafka-rdkafka (0.21.0-x86_64-linux-musl)
50
+ karafka-rdkafka (0.22.2-x86_64-linux-musl)
51
51
  ffi (~> 1.15)
52
52
  json (> 2.0)
53
53
  logger
@@ -56,26 +56,31 @@ GEM
56
56
  logger (1.7.0)
57
57
  mini_portile2 (2.8.9)
58
58
  rake (13.3.0)
59
- rspec (3.13.1)
59
+ rspec (3.13.2)
60
60
  rspec-core (~> 3.13.0)
61
61
  rspec-expectations (~> 3.13.0)
62
62
  rspec-mocks (~> 3.13.0)
63
- rspec-core (3.13.4)
63
+ rspec-core (3.13.6)
64
64
  rspec-support (~> 3.13.0)
65
65
  rspec-expectations (3.13.5)
66
66
  diff-lcs (>= 1.2.0, < 2.0)
67
67
  rspec-support (~> 3.13.0)
68
- rspec-mocks (3.13.5)
68
+ rspec-mocks (3.13.6)
69
69
  diff-lcs (>= 1.2.0, < 2.0)
70
70
  rspec-support (~> 3.13.0)
71
- rspec-support (3.13.4)
71
+ rspec-support (3.13.6)
72
72
  simplecov (0.22.0)
73
73
  docile (~> 1.1)
74
74
  simplecov-html (~> 0.11)
75
75
  simplecov_json_formatter (~> 0.1)
76
- simplecov-html (0.13.1)
76
+ simplecov-html (0.13.2)
77
77
  simplecov_json_formatter (0.1.4)
78
78
  warning (1.5.0)
79
+ yard (0.9.37)
80
+ yard-lint (1.2.3)
81
+ yard (~> 0.9)
82
+ zeitwerk (~> 2.6)
83
+ zeitwerk (2.7.3)
79
84
 
80
85
  PLATFORMS
81
86
  aarch64-linux-gnu
@@ -96,6 +101,7 @@ DEPENDENCIES
96
101
  rspec
97
102
  simplecov
98
103
  warning
104
+ yard-lint
99
105
 
100
106
  BUNDLED WITH
101
107
  2.6.9
data/karafka-core.gemspec CHANGED
@@ -7,7 +7,7 @@ require 'karafka/core/version'
7
7
 
8
8
  Gem::Specification.new do |spec|
9
9
  spec.name = 'karafka-core'
10
- spec.version = ::Karafka::Core::VERSION
10
+ spec.version = Karafka::Core::VERSION
11
11
  spec.platform = Gem::Platform::RUBY
12
12
  spec.authors = ['Maciej Mensfeld']
13
13
  spec.email = %w[contact@karafka.io]
@@ -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.1.0'
22
+ spec.required_ruby_version = '>= 3.2.0'
23
23
 
24
24
  spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(spec)/}) }
25
25
  spec.require_paths = %w[lib]
@@ -85,15 +85,16 @@ module Karafka
85
85
  def deep_dup
86
86
  dupped = Node.new(node_name, nestings)
87
87
 
88
- dupped.children += children.map do |value|
89
- if value.is_a?(Leaf)
90
- # After inheritance we need to reload the state so the leafs are recompiled again
91
- value = value.dup
92
- value.compiled = false
93
- value
94
- else
95
- value.deep_dup
96
- end
88
+ children.each do |value|
89
+ dupped.children << if value.is_a?(Leaf)
90
+ # After inheritance we need to reload the state so the leafs are
91
+ # recompiled again
92
+ value = value.dup
93
+ value.compiled = false
94
+ value
95
+ else
96
+ value.deep_dup
97
+ end
97
98
  end
98
99
 
99
100
  dupped
@@ -37,9 +37,8 @@ module Karafka
37
37
  end
38
38
 
39
39
  # Allows for a per instance configuration (if needed)
40
- # @param block [Proc] block for configuration
41
- def configure(&block)
42
- config.configure(&block)
40
+ def configure(&)
41
+ config.configure(&)
43
42
  end
44
43
  end
45
44
 
@@ -58,9 +57,8 @@ module Karafka
58
57
  end
59
58
 
60
59
  # Allows for a per class configuration (if needed)
61
- # @param block [Proc] block for configuration
62
- def configure(&block)
63
- config.configure(&block)
60
+ def configure(&)
61
+ config.configure(&)
64
62
  end
65
63
 
66
64
  # Pipes the settings setup to the config root node
@@ -27,16 +27,15 @@ module Karafka
27
27
  # Allows for definition of a scope/namespace for nested validations
28
28
  #
29
29
  # @param path [Symbol] path in the hash for nesting
30
- # @param block [Proc] nested rule code or more nestings inside
31
30
  #
32
31
  # @example
33
32
  # nested(:key) do
34
33
  # required(:inside) { |inside| inside.is_a?(String) }
35
34
  # end
36
- def nested(path, &block)
35
+ def nested(path, &)
37
36
  init_accu
38
37
  @nested << path
39
- instance_eval(&block)
38
+ instance_eval(&)
40
39
  @nested.pop
41
40
  end
42
41
 
@@ -169,10 +168,8 @@ module Karafka
169
168
 
170
169
  return if result == true
171
170
 
172
- if result
173
- result.each do |sub_result|
174
- sub_result[0] = scope + sub_result[0]
175
- end
171
+ result&.each do |sub_result|
172
+ sub_result[0] = scope + sub_result[0]
176
173
  end
177
174
 
178
175
  errors.push(*result)
@@ -7,6 +7,11 @@ module Karafka
7
7
  class Result
8
8
  attr_reader :errors
9
9
 
10
+ # Empty hash that we use when no errors to save on allocations
11
+ EMPTY_HASH = {}.freeze
12
+
13
+ private_constant :EMPTY_HASH
14
+
10
15
  # Builds a result object and remaps (if needed) error keys to proper error messages
11
16
  #
12
17
  # @param errors [Array<Array>] array with sub-arrays with paths and error keys
@@ -14,7 +19,7 @@ module Karafka
14
19
  def initialize(errors, contract)
15
20
  # Short track to skip object allocation for the happy path
16
21
  if errors.empty?
17
- @errors = {}
22
+ @errors = EMPTY_HASH
18
23
  return
19
24
  end
20
25
 
@@ -13,7 +13,7 @@ module Karafka
13
13
  # RSpec.extend SupportEngine::RSpecLocator.new(__FILE__)
14
14
  class RSpecLocator < Module
15
15
  # @param spec_helper_file_path [String] path to the spec_helper.rb file
16
- # @param inflections [Hash<String, String>] optional inflections map
16
+ # @param inflections [Hash{String => String}] optional inflections map
17
17
  def initialize(spec_helper_file_path, inflections = {})
18
18
  super()
19
19
  @inflections = inflections
@@ -16,7 +16,7 @@ module Karafka
16
16
 
17
17
  # Hash access to the payload data (if present)
18
18
  #
19
- # @param [String, Symbol] name
19
+ # @param name [String, Symbol]
20
20
  def [](name)
21
21
  @payload.fetch(name)
22
22
  end
@@ -27,19 +27,15 @@ module Karafka
27
27
  #
28
28
  # @param event_id [String, Symbol] event id
29
29
  # @param payload [Hash]
30
- # @param block [Proc] block we want to instrument (if any)
31
- def instrument(event_id, payload = EMPTY_HASH, &block)
30
+ def instrument(event_id, payload = EMPTY_HASH, &)
32
31
  full_event_name = @mapped_events[event_id] ||= [event_id, @namespace].compact.join('.')
33
32
 
34
- @notifications_bus.instrument(full_event_name, payload, &block)
33
+ @notifications_bus.instrument(full_event_name, payload, &)
35
34
  end
36
35
 
37
36
  # Allows us to subscribe to the notification bus
38
- #
39
- # @param args [Array] any arguments that the notification bus subscription layer accepts
40
- # @param block [Proc] optional block for subscription
41
- def subscribe(*args, &block)
42
- @notifications_bus.subscribe(*args, &block)
37
+ def subscribe(*, &)
38
+ @notifications_bus.subscribe(*, &)
43
39
  end
44
40
 
45
41
  # Allows for removal of whatever was subscribed
@@ -50,14 +46,14 @@ module Karafka
50
46
  @notifications_bus.unsubscribe(listener_or_block)
51
47
  end
52
48
 
53
- # @return [Hash<String, Array>] hash where keys are events and values are arrays with
49
+ # @return [Hash{String => Array}] hash where keys are events and values are arrays with
54
50
  # listeners subscribed to particular events. Since different events may have different
55
51
  # listeners, this is returned that way.
56
52
  #
57
- # @note Please do not modify this hash. It should be used only for debugging.
58
- #
59
53
  # @example If you need to get only classes of listeners, you can run following code:
60
54
  # monitor.listeners.map(&:class)
55
+ #
56
+ # @note Please do not modify this hash. It should be used only for debugging.
61
57
  def listeners
62
58
  @notifications_bus.listeners
63
59
  end
@@ -107,7 +107,7 @@ module Karafka
107
107
  # Allows for code instrumentation
108
108
  # Runs the provided code and sends the instrumentation details to all registered listeners
109
109
  #
110
- # @param event_id [String] id of the event
110
+ # @param event_id [String]
111
111
  # @param payload [Hash] payload for the instrumentation
112
112
  # @yield [Proc] instrumented code
113
113
  # @return [Object] whatever the provided block (if any) returns
@@ -139,11 +139,31 @@ module Karafka
139
139
  return
140
140
  end
141
141
 
142
- event = Event.new(
143
- event_id,
144
- time ? payload.merge(time: time) : payload
145
- )
142
+ final_payload = build_payload(payload, time)
143
+ event = Event.new(event_id, final_payload)
146
144
 
145
+ notify_listeners(event_id, event, assigned_listeners)
146
+
147
+ result
148
+ end
149
+
150
+ private
151
+
152
+ # Builds the final payload with time information if available
153
+ # @param payload [Hash] original payload
154
+ # @param time [Float, nil] execution time if block was given
155
+ # @return [Hash] final payload
156
+ def build_payload(payload, time)
157
+ return payload unless time
158
+
159
+ payload.empty? ? { time: time } : payload.merge(time: time)
160
+ end
161
+
162
+ # Notifies all assigned listeners about the event
163
+ # @param event_id [String]
164
+ # @param event [Event] event object
165
+ # @param assigned_listeners [Array] list of listeners to notify
166
+ def notify_listeners(event_id, event, assigned_listeners)
147
167
  assigned_listeners.each do |listener|
148
168
  if listener.is_a?(Proc)
149
169
  listener.call(event)
@@ -151,8 +171,6 @@ module Karafka
151
171
  listener.send(@events_methods_map[event_id], event)
152
172
  end
153
173
  end
154
-
155
- result
156
174
  end
157
175
  end
158
176
  end
@@ -28,6 +28,8 @@ module Karafka
28
28
  # Operate on ms precision only
29
29
  @previous_at = monotonic_now.round
30
30
  @current_at = @previous_at
31
+ # Cache for memoized suffix keys to avoid repeated string allocations
32
+ @suffix_keys_cache = {}
31
33
  end
32
34
 
33
35
  # @param emited_stats [Hash] original emited statistics
@@ -62,16 +64,15 @@ module Karafka
62
64
  def diff(previous, current)
63
65
  if current.is_a?(Hash)
64
66
  filled_previous = previous || EMPTY_HASH
65
- filled_current = current || EMPTY_HASH
66
67
 
67
68
  # @note We cannot use #each_key as we modify the content of the current scope
68
69
  # in place (in case it's a hash)
69
70
  current.keys.each do |key|
70
71
  append(
71
72
  filled_previous,
72
- filled_current,
73
+ current,
73
74
  key,
74
- diff(filled_previous[key], filled_current[key])
75
+ diff(filled_previous[key], current[key])
75
76
  )
76
77
  end
77
78
  end
@@ -96,7 +97,7 @@ module Karafka
96
97
  return unless result.is_a?(Numeric)
97
98
  return if current.frozen?
98
99
 
99
- freeze_duration_key = "#{key}_fd"
100
+ freeze_duration_key, delta_key = suffix_keys_for(key)
100
101
 
101
102
  if result.zero?
102
103
  current[freeze_duration_key] = previous[freeze_duration_key] || 0
@@ -105,7 +106,18 @@ module Karafka
105
106
  current[freeze_duration_key] = 0
106
107
  end
107
108
 
108
- current["#{key}_d"] = result
109
+ current[delta_key] = result
110
+ end
111
+
112
+ # Returns memoized suffix keys for a given key to avoid repeated string allocations
113
+ #
114
+ # @param key [Object] the original key
115
+ # @return [Array<String>] frozen freeze_duration_key and delta_key
116
+ def suffix_keys_for(key)
117
+ @suffix_keys_cache[key] ||= [
118
+ "#{key}_fd".freeze,
119
+ "#{key}_d".freeze
120
+ ].freeze
109
121
  end
110
122
  end
111
123
  end
@@ -4,6 +4,6 @@ module Karafka
4
4
  module Core
5
5
  # Current Karafka::Core version
6
6
  # We follow the versioning schema of given Karafka version
7
- VERSION = '2.5.6'
7
+ VERSION = '2.5.8'
8
8
  end
9
9
  end
data/lib/karafka-core.rb CHANGED
@@ -28,10 +28,10 @@ module Karafka
28
28
  end
29
29
 
30
30
  # Patch rdkafka
31
- ::Rdkafka::Bindings.include(::Karafka::Core::Patches::Rdkafka::Bindings)
31
+ Rdkafka::Bindings.include(Karafka::Core::Patches::Rdkafka::Bindings)
32
32
 
33
- instrumentation = ::Karafka::Core::Instrumentation
34
- rd_config = ::Rdkafka::Config
33
+ instrumentation = Karafka::Core::Instrumentation
34
+ rd_config = Rdkafka::Config
35
35
 
36
36
  # Rdkafka uses a single global callback for things. We bypass that by injecting a manager for
37
37
  # each callback type. Callback manager allows us to register more than one callback
@@ -43,4 +43,4 @@ rd_config.oauthbearer_token_refresh_callback = instrumentation.oauthbearer_token
43
43
  # This loads librdkafka components into memory prior to initializing the client.
44
44
  # This mitigates macos forking issues.
45
45
  # @see https://github.com/confluentinc/librdkafka/issues/4590
46
- ::Rdkafka::Bindings.rd_kafka_global_init if ::Rdkafka::Bindings.respond_to?(:rd_kafka_global_init)
46
+ Rdkafka::Bindings.rd_kafka_global_init if Rdkafka::Bindings.respond_to?(:rd_kafka_global_init)
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.5.6
4
+ version: 2.5.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Maciej Mensfeld
@@ -46,7 +46,6 @@ extra_rdoc_files: []
46
46
  files:
47
47
  - ".coditsu/ci.yml"
48
48
  - ".console_irbrc"
49
- - ".diffend.yml"
50
49
  - ".github/CODEOWNERS"
51
50
  - ".github/FUNDING.yml"
52
51
  - ".github/ISSUE_TEMPLATE/bug_report.md"
@@ -59,6 +58,7 @@ files:
59
58
  - ".rspec"
60
59
  - ".ruby-gemset"
61
60
  - ".ruby-version"
61
+ - ".yard-lint.yml"
62
62
  - CHANGELOG.md
63
63
  - CODE_OF_CONDUCT.md
64
64
  - Gemfile
@@ -109,7 +109,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
109
109
  requirements:
110
110
  - - ">="
111
111
  - !ruby/object:Gem::Version
112
- version: 3.1.0
112
+ version: 3.2.0
113
113
  required_rubygems_version: !ruby/object:Gem::Requirement
114
114
  requirements:
115
115
  - - ">="
data/.diffend.yml DELETED
@@ -1,3 +0,0 @@
1
- project_id: '199f1b30-ba87-49e1-96d8-f4ea86732443'
2
- shareable_id: '6a6f2b22-021c-40cd-885c-82838f84f2f9'
3
- shareable_key: '9c7e0a66-7bff-4b90-9528-69d8d4c0bba4'