statsd-instrument 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Shopify
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -12,7 +12,7 @@ For Shopify, our retention periods are:
12
12
  2. 60 seconds of granularity for the last week
13
13
  3. 10 minutes of granularity for the last 5 years
14
14
 
15
- This is the same as what Etsy uses (mentioned in the README for [http://github.com/etsy/statd](http://github.com/etsy/statd])).
15
+ This is the same as what Etsy uses (mentioned in the README for http://github.com/etsy/statsd).
16
16
 
17
17
  ## Configuration
18
18
 
@@ -99,7 +99,7 @@ So now, if GoogleBase#insert raises an exception or returns false (ie. result ==
99
99
 
100
100
  ``` ruby
101
101
  GoogleBase.statsd_count_if :insert, 'GoogleBase.insert' do |response|
102
- result.code == 200
102
+ response.code == 200
103
103
  end
104
104
  ```
105
105
 
@@ -118,8 +118,8 @@ So if this method fails execution (raises or returns false) we'll increment the
118
118
  Again you can pass a block to define what success means.
119
119
 
120
120
  ``` ruby
121
- GoogleBase.statsd_count_if :insert, 'GoogleBase.insert' do |response|
122
- result.code == 200
121
+ GoogleBase.statsd_count_success :insert, 'GoogleBase.insert' do |response|
122
+ response.code == 200
123
123
  end
124
124
  ```
125
125
 
@@ -6,9 +6,6 @@ module StatsD
6
6
  end
7
7
  self.enabled = true
8
8
 
9
- trap("TTOU") { self.enabled = false }
10
- trap("TTIN") { self.enabled = true }
11
-
12
9
  # StatsD.server = 'localhost:1234'
13
10
  def self.server=(conn)
14
11
  self.host, port = conn.split(':')
@@ -19,7 +16,7 @@ module StatsD
19
16
  def statsd_measure(method, name)
20
17
  add_to_method(method, name, :measure) do |old_method, new_method, metric_name, *args|
21
18
  define_method(new_method) do |*args|
22
- StatsD.measure(send(metric_name)) { send(old_method, *args) }
19
+ StatsD.measure(metric_name) { send(old_method, *args) }
23
20
  end
24
21
  end
25
22
  end
@@ -36,7 +33,7 @@ module StatsD
36
33
  truthiness = (yield(result) rescue false) if block_given?
37
34
  result
38
35
  ensure
39
- StatsD.increment("#{send(metric_name)}." + (truthiness == false ? 'failure' : 'success'))
36
+ StatsD.increment("#{metric_name}." + (truthiness == false ? 'failure' : 'success'))
40
37
  end
41
38
  end
42
39
  end
@@ -54,7 +51,7 @@ module StatsD
54
51
  truthiness = (yield(result) rescue false) if block_given?
55
52
  result
56
53
  ensure
57
- StatsD.increment(send(metric_name)) if truthiness
54
+ StatsD.increment(metric_name) if truthiness
58
55
  end
59
56
  end
60
57
  end
@@ -63,27 +60,15 @@ module StatsD
63
60
  def statsd_count(method, name)
64
61
  add_to_method(method, name, :count) do |old_method, new_method, metric_name|
65
62
  define_method(new_method) do |*args|
66
- StatsD.increment(send(metric_name))
63
+ StatsD.increment(metric_name)
67
64
  send(old_method, *args)
68
65
  end
69
66
  end
70
67
  end
71
68
 
72
69
  private
73
- def statsd_memoize(metric_name, name)
74
- define_method(metric_name) do
75
- name = eval("\"#{name}\"", binding)
76
-
77
- self.class.send(:define_method, metric_name) do
78
- name
79
- end
80
- send(metric_name)
81
- end
82
- end
83
-
84
70
  def add_to_method(method, name, action, &block)
85
- metric_name = :"#{method}_#{name}_metric_name"
86
- statsd_memoize(metric_name, name)
71
+ metric_name = name
87
72
 
88
73
  method_name_without_statsd = :"#{method}_for_#{action}_on_#{self.name}_without_#{name}"
89
74
  # raw_ssl_request_for_measure_on_FedEx_without_ActiveMerchant.Shipping.#{self.class.name}.ssl_request
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "statsd-instrument"
3
- s.version = '1.0.0'
3
+ s.version = '1.0.1'
4
4
  s.authors = ["Jesse Storimer"]
5
5
  s.email = ["jesse@shopify.com"]
6
6
  s.homepage = "http://github.com/shopify/statsd-instrument"
@@ -23,6 +23,14 @@ class ActiveMerchant::Gateway < ActiveMerchant::Base
23
23
  rescue
24
24
  false
25
25
  end
26
+
27
+ def self.sync
28
+ true
29
+ end
30
+
31
+ def self.singleton_class
32
+ class << self; self; end
33
+ end
26
34
  end
27
35
 
28
36
  class ActiveMerchant::UniqueGateway < ActiveMerchant::Base
@@ -43,7 +51,7 @@ class StatsDTest < Test::Unit::TestCase
43
51
  end
44
52
 
45
53
  def test_statsd_count_if
46
- ActiveMerchant::Gateway.statsd_count_if :ssl_post, 'ActiveMerchant.Billing.#{self.class.name}.if'
54
+ ActiveMerchant::Gateway.statsd_count_if :ssl_post, 'ActiveMerchant.Gateway.if'
47
55
 
48
56
  StatsD.expects(:increment).with(includes('if')).once
49
57
  ActiveMerchant::Gateway.new.purchase(true)
@@ -51,7 +59,7 @@ class StatsDTest < Test::Unit::TestCase
51
59
  end
52
60
 
53
61
  def test_statsd_count_if_with_block
54
- ActiveMerchant::UniqueGateway.statsd_count_if :ssl_post, 'ActiveMerchant.Billing.#{self.class.name}.block' do |result|
62
+ ActiveMerchant::UniqueGateway.statsd_count_if :ssl_post, 'ActiveMerchant.Gateway.block' do |result|
55
63
  result[:success]
56
64
  end
57
65
 
@@ -61,7 +69,7 @@ class StatsDTest < Test::Unit::TestCase
61
69
  end
62
70
 
63
71
  def test_statsd_count_success
64
- ActiveMerchant::Gateway.statsd_count_success :ssl_post, 'ActiveMerchant.Billing.#{self.class.name}'
72
+ ActiveMerchant::Gateway.statsd_count_success :ssl_post, 'ActiveMerchant.Gateway'
65
73
 
66
74
  StatsD.expects(:increment).with(includes('success'))
67
75
  ActiveMerchant::Gateway.new.purchase(true)
@@ -71,7 +79,7 @@ class StatsDTest < Test::Unit::TestCase
71
79
  end
72
80
 
73
81
  def test_statsd_count_success_with_block
74
- ActiveMerchant::UniqueGateway.statsd_count_success :ssl_post, 'ActiveMerchant.Billing.#{self.class.name}' do |result|
82
+ ActiveMerchant::UniqueGateway.statsd_count_success :ssl_post, 'ActiveMerchant.Gateway' do |result|
75
83
  result[:success]
76
84
  end
77
85
 
@@ -83,19 +91,27 @@ class StatsDTest < Test::Unit::TestCase
83
91
  end
84
92
 
85
93
  def test_statsd_count
86
- ActiveMerchant::Gateway.statsd_count :ssl_post, 'ActiveMerchant.Billing.#{self.class.name}.ssl_post'
94
+ ActiveMerchant::Gateway.statsd_count :ssl_post, 'ActiveMerchant.Gateway.ssl_post'
87
95
 
88
96
  StatsD.expects(:increment).with(includes('ssl_post'))
89
97
  ActiveMerchant::Gateway.new.purchase(true)
90
98
  end
91
99
 
92
100
  def test_statsd_measure
93
- ActiveMerchant::UniqueGateway.statsd_measure :ssl_post, 'ActiveMerchant.Billing.#{self.class.name}.ssl_post'
101
+ ActiveMerchant::UniqueGateway.statsd_measure :ssl_post, 'ActiveMerchant.Gateway.ssl_post'
94
102
 
95
103
  StatsD.expects(:measure).with(includes('ssl_post')).returns({:success => true})
96
104
  ActiveMerchant::UniqueGateway.new.purchase(true)
97
105
  end
98
106
 
107
+ def test_instrumenting_class_method
108
+ ActiveMerchant::Gateway.singleton_class.extend StatsD::Instrument
109
+ ActiveMerchant::Gateway.singleton_class.statsd_count :sync, 'ActiveMerchant.Gateway.sync'
110
+
111
+ StatsD.expects(:increment).with(includes('sync'))
112
+ ActiveMerchant::Gateway.sync
113
+ end
114
+
99
115
  def test_count_with_sampling
100
116
  StatsD.unstub(:increment)
101
117
  StatsD.stubs(:rand).returns(0.6)
@@ -131,18 +147,4 @@ class StatsDTest < Test::Unit::TestCase
131
147
  StatsD.increment('fooz')
132
148
  StatsD.enabled = true
133
149
  end
134
-
135
- def test_receiving_TTOU_should_disable
136
- Process.kill("TTOU", $$)
137
- sleep 0.5
138
- assert !StatsD.enabled
139
- end
140
-
141
- def test_receiving_TTIN_should_disable
142
- StatsD.enabled = false
143
-
144
- Process.kill("TTIN", $$)
145
- sleep 0.5
146
- assert StatsD.enabled
147
- end
148
150
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: statsd-instrument
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 21
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 0
9
- - 0
10
- version: 1.0.0
9
+ - 1
10
+ version: 1.0.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Jesse Storimer
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-07-28 00:00:00 -04:00
18
+ date: 2011-08-15 00:00:00 -04:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -44,6 +44,7 @@ extra_rdoc_files: []
44
44
  files:
45
45
  - .gitignore
46
46
  - Gemfile
47
+ - LICENSE
47
48
  - README.md
48
49
  - Rakefile
49
50
  - lib/statsd-instrument.rb
@@ -80,7 +81,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
80
81
  requirements: []
81
82
 
82
83
  rubyforge_project:
83
- rubygems_version: 1.3.9.2
84
+ rubygems_version: 1.6.2
84
85
  signing_key:
85
86
  specification_version: 3
86
87
  summary: A StatsD client for Ruby apps