statsd-instrument 2.1.2 → 2.1.3

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
  SHA1:
3
- metadata.gz: 185cb2c919df0365e7808fdc36f0eece2ffac2aa
4
- data.tar.gz: 6f64c341a7d7cd1ef9ae7400b99cca75641388f8
3
+ metadata.gz: 07d8112cad58dadf807022eb9f47f444605687bc
4
+ data.tar.gz: 2251f7bd1bff223149eff0138b62c386394ddffc
5
5
  SHA512:
6
- metadata.gz: 95db3eab39e1cecaa4938bab5df81de7f9c4c0b36d8f0640a0a95b6b0d036f65edb91f180a41d3ee64446841430f29d58d42ad9c58bfec1967114236f0d18030
7
- data.tar.gz: 7df38af3a361e4ba803994f09292c66c2c78ecaf681e02aa937982cdd7ab9005c0872a1442a96d0d2fdcafc43e36535363a38cb3dadc94cc3bf49761bc49b6cd
6
+ metadata.gz: db2b61af65189ebd3fa0e9c9fd2e3e816562a3a47a6c622055ee364b471773ac1b047d2313e48fd36869892deae7ec59f35f641edd22fcc132ee33360bde7345
7
+ data.tar.gz: b01a840d4aabef2139c4501596680a65d790a1f6afa43a95575db0f8a8372986a8ed08cb92695205eb2532f98fe64a56b415af0948eacfefdabcb15933e6a94e
data/CHANGELOG.md CHANGED
@@ -5,6 +5,11 @@ please at an entry to the "unreleased changes" section below.
5
5
 
6
6
  ### Unreleased changes
7
7
 
8
+ ### Version 2.1.3
9
+
10
+ - The `assert_statsd_calls` test helper will now raise an exception whenever a block isn't passed.
11
+ - Sending stats inside an exit handler will no longer cause programs to exit abruptly.
12
+
8
13
  ### Version 2.1.2
9
14
 
10
15
  - Use `prepend` instead of rewriting classes for metaprogramming methods.
@@ -33,6 +33,10 @@ module StatsD::Instrument::Assertions
33
33
 
34
34
  # @private
35
35
  def assert_statsd_calls(expected_metrics, &block)
36
+ unless block
37
+ raise ArgumentError, "block must be given"
38
+ end
39
+
36
40
  metrics = capture_statsd_calls(&block)
37
41
  matched_expected_metrics = []
38
42
 
@@ -64,7 +64,7 @@ module StatsD::Instrument::Backends
64
64
  def generate_packet(metric)
65
65
  command = "#{metric.name}:#{metric.value}|#{metric.type}"
66
66
  command << "|@#{metric.sample_rate}" if metric.sample_rate < 1 || (implementation == :statsite && metric.sample_rate > 1)
67
- if metric.tags
67
+ if metric.tags
68
68
  if tags_supported?
69
69
  command << "|##{metric.tags.join(',')}"
70
70
  else
@@ -84,6 +84,11 @@ module StatsD::Instrument::Backends
84
84
  synchronize do
85
85
  socket.send(command, 0) > 0
86
86
  end
87
+ rescue ThreadError => e
88
+ # In cases where a TERM or KILL signal has been sent, and we send stats as
89
+ # part of a signal handler, locks cannot be acquired, so we do our best
90
+ # to try and send the command without a lock.
91
+ socket.send(command, 0) > 0
87
92
  rescue SocketError, IOError, SystemCallError => e
88
93
  StatsD.logger.error "[StatsD] #{e.class.name}: #{e.message}"
89
94
  end
@@ -1,5 +1,5 @@
1
1
  module StatsD
2
2
  module Instrument
3
- VERSION = "2.1.2"
3
+ VERSION = "2.1.3"
4
4
  end
5
5
  end
@@ -77,7 +77,7 @@ class StatsDInstrumentationTest < Minitest::Test
77
77
  ActiveMerchant::Gateway.new.purchase(true)
78
78
  ActiveMerchant::Gateway.new.purchase(false)
79
79
  end
80
-
80
+ ensure
81
81
  ActiveMerchant::Gateway.statsd_remove_count_if :ssl_post, 'ActiveMerchant.Gateway.if'
82
82
  end
83
83
 
@@ -90,7 +90,7 @@ class StatsDInstrumentationTest < Minitest::Test
90
90
  assert_equal 'true', ActiveMerchant::Base.new.post_with_block { 'true' }
91
91
  assert_equal 'false', ActiveMerchant::Base.new.post_with_block { 'false' }
92
92
  end
93
-
93
+ ensure
94
94
  ActiveMerchant::Base.statsd_remove_count_if :post_with_block, 'ActiveMerchant.Base.post_with_block'
