sidekiq-influxdb 1.4.1 → 1.4.2
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/CHANGELOG.md +5 -0
- data/README.md +25 -3
- data/lib/sidekiq/influxdb/version.rb +1 -1
- data/lib/sidekiq/middleware/server/influxdb.rb +24 -18
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 607a8f119a12166e7e1e9b266d5e8a6f15c665b2f4c3dd8d8f83dbf4485bf2ce
|
|
4
|
+
data.tar.gz: a7daceac5ae7b29a3d45b5cffaa0ee73e90bfe6b6a795659e0d465e28037a865
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 7de72f2c1014b3eacdcfb03e15eebfe4d3521c4e2379f029ed3ab07fd97ccce6e9639977985c4a50a59dd786940f6b21452835513123847a6f7c474f1a1105e0
|
|
7
|
+
data.tar.gz: affc2415b5ed9a874e3a9804128bcfc320081d1a324bcde8bd583e6d054a72fd2f30f0ba3aeca18bfa5a00778ea80ceed48a820f33c2f9aabfbacd785ef280d1
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
# Sidekiq-InfluxDB Changelog
|
|
2
2
|
|
|
3
|
+
## 1.4.2 (2026-06-05)
|
|
4
|
+
|
|
5
|
+
* Sidekiq 8 support: convert millisecond `created_at` (Integer) to seconds for `waited`, `creation_time`, and `total`
|
|
6
|
+
* Added `measurement_key` option (`:values` by default, use `:fields` for InfluxDB 2 clients)
|
|
7
|
+
|
|
3
8
|
## 1.4.1 (2021-04-20)
|
|
4
9
|
|
|
5
10
|
* Ruby 3 support
|
data/README.md
CHANGED
|
@@ -5,7 +5,8 @@
|
|
|
5
5
|
[](https://coveralls.io/github/funbox/sidekiq-influxdb)
|
|
6
6
|
|
|
7
7
|
[Sidekiq](https://github.com/mperham/sidekiq/wiki) server middleware
|
|
8
|
-
that writes job lifecycle events as points to an [InfluxDB](http://docs.influxdata.com/influxdb/v1.3/) database
|
|
8
|
+
that writes job lifecycle events as points to an [InfluxDB](http://docs.influxdata.com/influxdb/v1.3/) database
|
|
9
|
+
(or any client with a compatible `write_point` API, including [InfluxDB 2](https://github.com/influxdata/influxdb-client-ruby)).
|
|
9
10
|
Also includes classes that write global Sidekiq metrics and queue metrics.
|
|
10
11
|
|
|
11
12
|
## Installation
|
|
@@ -50,11 +51,32 @@ Sidekiq.configure_server do |config|
|
|
|
50
51
|
retention_policy: 'rp_name', # In case you want to write metrics to a non-default RP.
|
|
51
52
|
start_events: true, # Whether or not you want to know when jobs started. See `event` tag description below.
|
|
52
53
|
tags: {application: 'MyApp'}, # Anything you need on top. **Make sure that tag values have low cardinality!**
|
|
53
|
-
except: [UnimportantJob]
|
|
54
|
+
except: [UnimportantJob], # These job classes will be executed without sending any metrics.
|
|
55
|
+
measurement_key: :values # Use :fields for InfluxDB 2 clients. Default: :values.
|
|
54
56
|
end
|
|
55
57
|
end
|
|
56
58
|
```
|
|
57
59
|
|
|
60
|
+
### Sidekiq 8
|
|
61
|
+
|
|
62
|
+
Sidekiq 8 stores `created_at` as epoch **milliseconds** (Integer).
|
|
63
|
+
Earlier versions used epoch **seconds** (Float).
|
|
64
|
+
The middleware detects the format automatically — no configuration change is required when upgrading Sidekiq.
|
|
65
|
+
|
|
66
|
+
### InfluxDB 2
|
|
67
|
+
|
|
68
|
+
The default payload key is `values` (InfluxDB 1.x and the [`influxdb`](https://github.com/influxdata/influxdb-ruby) gem).
|
|
69
|
+
InfluxDB 2 clients ([`influxdb-client`](https://github.com/influxdata/influxdb-client-ruby)) expect `fields` instead:
|
|
70
|
+
|
|
71
|
+
```ruby
|
|
72
|
+
chain.add Sidekiq::Middleware::Server::InfluxDB,
|
|
73
|
+
influxdb_client: my_influxdb2_client,
|
|
74
|
+
measurement_key: :fields
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
Your client must implement `write_point(series_name, data, precision, retention)` and accept a hash with
|
|
78
|
+
`tags`, the configured measurement key (`values` or `fields`), and `timestamp`.
|
|
79
|
+
|
|
58
80
|
This library assumes that you already have an InfluxDB client object set up the way you like.
|
|
59
81
|
It does not try to create one for you.
|
|
60
82
|
If that is not the case, you can learn how to create a client
|
|
@@ -88,7 +110,7 @@ Tags (repetitive indexed data; for filtering and grouping by):
|
|
|
88
110
|
* `error` — if `event=error`, this tag contains the exception class name.
|
|
89
111
|
* Your own tags from the initializer.
|
|
90
112
|
|
|
91
|
-
Values (unique non-indexed data; for aggregation):
|
|
113
|
+
Values / fields (unique non-indexed data; for aggregation; the key name depends on `measurement_key`):
|
|
92
114
|
|
|
93
115
|
* `jid` — unique job ID.
|
|
94
116
|
* `creation_time` — job creation time.
|
|
@@ -5,6 +5,8 @@ module Sidekiq
|
|
|
5
5
|
module Server
|
|
6
6
|
class InfluxDB
|
|
7
7
|
|
|
8
|
+
MILLISECONDS_PER_SECOND = 1000.0
|
|
9
|
+
|
|
8
10
|
def initialize(options = {})
|
|
9
11
|
@influxdb = options.fetch(:influxdb_client)
|
|
10
12
|
@series = options.fetch(:series_name, 'sidekiq_jobs')
|
|
@@ -13,6 +15,7 @@ module Sidekiq
|
|
|
13
15
|
@tags = options.fetch(:tags, {})
|
|
14
16
|
@secret_agents = class_names(options.fetch(:except, []))
|
|
15
17
|
@clock = options.fetch(:clock, -> { Time.now.to_f })
|
|
18
|
+
@measurement_key = options.fetch(:measurement_key, :values)
|
|
16
19
|
end
|
|
17
20
|
|
|
18
21
|
def call(_worker, msg, _queue)
|
|
@@ -22,49 +25,52 @@ module Sidekiq
|
|
|
22
25
|
end
|
|
23
26
|
|
|
24
27
|
started_at = @clock.call
|
|
25
|
-
waited = started_at - msg
|
|
26
|
-
record(started_at, msg, {event: 'start'}, {waited: waited}) if @start_events
|
|
28
|
+
waited = started_at - created_at_in_seconds(msg)
|
|
29
|
+
record(started_at, msg, { event: 'start' }, { waited: waited }) if @start_events
|
|
27
30
|
|
|
31
|
+
error = nil
|
|
28
32
|
begin
|
|
29
33
|
yield
|
|
30
|
-
tags = {event: 'finish'}
|
|
31
|
-
rescue => e
|
|
32
|
-
tags = {event: 'error', error: e.class.name}
|
|
34
|
+
tags = { event: 'finish' }
|
|
35
|
+
rescue StandardError => e
|
|
36
|
+
tags = { event: 'error', error: e.class.name }
|
|
37
|
+
error = e
|
|
33
38
|
end
|
|
34
39
|
|
|
35
40
|
finished_at = @clock.call
|
|
36
41
|
worked = finished_at - started_at
|
|
37
|
-
record(finished_at, msg, tags, {waited: waited, worked: worked, total: waited + worked})
|
|
42
|
+
record(finished_at, msg, tags, { waited: waited, worked: worked, total: waited + worked })
|
|
38
43
|
|
|
39
|
-
raise
|
|
44
|
+
raise error if error
|
|
40
45
|
end
|
|
41
46
|
|
|
42
47
|
private
|
|
43
48
|
|
|
44
49
|
def class_names(except)
|
|
45
|
-
Set.new([except].flatten.map
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
def class_name(class_or_name)
|
|
49
|
-
class_or_name.name
|
|
50
|
-
rescue NoMethodError
|
|
51
|
-
class_or_name
|
|
50
|
+
Set.new([except].flatten.map(&:to_s))
|
|
52
51
|
end
|
|
53
52
|
|
|
54
53
|
def job_class_name(msg)
|
|
55
54
|
msg['wrapped'] || msg['class']
|
|
56
55
|
end
|
|
57
56
|
|
|
58
|
-
def
|
|
57
|
+
def created_at_in_seconds(msg)
|
|
58
|
+
created_at = msg['created_at']
|
|
59
|
+
return created_at unless created_at.is_a?(Integer)
|
|
60
|
+
|
|
61
|
+
created_at / MILLISECONDS_PER_SECOND
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def record(t, msg, tags, measurement = {})
|
|
59
65
|
save(
|
|
60
66
|
tags: {
|
|
61
67
|
class: job_class_name(msg),
|
|
62
68
|
queue: msg['queue']
|
|
63
69
|
}.merge(tags).merge(@tags),
|
|
64
|
-
|
|
70
|
+
@measurement_key => {
|
|
65
71
|
jid: msg['jid'],
|
|
66
|
-
creation_time: msg
|
|
67
|
-
}.merge(
|
|
72
|
+
creation_time: created_at_in_seconds(msg)
|
|
73
|
+
}.merge(measurement),
|
|
68
74
|
timestamp: in_correct_precision(t)
|
|
69
75
|
)
|
|
70
76
|
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.
|
|
4
|
+
version: 1.4.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Ilya Vassilevsky
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2026-06-05 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: influxdb
|