harness 0.2.5 → 0.2.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,34 @@
1
+ module Sidekiq
2
+ module Middleware
3
+ module Server
4
+ class HarnessInstrumentation
5
+ def call(worker_class, item, queue)
6
+ if instrument? worker_class
7
+ options = {}
8
+ options[:gauge] = "#{worker_class.class.to_s.underscore}.sidekiq"
9
+ options[:counter] = "#{worker_class.class.to_s.pluralize.underscore}.sidekiq"
10
+
11
+ ActiveSupport::Notifications.instrument "#{worker_class.class.to_s.underscore}.sidekiq", options do
12
+ yield
13
+ end
14
+
15
+ ActiveSupport::Notifications.instrument "job.sidekiq", :counter => true
16
+ else
17
+ yield
18
+ end
19
+ end
20
+
21
+ private
22
+ def instrument?(worker_class)
23
+ worker_class !~ /^Harness/
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
29
+
30
+ Sidekiq.configure_server do |config|
31
+ config.server_middleware do |chain|
32
+ chain.add Sidekiq::Middleware::Server::HarnessInstrumentation
33
+ end
34
+ end
@@ -30,14 +30,24 @@ module Harness
30
30
  end
31
31
 
32
32
  initializer "harness.queue" do
33
- if defined? Resque
33
+ Harness.config.queue = Harness::SyncronousQueue
34
+ end
35
+
36
+ initializer "harness.queue.production" do |app|
37
+ use_real_queue = Rails.env != 'development' && Rails.env != 'test'
38
+
39
+ if defined?(Resque) && use_real_queue
34
40
  require 'harness/queues/resque_queue'
35
41
  Harness.config.queue = :resque
36
- elsif defined? Sidekiq
42
+ elsif defined?(Sidekiq) && use_real_queue
37
43
  require 'harness/queues/sidekiq_queue'
38
44
  Harness.config.queue = :sidekiq
39
- else
40
- Harness.config.queue = Harness::SyncronousQueue
45
+ end
46
+ end
47
+
48
+ initializer "harness.sidekiq" do |app|
49
+ if defined? Sidekiq
50
+ require 'harness/integration/sidekiq'
41
51
  end
42
52
  end
43
53
  end
@@ -1,3 +1,3 @@
1
1
  module Harness
2
- VERSION = "0.2.5"
2
+ VERSION = "0.2.6"
3
3
  end
@@ -0,0 +1,34 @@
1
+ require 'test_helper'
2
+ require 'sidekiq'
3
+ require 'harness/integration/sidekiq'
4
+
5
+ class SidekiqIntegrationTest < IntegrationTest
6
+ def middleware
7
+ Sidekiq::Middleware::Server::HarnessInstrumentation.new
8
+ end
9
+
10
+ def tests_logs_job_performance_stats
11
+ middleware.call("report", nil, nil) { }
12
+
13
+ assert_gauge_logged "report.sidekiq"
14
+ assert_counter_logged "reports.sidekiq"
15
+ end
16
+
17
+ def tests_logs_a_counter_of_all_jobs
18
+ middleware.call("reports", nil, nil) { }
19
+
20
+ assert_counter_logged "job.sidekiq"
21
+ end
22
+
23
+ def test_ignores_harness_jobs
24
+ middleware.call("Harness::SidekiqQueue::SendCounter", nil, nil) { }
25
+
26
+ assert_empty counters
27
+ assert_empty gauges
28
+
29
+ middleware.call("Harness::SidekiqQueue::SendGauge", nil, nil) { }
30
+
31
+ assert_empty counters
32
+ assert_empty gauges
33
+ end
34
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: harness
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.5
4
+ version: 0.2.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-05-08 00:00:00.000000000 Z
12
+ date: 2012-05-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
16
- requirement: &70254849265340 !ruby/object:Gem::Requirement
16
+ requirement: &70238567232420 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '3'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70254849265340
24
+ version_requirements: *70238567232420
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: redis
27
- requirement: &70254849264700 !ruby/object:Gem::Requirement
27
+ requirement: &70238567232000 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70254849264700
35
+ version_requirements: *70238567232000
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: redis-namespace
38
- requirement: &70254849264220 !ruby/object:Gem::Requirement
38
+ requirement: &70238567231540 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *70254849264220
46
+ version_requirements: *70238567231540
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: simplecov
49
- requirement: &70254849263400 !ruby/object:Gem::Requirement
49
+ requirement: &70238567231120 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *70254849263400
57
+ version_requirements: *70238567231120
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: webmock
60
- requirement: &70254849262580 !ruby/object:Gem::Requirement
60
+ requirement: &70238567230700 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '0'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *70254849262580
68
+ version_requirements: *70238567230700
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: resque
71
- requirement: &70254851992420 !ruby/object:Gem::Requirement
71
+ requirement: &70238567230280 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: '0'
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *70254851992420
79
+ version_requirements: *70238567230280
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: sidekiq
82
- requirement: &70254851996240 !ruby/object:Gem::Requirement
82
+ requirement: &70238567229860 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ! '>='
@@ -87,7 +87,7 @@ dependencies:
87
87
  version: '0'
88
88
  type: :development
89
89
  prerelease: false
90
- version_requirements: *70254851996240
90
+ version_requirements: *70238567229860
91
91
  description: ''
92
92
  email:
93
93
  - me@broadcastingadam.com
@@ -113,6 +113,7 @@ files:
113
113
  - lib/harness/integration/action_mailer.rb
114
114
  - lib/harness/integration/action_view.rb
115
115
  - lib/harness/integration/active_support.rb
116
+ - lib/harness/integration/sidekiq.rb
116
117
  - lib/harness/job.rb
117
118
  - lib/harness/measurement.rb
118
119
  - lib/harness/meter.rb
@@ -128,6 +129,7 @@ files:
128
129
  - test/integration/integrations/action_mailer_test.rb
129
130
  - test/integration/integrations/action_view_test.rb
130
131
  - test/integration/integrations/active_support_test.rb
132
+ - test/integration/integrations/sidekiq_test.rb
131
133
  - test/integration/logging_test.rb
132
134
  - test/integration/meter_test.rb
133
135
  - test/integration/queues/resque_test.rb
@@ -171,6 +173,7 @@ test_files:
171
173
  - test/integration/integrations/action_mailer_test.rb
172
174
  - test/integration/integrations/action_view_test.rb
173
175
  - test/integration/integrations/active_support_test.rb
176
+ - test/integration/integrations/sidekiq_test.rb
174
177
  - test/integration/logging_test.rb
175
178
  - test/integration/meter_test.rb
176
179
  - test/integration/queues/resque_test.rb