Skip to content

Commit

Permalink
Blacklisted queues should not send general metrics
Browse files Browse the repository at this point in the history
When the middleware is called and a blacklisted queue is referenced,
we should short-circuit processing altogether and not even query/report 
the general set of metrics.
  • Loading branch information
Jay Zeschin committed Sep 21, 2015
1 parent 6732198 commit 1cb6994
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 21 deletions.
3 changes: 1 addition & 2 deletions lib/librato-sidekiq/middleware.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def call(worker_instance, msg, queue, redis_pool = nil)
result = yield
elapsed = (Time.now - start_time).to_f

return result unless enabled
return result unless enabled && allowed_to_submit(queue, worker_instance)
# puts "#{worker_instance} #{queue}"

stats = ::Sidekiq::Stats.new
Expand All @@ -76,7 +76,6 @@ def call(worker_instance, msg, queue, redis_pool = nil)

def track(tracking_group, stats, worker_instance, msg, queue, elapsed)
submit_general_stats tracking_group, stats
return unless allowed_to_submit queue, worker_instance
# puts "doing Librato insert"
tracking_group.group queue.to_s do |q|
q.increment 'processed'
Expand Down
7 changes: 2 additions & 5 deletions spec/unit/client_middleware_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,8 @@
middleware.blacklist_queues << queue_name
end

it { expect { |b| middleware.call(some_worker_instance, some_message, queue_name, &b) }.to yield_with_no_args }

it 'should measure increment queued metric' do
expect(meter).to receive(:increment).with 'queued'
middleware.call(some_worker_instance, some_message, queue_name) {}
it 'should not send any metrics' do
Librato.should_not_receive(:group)
end

end
Expand Down
16 changes: 2 additions & 14 deletions spec/unit/middleware_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,20 +87,8 @@
middleware.blacklist_queues << queue_name
end

it { expect { |b| middleware.call(some_worker_instance, some_message, queue_name, &b) }.to yield_with_no_args }

it 'should measure increment processed metric' do
expect(meter).to receive(:increment).with "processed"
middleware.call(some_worker_instance, some_message, queue_name) {}
end

it 'should measure general metrics' do
{"enqueued" => 1, "failed" => 2, "scheduled" => 3 }.each do |method, stat|
expect(meter).to receive(:measure).with(method.to_s, stat)
end
expect(meter).to receive(:increment).with "processed"

middleware.call(some_worker_instance, some_message, queue_name) {}
it 'should not send any metrics' do
Librato.should_not_receive(:group)
end

end
Expand Down

0 comments on commit 1cb6994

Please sign in to comment.