karafka-core 2.5.11 → 2.5.13
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 +3 -3
- data/.github/workflows/push.yml +2 -2
- data/CHANGELOG.md +6 -0
- data/Gemfile.lock +1 -1
- data/karafka-core.gemspec +1 -1
- data/lib/karafka/core/monitoring/statistics_decorator.rb +14 -4
- data/lib/karafka/core/version.rb +1 -1
- metadata +1 -25
- data/test/lib/karafka/core/configurable/leaf_test.rb +0 -3
- data/test/lib/karafka/core/configurable/node_test.rb +0 -3
- data/test/lib/karafka/core/configurable_test.rb +0 -504
- data/test/lib/karafka/core/contractable/contract_test.rb +0 -241
- data/test/lib/karafka/core/contractable/result_test.rb +0 -106
- data/test/lib/karafka/core/contractable/rule_test.rb +0 -5
- data/test/lib/karafka/core/contractable_test.rb +0 -3
- data/test/lib/karafka/core/helpers/time_test.rb +0 -29
- data/test/lib/karafka/core/instrumentation/callbacks_manager_test.rb +0 -81
- data/test/lib/karafka/core/instrumentation_test.rb +0 -35
- data/test/lib/karafka/core/monitoring/event_test.rb +0 -62
- data/test/lib/karafka/core/monitoring/monitor_test.rb +0 -237
- data/test/lib/karafka/core/monitoring/notifications_test.rb +0 -275
- data/test/lib/karafka/core/monitoring/statistics_decorator_test.rb +0 -503
- data/test/lib/karafka/core/monitoring_test.rb +0 -3
- data/test/lib/karafka/core/patches/rdkafka/bindings_test.rb +0 -25
- data/test/lib/karafka/core/taggable/tags_test.rb +0 -66
- data/test/lib/karafka/core/taggable_test.rb +0 -36
- data/test/lib/karafka/core/version_test.rb +0 -5
- data/test/lib/karafka/core_test.rb +0 -13
- data/test/lib/karafka-core_test.rb +0 -3
- data/test/support/class_builder.rb +0 -24
- data/test/support/describe_current_helper.rb +0 -41
- data/test/test_helper.rb +0 -55
|
@@ -1,237 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
describe_current do
|
|
4
|
-
subject(:monitor) do
|
|
5
|
-
described_class.new(
|
|
6
|
-
notifications_bus,
|
|
7
|
-
namespace
|
|
8
|
-
)
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
let(:notifications_bus) { Karafka::Core::Monitoring::Notifications.new }
|
|
12
|
-
|
|
13
|
-
before do
|
|
14
|
-
notifications_bus.register_event("test")
|
|
15
|
-
notifications_bus.register_event("test.namespace")
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
context "when we do not use any namespace" do
|
|
19
|
-
let(:namespace) { nil }
|
|
20
|
-
let(:collected_data) { [] }
|
|
21
|
-
|
|
22
|
-
before do
|
|
23
|
-
collected = collected_data
|
|
24
|
-
|
|
25
|
-
monitor.subscribe("test") do |event|
|
|
26
|
-
collected << event
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
monitor.instrument("test") { 1 }
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
it { assert_equal 1, collected_data.size }
|
|
33
|
-
it { assert_equal "test", collected_data.first.id }
|
|
34
|
-
it { assert_includes monitor.listeners.keys, "test" }
|
|
35
|
-
it { assert_kind_of Array, monitor.listeners["test"] }
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
context "when we do use a namespace" do
|
|
39
|
-
let(:namespace) { "namespace" }
|
|
40
|
-
let(:collected_data) { [] }
|
|
41
|
-
|
|
42
|
-
before do
|
|
43
|
-
collected = collected_data
|
|
44
|
-
|
|
45
|
-
monitor.subscribe("test.namespace") do |event|
|
|
46
|
-
collected << event
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
monitor.instrument("test") { 1 }
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
it { assert_equal 1, collected_data.size }
|
|
53
|
-
it { assert_equal "test.namespace", collected_data.first.id }
|
|
54
|
-
it { assert_includes monitor.listeners.keys, "test" }
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
describe "#unsubscribe" do
|
|
58
|
-
context "when we do not use any namespace" do
|
|
59
|
-
let(:namespace) { nil }
|
|
60
|
-
let(:collected_data) { [] }
|
|
61
|
-
let(:block_listener) do
|
|
62
|
-
proc do |event|
|
|
63
|
-
collected_data << event
|
|
64
|
-
end
|
|
65
|
-
end
|
|
66
|
-
|
|
67
|
-
before do
|
|
68
|
-
monitor.subscribe("test", &block_listener)
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
it "expect to remove the listener from the event" do
|
|
72
|
-
monitor.unsubscribe(block_listener)
|
|
73
|
-
monitor.instrument("test") { 1 }
|
|
74
|
-
|
|
75
|
-
assert_empty collected_data
|
|
76
|
-
end
|
|
77
|
-
|
|
78
|
-
it "expect to remove the listener from the notifications bus listeners" do
|
|
79
|
-
assert_includes monitor.listeners["test"], block_listener
|
|
80
|
-
monitor.unsubscribe(block_listener)
|
|
81
|
-
|
|
82
|
-
refute_includes monitor.listeners["test"], block_listener
|
|
83
|
-
end
|
|
84
|
-
end
|
|
85
|
-
|
|
86
|
-
context "when we do use a namespace" do
|
|
87
|
-
let(:namespace) { "namespace" }
|
|
88
|
-
let(:collected_data) { [] }
|
|
89
|
-
let(:block_listener) do
|
|
90
|
-
proc do |event|
|
|
91
|
-
collected_data << event
|
|
92
|
-
end
|
|
93
|
-
end
|
|
94
|
-
|
|
95
|
-
before do
|
|
96
|
-
monitor.subscribe("test.namespace", &block_listener)
|
|
97
|
-
end
|
|
98
|
-
|
|
99
|
-
it "expect to remove the listener from the namespaced event" do
|
|
100
|
-
monitor.unsubscribe(block_listener)
|
|
101
|
-
monitor.instrument("test") { 1 }
|
|
102
|
-
|
|
103
|
-
assert_empty collected_data
|
|
104
|
-
end
|
|
105
|
-
|
|
106
|
-
it "expect to remove the listener from the notifications bus listeners" do
|
|
107
|
-
assert_includes monitor.listeners["test.namespace"], block_listener
|
|
108
|
-
monitor.unsubscribe(block_listener)
|
|
109
|
-
|
|
110
|
-
refute_includes monitor.listeners["test.namespace"], block_listener
|
|
111
|
-
end
|
|
112
|
-
end
|
|
113
|
-
|
|
114
|
-
context "when we have an object listener" do
|
|
115
|
-
let(:namespace) { nil }
|
|
116
|
-
let(:listener_class) do
|
|
117
|
-
Class.new do
|
|
118
|
-
attr_reader :accu
|
|
119
|
-
|
|
120
|
-
def initialize
|
|
121
|
-
@accu = []
|
|
122
|
-
end
|
|
123
|
-
|
|
124
|
-
def on_test(event)
|
|
125
|
-
@accu << event
|
|
126
|
-
end
|
|
127
|
-
end
|
|
128
|
-
end
|
|
129
|
-
|
|
130
|
-
let(:listener) { listener_class.new }
|
|
131
|
-
|
|
132
|
-
before do
|
|
133
|
-
monitor.subscribe(listener)
|
|
134
|
-
end
|
|
135
|
-
|
|
136
|
-
it "expect to remove the object listener" do
|
|
137
|
-
monitor.unsubscribe(listener)
|
|
138
|
-
monitor.instrument("test") { 1 }
|
|
139
|
-
|
|
140
|
-
assert_empty listener.accu
|
|
141
|
-
end
|
|
142
|
-
|
|
143
|
-
it "expect to remove the listener from the notifications bus listeners" do
|
|
144
|
-
assert_includes monitor.listeners["test"], listener
|
|
145
|
-
monitor.unsubscribe(listener)
|
|
146
|
-
|
|
147
|
-
refute_includes monitor.listeners["test"], listener
|
|
148
|
-
end
|
|
149
|
-
end
|
|
150
|
-
|
|
151
|
-
context "when trying to unsubscribe a listener that was never subscribed" do
|
|
152
|
-
let(:namespace) { nil }
|
|
153
|
-
let(:unsubscribed_listener) do
|
|
154
|
-
proc { |event| event }
|
|
155
|
-
end
|
|
156
|
-
|
|
157
|
-
it "expect not to raise any errors" do
|
|
158
|
-
monitor.unsubscribe(unsubscribed_listener)
|
|
159
|
-
end
|
|
160
|
-
end
|
|
161
|
-
|
|
162
|
-
context "when multiple listeners are subscribed and we unsubscribe one" do
|
|
163
|
-
let(:namespace) { nil }
|
|
164
|
-
let(:first_collected) { [] }
|
|
165
|
-
let(:second_collected) { [] }
|
|
166
|
-
|
|
167
|
-
let(:first_listener) do
|
|
168
|
-
proc { |event| first_collected << event }
|
|
169
|
-
end
|
|
170
|
-
|
|
171
|
-
let(:second_listener) do
|
|
172
|
-
proc { |event| second_collected << event }
|
|
173
|
-
end
|
|
174
|
-
|
|
175
|
-
let(:first_listener_added) do
|
|
176
|
-
monitor.listeners["test"][0]
|
|
177
|
-
end
|
|
178
|
-
|
|
179
|
-
before do
|
|
180
|
-
monitor.subscribe("test", &first_listener)
|
|
181
|
-
monitor.subscribe("test", &second_listener)
|
|
182
|
-
first_listener_added
|
|
183
|
-
end
|
|
184
|
-
|
|
185
|
-
it "expect to only remove the specified listener" do
|
|
186
|
-
monitor.unsubscribe(first_listener_added)
|
|
187
|
-
monitor.instrument("test") { 1 }
|
|
188
|
-
|
|
189
|
-
assert_empty first_collected
|
|
190
|
-
refute_empty second_collected
|
|
191
|
-
end
|
|
192
|
-
|
|
193
|
-
it "expect to keep the other listener in the listeners hash" do
|
|
194
|
-
assert_includes monitor.listeners["test"], first_listener
|
|
195
|
-
assert_includes monitor.listeners["test"], second_listener
|
|
196
|
-
monitor.unsubscribe(first_listener_added)
|
|
197
|
-
|
|
198
|
-
refute_includes monitor.listeners["test"], first_listener_added
|
|
199
|
-
assert_includes monitor.listeners["test"], second_listener
|
|
200
|
-
end
|
|
201
|
-
end
|
|
202
|
-
|
|
203
|
-
context "when listener is subscribed to multiple events" do
|
|
204
|
-
let(:namespace) { nil }
|
|
205
|
-
let(:collected_data) { [] }
|
|
206
|
-
let(:multi_event_listener) do
|
|
207
|
-
Class.new do
|
|
208
|
-
attr_reader :accu
|
|
209
|
-
|
|
210
|
-
def initialize
|
|
211
|
-
@accu = []
|
|
212
|
-
end
|
|
213
|
-
|
|
214
|
-
def on_test(event)
|
|
215
|
-
@accu << event
|
|
216
|
-
end
|
|
217
|
-
|
|
218
|
-
def on_test_namespace(event)
|
|
219
|
-
@accu << event
|
|
220
|
-
end
|
|
221
|
-
end.new
|
|
222
|
-
end
|
|
223
|
-
|
|
224
|
-
before do
|
|
225
|
-
monitor.subscribe(multi_event_listener)
|
|
226
|
-
end
|
|
227
|
-
|
|
228
|
-
it "expect to remove the listener from all events" do
|
|
229
|
-
monitor.unsubscribe(multi_event_listener)
|
|
230
|
-
monitor.instrument("test") { 1 }
|
|
231
|
-
monitor.instrument("test.namespace") { 1 }
|
|
232
|
-
|
|
233
|
-
assert_empty multi_event_listener.accu
|
|
234
|
-
end
|
|
235
|
-
end
|
|
236
|
-
end
|
|
237
|
-
end
|
|
@@ -1,275 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
describe_current do
|
|
4
|
-
subject(:notifications) { described_class.new }
|
|
5
|
-
|
|
6
|
-
let(:event_name) { "message.produced_async" }
|
|
7
|
-
let(:event_not_registered_error) { Karafka::Core::Monitoring::Notifications::EventNotRegistered }
|
|
8
|
-
|
|
9
|
-
before { notifications.register_event(event_name) }
|
|
10
|
-
|
|
11
|
-
describe "#instrument" do
|
|
12
|
-
let(:result) { rand }
|
|
13
|
-
let(:instrumentation) do
|
|
14
|
-
notifications.instrument(
|
|
15
|
-
event_name,
|
|
16
|
-
call: self,
|
|
17
|
-
error: StandardError
|
|
18
|
-
) { result }
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
it "expect to return blocks execution value" do
|
|
22
|
-
assert_equal result, instrumentation
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
context "when we want to instrument event that was not registered" do
|
|
26
|
-
it "expect to raise error" do
|
|
27
|
-
expected_error = event_not_registered_error
|
|
28
|
-
assert_raises(expected_error) { notifications.instrument("na") }
|
|
29
|
-
end
|
|
30
|
-
end
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
describe "#subscribe" do
|
|
34
|
-
context "when we have a block based listener" do
|
|
35
|
-
let(:subscription) { notifications.subscribe(event_name) { |_event| nil } }
|
|
36
|
-
|
|
37
|
-
context "when we try to subscribe to an unsupported event" do
|
|
38
|
-
it "expect to raise error" do
|
|
39
|
-
expected_error = event_not_registered_error
|
|
40
|
-
assert_raises(expected_error) { notifications.subscribe("na") { |_event| nil } }
|
|
41
|
-
end
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
context "when we try to subscribe to a supported event" do
|
|
45
|
-
let(:event_name) { "message.produced_async" }
|
|
46
|
-
|
|
47
|
-
it { subscription }
|
|
48
|
-
end
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
context "when we have an object listener" do
|
|
52
|
-
let(:subscription) { notifications.subscribe(listener.new) }
|
|
53
|
-
let(:listener) do
|
|
54
|
-
Class.new do
|
|
55
|
-
def on_message_produced_async(_event)
|
|
56
|
-
true
|
|
57
|
-
end
|
|
58
|
-
end
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
it { subscription }
|
|
62
|
-
end
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
describe "#unsubscribe" do
|
|
66
|
-
context "when we have a block based listener" do
|
|
67
|
-
let(:tracked) { [] }
|
|
68
|
-
let(:block_listener) do
|
|
69
|
-
proc do |event|
|
|
70
|
-
tracked << event
|
|
71
|
-
end
|
|
72
|
-
end
|
|
73
|
-
|
|
74
|
-
before do
|
|
75
|
-
notifications.subscribe(event_name, &block_listener)
|
|
76
|
-
end
|
|
77
|
-
|
|
78
|
-
it "expect to remove the block from the event" do
|
|
79
|
-
notifications.unsubscribe(block_listener)
|
|
80
|
-
notifications.instrument(event_name)
|
|
81
|
-
|
|
82
|
-
assert_empty tracked
|
|
83
|
-
end
|
|
84
|
-
|
|
85
|
-
context "when the same block is subscribed to multiple events" do
|
|
86
|
-
let(:second_event) { "message.consumed" }
|
|
87
|
-
|
|
88
|
-
before do
|
|
89
|
-
notifications.register_event(second_event)
|
|
90
|
-
notifications.subscribe(second_event, &block_listener)
|
|
91
|
-
end
|
|
92
|
-
|
|
93
|
-
it "expect to remove the block from all events" do
|
|
94
|
-
notifications.unsubscribe(block_listener)
|
|
95
|
-
notifications.instrument(event_name)
|
|
96
|
-
notifications.instrument(second_event)
|
|
97
|
-
|
|
98
|
-
assert_empty tracked
|
|
99
|
-
end
|
|
100
|
-
end
|
|
101
|
-
end
|
|
102
|
-
|
|
103
|
-
context "when we have an object listener" do
|
|
104
|
-
let(:listener_class) do
|
|
105
|
-
Class.new do
|
|
106
|
-
attr_reader :accu
|
|
107
|
-
|
|
108
|
-
def initialize
|
|
109
|
-
@accu = []
|
|
110
|
-
end
|
|
111
|
-
|
|
112
|
-
def on_message_produced_async(event)
|
|
113
|
-
@accu << event
|
|
114
|
-
end
|
|
115
|
-
|
|
116
|
-
def on_message_consumed(event)
|
|
117
|
-
@accu << event
|
|
118
|
-
end
|
|
119
|
-
end
|
|
120
|
-
end
|
|
121
|
-
|
|
122
|
-
let(:listener) { listener_class.new }
|
|
123
|
-
|
|
124
|
-
before do
|
|
125
|
-
notifications.subscribe(listener)
|
|
126
|
-
end
|
|
127
|
-
|
|
128
|
-
it "expect to remove the listener from the event" do
|
|
129
|
-
notifications.unsubscribe(listener)
|
|
130
|
-
notifications.instrument(event_name)
|
|
131
|
-
|
|
132
|
-
assert_empty listener.accu
|
|
133
|
-
end
|
|
134
|
-
|
|
135
|
-
context "when the listener is subscribed to multiple events" do
|
|
136
|
-
let(:second_event) { "message.consumed" }
|
|
137
|
-
|
|
138
|
-
before do
|
|
139
|
-
notifications.register_event(second_event)
|
|
140
|
-
notifications.subscribe(listener)
|
|
141
|
-
end
|
|
142
|
-
|
|
143
|
-
it "expect to remove the listener from all events" do
|
|
144
|
-
notifications.unsubscribe(listener)
|
|
145
|
-
notifications.instrument(event_name)
|
|
146
|
-
notifications.instrument(second_event)
|
|
147
|
-
|
|
148
|
-
assert_empty listener.accu
|
|
149
|
-
end
|
|
150
|
-
end
|
|
151
|
-
end
|
|
152
|
-
|
|
153
|
-
context "when trying to unsubscribe a listener that was never subscribed" do
|
|
154
|
-
let(:unsubscribed_listener) do
|
|
155
|
-
Class.new do
|
|
156
|
-
def on_message_produced_async(_event)
|
|
157
|
-
true
|
|
158
|
-
end
|
|
159
|
-
end.new
|
|
160
|
-
end
|
|
161
|
-
|
|
162
|
-
it "expect not to raise any errors" do
|
|
163
|
-
notifications.unsubscribe(unsubscribed_listener)
|
|
164
|
-
end
|
|
165
|
-
end
|
|
166
|
-
|
|
167
|
-
context "when multiple listeners are subscribed and we unsubscribe one" do
|
|
168
|
-
let(:tracked_first) { [] }
|
|
169
|
-
let(:tracked_second) { [] }
|
|
170
|
-
|
|
171
|
-
let(:first_listener) do
|
|
172
|
-
proc { |event| tracked_first << event }
|
|
173
|
-
end
|
|
174
|
-
|
|
175
|
-
let(:second_listener) do
|
|
176
|
-
proc { |event| tracked_second << event }
|
|
177
|
-
end
|
|
178
|
-
|
|
179
|
-
before do
|
|
180
|
-
notifications.subscribe(event_name, &first_listener)
|
|
181
|
-
notifications.subscribe(event_name, &second_listener)
|
|
182
|
-
end
|
|
183
|
-
|
|
184
|
-
it "expect to only remove the specified listener" do
|
|
185
|
-
notifications.unsubscribe(first_listener)
|
|
186
|
-
notifications.instrument(event_name)
|
|
187
|
-
|
|
188
|
-
assert_empty tracked_first
|
|
189
|
-
refute_empty tracked_second
|
|
190
|
-
end
|
|
191
|
-
end
|
|
192
|
-
end
|
|
193
|
-
|
|
194
|
-
describe "#available_events" do
|
|
195
|
-
it { assert_equal [event_name], notifications.available_events }
|
|
196
|
-
end
|
|
197
|
-
|
|
198
|
-
describe "#clear" do
|
|
199
|
-
describe "without an argument" do
|
|
200
|
-
before { notifications.subscribe(event_name) { raise } }
|
|
201
|
-
|
|
202
|
-
it "expect not to raise any errors as after clearing subscription should no longer work" do
|
|
203
|
-
notifications.clear
|
|
204
|
-
notifications.instrument(event_name)
|
|
205
|
-
end
|
|
206
|
-
end
|
|
207
|
-
|
|
208
|
-
describe "one event given" do
|
|
209
|
-
let(:instrumented) { [] }
|
|
210
|
-
|
|
211
|
-
before do
|
|
212
|
-
notifications.register_event("some-other-event")
|
|
213
|
-
notifications.subscribe(event_name) { instrumented.push(1) }
|
|
214
|
-
notifications.subscribe("some-other-event") { instrumented.push(2) }
|
|
215
|
-
end
|
|
216
|
-
|
|
217
|
-
it "expect to only get one event" do
|
|
218
|
-
notifications.clear("some-other-event")
|
|
219
|
-
notifications.instrument(event_name)
|
|
220
|
-
notifications.instrument("some-other-event")
|
|
221
|
-
|
|
222
|
-
assert_equal [1], instrumented
|
|
223
|
-
end
|
|
224
|
-
end
|
|
225
|
-
|
|
226
|
-
describe "clearing non-existing event" do
|
|
227
|
-
it "expect to raise an error" do
|
|
228
|
-
assert_raises(event_not_registered_error) {
|
|
229
|
-
notifications.clear("some-nonexistent-event")
|
|
230
|
-
}
|
|
231
|
-
end
|
|
232
|
-
end
|
|
233
|
-
end
|
|
234
|
-
|
|
235
|
-
describe "subscription and instrumentation flow" do
|
|
236
|
-
context "when we subscribe with a proc listener" do
|
|
237
|
-
let(:tracked) { [] }
|
|
238
|
-
|
|
239
|
-
before do
|
|
240
|
-
notifications.subscribe(event_name) do |event|
|
|
241
|
-
tracked << event
|
|
242
|
-
end
|
|
243
|
-
|
|
244
|
-
notifications.instrument(event_name)
|
|
245
|
-
end
|
|
246
|
-
|
|
247
|
-
it { assert_equal event_name, tracked[0].id }
|
|
248
|
-
end
|
|
249
|
-
|
|
250
|
-
context "when we subscribe with a class listener" do
|
|
251
|
-
let(:listener_class) do
|
|
252
|
-
Class.new do
|
|
253
|
-
attr_reader :accu
|
|
254
|
-
|
|
255
|
-
def initialize
|
|
256
|
-
@accu = []
|
|
257
|
-
end
|
|
258
|
-
|
|
259
|
-
def on_message_produced_async(event)
|
|
260
|
-
@accu << event
|
|
261
|
-
end
|
|
262
|
-
end
|
|
263
|
-
end
|
|
264
|
-
|
|
265
|
-
let(:listener) { listener_class.new }
|
|
266
|
-
|
|
267
|
-
before do
|
|
268
|
-
notifications.subscribe(listener)
|
|
269
|
-
notifications.instrument(event_name)
|
|
270
|
-
end
|
|
271
|
-
|
|
272
|
-
it { assert_equal event_name, listener.accu[0].id }
|
|
273
|
-
end
|
|
274
|
-
end
|
|
275
|
-
end
|