yabeda-activejob 0.1.0 → 0.3.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: 75adb58471b09079b2c7137a9e6d245ca34a87f5943bddbcca8488aa8a7fed21
4
- data.tar.gz: 4eaff38047f48d812c9ec216520d1d180e04ee0a1c28fed56a74af3dff1cb31d
3
+ metadata.gz: '08158815f9482115a22e494dd4f3b65fd296adb566f1b641f3fa39b15d232bcd'
4
+ data.tar.gz: 5d57d4ee2d12c75453f852422d044728cff9d7631928f04a76886d321b425bd0
5
5
  SHA512:
6
- metadata.gz: 722e179fb2e42ea0724f83fa58e4f078419ea6b213570ba651abbde64f79516999fd8de3b10c8ff6adb79191bacaf5d4a7b17c1aef360ce400be5ecae8ba5703
7
- data.tar.gz: 1b53949b9e40c84df03d36065be01efa4b321b9f9e261f9dd3b4b774a0cfd1cdd53ede740fb2a1b2b06537991f1cb9c1350cee8bf2723ecc9b2ff3ada67774bd
6
+ metadata.gz: ea6312266b05349917950bae645a413a257e3ed970ec4b9a5b82d0a177487a6dea3529a144849e489bd37c4aff4ea21a53058d4857226b3f154816c7e551f069
7
+ data.tar.gz: 7e60c91f4613c747e8572ddbebbad53c7c42613845e3dadb7d3df3b89486ebd332fa9f90bf993d2da4a72b87f917f4ffa4ca98397cdb03f3dac0eb65e4eb8ea2
data/README.md CHANGED
@@ -1,4 +1,8 @@
1
1
  # Yabeda::ActiveJob
