sidekiq-instrument 0.6.2 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +17 -2
- data/lib/sidekiq/instrument/middleware/client.rb +14 -6
- data/lib/sidekiq/instrument/middleware/server.rb +21 -3
- data/lib/sidekiq/instrument/mixin.rb +7 -0
- data/lib/sidekiq/instrument/version.rb +1 -1
- data/lib/sidekiq/instrument/worker_metrics.rb +1 -1
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c7de17bf15cf561935e482b332b89974f84409e0c1bfa00a544503ce95bcfd8d
|
4
|
+
data.tar.gz: 1732bbfc31fc7c04fe066613845f9e81917873f2fc25ae93ec960aba611c347d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 65c1f85a4c9a13b4cd2c3585712af41b07a8979f2a736c44d971fc5175d737f7a7cb6104d6383af714d94273a41e017bae361e29f7381587294d463432bf7551
|
7
|
+
data.tar.gz: b1f25cab5729fe6bcb76a81556fc18583ab800b3dd2a66c50c9fea3834abcf1a422aabb06bc6d5ef39b69be4675ab35e1dab9c53e43920e377888fd91aa79b2d
|
data/README.md
CHANGED
@@ -84,6 +84,12 @@ For each job, the following metrics will be reported:
|
|
84
84
|
4. **shared.sidekiq._queue_._job_.error**: counter incremented each time a
|
85
85
|
job fails.
|
86
86
|
|
87
|
+
For job retry attempts, the above 4 metrics will still be reported but the enqueue/dequeue metrics
|
88
|
+
will have a `.retry` appended:
|
89
|
+
|
90
|
+
1. **shared.sidekiq._queue_._job_.enqueue.retry**
|
91
|
+
2. **shared.sidekiq._queue_._job_.dequeue.retry**
|
92
|
+
|
87
93
|
The metric names can be changed by overriding the `statsd_metric_name`
|
88
94
|
method in your worker classes.
|
89
95
|
|
@@ -92,7 +98,7 @@ For each queue, the following metrics will be reported:
|
|
92
98
|
2. **shared.sidekiq._queue_.latency**: gauge of how long the oldest job has been in the queue
|
93
99
|
|
94
100
|
For each worker, the following metrics and tags will be reported:
|
95
|
-
1. **sidekiq.worker_metrics.in_queue.#{key}**: number of jobs "in queue" per worker, uses redis to track increment/decrement
|
101
|
+
1. **sidekiq.worker_metrics.in_queue.#{key}**: number of jobs "in queue" per worker, uses redis to track increment/decrement (**this metric is currently inaccurate**)
|
96
102
|
|
97
103
|
## DogStatsD Keys
|
98
104
|
For each job, the following metrics and tags will be reported:
|
@@ -106,14 +112,23 @@ For each job, the following metrics and tags will be reported:
|
|
106
112
|
4. **sidekiq.error (tags: {queue: _queue_, worker: _job_})**: counter incremented each time a
|
107
113
|
job fails.
|
108
114
|
|
115
|
+
For job retry attempts, the above 4 metrics will still be reported but the enqueue/dequeue metrics
|
116
|
+
will have a `.retry` appended:
|
117
|
+
|
118
|
+
1. **sidekiq.enqueue.retry (tags: {queue: _queue_, worker: _job_})**
|
119
|
+
2. **sidekiq.dequeue.retry (tags: {queue: _queue_, worker: _job_})**
|
120
|
+
|
109
121
|
For each queue, the following metrics and tags will be reported:
|
110
122
|
1. **sidekiq.queue.size (tags: {queue: _queue_})**: gauge of how many jobs are in the queue
|
111
123
|
2. **sidekiq.queue.latency (tags: {queue: _queue_})**: gauge of how long the oldest job has been in the queue
|
112
124
|
|
113
125
|
For each worker, the following metrics and tags will be reported:
|
114
|
-
1. **sidekiq.worker_metrics.in_queue.#{key}**: number of jobs "in queue" per worker, uses redis to track increment/decrement
|
126
|
+
1. **sidekiq.worker_metrics.in_queue.#{key}**: number of jobs "in queue" per worker, uses redis to track increment/decrement (**this metric is currently inaccurate**)
|
115
127
|
|
116
128
|
## Worker
|
129
|
+
|
130
|
+
**WARNING: The metrics reported by this Worker are currently inaccurate.**
|
131
|
+
|
117
132
|
There is a worker, `Sidekiq::Instrument::Worker`, that submits gauges
|
118
133
|
for various interesting statistics; namely, the bulk of the information in `Sidekiq::Stats`
|
119
134
|
and the sizes of each individual queue. While the worker class is a fully valid Sidekiq worker,
|
@@ -7,16 +7,24 @@ module Sidekiq::Instrument
|
|
7
7
|
class ClientMiddleware
|
8
8
|
include Sidekiq::Instrument::MetricNames
|
9
9
|
|
10
|
-
def call(worker_class, job, queue,
|
10
|
+
def call(worker_class, job, queue, _redis_pool)
|
11
11
|
# worker_class is a const in sidekiq >= 6.x
|
12
12
|
klass = Object.const_get(worker_class.to_s)
|
13
13
|
class_instance = klass.new
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
14
|
+
|
15
|
+
# This is needed because the ClientMiddleware is called twice for scheduled jobs
|
16
|
+
# - Once when it gets scheduled
|
17
|
+
# - Once when it gets dequeued for processing
|
18
|
+
# We only want to increment the enqueue metric when the job is scheduled and
|
19
|
+
# Sidekiq::Context.current[:class] is only ever set when the job is scheduled
|
20
|
+
if Sidekiq::Context.current[:class].present?
|
21
|
+
WorkerMetrics.trace_workers_increment_counter(klass.name.underscore)
|
22
|
+
Statter.statsd.increment(metric_name(class_instance, 'enqueue'))
|
23
|
+
Statter.dogstatsd&.increment('sidekiq.enqueue', worker_dog_options(class_instance))
|
24
|
+
end
|
25
|
+
|
18
26
|
Statter.dogstatsd&.flush(sync: true)
|
19
|
-
|
27
|
+
yield
|
20
28
|
end
|
21
29
|
end
|
22
30
|
end
|
@@ -7,9 +7,10 @@ module Sidekiq::Instrument
|
|
7
7
|
class ServerMiddleware
|
8
8
|
include Sidekiq::Instrument::MetricNames
|
9
9
|
|
10
|
-
def call(worker,
|
11
|
-
|
12
|
-
Statter.dogstatsd&.increment(
|
10
|
+
def call(worker, job, _queue, &block)
|
11
|
+
dequeue_string = is_retry(job) ? 'dequeue.retry' : 'dequeue'
|
12
|
+
Statter.dogstatsd&.increment("sidekiq.#{dequeue_string}", worker_dog_options(worker))
|
13
|
+
Statter.statsd.increment(metric_name(worker, dequeue_string))
|
13
14
|
|
14
15
|
start_time = Time.now
|
15
16
|
yield block
|
@@ -17,6 +18,12 @@ module Sidekiq::Instrument
|
|
17
18
|
Statter.statsd.measure(metric_name(worker, 'runtime'), execution_time_ms)
|
18
19
|
Statter.dogstatsd&.timing('sidekiq.runtime', execution_time_ms, worker_dog_options(worker))
|
19
20
|
rescue StandardError => e
|
21
|
+
# if we have retries left, increment the enqueue.retry counter to indicate the job is going back on the queue
|
22
|
+
if max_retries(worker) > current_retries(job) + 1
|
23
|
+
WorkerMetrics.trace_workers_increment_counter(worker.class.to_s.underscore)
|
24
|
+
Statter.dogstatsd&.increment('sidekiq.enqueue.retry', worker_dog_options(worker))
|
25
|
+
end
|
26
|
+
|
20
27
|
Statter.statsd.increment(metric_name(worker, 'error'))
|
21
28
|
Statter.dogstatsd&.increment('sidekiq.error', worker_dog_options(worker))
|
22
29
|
raise e
|
@@ -24,5 +31,16 @@ module Sidekiq::Instrument
|
|
24
31
|
WorkerMetrics.trace_workers_decrement_counter(worker.class.to_s.underscore)
|
25
32
|
Statter.dogstatsd&.flush(sync: true)
|
26
33
|
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
# returns -1 if no retries have been attempted
|
38
|
+
def current_retries(job)
|
39
|
+
job["retry_count"] || -1
|
40
|
+
end
|
41
|
+
|
42
|
+
def is_retry(job)
|
43
|
+
current_retries(job) >= 0
|
44
|
+
end
|
27
45
|
end
|
28
46
|
end
|
@@ -12,6 +12,13 @@ module Sidekiq::Instrument
|
|
12
12
|
{ tags: ["queue:#{queue_name(worker)}", "worker:#{underscore(class_name(worker))}"] }
|
13
13
|
end
|
14
14
|
|
15
|
+
def max_retries(worker)
|
16
|
+
retries = worker.class.get_sidekiq_options['retry'] || Sidekiq[:max_retries]
|
17
|
+
return Sidekiq[:max_retries] if retries.to_s.eql?("true")
|
18
|
+
return 0 if retries.eql?("false")
|
19
|
+
retries
|
20
|
+
end
|
21
|
+
|
15
22
|
private
|
16
23
|
|
17
24
|
def queue_name(worker)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sidekiq-instrument
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Loan Application Services
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-08-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sidekiq
|
@@ -196,7 +196,7 @@ dependencies:
|
|
196
196
|
- - ">="
|
197
197
|
- !ruby/object:Gem::Version
|
198
198
|
version: '0'
|
199
|
-
description:
|
199
|
+
description:
|
200
200
|
email:
|
201
201
|
- application_services@enova.com
|
202
202
|
executables: []
|
@@ -227,7 +227,7 @@ homepage: https://github.com/enova/sidekiq-instrument
|
|
227
227
|
licenses:
|
228
228
|
- MIT
|
229
229
|
metadata: {}
|
230
|
-
post_install_message:
|
230
|
+
post_install_message:
|
231
231
|
rdoc_options: []
|
232
232
|
require_paths:
|
233
233
|
- lib
|
@@ -242,8 +242,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
242
242
|
- !ruby/object:Gem::Version
|
243
243
|
version: '0'
|
244
244
|
requirements: []
|
245
|
-
rubygems_version: 3.1
|
246
|
-
signing_key:
|
245
|
+
rubygems_version: 3.0.3.1
|
246
|
+
signing_key:
|
247
247
|
specification_version: 4
|
248
248
|
summary: StatsD & DogStatsD Instrumentation for Sidekiq
|
249
249
|
test_files: []
|