Skip to content

Commit 32bd83b

Browse files
committed
Log action queue size on channel disconnect
Ticket: https://fatsoma.atlassian.net/browse/ENG-549 Print and report the main thread action queue size when a channel is closed on error. This is to check the main thread is effectively servicing the queued messages sent from the workers.
1 parent 437ef4a commit 32bd83b

2 files changed

Lines changed: 23 additions & 9 deletions

File tree

lib/hutch/channel_broker.rb

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,18 @@ def open_channel
6666

6767
# on_error handler logs and notifies any unhandled channel errors
6868
ch.on_error do |channel, method|
69-
logger.error "Channel error [channel=#{channel.inspect}, method=#{method.inspect}, active=#{active}]"
70-
71-
context = {method: method.inspect}
69+
action_queue_size = Thread.main[:action_queue].size
70+
71+
logger.error("Channel error [channel=#{channel.inspect}, " \
72+
"method=#{method.inspect}, " \
73+
"active=#{active}, " \
74+
"action_queue_size=#{action_queue_size}]"
75+
)
76+
77+
context = {
78+
method: method.inspect,
79+
action_queue_size: action_queue_size
80+
}
7281
if method.is_a?(AMQ::Protocol::Channel::Close)
7382
error_message = method.reply_text
7483
context[:reply_code] = method.reply_code

spec/hutch/channel_broker_spec.rb

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
before do
66
Hutch::Config.initialize(client_logger: Hutch::Logging.logger)
77
@config = Hutch::Config.to_hash
8+
stub_const('Honeybadger', honey_badger)
9+
allow(honey_badger).to receive(:add_breadcrumb)
10+
allow(honey_badger).to receive(:notify)
811
end
912
let!(:config) { @config }
1013
after do
@@ -13,6 +16,7 @@
1316
end
1417
let(:connection) { double(:connection) }
1518
let(:channel) { double(:channel) }
19+
let(:honey_badger) { double(:honey_badger) }
1620

1721
subject(:channel_broker) { Hutch::ChannelBroker.new(connection, config) }
1822

@@ -143,17 +147,16 @@ def test_on_error(*args)
143147
def confirm_select; end
144148
end.new
145149
end
146-
let(:honey_badger) { double(:honey_badger) }
147150
let(:config) { {} }
148151
let(:method) { Class.new }
152+
let(:action_queue_size) { 5 }
149153

150154
before do
151-
stub_const('Honeybadger', honey_badger)
152-
allow(honey_badger).to receive(:add_breadcrumb)
153-
allow(honey_badger).to receive(:notify)
154155
allow(connection).to receive(:create_channel).and_return(channel)
155156
allow(connection).to receive(:prefetch_channel)
156157
allow(channel).to receive(:confirm_select)
158+
allow(Thread.main).to receive(:[]).with(:action_queue)
159+
.and_return(double(size: action_queue_size))
157160
end
158161

159162
subject { channel_broker.open_channel }
@@ -204,7 +207,8 @@ def confirm_select; end
204207
let(:context) do
205208
{
206209
reply_code: reply_code,
207-
method: method.inspect
210+
method: method.inspect,
211+
action_queue_size: action_queue_size
208212
}
209213
end
210214

@@ -225,7 +229,8 @@ def confirm_select; end
225229
end
226230
let(:context) do
227231
{
228-
method: method.inspect
232+
method: method.inspect,
233+
action_queue_size: action_queue_size
229234
}
230235
end
231236

0 commit comments

Comments
 (0)