2
+ [![Gem Version](https://badge.fury.io/rb/yabeda-activejob.svg)](https://badge.fury.io/rb/yabeda-activejob)
3
+ ![Tests](https://github.com/Fullscript/yabeda-activejob/actions/workflows/test.yml/badge.svg)
4
+ ![Rubocop](https://github.com/Fullscript/yabeda-activejob/actions/workflows/lint.yml/badge.svg)
5
+
2
6
  Yabeda metrics around rails activejobs. The motivation came from wanting something similar to [yabeda-sidekiq](https://github.com/yabeda-rb/yabeda-sidekiq) for
3
7
  resque but decided to generalize even more with just doing it on the activejob level since that is likely more in use
4
8
  than just resque. and could implement a lot of the general metrics needed without having to leverage your used adapters
@@ -28,11 +32,11 @@ you can do the following:
28
32
 
29
33
  ## Metrics
30
34
 
31
- - Total jobs processed: `activejob.job_executed_total`
32
- - Total successful jobs processed: `activejob.job_success_total`
33
- - Total failed jobs processed: `activejob.job_failed_total`
34
- - Job runtime: `activejob.job_runtime` (in seconds)
35
- - Job latency: `activejob.job_latency` (in seconds)
35
+ - Total jobs processed: `activejob.executed_total`
36
+ - Total successful jobs processed: `activejob.success_total`
37
+ - Total failed jobs processed: `activejob.failed_total`
38
+ - Job runtime: `activejob.runtime` (in seconds)
39
+ - Job latency: `activejob.latency` (in seconds)
36
40
 
37
41
  ## License
38
42
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Yabeda
4
4
  module ActiveJob
5
- VERSION = "0.1.0"
5
+ VERSION = "0.3.0"
6
6
  end
7
7
  end
@@ -16,27 +16,27 @@ module Yabeda
16
16
  Yabeda.configure do
17
17
  group :activejob
18
18
 
19
- counter :job_executed_total, tags: %i[queue activejob executions],
20
- comment: "A counter of the total number of activejobs executed."
21
- counter :job_success_total, tags: %i[queue activejob executions],
22
- comment: "A counter of the total number of activejobs successfully processed."
23
- counter :job_failed_total, tags: %i[queue activejob executions failure_reason],
24
- comment: "A counter of the total number of jobs failed for an activejob."
25
-
26
- histogram :job_runtime, comment: "A histogram of the activejob execution time.",
27
- unit: :seconds, per: :activejob,
28
- tags: %i[queue activejob executions],
29
- buckets: LONG_RUNNING_JOB_RUNTIME_BUCKETS
30
-
31
- histogram :job_latency, comment: "The job latency, the difference in seconds between enqueued and running time",
32
- unit: :seconds, per: :activejob,
33
- tags: %i[queue activejob executions],
34
- buckets: LONG_RUNNING_JOB_RUNTIME_BUCKETS
19
+ counter :executed_total, tags: %i[queue activejob executions],
20
+ comment: "A counter of the total number of activejobs executed."
21
+ counter :enqueued_total, tags: %i[queue activejob executions],
22
+ comment: "A counter of the total number of activejobs enqueued."
23
+ counter :success_total, tags: %i[queue activejob executions],
24
+ comment: "A counter of the total number of activejobs successfully processed."
25
+ counter :failed_total, tags: %i[queue activejob executions failure_reason],
26
+ comment: "A counter of the total number of jobs failed for an activejob."
27
+
28
+ histogram :runtime, comment: "A histogram of the activejob execution time.",
29
+ unit: :seconds, per: :activejob,
30
+ tags: %i[queue activejob executions],
31
+ buckets: LONG_RUNNING_JOB_RUNTIME_BUCKETS
32
+
33
+ histogram :latency, comment: "The job latency, the difference in seconds between enqueued and running time",
34
+ unit: :seconds, per: :activejob,
35
+ tags: %i[queue activejob executions],
36
+ buckets: LONG_RUNNING_JOB_RUNTIME_BUCKETS
35
37
 
36
38
  # job complete event
37
39
  ActiveSupport::Notifications.subscribe "perform.active_job" do |*args|
38
- ::Rails.logger.debug("JOB COMPLETE")
39
-
40
40
  event = ActiveSupport::Notifications::Event.new(*args)
41
41
  labels = {
42
42
  activejob: event.payload[:job].class.to_s,
@@ -44,32 +44,42 @@ module Yabeda
44
44
  executions: event.payload[:job].instance_variable_get(:@executions).to_s,
45
45
  }
46
46
  if event.payload[:exception].present?
47
- activejob_job_failed_total.increment(
48
- labels.merge(failure_reason: event.payload[:exception].join(",")),
47
+ activejob_failed_total.increment(
48
+ labels.merge(failure_reason: event.payload[:exception].first.to_s),
49
49
  )
50
50
  else
51
- activejob_job_success_total.increment(labels)
51
+ activejob_success_total.increment(labels)
52
52
  end
53
53
 
54
- activejob_job_executed_total.increment(labels)
55
- activejob_job_runtime.measure(labels, Yabeda::ActiveJob.ms2s(event.duration))
54
+ activejob_executed_total.increment(labels)
55
+ activejob_runtime.measure(labels, Yabeda::ActiveJob.ms2s(event.duration))
56
56
  end
57
57
 
58
58
  # start job event
59
59
  ActiveSupport::Notifications.subscribe "perform_start.active_job" do |*args|
60
60
  event = ActiveSupport::Notifications::Event.new(*args)
61
- ::Rails.logger.debug("JOB START")
62
- puts "JOB START"
63
61
 
64
62
  labels = {
65
63
  activejob: event.payload[:job].class.to_s,
66
64
  queue: event.payload[:job].instance_variable_get(:@queue_name),
67
65
  executions: event.payload[:job].instance_variable_get(:@executions).to_s,
68
66
  }
69
- ::Rails.logger.info(labels.inspect)
70
67
 
71
68
  labels.merge!(event.payload.slice(*Yabeda.default_tags.keys - labels.keys))
72
- activejob_job_latency.measure(labels, Yabeda::ActiveJob.job_latency(event))
69
+ activejob_latency.measure(labels, Yabeda::ActiveJob.job_latency(event))
70
+ end
71
+
72
+ ActiveSupport::Notifications.subscribe "enqueue.active_job" do |*args|
73
+ event = ActiveSupport::Notifications::Event.new(*args)
74
+
75
+ labels = {
76
+ activejob: event.payload[:job].class.to_s,
77
+ queue: event.payload[:job].instance_variable_get(:@queue_name),
78
+ executions: event.payload[:job].instance_variable_get(:@executions).to_s,
79
+ }
80
+
81
+ labels.merge!(event.payload.slice(*Yabeda.default_tags.keys - labels.keys))
82
+ activejob_enqueued_total.increment(labels)
73
83
  end
74
84
  end
75
85
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yabeda-activejob
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fullscript
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-10-22 00:00:00.000000000 Z
11
+ date: 2022-10-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -94,6 +94,20 @@ dependencies:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
96
  version: '6.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: simplecov
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '0.21'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '0.21'
97
111
  description: Prometheus exporter for collecting metrics around your activejobs
98
112
  email:
99
113
  - josh.etsenake@fullscript.com