sidekiq-datadog 0.5.0 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e55b57e1e98640d8573d18c6b178ecfebf50096e452e2575a96830377515ff2b
4
- data.tar.gz: 915d6d656853099ce4a4c01c1acdfbb46bd66efd618702bc7c899177b30a3c35
3
+ metadata.gz: 02d15ba4b6e7d71e6f38be19ecaf8101c3360af31f59c6e11553c5c93d37f508
4
+ data.tar.gz: 61a1c4b3c26d636eb145548b1f7e795db2416df53aef320ab5ee57ac87f4395b
5
5
  SHA512:
6
- metadata.gz: ccd417b410a1d7a4bd54806f970f46ed726fde5fbc9a9c81337beffd63e32f55b857a10ffb66a2ab8676b38d17380578aa8fe37b2d09fe7f845562317678e76d
7
- data.tar.gz: 7836809f20864571790e501869c311012beb6b752d9550844d10b358c5d5ca6a734100101fced797b4de12d72363b7027fee036c0854b3b51360e473232210f9
6
+ metadata.gz: d41323865474c21cf476fe2a2d26745fe15154334f3486e9ca2ed01ba98193711b31d4822e5328dc810a0594eb8228aff4e35fd2d4c711ae3f5651886ba1ef89
7
+ data.tar.gz: 745c5c73bf6b82d7bedf500529ed9758a7f1f21628fd1f7af0a271ce4d6cc475f5e19e35bff6e61afee5b08c5b74597ddd49e6013fa8ebcd45087b223632136c
data/.rubocop.yml CHANGED
@@ -1,9 +1,8 @@
1
+ require: rubocop-performance
1
2
  inherit_from:
2
3
  - https://gitlab.com/bsm/misc/raw/master/rubocop/default.yml
3
-
4
4
  AllCops:
5
5
  TargetRubyVersion: "2.3"
6
-
7
6
  Naming/FileName:
8
7
  Exclude:
9
8
  - "lib/sidekiq-datadog.rb"
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- sidekiq-datadog (0.5.0)
4
+ sidekiq-datadog (0.5.1)
5
5
  dogstatsd-ruby (>= 4.2.0)
6
6
  sidekiq
7
7
 
@@ -35,20 +35,23 @@ GEM
35
35
  diff-lcs (>= 1.2.0, < 2.0)
36
36
  rspec-support (~> 3.8.0)
37
37
  rspec-support (3.8.0)
38
- rubocop (0.68.1)
38
+ rubocop (0.69.0)
39
39
  jaro_winkler (~> 1.5.1)
40
40
  parallel (~> 1.10)
41
- parser (>= 2.5, != 2.5.1.1)
41
+ parser (>= 2.6)
42
42
  rainbow (>= 2.2.2, < 4.0)
43
43
  ruby-progressbar (~> 1.7)
44
- unicode-display_width (>= 1.4.0, < 1.6)
44
+ unicode-display_width (>= 1.4.0, < 1.7)
45
+ rubocop-performance (1.3.0)
46
+ rubocop (>= 0.68.0)
45
47
  ruby-progressbar (1.10.0)
46
48
  sidekiq (5.2.7)
47
49
  connection_pool (~> 2.2, >= 2.2.2)
48
50
  rack (>= 1.5.0)
49
51
  rack-protection (>= 1.5.0)
50
52
  redis (>= 3.3.5, < 5)
51
- unicode-display_width (1.5.0)
53
+ timecop (0.9.1)
54
+ unicode-display_width (1.6.0)
52
55
 
53
56
  PLATFORMS
54
57
  ruby
@@ -58,7 +61,9 @@ DEPENDENCIES
58
61
  rake
59
62
  rspec
60
63
  rubocop
64
+ rubocop-performance
61
65
  sidekiq-datadog!
66
+ timecop
62
67
 
63
68
  BUNDLED WITH
64
69
  2.0.1
@@ -1,5 +1,5 @@
1
1
  module Sidekiq
2
2
  module Datadog
3
- VERSION = '0.5.0'.freeze
3
+ VERSION = '0.5.1'.freeze
4
4
  end
5
5
  end
@@ -42,19 +42,21 @@ module Sidekiq
42
42
 
43
43
  def call(worker, job, queue, *)
44
44
  start = Time.now
45
+ clock = Process.clock_gettime(Process::CLOCK_MONOTONIC, :millisecond)
46
+
45
47
  begin
46
48
  yield
