yabeda-activejob 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +74 -12
- data/lib/yabeda/activejob/version.rb +1 -1
- data/lib/yabeda/activejob.rb +11 -8
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3cd5ae2317f42f9d4e2a5b44bba2d44b792e07f9e55a7992af2e37dabbd6333f
|
4
|
+
data.tar.gz: 4da6bb136cb5a1ab33a7f3927b79f4a9a50a1188e32340d459ebdcfbf9ca2ca6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
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
|
-
|
13
|
-
|
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
|
-
|
27
|
-
you can do the following:
|
36
|
+
If using with resque:
|
28
37
|
```ruby
|
29
|
-
# config/initializers/yabeda.rb
|
30
|
-
|
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
|
36
|
-
- Total
|
37
|
-
- 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
|
data/lib/yabeda/activejob.rb
CHANGED
@@ -40,8 +40,8 @@ module Yabeda
|
|
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].
|
44
|
-
executions: event.payload[:job].
|
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(
|
@@ -61,12 +61,13 @@ module Yabeda
|
|
61
61
|
|
62
62
|
labels = {
|
63
63
|
activejob: event.payload[:job].class.to_s,
|
64
|
-
queue: event.payload[:job].
|
65
|
-
executions: event.payload[:job].
|
64
|
+
queue: event.payload[:job].queue_name,
|
65
|
+
executions: event.payload[:job].executions.to_s,
|
66
66
|
}
|
67
67
|
|
68
68
|
labels.merge!(event.payload.slice(*Yabeda.default_tags.keys - labels.keys))
|
69
|
-
|
69
|
+
job_latency = Yabeda::ActiveJob.job_latency(event)
|
70
|
+
activejob_latency.measure(labels, job_latency) if job_latency.present?
|
70
71
|
end
|
71
72
|
|
72
73
|
ActiveSupport::Notifications.subscribe "enqueue.active_job" do |*args|
|
@@ -74,8 +75,8 @@ module Yabeda
|
|
74
75
|
|
75
76
|
labels = {
|
76
77
|
activejob: event.payload[:job].class.to_s,
|
77
|
-
queue: event.payload[:job].
|
78
|
-
executions: event.payload[:job].
|
78
|
+
queue: event.payload[:job].queue_name,
|
79
|
+
executions: event.payload[:job].executions.to_s,
|
79
80
|
}
|
80
81
|
|
81
82
|
labels.merge!(event.payload.slice(*Yabeda.default_tags.keys - labels.keys))
|
@@ -86,7 +87,9 @@ module Yabeda
|
|
86
87
|
# rubocop: enable Metrics/MethodLength, Metrics/BlockLength, Metrics/AbcSize
|
87
88
|
|
88
89
|
def self.job_latency(event)
|
89
|
-
enqueue_time = event.payload[:job].
|
90
|
+
enqueue_time = event.payload[:job].enqueued_at
|
91
|
+
return nil unless enqueue_time.present?
|
92
|
+
|
90
93
|
enqueue_time = Time.parse(enqueue_time).utc
|
91
94
|
perform_at_time = Time.parse(event.end.to_s).utc
|
92
95
|
(perform_at_time - enqueue_time)
|