yabeda-activejob 0.2.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9b5abdf29dc1f2bea57820def73dbfe9ecb2eabdcff95a863e13c463fa332794
4
- data.tar.gz: d2341ad286ddd4a66f29eafadfacf0d30bb83c844b685f1bd09a7fe302eb33e9
3
+ metadata.gz: 3cd5ae2317f42f9d4e2a5b44bba2d44b792e07f9e55a7992af2e37dabbd6333f
4
+ data.tar.gz: 4da6bb136cb5a1ab33a7f3927b79f4a9a50a1188e32340d459ebdcfbf9ca2ca6
5
5
  SHA512:
6
- metadata.gz: 485073cf7a4925fc68cfce465507ec6890ed2b15edf69ca919ac0044b6013b4e872380252d83dfbdb0c1f743d71f60a8ce81c84811676c03709316759023f8af
7
- data.tar.gz: ab25a166ad4c2474e704554f1dbec5d8b8e90a325d99b751a118c6041f876ee60139d75e80c8a797b3022aa46963978d34e9caa5376d9ef42cf228c267a35ff4
6
+ metadata.gz: 2f73db31ff848abc54d5e43fb664cb28c5de70b7a5697a349d952bdf1a7e2e605eb8ebdb98edb31c90f0c8832c59162e29d278ae6846c73d0829be4a20ea3a54
7
+ data.tar.gz: 5c86775ae9e1811f2fd2e1e9558eeb9fb681635af322180e2d3828d3f7ab2be235b6ea579fb5f13c95324b32fe0e2a14fefa9d5240daffe018b4a3e910f5cea2
data/README.md CHANGED
@@ -5,12 +5,12 @@
5
5
 