47
- record(worker, job, queue, start)
49
+ record(worker, job, queue, start, clock)
48
50
  rescue StandardError => e
49
- record(worker, job, queue, start, e)
51
+ record(worker, job, queue, start, clock, e)
50
52
  raise
51
53
  end
52
54
  end
53
55
 
54
56
  private
55
57
 
56
- def record(worker, job, queue, start, error=nil)
57
- msec = ((Time.now - start) * 1000).round
58
+ def record(worker, job, queue, start, clock, error=nil) # rubocop:disable Metrics/ParameterLists
59
+ msec = Process.clock_gettime(Process::CLOCK_MONOTONIC, :millisecond) - clock
58
60
  tags = build_tags(worker, job, queue, error)
59
61
 
60
62
  @statsd.increment @metric_name, tags: tags
@@ -24,4 +24,6 @@ Gem::Specification.new do |s|
24
24
  s.add_development_dependency('rake')
25
25
  s.add_development_dependency('rspec')
26
26
  s.add_development_dependency('rubocop')
27
+ s.add_development_dependency('rubocop-performance')
28
+ s.add_development_dependency('timecop')
27
29
  end
@@ -8,25 +8,42 @@ describe Sidekiq::Middleware::Server::Datadog do
8
8
  ['custom:tag', ->(w, *) { "worker:#{w.class.name[1..2]}" }]
9
9
  end
10
10
  let(:options) { {} }
11
+ let(:enqueued_at) { 1461881794.9312189 }
12
+ let(:expected_queued_time_ms) { 444 }
13
+
14
+ before do
15
+ statsd.messages.clear
16
+
17
+ clock_gettime_call_count = 0
18
+ expect(Process).to receive(:clock_gettime).twice do
19
+ clock_gettime_call_count += 1
20
+ clock_gettime_call_count == 1 ? 0 : 333
21
+ end
22
+
23
+ Timecop.freeze(Time.at(enqueued_at + expected_queued_time_ms.to_f / 1000))
24
+ end
11
25
 
12
- before { statsd.messages.clear }
13
26
  subject { described_class.new(hostname: 'test.host', statsd: statsd, tags: tags, **options) }
14
27
 
15
28
  it 'should send an increment and timing event for each job run' do
16
- subject.call(worker, { 'enqueued_at' => 1461881794.9312189 }, 'default') { 'ok' }
29
+ subject.call(worker, { 'enqueued_at' => enqueued_at }, 'default') { 'ok' }
17
30
  expect(statsd.messages).to eq([
18
- 'sidekiq.job:1|c|#custom:tag,worker:oc,host:test.host,env:test,name:mock/worker,queue:default,status:ok',
19
- 'sidekiq.job.time:333|ms|#custom:tag,worker:oc,host:test.host,env:test,name:mock/worker,queue:default,status:ok',
20
- 'sidekiq.job.queued_time:333|ms|#custom:tag,worker:oc,host:test.host,env:test,name:mock/worker,queue:default,status:ok',
31
+ 'sidekiq.job:1|c|#custom:tag,worker:oc,host:test.host,env:test,name:mock/worker,'\
32
+ 'queue:default,status:ok',
33
+ 'sidekiq.job.time:333|ms|#custom:tag,worker:oc,host:test.host,env:test,name:mock/worker,'\
34
+ 'queue:default,status:ok',
35
+ "sidekiq.job.queued_time:#{expected_queued_time_ms}|ms|#custom:tag,worker:oc,host:test.host,"\
36
+ 'env:test,name:mock/worker,queue:default,status:ok',
21
37
  ])
22
38
  end
23
39
 
24
40
  it 'should support wrappers' do
25
- subject.call(worker, { 'enqueued_at' => 1461881794.9312189, 'wrapped' => 'wrap' }, nil) { 'ok' }
41
+ subject.call(worker, { 'enqueued_at' => enqueued_at, 'wrapped' => 'wrap' }, nil) { 'ok' }
26
42
  expect(statsd.messages).to eq([
27
43
  'sidekiq.job:1|c|#custom:tag,worker:oc,host:test.host,env:test,name:wrap,status:ok',
28
44
  'sidekiq.job.time:333|ms|#custom:tag,worker:oc,host:test.host,env:test,name:wrap,status:ok',
29
- 'sidekiq.job.queued_time:333|ms|#custom:tag,worker:oc,host:test.host,env:test,name:wrap,status:ok',
45
+ "sidekiq.job.queued_time:#{expected_queued_time_ms}|ms|#custom:tag,worker:oc,host:test.host,"\
46
+ 'env:test,name:wrap,status:ok',
30
47
  ])
