Skip to content

Commit

Permalink
add success metrics
Browse files Browse the repository at this point in the history
Signed-off-by: orioldsm <[email protected]>
  • Loading branch information
orioldsm committed Dec 5, 2024
1 parent 9c46244 commit 203ffb6
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 8 deletions.
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions lib/sidekiq/instrument/middleware/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion lib/sidekiq/instrument/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Sidekiq
module Instrument
VERSION = '0.7.4'
VERSION = '0.7.5'
end
end
13 changes: 10 additions & 3 deletions spec/sidekiq-instrument/server_middleware_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down

0 comments on commit 203ffb6

Please sign in to comment.