sidekiq-influxdb 1.2.0 → 1.3.0
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 +4 -4
- data/.rspec +1 -0
- data/CHANGELOG.md +11 -0
- data/LICENSE +21 -0
- data/Makefile +3 -0
- data/README.md +41 -28
- data/Rakefile +0 -2
- data/lib/sidekiq/influxdb/version.rb +1 -1
- data/lib/sidekiq/middleware/server/influxdb.rb +48 -30
- data/sidekiq-influxdb.gemspec +2 -2
- metadata +19 -19
- data/.ruby-version +0 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9e2aa43ef989ddeb19590a4aea63e35a4969ed0e992535edecb1d676a13d6bdd
|
4
|
+
data.tar.gz: 0ce207ffe7b3be565d079b2d6347492a1e5212d6a328a165c77f0298ebac51a7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 75a775a08db08522d7bf0151643d46b4e4f0a4164dfb277ede4757a1a7ce097e53d4d30ebcf2f1f8c0c8f364862d8b961a110ad9ea9d3efb2e1efcb2fe05c061
|
7
|
+
data.tar.gz: 461184d903b385e215f42fbc2c431562b8c03879b06f76a60763f078fa58ec0b877eee7e0658f661d7487996c7ff48c4072f8f64bef5835f1ecb9cbadb91df02
|
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--require ./spec/spec_helper.rb
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,16 @@
|
|
1
1
|
# Sidekiq-InfluxDB Changelog
|
2
2
|
|
3
|
+
## 1.3.0 (2020-09-23)
|
4
|
+
|
5
|
+
* Dropped dependency on Bundler and Rake for development. The `gem` command is enough, really.
|
6
|
+
* Dropped **run-time** dependency on InfluxDB client. It was always possible to pass any object as client anyway.
|
7
|
+
* Added 100% test coverage with RSpec.
|
8
|
+
* Fixed and improved the "ignored classes" feature:
|
9
|
+
* It now correctly ignores job class names even if they come via ActiveJob (wrapped).
|
10
|
+
* It is now possible to pass either an array of class names or a single class name.
|
11
|
+
* It is now possible to pass either classes themselves or class names as strings.
|
12
|
+
* Fixed timestamps for minute and hour precisions
|
13
|
+
|
3
14
|
## 1.2.0 (2019-05-03)
|
4
15
|
|
5
16
|
* Support all InfluxDB time resolutions (added `ns`, `m`, `h`)
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Ilya Vassilevsky
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/Makefile
CHANGED
data/README.md
CHANGED
@@ -6,7 +6,9 @@
|
|
6
6
|
|
7
7
|
Add this gem to your application's `Gemfile`:
|
8
8
|
|
9
|
-
|
9
|
+
```bash
|
10
|
+
bundle add sidekiq-influxdb
|
11
|
+
```
|
10
12
|
|
11
13
|
## Usage
|
12
14
|
|
@@ -30,36 +32,46 @@ Sidekiq.configure_server do |config|
|
|
30
32
|
end
|
31
33
|
```
|
32
34
|
|
35
|
+
You can learn how to create a client in [InfluxDB client documentation](https://github.com/influxdata/influxdb-ruby#creating-a-client).
|
36
|
+
|
37
|
+
**Warning:** This middleware is going to write _a lot_ of metrics.
|
38
|
+
Set up your InfluxDB client accordingly:
|
39
|
+
* either set `async: true` in the client's options to use its built-in batching feature,
|
40
|
+
* or install Telegraf, set up aggregation inside it, and set up InfluxDB client to send metrics to it,
|
41
|
+
* or both.
|
42
|
+
|
33
43
|
When you deploy this code, you will start getting the following series in your InfluxDB database:
|
34
44
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
45
|
+
```
|
46
|
+
> select * from sidekiq_jobs
|
47
|
+
name: sidekiq_jobs
|
48
|
+
time application class creation_time error event jid queue total waited worked
|
49
|
+
---- ----------- ----- ------------- ----- ----- --- ----- ----- ------ ------
|
50
|
+
1511707465061000000 MyApp FooJob 1511707459.0186539 start 51cc82fe75fbeba37b1ff18f default 6.042410135269165
|
51
|
+
1511707465061000000 MyApp FooJob 1511707459.0186539 finish 51cc82fe75fbeba37b1ff18f default 8.046684265136719 6.042410135269165 2.0042741298675537
|
52
|
+
1511707467068000000 MyApp BarJob 1511707461.019835 start 3891f241ab84d3aba728822e default 6.049134016036987
|
53
|
+
1511707467068000000 MyApp BarJob 1511707461.019835 NoMethodError error 3891f241ab84d3aba728822e default 8.056788206100464 6.049134016036987 2.0076541900634766
|
54
|
+
```
|
43
55
|
|
44
|
-
Tags (repetitive
|
56
|
+
Tags (repetitive indexed data; for filtering and grouping by):
|
45
57
|
|
46
|
-
* `time` —
|
47
|
-
* `queue` —
|
48
|
-
* `class` —
|
49
|
-
* `event` —
|
50
|
-
* `error` —
|
51
|
-
*
|
58
|
+
* `time` — standard InfluxDB timestamp. Precision of the supplied client is respected.
|
59
|
+
* `queue` — queue name.
|
60
|
+
* `class` — job class name. Classes from `except:` keyword argument are skipped (no data is sent to InfluxDB).
|
61
|
+
* `event` — what happened to the job at the specified `time`: `start`, `finish`, or `error`. If you initialize the middleware with `start_events: false`, there will be no `start` events.
|
62
|
+
* `error` — if `event=error`, this tag contains the exception class name.
|
63
|
+
* Your own tags from the initializer.
|
52
64
|
|
53
|
-
Values (unique
|
65
|
+
Values (unique non-indexed data; for aggregation):
|
54
66
|
|
55
|
-
* `jid` —
|
56
|
-
* `creation_time` —
|
67
|
+
* `jid` — unique job ID.
|
68
|
+
* `creation_time` — job creation time.
|
57
69
|
|
58
70
|
Values calculated by this gem (in seconds):
|
59
71
|
|
60
|
-
* `waited` —
|
61
|
-
* `worked` —
|
62
|
-
* `total` —
|
72
|
+
* `waited` — how long the job waited in the `queue` until Sidekiq got around to starting it.
|
73
|
+
* `worked` — how long it took to perform the job from start to finish or to an exception.
|
74
|
+
* `total` — how much time passed from job creation to finish. How long it took to do the job, in total.
|
63
75
|
|
64
76
|
This schema allows querying various job metrics effectively.
|
65
77
|
|
@@ -82,16 +94,17 @@ Et cetera.
|
|
82
94
|
* [Sidekiq middleware](https://github.com/mperham/sidekiq/wiki/Middleware)
|
83
95
|
* [InfluxDB client](https://github.com/influxdata/influxdb-ruby)
|
84
96
|
|
85
|
-
After checking out the repo, run `bin/setup` to install dependencies.
|
86
|
-
|
87
|
-
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
97
|
+
After checking out the repo, run `bin/setup` to install dependencies.
|
98
|
+
You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
88
99
|
|
89
100
|
## Contributing
|
90
101
|
|
91
|
-
Bug reports and pull requests are welcome on GitHub at
|
102
|
+
Bug reports and pull requests are welcome on GitHub at [github.com/funbox/sidekiq-influxdb](https://github.com/funbox/sidekiq-influxdb).
|
103
|
+
This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
92
104
|
|
93
105
|
## Code of Conduct
|
94
106
|
|
95
|
-
Everyone interacting in the Sidekiq::InfluxDB project’s codebases, issue trackers,
|
107
|
+
Everyone interacting in the `Sidekiq::InfluxDB` project’s codebases, issue trackers,
|
108
|
+
chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/funbox/sidekiq-influxdb/blob/master/CODE_OF_CONDUCT.md).
|
96
109
|
|
97
|
-
[](https://funbox.ru)
|
data/Rakefile
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
require 'set'
|
2
|
-
require 'influxdb'
|
3
2
|
|
4
3
|
module Sidekiq
|
5
4
|
module Middleware
|
@@ -12,53 +11,72 @@ module Sidekiq
|
|
12
11
|
retention_policy: nil,
|
13
12
|
start_events: true,
|
14
13
|
tags: {},
|
15
|
-
except: []
|
14
|
+
except: [],
|
15
|
+
clock: -> { Time.now.to_f }
|
16
16
|
)
|
17
17
|
@influxdb = influxdb_client
|
18
18
|
@series = series_name
|
19
19
|
@retention = retention_policy
|
20
20
|
@start_events = start_events
|
21
21
|
@tags = tags
|
22
|
-
@secret_agents =
|
22
|
+
@secret_agents = class_names(except)
|
23
|
+
@clock = clock
|
23
24
|
end
|
24
25
|
|
25
|
-
def call(
|
26
|
-
if @secret_agents.include?(
|
26
|
+
def call(_worker, msg, _queue)
|
27
|
+
if @secret_agents.include?(job_class_name(msg))
|
27
28
|
yield
|
28
29
|
return
|
29
30
|
end
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
event: 'start',
|
36
|
-
}.merge(@tags),
|
37
|
-
values: {
|
38
|
-
jid: msg['jid'],
|
39
|
-
creation_time: msg['created_at'],
|
40
|
-
waited: t - msg['created_at'],
|
41
|
-
},
|
42
|
-
timestamp: in_correct_precision(t)
|
43
|
-
}
|
44
|
-
save(data) if @start_events
|
31
|
+
|
32
|
+
started_at = @clock.call
|
33
|
+
waited = started_at - msg['created_at']
|
34
|
+
record(started_at, msg, {event: 'start'}, {waited: waited}) if @start_events
|
35
|
+
|
45
36
|
begin
|
46
37
|
yield
|
47
|
-
|
38
|
+
tags = {event: 'finish'}
|
48
39
|
rescue => e
|
49
|
-
|
50
|
-
data[:tags][:error] = e.class.name
|
40
|
+
tags = {event: 'error', error: e.class.name}
|
51
41
|
end
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
42
|
+
|
43
|
+
finished_at = @clock.call
|
44
|
+
worked = finished_at - started_at
|
45
|
+
record(finished_at, msg, tags, {waited: waited, worked: worked, total: waited + worked})
|
46
|
+
|
57
47
|
raise e if e
|
58
48
|
end
|
59
49
|
|
60
50
|
private
|
61
51
|
|
52
|
+
def class_names(except)
|
53
|
+
Set.new([except].flatten.map{|e| class_name(e) })
|
54
|
+
end
|
55
|
+
|
56
|
+
def class_name(class_or_name)
|
57
|
+
class_or_name.name
|
58
|
+
rescue NoMethodError
|
59
|
+
class_or_name
|
60
|
+
end
|
61
|
+
|
62
|
+
def job_class_name(msg)
|
63
|
+
msg['wrapped'] || msg['class']
|
64
|
+
end
|
65
|
+
|
66
|
+
def record(t, msg, tags, values = {})
|
67
|
+
save(
|
68
|
+
tags: {
|
69
|
+
class: job_class_name(msg),
|
70
|
+
queue: msg['queue']
|
71
|
+
}.merge(tags).merge(@tags),
|
72
|
+
values: {
|
73
|
+
jid: msg['jid'],
|
74
|
+
creation_time: msg['created_at']
|
75
|
+
}.merge(values),
|
76
|
+
timestamp: in_correct_precision(t)
|
77
|
+
)
|
78
|
+
end
|
79
|
+
|
62
80
|
def save(data)
|
63
81
|
@influxdb.write_point(@series, data, precision, @retention)
|
64
82
|
end
|
@@ -74,8 +92,8 @@ module Sidekiq
|
|
74
92
|
when 's' then t.to_i
|
75
93
|
when 'u' then (t * 1_000_000).to_i
|
76
94
|
when 'ns' then (t * 1_000_000_000).to_i
|
77
|
-
when 'm' then (t / 60).to_i
|
78
|
-
when 'h' then (t / 60 / 60).to_i
|
95
|
+
when 'm' then (t / 60).to_i * 60
|
96
|
+
when 'h' then (t / 60 / 60).to_i * 60 * 60
|
79
97
|
end
|
80
98
|
end
|
81
99
|
|
data/sidekiq-influxdb.gemspec
CHANGED
@@ -21,6 +21,6 @@ Gem::Specification.new do |spec|
|
|
21
21
|
spec.add_runtime_dependency "influxdb"
|
22
22
|
spec.add_runtime_dependency "sidekiq"
|
23
23
|
|
24
|
-
spec.add_development_dependency "
|
25
|
-
spec.add_development_dependency "
|
24
|
+
spec.add_development_dependency "rspec"
|
25
|
+
spec.add_development_dependency "simplecov"
|
26
26
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sidekiq-influxdb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ilya Vassilevsky
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-09-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: influxdb
|
@@ -39,34 +39,34 @@ dependencies:
|
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: rspec
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - "
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
54
|
+
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: simplecov
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - "
|
59
|
+
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
61
|
+
version: '0'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- - "
|
66
|
+
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
69
|
-
description:
|
68
|
+
version: '0'
|
69
|
+
description:
|
70
70
|
email:
|
71
71
|
- vassilevsky@gmail.com
|
72
72
|
executables: []
|
@@ -74,10 +74,11 @@ extensions: []
|
|
74
74
|
extra_rdoc_files: []
|
75
75
|
files:
|
76
76
|
- ".gitignore"
|
77
|
-
- ".
|
77
|
+
- ".rspec"
|
78
78
|
- CHANGELOG.md
|
79
79
|
- CODE_OF_CONDUCT.md
|
80
80
|
- Gemfile
|
81
|
+
- LICENSE
|
81
82
|
- Makefile
|
82
83
|
- README.md
|
83
84
|
- Rakefile
|
@@ -88,7 +89,7 @@ files:
|
|
88
89
|
homepage: https://github.com/vassilevsky/sidekiq-influxdb
|
89
90
|
licenses: []
|
90
91
|
metadata: {}
|
91
|
-
post_install_message:
|
92
|
+
post_install_message:
|
92
93
|
rdoc_options: []
|
93
94
|
require_paths:
|
94
95
|
- lib
|
@@ -103,9 +104,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
103
104
|
- !ruby/object:Gem::Version
|
104
105
|
version: '0'
|
105
106
|
requirements: []
|
106
|
-
|
107
|
-
|
108
|
-
signing_key:
|
107
|
+
rubygems_version: 3.0.3
|
108
|
+
signing_key:
|
109
109
|
specification_version: 4
|
110
110
|
summary: Writes Sidekiq job metrics to InfluxDB
|
111
111
|
test_files: []
|
data/.ruby-version
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
2.5.1
|