honeykiq 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +17 -0
- data/Gemfile.lock +7 -1
- data/README.md +42 -8
- data/honeykiq.gemspec +1 -0
- data/lib/honeykiq.rb +1 -4
- data/lib/honeykiq/periodic_reporter.rb +0 -1
- data/lib/honeykiq/server_middleware.rb +62 -0
- data/lib/honeykiq/version.rb +1 -1
- metadata +17 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 44fbbee328df450194663816c3f3cdb196970dfd8be5b9bcb547569255e44513
|
4
|
+
data.tar.gz: cb8fbe2e9ab677c6f2aa360729b23f26de1b0c37a417057c142307850e260da3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0e85c6f494daadd232009dec33a5fe616d058a1a7e69f04bd7fd124b2c96f7cec240cb4fc6a5df0c7a435087de101f7de0adedc13032276d69e2def17d4378bd
|
7
|
+
data.tar.gz: 8d9bcfcdedd91ffa9d26b537e2fa38a44386053a172c67b44029742b795b6341f47568df28096035c6b24f9b12e517e3f88871502694559ba46805cc057a5780
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# Changelog
|
2
|
+
All notable changes to this project will be documented in this file.
|
3
|
+
|
4
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
5
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
6
|
+
|
7
|
+
## [Unreleased]
|
8
|
+
|
9
|
+
## [0.2.0]
|
10
|
+
### Added
|
11
|
+
- `Honeykiq::ServerMiddleware` 🙌
|
12
|
+
|
13
|
+
### Removed
|
14
|
+
- `Honeykiq.periodic_reporter`. (Use `Honeykiq::PeriodicReporter.new` instead.)
|
15
|
+
|
16
|
+
[Unreleased]: https://github.com/olivierlacan/keep-a-changelog/compare/v0.2.0...HEAD
|
17
|
+
[0.2.0]: https://github.com/olivierlacan/keep-a-changelog/compare/v0.1.0...v0.2.0
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
honeykiq (0.
|
4
|
+
honeykiq (0.2.0)
|
5
5
|
sidekiq
|
6
6
|
|
7
7
|
GEM
|
@@ -13,6 +13,7 @@ GEM
|
|
13
13
|
carwow_rubocop (2.1.1)
|
14
14
|
rubocop (~> 0.58)
|
15
15
|
rubocop-rspec (~> 1.28)
|
16
|
+
coderay (1.1.2)
|
16
17
|
connection_pool (2.2.2)
|
17
18
|
diff-lcs (1.3)
|
18
19
|
domain_name (0.5.20180417)
|
@@ -30,10 +31,14 @@ GEM
|
|
30
31
|
libhoney (1.11.0)
|
31
32
|
addressable (~> 2.0)
|
32
33
|
http (>= 2.0, < 4.0)
|
34
|
+
method_source (0.9.2)
|
33
35
|
parallel (1.12.1)
|
34
36
|
parser (2.5.3.0)
|
35
37
|
ast (~> 2.4.0)
|
36
38
|
powerpack (0.1.2)
|
39
|
+
pry (0.12.2)
|
40
|
+
coderay (~> 1.1.0)
|
41
|
+
method_source (~> 0.9.0)
|
37
42
|
public_suffix (3.0.3)
|
38
43
|
rack (2.0.6)
|
39
44
|
rack-protection (2.0.4)
|
@@ -82,6 +87,7 @@ DEPENDENCIES
|
|
82
87
|
carwow_rubocop
|
83
88
|
honeykiq!
|
84
89
|
libhoney
|
90
|
+
pry
|
85
91
|
rake
|
86
92
|
rspec
|
87
93
|
|
data/README.md
CHANGED
@@ -14,15 +14,49 @@ gem 'honeykiq'
|
|
14
14
|
|
15
15
|
## Usage
|
16
16
|
|
17
|
-
|
18
|
-
scheduled to report every few seconds depending on your use case.
|
17
|
+
The library provides two use cases:
|
19
18
|
|
20
|
-
|
19
|
+
- [`Honeykiq::ServerMiddleware`]
|
20
|
+
- [`Honeykiq::PeriodicReporter`]
|
21
21
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
22
|
+
[`Honeykiq::ServerMiddleware`]: #HoneykiqServerMiddleware
|
23
|
+
[`Honeykiq::PeriodicReporter`]: #HoneykiqPeriodicReporter
|
24
|
+
|
25
|
+
### Honeykiq::ServerMiddleware
|
26
|
+
|
27
|
+
Add it to Sidekiq server middleware chain and pass a `Libhoney::Client` as
|
28
|
+
shown below. It will send an event to Honeycomb once a job finishes or fails.
|
29
|
+
Have a look at [server_middleware.rb] to see what kind of information we send.
|
30
|
+
|
31
|
+
[server_middleware.rb]: https://github.com/carwow/honeykiq/blob/master/lib/honeykiq/server_middleware.rb
|
32
|
+
|
33
|
+
```ruby
|
34
|
+
Sidekiq.configure_server do |config|
|
35
|
+
config.server_middleware do |chain|
|
36
|
+
chain.add Honeykiq::ServerMiddleware,
|
37
|
+
honey_client: Libhoney::Client.new(
|
38
|
+
writekey: ENV.fetch('HONEYCOMB_WRITE_KEY'),
|
39
|
+
dataset: ENV.fetch('HONEYCOMB_DATASET')
|
40
|
+
)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
```
|
44
|
+
|
45
|
+
**Note on long running jobs:** If you have long running jobs an event is only
|
46
|
+
sent to Honeycomb when it finishes so it may appear as no jobs are running.
|
47
|
+
Also if the process gets a SIGKILL then no event is sent about that job and the
|
48
|
+
job may keep retrying and not appear in Honeycomb. The `PeriodicReporter`
|
49
|
+
should help with this but we are thinking of a nicer approach.
|
50
|
+
|
51
|
+
### Honeykiq::PeriodicReporter
|
52
|
+
|
53
|
+
The periodic reporter should be scheduled to report every few seconds depending
|
54
|
+
on your use case (e.g. 30 seconds). Every time the `#report` method is called
|
55
|
+
it will send a total of `1 + P + Q` events to Honeycomb where P and Q are the
|
56
|
+
number of processes and queues respectively.
|
57
|
+
|
58
|
+
It sends three types of events: instance, process, and queue. Have a look at
|
59
|
+
[periodic_reporter.rb] to see what kind of information we send for each type.
|
26
60
|
|
27
61
|
[periodic_reporter.rb]: https://github.com/carwow/honeykiq/blob/master/lib/honeykiq/periodic_reporter.rb
|
28
62
|
|
@@ -45,7 +79,7 @@ module SidekiqHealth
|
|
45
79
|
end
|
46
80
|
|
47
81
|
def self.reporter
|
48
|
-
@reporter ||= Honeykiq.
|
82
|
+
@reporter ||= Honeykiq::PeriodicReporter.new(honey_client: honey_client)
|
49
83
|
end
|
50
84
|
|
51
85
|
def self.honey_client
|
data/honeykiq.gemspec
CHANGED
@@ -29,6 +29,7 @@ Gem::Specification.new do |spec|
|
|
29
29
|
spec.add_development_dependency 'bundler'
|
30
30
|
spec.add_development_dependency 'carwow_rubocop'
|
31
31
|
spec.add_development_dependency 'libhoney'
|
32
|
+
spec.add_development_dependency 'pry'
|
32
33
|
spec.add_development_dependency 'rake'
|
33
34
|
spec.add_development_dependency 'rspec'
|
34
35
|
end
|
data/lib/honeykiq.rb
CHANGED
@@ -1,8 +1,5 @@
|
|
1
1
|
module Honeykiq
|
2
2
|
autoload :Version, 'honeykiq/version'
|
3
3
|
autoload :PeriodicReporter, 'honeykiq/periodic_reporter'
|
4
|
-
|
5
|
-
def self.periodic_reporter(honey_client:)
|
6
|
-
@reporter = Honeykiq::PeriodicReporter.new(honey_client: honey_client)
|
7
|
-
end
|
4
|
+
autoload :ServerMiddleware, 'honeykiq/server_middleware'
|
8
5
|
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'sidekiq/api'
|
2
|
+
|
3
|
+
module Honeykiq
|
4
|
+
class ServerMiddleware
|
5
|
+
def initialize(options = {})
|
6
|
+
@honey_client = options.fetch(:honey_client)
|
7
|
+
end
|
8
|
+
|
9
|
+
def call(_worker, msg, queue_name)
|
10
|
+
event = @honey_client.event.add(**all_fields(msg, queue_name))
|
11
|
+
duration_ms(event) { yield }
|
12
|
+
event.add_field(:'job.status', 'finished')
|
13
|
+
rescue StandardError => error
|
14
|
+
event&.add_field(:'job.status', 'failed')
|
15
|
+
event&.add(error_info(error))
|
16
|
+
raise
|
17
|
+
ensure
|
18
|
+
event&.send
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def all_fields(msg, queue_name)
|
24
|
+
{
|
25
|
+
type: :job,
|
26
|
+
**job_fields(Sidekiq::Job.new(msg, queue_name)),
|
27
|
+
**queue_fields(Sidekiq::Queue.new(queue_name)),
|
28
|
+
'meta.thread_id': Thread.current.object_id
|
29
|
+
}
|
30
|
+
end
|
31
|
+
|
32
|
+
def job_fields(job)
|
33
|
+
{
|
34
|
+
'job.class': job.display_class,
|
35
|
+
'job.attempt_number': (job['retry_count'].to_i.nonzero? || 0) + 1,
|
36
|
+
'job.id': job.jid,
|
37
|
+
'job.arguments_bytes': job.args.to_json.bytesize,
|
38
|
+
'job.latency_sec': job.latency,
|
39
|
+
'job.batch_id': job['bid']
|
40
|
+
}.compact
|
41
|
+
end
|
42
|
+
|
43
|
+
def queue_fields(queue)
|
44
|
+
{
|
45
|
+
'queue.name': queue.name,
|
46
|
+
'queue.size': queue.size
|
47
|
+
}
|
48
|
+
end
|
49
|
+
|
50
|
+
def duration_ms(event)
|
51
|
+
start_time = Time.now
|
52
|
+
yield
|
53
|
+
ensure
|
54
|
+
duration = Time.now - start_time
|
55
|
+
event.add_field(:duration_ms, duration * 1000)
|
56
|
+
end
|
57
|
+
|
58
|
+
def error_info(error)
|
59
|
+
{ 'error.class': error.class.name, 'error.message': error.message }
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
data/lib/honeykiq/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: honeykiq
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- carwow Developers
|
@@ -66,6 +66,20 @@ dependencies:
|
|
66
66
|
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: pry
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
69
83
|
- !ruby/object:Gem::Dependency
|
70
84
|
name: rake
|
71
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -105,6 +119,7 @@ files:
|
|
105
119
|
- ".gitignore"
|
106
120
|
- ".rspec"
|
107
121
|
- ".rubocop.yml"
|
122
|
+
- CHANGELOG.md
|
108
123
|
- Gemfile
|
109
124
|
- Gemfile.lock
|
110
125
|
- LICENSE.txt
|
@@ -113,6 +128,7 @@ files:
|
|
113
128
|
- honeykiq.gemspec
|
114
129
|
- lib/honeykiq.rb
|
115
130
|
- lib/honeykiq/periodic_reporter.rb
|
131
|
+
- lib/honeykiq/server_middleware.rb
|
116
132
|
- lib/honeykiq/version.rb
|
117
133
|
homepage: https://github.com/carwow/honeykiq
|
118
134
|
licenses:
|