harness 0.2.16 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -194,7 +194,16 @@ Harness.redis = Redis.new
194
194
  ## Rails Integration
195
195
 
196
196
  Harness will automatically log metrics coming from `ActionPack`,
197
- `ActiveRecord`, `ActiveSupport` and `ActionMailer`.
197
+ `ActiveRecord`, and `ActionMailer`. `ActiveSupport` instrumentation is
198
+ disabled by default. Also, custom integrations are disabled by default.
199
+ You can turn on instrumentation for specific components like so:
200
+
201
+ ```ruby
202
+ config.harness.instrument.action_controller = false
203
+ config.harness.instrument.active_support = true
204
+ config.harness.instrument.sidekiq = true
205
+ config.harness.instrument.active_model_serializers = true
206
+ ```
198
207
 
199
208
  You can configure Harness from `application.rb`
200
209
 
@@ -23,4 +23,6 @@ Gem::Specification.new do |gem|
23
23
  gem.add_development_dependency "webmock"
24
24
  gem.add_development_dependency "resque"
25
25
  gem.add_development_dependency "sidekiq"
26
+ gem.add_development_dependency "active_model_serializers"
27
+ gem.add_development_dependency "rails"
26
28
  end
@@ -1,7 +1,5 @@
1
1
  require "harness/version"
2
2
 
3
- require 'thread'
4
-
5
3
  require 'redis'
6
4
  require 'redis/namespace'
7
5
 
@@ -11,6 +9,8 @@ require 'active_support/core_ext/hash/keys'
11
9
  require 'active_support/core_ext/numeric'
12
10
  require 'active_support/core_ext/integer'
13
11
 
12
+ require 'active_support/ordered_options'
13
+
14
14
  module Harness
15
15
  class LoggingError < RuntimeError ; end
16
16
  class NoCounter < RuntimeError ; end
@@ -18,6 +18,11 @@ module Harness
18
18
  class Config
19
19
  attr_reader :adapter, :queue
20
20
  attr_accessor :namespace
21
+ attr_reader :instrument
22
+
23
+ def initialize
24
+ @instrument = ActiveSupport::OrderedOptions.new
25
+ end
21
26
 
22
27
  def adapter=(val)
23
28
  if val.is_a? Symbol
