inst-jobs-statsd 3.0.2 → 4.0.0

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: c4a9d57f59dc527218751eb536cac69af6d5eb257d216d8b01cd5f00de7d10b8
4
+ data.tar.gz: 7398542a12623da8a74be2d1158d25f48bdb6b68433532608b10e2dbbec21c78
5
5
  SHA512:
6
- metadata.gz: 1a35e512b5a4b8a1e87205fa97a03922d70b95298635dda6d5778e9bcd110bb02b74dfd36791a963ca169dddbaafcac448c2e33beb1d640b27955f793138d990
7
- data.tar.gz: bd8808fa5e79266049f4cc9852df42c8bea046fc19d96c0402831df006e1c2a982a8d0475f12ac603bc0b0baf7224585546f78b79b3a650611f06d67cc1fe283
6
+ metadata.gz: fd829e71ac4403783556005c4ab5cf2fb2eed80238f5f2e8785c6297a5b1330f7ecda868e88a69b92cd197c53ebfe8445b202e24f81bfd852b9db6105fd68956
7
+ data.tar.gz: cb5c46e89d724dab97743d5c3db895a3f8e8d3a5857d9a4af443ba91ee89a505879f7b3ec6e8f670fcaeb0b48957567c5487d4c9d6facf0ce9a22d5a6958f6c8
@@ -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
46
  .where("locked_at IS NULL OR locked_by = 'on_hold'") # 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.0"
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.0
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-19 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: []