inst-jobs-statsd 3.0.2 → 4.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d5760a670863e6b529a17f1443c45b360ed9762b35ad9fe432a4bd66c5b3e90d
4
- data.tar.gz: 0efe20cd91f2dcb8cb55b5f4df13c372aa2f1b60ff2401c5379a453ed16e1bae
3
+ metadata.gz: 2842be633e3d25b6880b6ff576d9b00a37d56d2a28713ea424aa670181280efe
4
+ data.tar.gz: 6463453b401639f55f7335cb66a0590a48da0ef545cb81d64652dca7656c47e1
5
5
  SHA512:
6
- metadata.gz: 1a35e512b5a4b8a1e87205fa97a03922d70b95298635dda6d5778e9bcd110bb02b74dfd36791a963ca169dddbaafcac448c2e33beb1d640b27955f793138d990
7
- data.tar.gz: bd8808fa5e79266049f4cc9852df42c8bea046fc19d96c0402831df006e1c2a982a8d0475f12ac603bc0b0baf7224585546f78b79b3a650611f06d67cc1fe283
6
+ metadata.gz: b4f9cc39873e1c1648922de0335c2d81d62d96c637e1c0e78a25e219965284178f55873185710c2223a4c73e69f81001ec9d21a69f4dbfee4be3698f0b087d42
7
+ data.tar.gz: 8f30d404ce68bac3b0ca1cfb099f04e48e50b754b5b88cac8f13b03bde7613184bbdd7f2ab6b518a2f03a496f3bb78d29a9e68d97a73f1b8d579e416f931032b
@@ -14,8 +14,9 @@ module InstJobsStatsd
14
14
  end
15
15
 
16
16
  def self.report_failed_depth
17
- count = Delayed::Job::Failed.count
18
- Periodic.report_gauge(:failed_depth, count)
17
+ count_by_queue = Delayed::Job::Failed.group(:queue).count
18
+
19
+ Periodic.report_gauge_by_queue(:failed_depth, count_by_queue)
19
20
  end
20
21
  end
21
22
  end
@@ -20,10 +20,7 @@ module InstJobsStatsd
20
20
  end
21
21
 
22
22
  def self.report_queue_depth
23
- # count = Delayed::Job.jobs_count(:current) <-- includes running / locked
24
- scope = queued_jobs_scope
25
- count = scope.count
26
- Periodic.report_gauge(:queue_depth, count)
23
+ Periodic.report_gauge_by_queue(:queue_depth, queued_jobs_scope.count)
27
24
  end
28
25
 
29
26
  # Limit the jobs included in this gauge to prevent blowing up
@@ -34,16 +31,20 @@ module InstJobsStatsd
34
31
  # the count is capped, the metric will continue to grow
35
32
  # if the queue is actually stalled
36
33
  def self.report_queue_age
37
- jobs_run_at = queued_jobs_scope.limit(10_000).pluck(:run_at)
38
- age_secs = jobs_run_at.map { |t| Delayed::Job.db_time_now - t }
39
- Periodic.report_gauge(:queue_age_total, age_secs.sum)
40
- Periodic.report_gauge(:queue_age_max, age_secs.max || 0)
34
+ jobs_run_at_by_queue = queued_jobs_scope.limit(10_000).pluck(:queue, "ARRAY_AGG(run_at)").to_h
35
+ age_secs_by_queue = jobs_run_at_by_queue.transform_values { |v| v.map { |t| Delayed::Job.db_time_now - t } }
36
+ age_max_by_queue = age_secs_by_queue.transform_values(&:max)
37
+ age_total_by_queue = age_secs_by_queue.transform_values(&:sum)
38
+
39
+ Periodic.report_gauge_by_queue(:queue_age_total, age_total_by_queue)
40
+ Periodic.report_gauge_by_queue(:queue_age_max, age_max_by_queue)
41
41
  end
42
42
 
43
43
  def self.queued_jobs_scope
44
44
  Delayed::Job
45
45
  .current
46
- .where("locked_at IS NULL OR locked_by = 'on_hold'") # not running
46
+ .where("locked_at IS NULL OR locked_by = ?", Delayed::Backend::Base::ON_HOLD_LOCKED_BY) # not running
47
+ .group(:queue)
47
48
  end
