diff --git a/README.md b/README.md index 8364e00..2a2e446 100644 --- a/README.md +++ b/README.md @@ -81,9 +81,10 @@ For each job, the following metrics will be reported: job is pushed onto the queue. 3. **shared.sidekiq._queue_._job_.dequeue**: counter incremented just before worker begins performing a job. -4. **shared.sidekiq._queue_._job_.runtime**: timer of the total time spent +4. **shared.sidekiq._queue_._job_.success**: counter incremented each time a job succeeds. +5. **shared.sidekiq._queue_._job_.runtime**: timer of the total time spent in `perform`, in milliseconds. -5. **shared.sidekiq._queue_._job_.error**: counter incremented each time a +6. **shared.sidekiq._queue_._job_.error**: counter incremented each time a job fails. For job retry attempts, metrics 2-5 will still be reported but the enqueue/dequeue metrics @@ -111,9 +112,10 @@ For each job, the following metrics and tags will be reported: job is pushed onto the queue. 3. **sidekiq.dequeue (tags: {queue: _queue_, worker: _job_})**: counter incremented just before worker begins performing a job. -4. **sidekiq.runtime (tags: {queue: _queue_, worker: _job_})**: timer of the total time spent +4. **sidekiq.success (tags: {queue: _queue_, worker: _job_})**: counter incremented each time a job succeeds. +5. **sidekiq.runtime (tags: {queue: _queue_, worker: _job_})**: timer of the total time spent in `perform`, in milliseconds. -5. **sidekiq.error (tags: {queue: _queue_, worker: _job_, error: _errorclass_})**: counter incremented each time a +6. **sidekiq.error (tags: {queue: _queue_, worker: _job_, error: _errorclass_})**: counter incremented each time a job fails. For job retry attempts, the above 4 metrics will still be reported but the enqueue/dequeue metrics diff --git a/lib/sidekiq/instrument/middleware/server.rb b/lib/sidekiq/instrument/middleware/server.rb index bb0134f..01fbc86 100644 --- a/lib/sidekiq/instrument/middleware/server.rb +++ b/lib/sidekiq/instrument/middleware/server.rb @@ -16,6 +16,8 @@ def call(worker, job, _queue, &block) yield block execution_time_ms = (Time.now - start_time) * 1000 Statter.dogstatsd&.timing('sidekiq.runtime', execution_time_ms, worker_dog_options(worker, job)) + Statter.statsd.increment(metric_name(worker, 'success')) + Statter.dogstatsd&.increment('sidekiq.success', worker_dog_options(worker, job)) Statter.statsd.measure(metric_name(worker, 'runtime'), execution_time_ms) rescue Exception => e dd_options = worker_dog_options(worker, job) diff --git a/lib/sidekiq/instrument/version.rb b/lib/sidekiq/instrument/version.rb index f3efa3b..ccdcb79 100644 --- a/lib/sidekiq/instrument/version.rb +++ b/lib/sidekiq/instrument/version.rb @@ -1,5 +1,5 @@ module Sidekiq module Instrument - VERSION = '0.7.4' + VERSION = '0.7.5' end end diff --git a/spec/sidekiq-instrument/server_middleware_spec.rb b/spec/sidekiq-instrument/server_middleware_spec.rb index 7eedbf0..3aef824 100644 --- a/spec/sidekiq-instrument/server_middleware_spec.rb +++ b/spec/sidekiq-instrument/server_middleware_spec.rb @@ -32,16 +32,20 @@ Sidekiq[:max_retries] = 0 end - it 'increments StatsD dequeue counter' do + it 'increments StatsD dequeue and success counters' do expect do MyWorker.perform_async - end.to trigger_statsd_increment('shared.sidekiq.default.MyWorker.dequeue') + end.to trigger_statsd_increment('shared.sidekiq.default.MyWorker.dequeue') && + trigger_statsd_increment('shared.sidekiq.default.MyWorker.success') end - it 'increments DogStatsD dequeue counter' do + it 'increments DogStatsD dequeue and success counters' do expect( Sidekiq::Instrument::Statter.dogstatsd ).to receive(:increment).with('sidekiq.dequeue', expected_dog_options).once + expect( + Sidekiq::Instrument::Statter.dogstatsd + ).to receive(:increment).with('sidekiq.success', expected_dog_options).once MyWorker.perform_async end @@ -64,6 +68,9 @@ expect( Sidekiq::Instrument::Statter.dogstatsd ).to receive(:increment).with('sidekiq.dequeue', expected_dog_options).once + expect( + Sidekiq::Instrument::Statter.dogstatsd + ).to receive(:increment).with('sidekiq.success', expected_dog_options).once MyWorker.set(tags: [tag]).perform_async end end