6
6
  Yabeda metrics around rails activejobs. The motivation came from wanting something similar to [yabeda-sidekiq](https://github.com/yabeda-rb/yabeda-sidekiq) for
7
7
  resque but decided to generalize even more with just doing it on the activejob level since that is likely more in use
8
- than just resque. and could implement a lot of the general metrics needed without having to leverage your used adapters
9
- implementation and oh the redis calls.
10
- The intent is to have this plugin with an exporter such as [prometheus](https://github.com/yabeda-rb/yabeda-prometheus).
8
+ than just resque. and could implement a lot of the general metrics needed without having to leverage the adapter
9
+ implementation and, oh the redis calls.
11
10
 
12
- ## Usage
13
- How to use my plugin.
11
+ Sample [Grafana dashboard](https://grafana.com/grafana/dashboards/17303) ID: [17303](https://grafana.com/grafana/dashboards/17303)
12
+
13
+ The intent is to have this plugin with an exporter such as [prometheus](https://github.com/yabeda-rb/yabeda-prometheus).
14
14
 
15
15
  ## Installation
16
16
  Add this line to your application's Gemfile:
@@ -21,22 +21,84 @@ gem 'yabeda-activejob'
21
21
  # gem 'yabeda-prometheus'
22
22
  ```
23
23
 
24
+ And then execute:
25
+
26
+ $ bundle
24
27
  ### Registering metrics on server process start
28
+ Depending on your activejob adapter the installation process may be different for you. If using sidekiq:
29
+ ```ruby
30
+ # config/initializers/sidekiq or elsewhere
31
+ Sidekiq.configure_server do |_config|
32
+ Yabeda::ActiveJob.install!
33
+ end
34
+ ```
25
35
 
26
- Currently, yabeda-activejob does not automatically install on your rails server (this will be added in the future). For now to install
27
- you can do the following:
36
+ If using with resque:
28
37
  ```ruby
29
- # config/initializers/yabeda.rb
30
- Yabeda::ActiveJob.install!
38
+ # config/initializers/yabeda.rb or elsewhere
39
+ Yabeda::ActiveJob.install!
31
40
  ```
41
+ If using resque you may need to use [yabeda-prometheus-mmap](https://github.com/yabeda-rb/yabeda-prometheus-mmap) or set your storage type to direct file store so that the metrics are available
42
+ to your collector.
43
+
44
+ To set your storage type to direct file store you can do the following in your yabeda initializer:
45
+
46
+ ```ruby
47
+ # config/initializers/yabeda.rb or elsewhere
48
+ Prometheus::Client.config.data_store = Prometheus::Client::DataStores::DirectFileStore.new(dir: "/tmp")
49
+ ```
50
+
51
+ **Note** if using direct file datastore it must be called before registering any metrics.
32
52
 
33
53
  ## Metrics
34
54
 
35
- - Total jobs processed: `activejob.executed_total`
36
- - Total successful jobs processed: `activejob.success_total`
37
- - Total failed jobs processed: `activejob.failed_total`
55
+ - Total enqueued jobs: `activejob.enqueued_total` segmented by: queue, activejob(job class name), executions(number of executions)
56
+ - Total jobs processed: `activejob.executed_total` segmented by: queue, activejob(job class name), executions(number of executions)
57
+ - Total successful jobs processed: `activejob.success_total` segmented by: queue, activejob(job class name), executions(number of executions)
58
+ - Total failed jobs processed: `activejob.failed_total` segmented by: queue, activejob(job class name), executions(number of executions), failure_reason(error class)
38
59
  - Job runtime: `activejob.runtime` (in seconds)
39
60
  - Job latency: `activejob.latency` (in seconds)
40
61
 
62
+ ## Contributing
63
+
64
+ Bug reports and pull requests are welcome on GitHub at https://github.com/Fullscript/yabeda-activejob.
65
+
66
+ ### Releasing
67
+
68
+ 1. Bump version number in `lib/yabeda/activejob/version.rb`
69
+
70
+ In case of pre-releases keep in mind [rubygems/rubygems#3086](https://github.com/rubygems/rubygems/issues/3086) and check version with command like `Gem::Version.new(Yabeda::ActiveJob::VERSION).to_s`
71
+
72
+ 2. Fill `CHANGELOG.md` with missing changes, add header with version and date.
73
+
74
+ 3. Make a commit:
75
+
76
+ ```sh
77
+ git add lib/yabeda/activejob/version.rb CHANGELOG.md
78
+ version=$(ruby -r ./lib/yabeda/activejob/version.rb -e "puts Gem::Version.new(Yabeda::ActiveJob::VERSION)")
79
+ git commit --message="${version}: " --edit
80
+ ```
81
+
82
+ 4. Create annotated tag:
83
+
84
+ ```sh
85
+ git tag v${version} --annotate --message="${version}: " --edit --sign
86
+ ```
87
+
88
+ 5. Fill version name into subject line and (optionally) some description (list of changes will be taken from changelog and appended automatically)
89
+
90
+ 6. Push it:
91
+
92
+ ```sh
93
+ git push --follow-tags
94
+ ```
95
+
96
+ 7. GitHub Actions will create a new release, build and push gem into RubyGems! You're done!
97
+
41
98
  ## License
99
+
42
100
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
101
+
102
+ [Yabeda-sidekiq]: https://github.com/yabeda-rb/yabeda-sidekiq "Inspiration for this gem"
103
+ [yabeda]: https://github.com/yabeda-rb/yabeda
104
+ [yabeda-prometheus]: https://github.com/yabeda-rb/yabeda-prometheus
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Yabeda
4
4
  module ActiveJob
5
- VERSION = "0.2.0"
5
+ VERSION = "0.3.1"
6
6
  end
7
7
  end
@@ -18,6 +18,8 @@ module Yabeda
18
18
 
19
19
  counter :executed_total, tags: %i[queue activejob executions],
20
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."
21
23
  counter :success_total, tags: %i[queue activejob executions],
22
24
  comment: "A counter of the total number of activejobs successfully processed."
23
25
  counter :failed_total, tags: %i[queue activejob executions failure_reason],
@@ -35,13 +37,11 @@ module Yabeda
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,
43
- queue: event.payload[:job].instance_variable_get(:@queue_name).to_s,
44
- executions: event.payload[:job].instance_variable_get(:@executions).to_s,
43
+ queue: event.payload[:job].queue_name.to_s,
44
+ executions: event.payload[:job].executions.to_s,
45
45
  }
46
46
  if event.payload[:exception].present?
47
47
  activejob_failed_total.increment(
@@ -58,24 +58,38 @@ module Yabeda
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
61
 
63
62
  labels = {
64
63
  activejob: event.payload[:job].class.to_s,
65
- queue: event.payload[:job].instance_variable_get(:@queue_name),
66
- executions: event.payload[:job].instance_variable_get(:@executions).to_s,
64
+ queue: event.payload[:job].queue_name,
65
+ executions: event.payload[:job].executions.to_s,
67
66
  }
68
- ::Rails.logger.info(labels.inspect)
69
67
 
70
68
  labels.merge!(event.payload.slice(*Yabeda.default_tags.keys - labels.keys))
71
- activejob_latency.measure(labels, Yabeda::ActiveJob.job_latency(event))
69
+ job_latency = Yabeda::ActiveJob.job_latency(event)
70
+ activejob_latency.measure(labels, job_latency) if job_latency.present?
71
+ end
72
+
73
+ ActiveSupport::Notifications.subscribe "enqueue.active_job" do |*args|
74
+ event = ActiveSupport::Notifications::Event.new(*args)
75
+
76
+ labels = {
77
+ activejob: event.payload[:job].class.to_s,
78
+ queue: event.payload[:job].queue_name,
79
+ executions: event.payload[:job].executions.to_s,
80
+ }
81
+
82
+ labels.merge!(event.payload.slice(*Yabeda.default_tags.keys - labels.keys))
83
+ activejob_enqueued_total.increment(labels)
72
84
  end
73
85
  end
74
86
  end
75
87
  # rubocop: enable Metrics/MethodLength, Metrics/BlockLength, Metrics/AbcSize
76
88
 
77
89
  def self.job_latency(event)
78
- enqueue_time = event.payload[:job].instance_variable_get(:@enqueued_at)
90
+ enqueue_time = event.payload[:job].enqueued_at
91
+ return nil unless enqueue_time.present?
92
+
79
93
  enqueue_time = Time.parse(enqueue_time).utc
80
94
  perform_at_time = Time.parse(event.end.to_s).utc
81
95
  (perform_at_time - enqueue_time)
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.2.0
4
+ version: 0.3.1
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