pliny-sidekiq 0.1.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 +7 -0
- data/.gitignore +9 -0
- data/.travis.yml +4 -0
- data/Gemfile +4 -0
- data/LICENSE +21 -0
- data/README.md +58 -0
- data/Rakefile +5 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/lib/pliny/sidekiq.rb +12 -0
- data/lib/pliny/sidekiq/middleware/client/log.rb +16 -0
- data/lib/pliny/sidekiq/middleware/client/request_id.rb +26 -0
- data/lib/pliny/sidekiq/middleware/server/log.rb +35 -0
- data/lib/pliny/sidekiq/middleware/server/request_id.rb +18 -0
- data/lib/pliny/sidekiq/version.rb +5 -0
- data/pliny-sidekiq.gemspec +27 -0
- metadata +158 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: cb79fb9d67b16721259bf2dd96c67be3641488c9
|
4
|
+
data.tar.gz: 60ff08f17f5ea9ac681ac44dd4e503f0edb56c9c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f657e177637640a732825faa13407bfcb5d5f6b18377f5b39bb833965be95cf399225838c882731616188670ccd090158093ff7c3f423f15290ca80805d01652
|
7
|
+
data.tar.gz: ab2ba97d3bc0c734b1f3b609b07149b4d2ab6156901347d69f312eaa3018118dbad5590999f12ce538718ea11552811f5952e1f21e3e1541c3b466e7ed7df76a
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Guðmundur Bjarni Ólafsson
|
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 all
|
13
|
+
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 THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
# Pliny::Sidekiq
|
2
|
+
|
3
|
+
Sidekiq middlewares for making life nicer when using Pliny
|
4
|
+
|
5
|
+
- Passes `request_id`s to and between jobs.
|
6
|
+
- logfmts when jobs are enqueued and being processed.
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
Add this line to your application's Gemfile:
|
11
|
+
|
12
|
+
```ruby
|
13
|
+
gem 'pliny-sidekiq'
|
14
|
+
```
|
15
|
+
|
16
|
+
And then execute:
|
17
|
+
|
18
|
+
$ bundle
|
19
|
+
|
20
|
+
Or install it yourself as:
|
21
|
+
|
22
|
+
$ gem install pliny-sidekiq
|
23
|
+
|
24
|
+
## Usage
|
25
|
+
|
26
|
+
Create a `config/initializers/sidekiq.rb` and with the following contents
|
27
|
+
|
28
|
+
```ruby
|
29
|
+
Sidekiq.configure_server do |config|
|
30
|
+
config.server_middleware do |chain|
|
31
|
+
chain.add Pliny::Sidekiq::Middleware::Server::RequestId
|
32
|
+
chain.add Pliny::Sidekiq::Middleware::Server::Log, metric_prefix: 'my-app'
|
33
|
+
end
|
34
|
+
|
35
|
+
config.client_middleware do |chain|
|
36
|
+
chain.add Pliny::Sidekiq::Middleware::Client::RequestId
|
37
|
+
chain.add Pliny::Sidekiq::Middleware::Client::Log
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
Sidekiq.configure_client do |config|
|
42
|
+
config.client_middleware do |chain|
|
43
|
+
chain.add Pliny::Sidekiq::Middleware::Client::RequestId
|
44
|
+
chain.add Pliny::Sidekiq::Middleware::Client::Log
|
45
|
+
end
|
46
|
+
end
|
47
|
+
```
|
48
|
+
|
49
|
+
## Development
|
50
|
+
|
51
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake false` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
52
|
+
|
53
|
+
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).
|
54
|
+
|
55
|
+
## Contributing
|
56
|
+
|
57
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/gudmundur/pliny-sidekiq.
|
58
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "pliny/sidekiq"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
require "pliny/sidekiq/version"
|
2
|
+
require "pliny/sidekiq/middleware/client/log"
|
3
|
+
require "pliny/sidekiq/middleware/client/request_id"
|
4
|
+
require "pliny/sidekiq/middleware/server/log"
|
5
|
+
require "pliny/sidekiq/middleware/server/request_id"
|
6
|
+
|
7
|
+
module Pliny
|
8
|
+
module Sidekiq
|
9
|
+
module Middleware
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Pliny::Sidekiq::Middleware
|
2
|
+
module Client
|
3
|
+
class Log
|
4
|
+
def call(worker_class, msg, queue, redis_pool)
|
5
|
+
yield.tap do
|
6
|
+
Pliny.log(
|
7
|
+
job: msg['class'],
|
8
|
+
job_id: msg['jid'],
|
9
|
+
enqueued: true,
|
10
|
+
enqueued_at: Time.at(msg['enqueued_at'])
|
11
|
+
)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Pliny::Sidekiq::Middleware
|
2
|
+
module Client
|
3
|
+
class RequestId
|
4
|
+
def call(worker_class, msg, queue, redis_pool)
|
5
|
+
@args = msg['args']
|
6
|
+
msg['request_ids'] = request_id.split(',') if request_id
|
7
|
+
yield
|
8
|
+
end
|
9
|
+
|
10
|
+
private
|
11
|
+
|
12
|
+
attr_reader :args
|
13
|
+
|
14
|
+
def request_id
|
15
|
+
@request_id ||=
|
16
|
+
request_id_args || Pliny::RequestStore.store[:request_id]
|
17
|
+
end
|
18
|
+
|
19
|
+
def request_id_args
|
20
|
+
return nil if !args.last.is_a?(Hash)
|
21
|
+
options = args.last
|
22
|
+
options[:request_id] || options['request_id']
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module Pliny::Sidekiq::Middleware
|
2
|
+
module Server
|
3
|
+
class Log
|
4
|
+
def initialize(metric_prefix: nil)
|
5
|
+
@metric_prefix = metric_prefix
|
6
|
+
end
|
7
|
+
|
8
|
+
def call(worker, job, queue)
|
9
|
+
context = {
|
10
|
+
sidekiq: true,
|
11
|
+
job_id: job['jid'],
|
12
|
+
}
|
13
|
+
|
14
|
+
Pliny.context(context) do
|
15
|
+
count("worker.#{worker.class.to_s.gsub('::', '.')}")
|
16
|
+
count("queue.#{queue}")
|
17
|
+
|
18
|
+
Pliny.log(job: job['class'], job_retry: job['retry']) do
|
19
|
+
yield
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def count(key, value=1)
|
27
|
+
Pliny.log("count##{metric_prefix}sidekiq.#{key}" => value)
|
28
|
+
end
|
29
|
+
|
30
|
+
def metric_prefix
|
31
|
+
@metric_prefix.nil? ? '' : "#{@metric_prefix}."
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Pliny::Sidekiq::Middleware
|
2
|
+
module Server
|
3
|
+
class RequestId
|
4
|
+
def initialize(store: Pliny::RequestStore)
|
5
|
+
@store = store
|
6
|
+
end
|
7
|
+
|
8
|
+
def call(worker, job, queue)
|
9
|
+
@store.clear!
|
10
|
+
@store.seed({
|
11
|
+
'REQUEST_IDS' => job['request_ids']
|
12
|
+
}) if job.include?('request_ids')
|
13
|
+
|
14
|
+
yield
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'pliny/sidekiq/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "pliny-sidekiq"
|
8
|
+
spec.version = Pliny::Sidekiq::VERSION
|
9
|
+
spec.license = 'MIT'
|
10
|
+
spec.authors = ["Guðmundur Bjarni Ólafsson"]
|
11
|
+
spec.email = ["gudmundur.bjarni@gmail.com"]
|
12
|
+
|
13
|
+
spec.summary = %q{Pliny logging and request_id support for Sidekiq}
|
14
|
+
spec.homepage = "https://github.com/gudmundur/pliny-sidekiq"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
|
+
spec.require_paths = ["lib"]
|
18
|
+
|
19
|
+
spec.add_dependency "pliny"
|
20
|
+
spec.add_dependency "sidekiq"
|
21
|
+
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.10"
|
23
|
+
spec.add_development_dependency "pry"
|
24
|
+
spec.add_development_dependency "pry-byebug"
|
25
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
26
|
+
spec.add_development_dependency "rspec", "~> 3.3"
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,158 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: pliny-sidekiq
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Guðmundur Bjarni Ólafsson
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-10-08 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: pliny
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: sidekiq
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.10'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.10'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: pry
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: pry-byebug
|
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'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rake
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '10.0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '10.0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rspec
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '3.3'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '3.3'
|
111
|
+
description:
|
112
|
+
email:
|
113
|
+
- gudmundur.bjarni@gmail.com
|
114
|
+
executables: []
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files: []
|
117
|
+
files:
|
118
|
+
- ".gitignore"
|
119
|
+
- ".travis.yml"
|
120
|
+
- Gemfile
|
121
|
+
- LICENSE
|
122
|
+
- README.md
|
123
|
+
- Rakefile
|
124
|
+
- bin/console
|
125
|
+
- bin/setup
|
126
|
+
- lib/pliny/sidekiq.rb
|
127
|
+
- lib/pliny/sidekiq/middleware/client/log.rb
|
128
|
+
- lib/pliny/sidekiq/middleware/client/request_id.rb
|
129
|
+
- lib/pliny/sidekiq/middleware/server/log.rb
|
130
|
+
- lib/pliny/sidekiq/middleware/server/request_id.rb
|
131
|
+
- lib/pliny/sidekiq/version.rb
|
132
|
+
- pliny-sidekiq.gemspec
|
133
|
+
homepage: https://github.com/gudmundur/pliny-sidekiq
|
134
|
+
licenses:
|
135
|
+
- MIT
|
136
|
+
metadata: {}
|
137
|
+
post_install_message:
|
138
|
+
rdoc_options: []
|
139
|
+
require_paths:
|
140
|
+
- lib
|
141
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
147
|
+
requirements:
|
148
|
+
- - ">="
|
149
|
+
- !ruby/object:Gem::Version
|
150
|
+
version: '0'
|
151
|
+
requirements: []
|
152
|
+
rubyforge_project:
|
153
|
+
rubygems_version: 2.4.5
|
154
|
+
signing_key:
|
155
|
+
specification_version: 4
|
156
|
+
summary: Pliny logging and request_id support for Sidekiq
|
157
|
+
test_files: []
|
158
|
+
has_rdoc:
|