harness 0.2.4 → 0.2.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -62,12 +62,10 @@ module Harness
62
62
  end
63
63
 
64
64
  def self.sanitize(name)
65
- base = name.gsub(/^!/, 'bang.')
66
-
67
65
  if Harness.config.namespace
68
66
  "#{name}.#{Harness.config.namespace}"
69
67
  else
70
- base
68
+ name
71
69
  end
72
70
  end
73
71
  end
@@ -1,6 +1,8 @@
1
1
  ActiveSupport::Notifications.subscribe %r{.+} do |*args|
2
2
  event = ActiveSupport::Notifications::Event.new(*args)
3
3
 
4
- Harness::Gauge.from_event(event).log if event.payload[:gauge]
5
- Harness::Counter.from_event(event).log if event.payload[:counter]
4
+ unless event.payload[:exception]
5
+ Harness::Gauge.from_event(event).log if event.payload[:gauge]
6
+ Harness::Counter.from_event(event).log if event.payload[:counter]
7
+ end
6
8
  end
@@ -1,9 +1,9 @@
1
1
  events = %w(write_fragment read_fragment expire_fragment write_page expire_page process_action send_file)
2
2
 
3
- regex = %r{#{events.join("|")}.action_controller}
4
-
5
- ActiveSupport::Notifications.subscribe regex do |*args|
6
- event = ActiveSupport::Notifications::Event.new(*args)
7
- gauge = Harness::Gauge.from_event event
8
- gauge.log
3
+ events.each do |name|
4
+ ActiveSupport::Notifications.subscribe "#{name}.action_controller" do |*args|
5
+ event = ActiveSupport::Notifications::Event.new(*args)
6
+ gauge = Harness::Gauge.from_event event
7
+ gauge.log
8
+ end
9
9
  end
@@ -1,10 +1,9 @@
1
1
  events = %w(receive deliver)
2
2
 
3
- regex = %r{#{events.join("|")}.action_mailer}
4
-
5
- ActiveSupport::Notifications.subscribe regex do |*args|
6
- event = ActiveSupport::Notifications::Event.new(*args)
7
- gauge = Harness::Gauge.from_event event
8
- gauge.log
3
+ events.each do |name|
4
+ ActiveSupport::Notifications.subscribe "#{name}.action_mailer" do |*args|
5
+ event = ActiveSupport::Notifications::Event.new(*args)
6
+ gauge = Harness::Gauge.from_event event
7
+ gauge.log
8
+ end
9
9
  end
10
-
@@ -1,10 +1,9 @@
1
1
  events = %w(render_template render_partial)
2
2
 
3
- regex = %r{#{events.join("|")}.action_view}
4
-
5
- ActiveSupport::Notifications.subscribe regex do |*args|
6
- event = ActiveSupport::Notifications::Event.new(*args)
7
- gauge = Harness::Gauge.from_event event
8
- gauge.log
3
+ events.each do |name|
4
+ ActiveSupport::Notifications.subscribe "#{name}.action_view" do |*args|
5
+ event = ActiveSupport::Notifications::Event.new(*args)
6
+ gauge = Harness::Gauge.from_event event
7
+ gauge.log
8
+ end
9
9
  end
10
-
@@ -1,9 +1,9 @@
1
1
  events = %w(cache_read cache_generate cache_fetch_hit cache_write cache_delete)
2
2
 
3
- regex = %r{#{events.join("|")}.active_support}
4
-
5
- ActiveSupport::Notifications.subscribe regex do |*args|
6
- event = ActiveSupport::Notifications::Event.new(*args)
7
- gauge = Harness::Gauge.from_event event
8
- gauge.log
3
+ events.each do |name|
4
+ ActiveSupport::Notifications.subscribe "#{name}.active_support" do |*args|
5
+ event = ActiveSupport::Notifications::Event.new(*args)
6
+ gauge = Harness::Gauge.from_event event
7
+ gauge.log
8
+ end
9
9
  end
@@ -1,3 +1,3 @@
1
1
  module Harness
2
- VERSION = "0.2.4"
2
+ VERSION = "0.2.5"
3
3
  end
@@ -25,4 +25,26 @@ class ActiveSupportTestCase < IntegrationTest
25
25
  assert_counter_logged "test-counter"
26
26
  assert_gauge_logged "test-gauge"
27
27
  end
28
+
29
+ def test_does_not_log_counter_on_exception
30
+ begin
31
+ ActiveSupport::Notifications.instrument "counter_test.harness", :counter => true do |args|
32
+ raise
33
+ end
34
+ rescue
35
+ end
36
+
37
+ refute_counter_logged "counter_test.harness"
38
+ end
39
+
40
+ def test_does_not_log_gauge_on_exception
41
+ begin
42
+ ActiveSupport::Notifications.instrument "gauge_test.harness", :gauge => true do |args|
43
+ raise
44
+ end
45
+ rescue
46
+ end
47
+
48
+ refute_gauge_logged "gauge_test.harness"
49
+ end
28
50
  end
@@ -13,10 +13,20 @@ class ActionViewIntegration < IntegrationTest
13
13
  assert_gauge_logged "render_partial.action_view"
14
14
  end
15
15
 
16
+ def test_skips_internal_partial_events
17
+ instrument "!render_partial"
18
+
19
+ refute_gauge_logged "!render_partial.action_view"
20
+ end
21
+
22
+ def test_skips_internal_template_events
23
+ instrument "!render_template"
24
+
25
+ refute_gauge_logged "!render_template.action_view"
26
+ end
27
+
16
28
  private
17
29
  def instrument(event)
18
- ActiveSupport::Notifications.instrument "#{event}.action_view" do |*args|
19
- # nada
20
- end
30
+ ActiveSupport::Notifications.instrument "#{event}.action_view"
21
31
  end
22
32
  end
@@ -35,6 +35,14 @@ class IntegrationTest < MiniTest::Unit::TestCase
35
35
  refute_empty counters.select {|c| c.name = name }, "Expected #{counters.inspect} to contain a #{name} result"
36
36
  end
37
37
 
38
+ def refute_gauge_logged(name)
39
+ assert_empty gauges.select {|g| g.name = name }, "No gauge expected to be logged"
40
+ end
41
+
42
+ def refute_counter_logged(name)
43
+ assert_empty counters.select {|c| c.name = name }, "No counter expected to be logged"
44
+ end
45
+
38
46
  def gauges
39
47
  Harness::MemoryAdapter.gauges
40
48
  end
@@ -21,13 +21,7 @@ class LibratoAdapterTest < MiniTest::Unit::TestCase
21
21
 
22
22
  Harness::LibratoAdapter.config.email = email
23
23
  Harness::LibratoAdapter.config.token = token
24
- end
25
-
26
- def teardown
27
- WebMock.reset!
28
-
29
- Harness::LibratoAdapter.config.email = nil
30
- Harness::LibratoAdapter.config.token = nil
24
+ Harness.config.namespace = nil
31
25
  end
32
26
 
33
27
  def test_gauge_is_logged
@@ -50,12 +44,12 @@ class LibratoAdapterTest < MiniTest::Unit::TestCase
50
44
  assert_requested expected_request
51
45
  end
52
46
 
53
- def test_gauge_id_is_sanitized
54
- @gauge.id = "!process_action.action_controller"
47
+ def test_gauge_is_logged_with_namespace
48
+ Harness.config.namespace = :foo
55
49
 
56
50
  json = {
57
51
  :gauges => [{
58
- :name => "bang.process_action.action_controller",
52
+ :name => "#{@gauge.id}.foo",
59
53
  :display_name => @gauge.name,
60
54
  :value => @gauge.value,
61
55
  :measure_time => @gauge.time.to_i,
@@ -72,7 +66,6 @@ class LibratoAdapterTest < MiniTest::Unit::TestCase
72
66
  assert_requested expected_request
73
67
  end
74
68
 
75
-
76
69
  def test_logging_gague_raises_an_exception
77
70
  stub_request(:post, %r{metrics}).to_return(:status => 500, :body => "message")
78
71
 
@@ -118,12 +111,12 @@ class LibratoAdapterTest < MiniTest::Unit::TestCase
118
111
  assert_requested expected_request
119
112
  end
120
113
 
121
- def test_counter_id_is_sanitized
122
- @counter.id = "!total_requests.action_controller"
114
+ def test_counter_is_logged_with_namespace
115
+ Harness.config.namespace = :foo
123
116
 
124
117
  json = {
125
118
  :counters => [{
126
- :name => "bang.total_requests.action_controller",
119
+ :name => "#{@counter.id}.foo",
127
120
  :display_name => @counter.name,
128
121
  :value => @counter.value,
129
122
  :measure_time => @counter.time.to_i,
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.4
4
+ version: 0.2.5
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-04-20 00:00:00.000000000 Z
12
+ date: 2012-05-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
16
- requirement: &70204325832440 !ruby/object:Gem::Requirement
16
+ requirement: &70254849265340 !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: *70204325832440
24
+ version_requirements: *70254849265340
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: redis
27
- requirement: &70204325832020 !ruby/object:Gem::Requirement
27
+ requirement: &70254849264700 !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: *70204325832020
35
+ version_requirements: *70254849264700
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: redis-namespace
38
- requirement: &70204325831560 !ruby/object:Gem::Requirement
38
+ requirement: &70254849264220 !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: *70204325831560
46
+ version_requirements: *70254849264220
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: simplecov
49
- requirement: &70204325831140 !ruby/object:Gem::Requirement
49
+ requirement: &70254849263400 !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: *70204325831140
57
+ version_requirements: *70254849263400
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: webmock
60
- requirement: &70204325830720 !ruby/object:Gem::Requirement
60
+ requirement: &70254849262580 !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: *70204325830720
68
+ version_requirements: *70254849262580
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: resque
71
- requirement: &70204325830300 !ruby/object:Gem::Requirement
71
+ requirement: &70254851992420 !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: *70204325830300
79
+ version_requirements: *70254851992420
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: sidekiq
82
- requirement: &70204325829880 !ruby/object:Gem::Requirement
82
+ requirement: &70254851996240 !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: *70204325829880
90
+ version_requirements: *70254851996240
91
91
  description: ''
92
92
  email:
93
93
  - me@broadcastingadam.com
@@ -152,18 +152,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
152
152
  - - ! '>='
153
153
  - !ruby/object:Gem::Version
154
154
  version: '0'
155
- segments:
156
- - 0
157
- hash: -2209955114685400060
158
155
  required_rubygems_version: !ruby/object:Gem::Requirement
159
156
  none: false
160
157
  requirements:
161
158
  - - ! '>='
162
159
  - !ruby/object:Gem::Version
163
160
  version: '0'
164
- segments:
165
- - 0
166
- hash: -2209955114685400060
167
161
  requirements: []
168
162
  rubyforge_project:
169
163
  rubygems_version: 1.8.11