Skip to content

Commit 9f0fa7b

Browse files
authored
Merge pull request #34 from Fatsoma/ENG-549-log-queue-size
Log action queue size on channel disconnect
2 parents 437ef4a + 8eee117 commit 9f0fa7b

2 files changed

Lines changed: 28 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: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,23 @@
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(:instrumentation)
11+
allow(honey_badger).to receive(:notify)
12+
allow(logger).to receive(:info)
13+
allow(logger).to receive(:error)
14+
allow(channel_broker).to receive(:logger).and_return(logger)
815
end
916
let!(:config) { @config }
1017
after do
1118
Hutch::Config.instance_variable_set(:@config, nil)
1219
Hutch::Config.initialize
1320
end
21+
let(:logger) { double(:logger) }
1422
let(:connection) { double(:connection) }
1523
let(:channel) { double(:channel) }
24+
let(:honey_badger) { double(:honey_badger) }
1625

1726
subject(:channel_broker) { Hutch::ChannelBroker.new(connection, config) }
1827

@@ -143,17 +152,16 @@ def test_on_error(*args)
143152
def confirm_select; end
144153
end.new
145154
end
146-
let(:honey_badger) { double(:honey_badger) }
147155
let(:config) { {} }
148156
let(:method) { Class.new }
157+
let(:action_queue_size) { 5 }
149158

150159
before do
151-
stub_const('Honeybadger', honey_badger)
152-
allow(honey_badger).to receive(:add_breadcrumb)
153-
allow(honey_badger).to receive(:notify)
154160
allow(connection).to receive(:create_channel).and_return(channel)
155161
allow(connection).to receive(:prefetch_channel)
156162
allow(channel).to receive(:confirm_select)
163+
allow(Thread.main).to receive(:[]).with(:action_queue)
164+
.and_return(double(size: action_queue_size))
157165
end
158166

159167
subject { channel_broker.open_channel }
@@ -204,7 +212,8 @@ def confirm_select; end
204212
let(:context) do
205213
{
206214
reply_code: reply_code,
207-
method: method.inspect
215+
method: method.inspect,
216+
action_queue_size: action_queue_size
208217
}
209218
end
210219

@@ -225,7 +234,8 @@ def confirm_select; end
225234
end
226235
let(:context) do
227236
{
228-
method: method.inspect
237+
method: method.inspect,
238+
action_queue_size: action_queue_size
229239
}
230240
end
231241

0 commit comments

Comments
 (0)