31
48
  end
32
49
 
@@ -36,8 +53,10 @@ describe Sidekiq::Middleware::Server::Datadog do
36
53
  }).to raise_error('doh!')
37
54
 
38
55
  expect(statsd.messages).to eq([
39
- 'sidekiq.job:1|c|#custom:tag,worker:oc,host:test.host,env:test,name:mock/worker,status:error,error:runtime',
40
- 'sidekiq.job.time:333|ms|#custom:tag,worker:oc,host:test.host,env:test,name:mock/worker,status:error,error:runtime',
56
+ 'sidekiq.job:1|c|#custom:tag,worker:oc,host:test.host,env:test,name:mock/worker,'\
57
+ 'status:error,error:runtime',
58
+ 'sidekiq.job.time:333|ms|#custom:tag,worker:oc,host:test.host,env:test,name:mock/worker,'\
59
+ 'status:error,error:runtime',
41
60
  ])
42
61
  end
43
62
 
@@ -47,12 +66,15 @@ describe Sidekiq::Middleware::Server::Datadog do
47
66
  end
48
67
 
49
68
  it 'should generate the correct tags' do
50
- subject.call(worker, { 'enqueued_at' => 1461881794.9312189, 'args' => [1, 2] }, 'default') { 'ok' }
69
+ subject.call(worker, { 'enqueued_at' => enqueued_at, 'args' => [1, 2] }, 'default') { 'ok' }
51
70
 
52
71
  expect(statsd.messages).to eq([
53
- 'sidekiq.job:1|c|#custom:tag,arg:1,arg:2,host:test.host,env:test,name:mock/worker,queue:default,status:ok',
54
- 'sidekiq.job.time:333|ms|#custom:tag,arg:1,arg:2,host:test.host,env:test,name:mock/worker,queue:default,status:ok',
55
- 'sidekiq.job.queued_time:333|ms|#custom:tag,arg:1,arg:2,host:test.host,env:test,name:mock/worker,queue:default,status:ok',
72
+ 'sidekiq.job:1|c|#custom:tag,arg:1,arg:2,host:test.host,env:test,name:mock/worker,'\
73
+ 'queue:default,status:ok',
74
+ 'sidekiq.job.time:333|ms|#custom:tag,arg:1,arg:2,host:test.host,env:test,name:mock/worker,'\
75
+ 'queue:default,status:ok',
76
+ "sidekiq.job.queued_time:#{expected_queued_time_ms}|ms|#custom:tag,arg:1,arg:2,"\
77
+ 'host:test.host,env:test,name:mock/worker,queue:default,status:ok',
56
78
  ])
57
79
  end
58
80
  end
@@ -67,7 +89,7 @@ describe Sidekiq::Middleware::Server::Datadog do
67
89
  expect(statsd.messages).to eq([
68
90
  'sidekiq.job:1|c|#queue:default,status:ok',
69
91
  'sidekiq.job.time:333|ms|#queue:default,status:ok',
70
- 'sidekiq.job.queued_time:333|ms|#queue:default,status:ok',
92
+ "sidekiq.job.queued_time:#{expected_queued_time_ms}|ms|#queue:default,status:ok",
71
93
  ])
72
94
  end
73
95
  end
data/spec/spec_helper.rb CHANGED
@@ -1,15 +1,11 @@
1
1
  ENV['RACK_ENV'] ||= 'test'
2
2
  require 'sidekiq-datadog'
3
+ require 'timecop'
3
4
 
4
5
  module Mock
5
- class Worker
6
- end
6
+ class Worker; end
7
7
 
8
8
  class Statsd < ::Datadog::Statsd
9
- def timing(stat, _millis, opts={})
10
- super(stat, 333, opts)
11
- end
12
-
13
9
  def send_stat(message)
14
10
  messages.push message
15
11
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sidekiq-datadog
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dimitrij Denissenko
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-05-07 00:00:00.000000000 Z
11
+ date: 2019-05-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dogstatsd-ruby
@@ -94,6 +94,34 @@ dependencies:
94
94
  - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rubocop-performance
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: timecop
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
97
125
  description: Datadog metrics for sidekiq
98
126
  email:
99
127
  - dimitrij@blacksquaremedia.com