95
95
  end
96
96
 
@@ -103,7 +103,7 @@ class StatsDInstrumentationTest < Minitest::Test
103
103
  ActiveMerchant::UniqueGateway.new.purchase(true)
104
104
  ActiveMerchant::UniqueGateway.new.purchase(false)
105
105
  end
106
-
106
+ ensure
107
107
  ActiveMerchant::UniqueGateway.statsd_remove_count_if :ssl_post, 'ActiveMerchant.Gateway.block'
108
108
  end
109
109
 
@@ -119,7 +119,7 @@ class StatsDInstrumentationTest < Minitest::Test
119
119
  ActiveMerchant::Gateway.new.purchase(false)
120
120
  ActiveMerchant::Gateway.new.purchase(true)
121
121
  end
122
-
122
+ ensure
123
123
  ActiveMerchant::Gateway.statsd_remove_count_success :ssl_post, 'ActiveMerchant.Gateway'
124
124
  end
125
125
 
@@ -137,7 +137,7 @@ class StatsDInstrumentationTest < Minitest::Test
137
137
  assert_equal 'successful', ActiveMerchant::Base.new.post_with_block { 'successful' }
138
138
  assert_equal 'not so successful', ActiveMerchant::Base.new.post_with_block { 'not so successful' }
139
139
  end
140
-
140
+ ensure
141
141
  ActiveMerchant::Base.statsd_remove_count_success :post_with_block, 'ActiveMerchant.Base.post_with_block'
142
142
  end
143
143
 
@@ -153,7 +153,7 @@ class StatsDInstrumentationTest < Minitest::Test
153
153
  assert_statsd_increment('ActiveMerchant.Gateway.failure') do
154
154
  ActiveMerchant::UniqueGateway.new.purchase(false)
155
155
  end
156
-
156
+ ensure
157
157
  ActiveMerchant::UniqueGateway.statsd_remove_count_success :ssl_post, 'ActiveMerchant.Gateway'
158
158
  end
159
159
 
@@ -163,7 +163,7 @@ class StatsDInstrumentationTest < Minitest::Test
163
163
  assert_statsd_increment('ActiveMerchant.Gateway.ssl_post') do
164
164
  ActiveMerchant::Gateway.new.purchase(true)
165
165
  end
166
-
166
+ ensure
167
167
  ActiveMerchant::Gateway.statsd_remove_count :ssl_post, 'ActiveMerchant.Gateway.ssl_post'
168
168
  end
169
169
 
@@ -174,7 +174,7 @@ class StatsDInstrumentationTest < Minitest::Test
174
174
  assert_statsd_increment('gatewaysubclass.insert.true') do
175
175
  GatewaySubClass.new.purchase(true)
176
176
  end
177
-
177
+ ensure
178
178
  ActiveMerchant::Gateway.statsd_remove_count(:ssl_post, metric_namer)
179
179
  end
180
180
 
@@ -184,7 +184,7 @@ class StatsDInstrumentationTest < Minitest::Test
184
184
  assert_statsd_increment('ActiveMerchant.Base.post_with_block') do
185
185
  assert_equal 'block called', ActiveMerchant::Base.new.post_with_block { 'block called' }
186
186
  end
187
-
187
+ ensure
188
188
  ActiveMerchant::Base.statsd_remove_count :post_with_block, 'ActiveMerchant.Base.post_with_block'
189
189
  end
190
190
 
@@ -194,7 +194,7 @@ class StatsDInstrumentationTest < Minitest::Test
194
194
  assert_statsd_measure('ActiveMerchant.Gateway.ssl_post', sample_rate: 0.3) do
195
195
  ActiveMerchant::UniqueGateway.new.purchase(true)
196
196
  end
197
-
197
+ ensure
198
198
  ActiveMerchant::UniqueGateway.statsd_remove_measure :ssl_post, 'ActiveMerchant.Gateway.ssl_post'
199
199
  end
200
200
 
@@ -204,17 +204,24 @@ class StatsDInstrumentationTest < Minitest::Test
204
204
  assert_statsd_measure('ActiveMerchant.Gateway.ssl_post') do
205
205
  ActiveMerchant::UniqueGateway.new.purchase(true)
206
206
  end
207
-
207
+ ensure
208
208
  ActiveMerchant::UniqueGateway.statsd_remove_measure :ssl_post, 'ActiveMerchant::Gateway.ssl_post'
209
209
  end
210
210
 
211
+ def test_statsd_measure_yells_without_block
212
+ err = assert_raises(ArgumentError) do
213
+ assert_statsd_measure('ActiveMerchant.Gateway.ssl_post')
214
+ end
215
+ assert_equal "block must be given", err.to_s
216
+ end
217
+
211
218
  def test_statsd_measure_with_method_receiving_block