@@ -0,0 +1,9 @@
1
+ events = %w(serializable_hash associations)
2
+
3
+ events.each do |name|
4
+ ActiveSupport::Notifications.subscribe %r{^#{name}.*\.serializer$} do |*args|
5
+ event = ActiveSupport::Notifications::Event.new(*args)
6
+ gauge = Harness::Gauge.from_event event
7
+ gauge.log
8
+ end
9
+ end
@@ -2,6 +2,19 @@ module Harness
2
2
  class Railtie < ::Rails::Railtie
3
3
  config.harness = Harness.config
4
4
 
5
+ # Set default instrumentation
6
+ config.harness.instrument.action_controller = true
7
+ config.harness.instrument.action_mailer = true
8
+ config.harness.instrument.action_view = true
9
+
10
+ config.harness.instrument.active_support = false
11
+
12
+ # Custom instrumentation can be turned on as follows
13
+ # See files in lib/harness/integration for available integrations
14
+ #
15
+ # config.harness.insturment.sidekiq = true
16
+ # config.harness.insturment.active_model_serializers = true
17
+
5
18
  rake_tasks do
6
19
  load "harness/tasks.rake"
7
20
  end
@@ -45,11 +58,9 @@ module Harness
45
58
  end
46
59
  end
47
60
 
48
- initializer "harness.sidekiq" do |app|
49
- use_real_queue = Rails.env != 'development' && Rails.env != 'test'
50
-
51
- if defined?(Sidekiq::Worker) && use_real_queue
52
- require 'harness/integration/sidekiq'
61
+ initializer "harness.instrumentation" do |app|
62
+ app.config.harness.instrument.each_pair do |integration, value|
63
+ require "harness/integration/#{integration}" if value
53
64
  end
54
65
  end
55
66
  end
@@ -1,3 +1,3 @@
1
1
  module Harness
2
- VERSION = "0.2.16"
2
+ VERSION = "0.3.0"
3
3
  end
@@ -0,0 +1,22 @@
1
+ require 'test_helper'
2
+ require 'harness/integration/active_model_serializers'
3
+
4
+ class ActiveModelSerializerIntegration < IntegrationTest
5
+ def test_serializable_hash_is_logged
6
+ instrument "serializable_hash"
7
+
8
+ assert_gauge_logged "serializable_hash.serializer"
9
+ end
10
+
11
+ def test_serializing_associations_is_logged
12
+ instrument "associations"
13
+
14
+ assert_gauge_logged "associations.serializer"
15
+ end
16
+
17
+ def instrument(event)
18
+ ActiveSupport::Notifications.instrument "#{event}.serializer" do |*args|
19
+ # nada
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,22 @@
1
+ require 'test_helper'
2
+ require 'rails'
3
+ require 'action_controller/railtie'
4
+ require 'harness/railtie'
5
+
6
+ class TestRailsApp < Rails::Application
7
+ config.active_support.deprecation = proc { |message, stack| }
8
+ initialize!
9
+ end
10
+
11
+ class RailtieTest < MiniTest::Unit::TestCase
12
+ def app
13
+ TestRailsApp
14
+ end
15
+
16
+ def test_configures_instrumentation
17
+ assert app.config.harness.instrument.action_controller
18
+ assert app.config.harness.instrument.action_mailer
19
+ assert app.config.harness.instrument.action_view
20
+ refute app.config.harness.instrument.active_support
21
+ end
22
+ 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.16
4
+ version: 0.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-06-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
16
- requirement: &70318611903480 !ruby/object:Gem::Requirement
16
+ requirement: &70133152109020 !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: *70318611903480
24
+ version_requirements: *70133152109020
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: redis
27
- requirement: &70318611903060 !ruby/object:Gem::Requirement
27
+ requirement: &70133152107200 !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: *70318611903060
35
+ version_requirements: *70133152107200
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: redis-namespace
38
- requirement: &70318611902580 !ruby/object:Gem::Requirement
38
+ requirement: &70133152104740 !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: *70318611902580
46
+ version_requirements: *70133152104740
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: simplecov
49
- requirement: &70318611902140 !ruby/object:Gem::Requirement
49
+ requirement: &70133152152020 !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: *70318611902140
57
+ version_requirements: *70133152152020
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: webmock
60
- requirement: &70318611901720 !ruby/object:Gem::Requirement
60
+ requirement: &70133152149760 !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: *70318611901720
68
+ version_requirements: *70133152149760
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: resque
71
- requirement: &70318611901300 !ruby/object:Gem::Requirement
71
+ requirement: &70133152148660 !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: *70318611901300
79
+ version_requirements: *70133152148660
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: sidekiq
82
- requirement: &70318611900880 !ruby/object:Gem::Requirement
82
+ requirement: &70133152148020 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ! '>='
@@ -87,7 +87,29 @@ dependencies:
87
87
  version: '0'
88
88
  type: :development
89
89
  prerelease: false
90
- version_requirements: *70318611900880
90
+ version_requirements: *70133152148020
91
+ - !ruby/object:Gem::Dependency
92
+ name: active_model_serializers
93
+ requirement: &70133152146920 !ruby/object:Gem::Requirement
94
+ none: false
95
+ requirements:
96
+ - - ! '>='
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ type: :development
100
+ prerelease: false
101
+ version_requirements: *70133152146920
102
+ - !ruby/object:Gem::Dependency
103
+ name: rails
104
+ requirement: &70133152145560 !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ type: :development
111
+ prerelease: false
112
+ version_requirements: *70133152145560
91
113
  description: ''
92
114
  email:
93
115
  - me@broadcastingadam.com
@@ -112,6 +134,7 @@ files:
112
134
  - lib/harness/integration/action_controller.rb
113
135
  - lib/harness/integration/action_mailer.rb
114
136
  - lib/harness/integration/action_view.rb
137
+ - lib/harness/integration/active_model_serializers.rb
115
138
  - lib/harness/integration/active_support.rb
116
139
  - lib/harness/integration/sidekiq.rb
117
140
  - lib/harness/job.rb
@@ -128,12 +151,14 @@ files:
128
151
  - test/integration/integrations/action_controller_test.rb
129
152
  - test/integration/integrations/action_mailer_test.rb
130
153
  - test/integration/integrations/action_view_test.rb
154
+ - test/integration/integrations/active_model_serializers_test.rb
131
155
  - test/integration/integrations/active_support_test.rb
132
156
  - test/integration/integrations/sidekiq_test.rb
133
157
  - test/integration/logging_test.rb
134
158
  - test/integration/meter_test.rb
135
159
  - test/integration/queues/resque_test.rb
136
160
  - test/integration/queues/sidekiq_test.rb
161
+ - test/integration/railtie_test.rb
137
162
  - test/test_helper.rb
138
163
  - test/unit/adapters/librato_adapter_test.rb
139
164
  - test/unit/adapters/memory_adapter_test.rb
@@ -172,12 +197,14 @@ test_files:
172
197
  - test/integration/integrations/action_controller_test.rb
173
198
  - test/integration/integrations/action_mailer_test.rb
174
199
  - test/integration/integrations/action_view_test.rb
200
+ - test/integration/integrations/active_model_serializers_test.rb
175
201
  - test/integration/integrations/active_support_test.rb
176
202
  - test/integration/integrations/sidekiq_test.rb
177
203
  - test/integration/logging_test.rb
178
204
  - test/integration/meter_test.rb
179
205
  - test/integration/queues/resque_test.rb
180
206
  - test/integration/queues/sidekiq_test.rb
207
+ - test/integration/railtie_test.rb
181
208
  - test/test_helper.rb
182
209
  - test/unit/adapters/librato_adapter_test.rb
183
210
  - test/unit/adapters/memory_adapter_test.rb