48
49
  end
49
50
  end
@@ -20,19 +20,21 @@ module InstJobsStatsd
20
20
  end
21
21
 
22
22
  def self.report_run_depth
23
- scope = running_jobs_scope
24
- Periodic.report_gauge(:run_depth, scope.count)
23
+ Periodic.report_gauge_by_queue(:run_depth, running_jobs_scope.count)
25
24
  end
26
25
 
27
26
  def self.report_run_age
28
- jobs_run_at = running_jobs_scope.limit(10_000).pluck(:run_at)
29
- age_secs = jobs_run_at.map { |t| Delayed::Job.db_time_now - t }
30
- Periodic.report_gauge(:run_age_total, age_secs.sum)
31
- Periodic.report_gauge(:run_age_max, age_secs.max || 0)
27
+ jobs_run_at_by_queue = running_jobs_scope.limit(10_000).pluck(:queue, "ARRAY_AGG(run_at)").to_h
28
+ age_secs_by_queue = jobs_run_at_by_queue.transform_values { |v| v.map { |t| Delayed::Job.db_time_now - t } }
29
+ age_max_by_queue = age_secs_by_queue.transform_values(&:max)
30
+ age_total_by_queue = age_secs_by_queue.transform_values(&:sum)
31
+
32
+ Periodic.report_gauge_by_queue(:run_age_total, age_total_by_queue)
33
+ Periodic.report_gauge_by_queue(:run_age_max, age_max_by_queue)
32
34
  end
33
35
 
34
36
  def self.running_jobs_scope
35
- Delayed::Job.running
37
+ Delayed::Job.running.group(:queue)
36
38
  end
37
39
  end
38
40
  end
@@ -13,9 +13,21 @@ module InstJobsStatsd
13
13
  @instance.add(proc)
14
14
  end
15
15
 
16
- def self.report_gauge(stat, value, job: nil, sample_rate: 1)
16
+ def self.report_gauge(stat, value, job: nil, sample_rate: 1, additional_tags: {})
17
17
  stats = Naming.qualified_names(stat, job)
18
- InstStatsd::Statsd.gauge(stats, value, sample_rate, short_stat: stat, tags: Naming.dd_job_tags(job))
18
+ InstStatsd::Statsd.gauge(stats,
19
+ value,
20
+ sample_rate,
21
+ short_stat: stat,
22
+ tags: Naming.dd_job_tags(job).merge(additional_tags))
23
+ end
24
+
25
+ def self.report_gauge_by_queue(stat, value_by_queue)
26
+ value_by_queue.each do |queue, count|
27
+ report_gauge(stat, count, additional_tags: { queue: queue })
28
+ end
29
+
30
+ report_gauge("#{stat}.total", value_by_queue.values.sum)
19
31
  end
20
32
 
21
33
  class Callbacks
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module InstJobsStatsd
4
- VERSION = "3.0.2"
4
+ VERSION = "4.0.1"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: inst-jobs-statsd
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.2
4
+ version: 4.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Slade
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-10-02 00:00:00.000000000 Z
11
+ date: 2024-02-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: inst-jobs
@@ -268,7 +268,7 @@ dependencies:
268
268
  - - "~>"
269
269
  - !ruby/object:Gem::Version
270
270
  version: 1.4.0
271
- description:
271
+ description:
272
272
  email:
273
273
  - jslade@instructure.com
274
274
  executables: []
@@ -298,7 +298,7 @@ licenses:
298
298
  - MIT
299
299
  metadata:
300
300
  rubygems_mfa_required: 'true'
301
- post_install_message:
301
+ post_install_message:
302
302
  rdoc_options: []
303
303
  require_paths:
304
304
  - lib
@@ -313,8 +313,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
313
313
  - !ruby/object:Gem::Version
314
314
  version: '0'
315
315
  requirements: []
316
- rubygems_version: 3.4.19
317
- signing_key:
316
+ rubygems_version: 3.1.6
317
+ signing_key:
318
318
  specification_version: 4
319
319
  summary: Stats reporting for inst-jobs
320
320
  test_files: []