sidekiq-datadog 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/.travis.yml +6 -0
- data/Gemfile +3 -0
- data/LICENSE.txt +22 -0
- data/README.md +33 -0
- data/Rakefile +7 -0
- data/lib/sidekiq/datadog/version.rb +5 -0
- data/lib/sidekiq/middleware/server/datadog.rb +90 -0
- data/lib/sidekiq-datadog.rb +1 -0
- data/sidekiq-datadog.gemspec +26 -0
- data/spec/sidekiq/datadog/version_spec.rb +7 -0
- data/spec/sidekiq/middleware/server/datadog_spec.rb +38 -0
- data/spec/spec_helper.rb +17 -0
- metadata +130 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 5aea86eaa87d26b2fa592d8ca714c4fffec52f3a
|
4
|
+
data.tar.gz: 34498e1f66cc33ac85f6056a803c625ddc7a5524
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 84c2b8fa2b0504fd69b67314b4f55b6ae32678fb07c29db9ba0526bb33bd8302293efe78961e77c7ff67d6587d61c4ec01834a88ea952b5603997328f91225f1
|
7
|
+
data.tar.gz: 8bc0124d01c54c5a76428ec09099e092cc504c964501b65254ad14ede5c7aa74e02d460454e6da08503e526f7c6d8ff9edbae3af7217564342925ebc88be00b9
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 Dimitrij Denissenko
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
sidekiq-datadog
|
2
|
+
=============
|
3
|
+
|
4
|
+
Datadog intrumentation for [Sidekiq](https://github.com/mperham/sidekiq), integrated via server middleware.
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
gem 'sidekiq-datadog'
|
11
|
+
|
12
|
+
Or install:
|
13
|
+
|
14
|
+
$ gem install sidekiq-datadog
|
15
|
+
|
16
|
+
Configure it in an initializer:
|
17
|
+
|
18
|
+
Sidekiq.configure_server do |config|
|
19
|
+
config.server_middleware do |chain|
|
20
|
+
chain.add Sidekiq::Middleware::Server::Datadog
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
For full configuration options, please see the [Documentation][http://www.rubydoc.info/gems/sidekiq-datadog].
|
25
|
+
|
26
|
+
## Contributing
|
27
|
+
|
28
|
+
1. Fork it
|
29
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
30
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
31
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
32
|
+
5. Make a pull request
|
33
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
require 'sidekiq'
|
2
|
+
require 'sidekiq/datadog/version'
|
3
|
+
require 'statsd'
|
4
|
+
require 'socket'
|
5
|
+
|
6
|
+
module Sidekiq
|
7
|
+
module Middleware
|
8
|
+
module Server
|
9
|
+
class Datadog
|
10
|
+
|
11
|
+
# Configure and install datadog instrumentation. Example:
|
12
|
+
#
|
13
|
+
# Sidekiq.configure_server do |config|
|
14
|
+
# config.server_middleware do |chain|
|
15
|
+
# chain.add Sidekiq::Middleware::Server::Datadog
|
16
|
+
# end
|
17
|
+
# end
|
18
|
+
#
|
19
|
+
# Options:
|
20
|
+
# * <tt>:hostname</tt> - the hostname used for instrumentation, defaults to system hostname, respects +INSTRUMENTATION_HOSTNAME+ env variable
|
21
|
+
# * <tt>:metric_name</tt> - the metric name (prefix) to use, defaults to "sidekiq.job"
|
22
|
+
# * <tt>:tags</tt> - array of custom tags, these can be plain strings or lambda blocks accepting a rack env instance
|
23
|
+
# * <tt>:statsd_host</tt> - the statsD host, defaults to "localhost", respects +STATSD_HOST+ env variable
|
24
|
+
# * <tt>:statsd_port</tt> - the statsD port, defaults to 8125, respects +STATSD_PORT+ env variable
|
25
|
+
# * <tt>:statsd</tt> - custom statsd instance
|
26
|
+
def initialize(opts = {})
|
27
|
+
hostname = opts[:hostname] || ENV['INSTRUMENTATION_HOSTNAME'] || Socket.gethostname
|
28
|
+
statsd_host = opts[:statsd_host] || ENV['STATSD_HOST'] || "localhost"
|
29
|
+
statsd_port = (opts[:statsd_port] || ENV['STATSD_PORT'] || 8125).to_i
|
30
|
+
|
31
|
+
@metric_name = opts[:metric_name] || "sidekiq.job"
|
32
|
+
@statsd = opts[:statsd] || ::Statsd.new(statsd_host, statsd_port)
|
33
|
+
@tags = opts[:tags] || []
|
34
|
+
|
35
|
+
if @tags.none? {|t| t =~ /^host\:/ }
|
36
|
+
@tags.push("host:#{hostname}")
|
37
|
+
end
|
38
|
+
|
39
|
+
env = Sidekiq.options[:environment] || ENV['RACK_ENV']
|
40
|
+
if env && @tags.none? {|t| t =~ /^env\:/ }
|
41
|
+
@tags.push("env:#{ENV['RACK_ENV']}")
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def call(worker, job, queue, *)
|
46
|
+
start = Time.now
|
47
|
+
begin
|
48
|
+
yield
|
49
|
+
record(worker, job, queue, start)
|
50
|
+
rescue => e
|
51
|
+
record(worker, job, queue, start, e)
|
52
|
+
raise
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
private
|
57
|
+
|
58
|
+
def record(worker, job, queue, start, error = nil)
|
59
|
+
ms = ((Time.now - start) * 1000).round
|
60
|
+
name = underscore(job['wrapped'] || worker.class.to_s)
|
61
|
+
tags = @tags.map do |tag|
|
62
|
+
case tag when String then tag when Proc then tag.call(worker, job, queue, error) end
|
63
|
+
end
|
64
|
+
|
65
|
+
tags.push "name:#{name}"
|
66
|
+
tags.push "queue:#{queue}" if queue
|
67
|
+
if error
|
68
|
+
kind = underscore(error.class.name.sub(/Error$/, ''))
|
69
|
+
tags.push "status:error", "error:#{kind}"
|
70
|
+
else
|
71
|
+
tags.push "status:ok"
|
72
|
+
end
|
73
|
+
tags.compact!
|
74
|
+
|
75
|
+
@statsd.increment @metric_name, :tags => tags
|
76
|
+
@statsd.timing "#{@metric_name}.time", ms, :tags => tags
|
77
|
+
end
|
78
|
+
|
79
|
+
def underscore(word)
|
80
|
+
word = word.to_s.gsub(/::/, '/')
|
81
|
+
word.gsub!(/([A-Z\d]+)([A-Z][a-z])/,'\1_\2')
|
82
|
+
word.gsub!(/([a-z\d])([A-Z])/,'\1_\2')
|
83
|
+
word.tr!("-", "_")
|
84
|
+
word.downcase
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require "sidekiq/middleware/server/datadog"
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'sidekiq/datadog/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = "sidekiq-datadog"
|
8
|
+
s.version = Sidekiq::Datadog::VERSION.dup
|
9
|
+
s.authors = ["Dimitrij Denissenko"]
|
10
|
+
s.email = ["dimitrij@blacksquaremedia.com"]
|
11
|
+
s.description = %q{Datadog metrics for sidekiq}
|
12
|
+
s.summary = %q{Datadog metrics for sidekiq}
|
13
|
+
s.homepage = "https://github.com/bsm/sidekiq-datadog"
|
14
|
+
|
15
|
+
s.files = `git ls-files`.split($/)
|
16
|
+
s.executables = s.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
s.test_files = s.files.grep(%r{^(spec)/})
|
18
|
+
s.require_paths = ["lib"]
|
19
|
+
|
20
|
+
s.add_runtime_dependency(%q<sidekiq>)
|
21
|
+
s.add_runtime_dependency(%q<dogstatsd-ruby>)
|
22
|
+
|
23
|
+
s.add_development_dependency(%q<rake>)
|
24
|
+
s.add_development_dependency(%q<bundler>)
|
25
|
+
s.add_development_dependency(%q<rspec>, "~> 3.0")
|
26
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Sidekiq::Middleware::Server::Datadog do
|
4
|
+
|
5
|
+
let(:statsd) { Mock::Statsd.new(nil, nil, {}, 10000) }
|
6
|
+
let(:worker) { Mock::Worker.new }
|
7
|
+
|
8
|
+
before { statsd.buffer.clear }
|
9
|
+
subject { described_class.new hostname: "test.host", statsd: statsd, tags: ["custom:tag", lambda{|w, *| "worker:#{w.class.name[1..2]}" }] }
|
10
|
+
|
11
|
+
it 'should send an increment and timing event for each job run' do
|
12
|
+
subject.call(worker, {}, 'default') { "ok" }
|
13
|
+
expect(statsd.buffer).to eq([
|
14
|
+
"sidekiq.job:1|c|#custom:tag,worker:oc,host:test.host,env:test,name:mock/worker,queue:default,status:ok",
|
15
|
+
"sidekiq.job.time:333|ms|#custom:tag,worker:oc,host:test.host,env:test,name:mock/worker,queue:default,status:ok",
|
16
|
+
])
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'should support wrappers' do
|
20
|
+
subject.call(worker, {'wrapped' => 'wrap'}, nil) { "ok" }
|
21
|
+
expect(statsd.buffer).to eq([
|
22
|
+
"sidekiq.job:1|c|#custom:tag,worker:oc,host:test.host,env:test,name:wrap,status:ok",
|
23
|
+
"sidekiq.job.time:333|ms|#custom:tag,worker:oc,host:test.host,env:test,name:wrap,status:ok",
|
24
|
+
])
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'should handle errors' do
|
28
|
+
expect(lambda {
|
29
|
+
subject.call(worker, {}, nil) { raise RuntimeError, "doh!" }
|
30
|
+
}).to raise_error("doh!")
|
31
|
+
|
32
|
+
expect(statsd.buffer).to eq([
|
33
|
+
"sidekiq.job:1|c|#custom:tag,worker:oc,host:test.host,env:test,name:mock/worker,status:error,error:runtime",
|
34
|
+
"sidekiq.job.time:333|ms|#custom:tag,worker:oc,host:test.host,env:test,name:mock/worker,status:error,error:runtime",
|
35
|
+
])
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
ENV['RACK_ENV'] ||= 'test'
|
2
|
+
|
3
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
4
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
5
|
+
|
6
|
+
require 'sidekiq-datadog'
|
7
|
+
|
8
|
+
module Mock
|
9
|
+
class Worker
|
10
|
+
end
|
11
|
+
|
12
|
+
class Statsd < ::Statsd
|
13
|
+
def timing(stat, ms, opts={}); super(stat, 333, opts); end
|
14
|
+
def flush_buffer; end
|
15
|
+
alias :send_stat :send_to_buffer
|
16
|
+
end
|
17
|
+
end
|
metadata
ADDED
@@ -0,0 +1,130 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sidekiq-datadog
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.3.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Dimitrij Denissenko
|
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: sidekiq
|
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: dogstatsd-ruby
|
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: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: bundler
|
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: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '3.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '3.0'
|
83
|
+
description: Datadog metrics for sidekiq
|
84
|
+
email:
|
85
|
+
- dimitrij@blacksquaremedia.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- ".travis.yml"
|
92
|
+
- Gemfile
|
93
|
+
- LICENSE.txt
|
94
|
+
- README.md
|
95
|
+
- Rakefile
|
96
|
+
- lib/sidekiq-datadog.rb
|
97
|
+
- lib/sidekiq/datadog/version.rb
|
98
|
+
- lib/sidekiq/middleware/server/datadog.rb
|
99
|
+
- sidekiq-datadog.gemspec
|
100
|
+
- spec/sidekiq/datadog/version_spec.rb
|
101
|
+
- spec/sidekiq/middleware/server/datadog_spec.rb
|
102
|
+
- spec/spec_helper.rb
|
103
|
+
homepage: https://github.com/bsm/sidekiq-datadog
|
104
|
+
licenses: []
|
105
|
+
metadata: {}
|
106
|
+
post_install_message:
|
107
|
+
rdoc_options: []
|
108
|
+
require_paths:
|
109
|
+
- lib
|
110
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
111
|
+
requirements:
|
112
|
+
- - ">="
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
version: '0'
|
115
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
116
|
+
requirements:
|
117
|
+
- - ">="
|
118
|
+
- !ruby/object:Gem::Version
|
119
|
+
version: '0'
|
120
|
+
requirements: []
|
121
|
+
rubyforge_project:
|
122
|
+
rubygems_version: 2.4.7
|
123
|
+
signing_key:
|
124
|
+
specification_version: 4
|
125
|
+
summary: Datadog metrics for sidekiq
|
126
|
+
test_files:
|
127
|
+
- spec/sidekiq/datadog/version_spec.rb
|
128
|
+
- spec/sidekiq/middleware/server/datadog_spec.rb
|
129
|
+
- spec/spec_helper.rb
|
130
|
+
has_rdoc:
|