212
219
  ActiveMerchant::Base.statsd_measure :post_with_block, 'ActiveMerchant.Base.post_with_block'
213
220
 
214
221
  assert_statsd_measure('ActiveMerchant.Base.post_with_block') do
215
222
  assert_equal 'block called', ActiveMerchant::Base.new.post_with_block { 'block called' }
216
223
  end
217
-
224
+ ensure
218
225
  ActiveMerchant::Base.statsd_remove_measure :post_with_block, 'ActiveMerchant.Base.post_with_block'
219
226
  end
220
227
 
@@ -225,7 +232,7 @@ class StatsDInstrumentationTest < Minitest::Test
225
232
  assert_statsd_increment('ActiveMerchant.Gateway.sync') do
226
233
  ActiveMerchant::Gateway.sync
227
234
  end
228
-
235
+ ensure
229
236
  ActiveMerchant::Gateway.singleton_class.statsd_remove_count :sync, 'ActiveMerchant.Gateway.sync'
230
237
  end
231
238
 
@@ -236,7 +243,7 @@ class StatsDInstrumentationTest < Minitest::Test
236
243
  assert_statsd_increment('ActiveMerchant.Gateway.sync', tags: ['key:value']) do
237
244
  ActiveMerchant::Gateway.sync
238
245
  end
239
-
246
+ ensure
240
247
  ActiveMerchant::Gateway.singleton_class.statsd_remove_count :sync, 'ActiveMerchant.Gateway.sync'
241
248
  end
242
249
 
@@ -19,13 +19,13 @@ class UDPBackendTest < Minitest::Test
19
19
 
20
20
  @backend.server = "localhost:1234"
21
21
  @backend.socket
22
-
22
+
23
23
  @backend.port = 2345
24
24
  @backend.socket
25
25
 
26
26
  @backend.host = '127.0.0.1'
27
27
  @backend.socket
28
- end
28
+ end
29
29
 
30
30
  def test_collect_respects_sampling_rate
31
31
  @socket.expects(:send).once.returns(1)
@@ -35,13 +35,13 @@ class UDPBackendTest < Minitest::Test
35
35
  @backend.collect_metric(metric)
36
36
 
37
37
  @backend.stubs(:rand).returns(0.6)
38
- @backend.collect_metric(metric)
38
+ @backend.collect_metric(metric)
39
39
  end
40
40
 
41
41
  def test_support_counter_syntax
42
42
  @backend.expects(:write_packet).with('counter:1|c').once
43
43
  StatsD.increment('counter', sample_rate: 1.0)
44
-
44
+
45
45
  @backend.expects(:write_packet).with('counter:1|c|@0.5').once
46
46
  StatsD.increment('counter', sample_rate: 0.5)
47
47
  end
@@ -100,7 +100,7 @@ class UDPBackendTest < Minitest::Test
100
100
  @backend.expects(:write_packet).never
101
101
  @logger.expects(:warn)
102
102
  StatsD.key_value('fookv', 3.33)
103
- end
103
+ end
104
104
 
105
105
  def test_support_tags_syntax_on_datadog
106
106
  @backend.implementation = :datadog
@@ -116,7 +116,7 @@ class UDPBackendTest < Minitest::Test
116
116
  end
117
117
 
118
118
  def test_socket_error_should_not_raise_but_log
119
- @socket.stubs(:connect).raises(SocketError)
119
+ @socket.stubs(:connect).raises(SocketError)
120
120
  @logger.expects(:error)
121
121
  StatsD.increment('fail')
122
122
  end
@@ -132,4 +132,29 @@ class UDPBackendTest < Minitest::Test
132
132
  @logger.expects(:error)
133
133
  StatsD.increment('fail')
134
134
  end
135
+
136
+ def test_synchronize_in_exit_handler_handles_thread_error_and_exits_cleanly
137
+ pid = fork do
138
+ Signal.trap('TERM') do
139
+ $sent_packet = false
140
+
141
+ class << @backend.socket
142
+ def send(command, *args)
143
+ $sent_packet = true if command == 'exiting:1|c'
144
+ command.length
145
+ end
146
+ end
147
+
148
+ StatsD.increment('exiting')
149
+ Process.exit!($sent_packet)
150
+ end
151
+
152
+ sleep 100
153
+ end
154
+
155
+ Process.kill('TERM', pid)
156
+ Process.waitpid(pid)
157
+
158
+ assert $?.success?, 'socket did not write on exit'
159
+ end
135
160
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: statsd-instrument
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.2
4
+ version: 2.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jesse Storimer
@@ -10,90 +10,90 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2016-12-06 00:00:00.000000000 Z
13
+ date: 2017-07-06 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rake
17
17
  requirement: !ruby/object:Gem::Requirement
