Skip to content

Commit

Permalink
draft3
Browse files Browse the repository at this point in the history
  • Loading branch information
hkim3163 committed Jun 21, 2023
1 parent a2e8241 commit 4e9c829
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 99 deletions.
2 changes: 0 additions & 2 deletions lib/sidekiq/instrument/worker_metrics.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ def trace_workers_increment_counter(klass_name, sidekiq_redis_pool_user)
return unless enabled?

Sidekiq.redis do |redis|
# redis.hsetnx(worker_metric_name, klass_name, 0)
redis.hincrby(worker_metric_name, klass_name, 1)
end
end
Expand All @@ -23,7 +22,6 @@ def trace_workers_decrement_counter(klass_name)
return unless enabled?

Sidekiq.redis do |redis|
# redis.hsetnx(worker_metric_name, klass_name, 0)
redis.hincrby(worker_metric_name, klass_name, -1)
end
end
Expand Down
95 changes: 0 additions & 95 deletions spec/sidekiq-instrument/worker_metrics_spec.rb

This file was deleted.

15 changes: 13 additions & 2 deletions spec/sidekiq-instrument/worker_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@

context 'when jobs in queues' do
before do
Sidekiq.disable! do
Sidekiq::Testing.disable! do
Sidekiq::Queue.all.each(&:clear)
MyWorker.perform_async
end
Expand Down Expand Up @@ -121,7 +121,7 @@
end

context 'with server and client middleware' do
# let(:expected_dog_options) { { tags: ['queue:default', 'worker:my_worker'] } }
let(:expected_dog_options) { { tags: ['queue:default', 'worker:my_other_worker'] } }
let(:worker_metric_name) do
"sidekiq_instrument_trace_workers::in_queue"
end
Expand Down Expand Up @@ -160,6 +160,17 @@
MyOtherWorker.perform_async
expect(redis.hget(worker_metric_name ,'my_other_worker')).to eq('2')
end

it 'increments the DogStatsD failure counter' do
expect(Sidekiq::Instrument::Statter.dogstatsd).to receive(:increment).with('sidekiq.enqueue', expected_dog_options).once
expect(Sidekiq::Instrument::Statter.dogstatsd).not_to receive(:time)
MyOtherWorker.perform_async rescue nil
end

it 'does not increase the redis counter' do
expect(Redis.new.hget worker_metric_name ,'my_worker').to eq(nil)
MyOtherWorker.perform_async rescue nil
end
end
end
end

0 comments on commit 4e9c829

Please sign in to comment.