18
18
  requirements:
19
- - - '>='
19
+ - - ">="
20
20
  - !ruby/object:Gem::Version
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
25
25
  requirements:
26
- - - '>='
26
+ - - ">="
27
27
  - !ruby/object:Gem::Version
28
28
  version: '0'
29
29
  - !ruby/object:Gem::Dependency
30
30
  name: minitest
31
31
  requirement: !ruby/object:Gem::Requirement
32
32
  requirements:
33
- - - '>='
33
+ - - ">="
34
34
  - !ruby/object:Gem::Version
35
35
  version: '0'
36
36
  type: :development
37
37
  prerelease: false
38
38
  version_requirements: !ruby/object:Gem::Requirement
39
39
  requirements:
40
- - - '>='
40
+ - - ">="
41
41
  - !ruby/object:Gem::Version
42
42
  version: '0'
43
43
  - !ruby/object:Gem::Dependency
44
44
  name: rspec
45
45
  requirement: !ruby/object:Gem::Requirement
46
46
  requirements:
47
- - - '>='
47
+ - - ">="
48
48
  - !ruby/object:Gem::Version
49
49
  version: '0'
50
50
  type: :development
51
51
  prerelease: false
52
52
  version_requirements: !ruby/object:Gem::Requirement
53
53
  requirements:
54
- - - '>='
54
+ - - ">="
55
55
  - !ruby/object:Gem::Version
56
56
  version: '0'
57
57
  - !ruby/object:Gem::Dependency
58
58
  name: mocha
59
59
  requirement: !ruby/object:Gem::Requirement
60
60
  requirements:
61
- - - '>='
61
+ - - ">="
62
62
  - !ruby/object:Gem::Version
63
63
  version: '0'
64
64
  type: :development
65
65
  prerelease: false
66
66
  version_requirements: !ruby/object:Gem::Requirement
67
67
  requirements:
68
- - - '>='
68
+ - - ">="
69
69
  - !ruby/object:Gem::Version
70
70
  version: '0'
71
71
  - !ruby/object:Gem::Dependency
72
72
  name: yard
73
73
  requirement: !ruby/object:Gem::Requirement
74
74
  requirements:
75
- - - '>='
75
+ - - ">="
76
76
  - !ruby/object:Gem::Version
77
77
  version: '0'
78
78
  type: :development
79
79
  prerelease: false
80
80
  version_requirements: !ruby/object:Gem::Requirement
81
81
  requirements:
82
- - - '>='
82
+ - - ">="
83
83
  - !ruby/object:Gem::Version
84
84
  version: '0'
85
85
  - !ruby/object:Gem::Dependency
86
86
  name: benchmark-ips
87
87
  requirement: !ruby/object:Gem::Requirement
88
88
  requirements:
89
- - - '>='
89
+ - - ">="
90
90
  - !ruby/object:Gem::Version
91
91
  version: '0'
92
92
  type: :development
93
93
  prerelease: false
94
94
  version_requirements: !ruby/object:Gem::Requirement
95
95
  requirements:
96
- - - '>='
96
+ - - ">="
97
97
  - !ruby/object:Gem::Version
98
98
  version: '0'
99
99
  description: A StatsD client for Ruby apps. Provides metaprogramming methods to inject
@@ -104,8 +104,8 @@ executables: []
104
104
  extensions: []
105
105
  extra_rdoc_files: []
106
106
  files:
107
- - .gitignore
108
- - .travis.yml
107
+ - ".gitignore"
108
+ - ".travis.yml"
109
109
  - CHANGELOG.md
110
110
  - CONTRIBUTING.md
111
111
  - Gemfile
@@ -152,17 +152,17 @@ require_paths:
152
152
  - lib
153
153
  required_ruby_version: !ruby/object:Gem::Requirement
154
154
  requirements:
155
- - - '>='
155
+ - - ">="
156
156
  - !ruby/object:Gem::Version
157
157
  version: '0'
158
158
  required_rubygems_version: !ruby/object:Gem::Requirement
159
159
  requirements:
160
- - - '>='
160
+ - - ">="
161
161
  - !ruby/object:Gem::Version
162
162
  version: '0'
163
163
  requirements: []
164
164
  rubyforge_project:
165
- rubygems_version: 2.0.14.1
165
+ rubygems_version: 2.5.2
166
166
  signing_key:
167
167
  specification_version: 4
168
168
  summary: A StatsD client for Ruby apps
@@ -180,4 +180,3 @@ test_files:
180
180
  - test/statsd_test.rb
181
181
  - test/test_helper.rb
182
182
  - test/udp_backend_test.rb
183
- has_rdoc: