statsd-instrument 2.0.12 → 2.1.0

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: 63dfe410622af6e685d7a2f6614f528152b36357
4
- data.tar.gz: 104d234cfd0350fcd4f079bec5baf965f86da6f3
3
+ metadata.gz: 18047951724aa18b3d78beeb6f41dc4de83af59c
4
+ data.tar.gz: aca4e756c32bfeb9564e485cd95406d11028cc05
5
5
  SHA512:
6
- metadata.gz: 69206e0b5124e2223184895448be069458c95023ff85bb684897bd9ff369d70f8b91e8dfbcec3cbf2f9e13c081612ef615fa1cfb21311a46ddea9fd5ad72aa6d
7
- data.tar.gz: 471d932952f69c70e1f73e92e2e8ce08841d91f054353690002d2e4017571b866cc1c6cb86028eee3830f97ab7ce2080fe001acb20c97be85565c64d675f7971
6
+ metadata.gz: d14651044e4b148c3caefaac65f7d4c7b49471ddf769c8124d9e9a5f0034eb4069c1139ea0ccb772e0ad78c1378599b0b5fae56f64c85d289df69c780096578b
7
+ data.tar.gz: e4187bb6b8d76a86e7fb0e46800fe5d2a7625234bb54cdb3630165590834fe5a27555367cb6148ae67a9993883bfa6be7decf6ad18abe50cf476d077cfb43ac3
@@ -277,7 +277,7 @@ module StatsD
277
277
  def measure(key, value = nil, *metric_options, &block)
278
278
  if value.is_a?(Hash) && metric_options.empty?
279
279
  metric_options = [value]
280
- value = nil
280
+ value = value.fetch(:value, nil)
281
281
  end
282
282
 
283
283
  result = nil
@@ -301,7 +301,7 @@ module StatsD
301
301
  def increment(key, value = 1, *metric_options)
302
302
  if value.is_a?(Hash) && metric_options.empty?
303
303
  metric_options = [value]
304
- value = 1
304
+ value = value.fetch(:value, 1)
305
305
  end
306
306
 
307
307
  collect_metric(hash_argument(metric_options).merge(type: :c, name: key, value: value))
@@ -313,6 +313,11 @@ module StatsD
313
313
  # @param metric_options [Hash] (default: {}) Metric options
314
314
  # @return (see #collect_metric)
315
315
  def gauge(key, value, *metric_options)
316
+ if value.is_a?(Hash) && metric_options.empty?
317
+ metric_options = [value]
318
+ value = value.fetch(:value, nil)
319
+ end
320
+
316
321
  collect_metric(hash_argument(metric_options).merge(type: :g, name: key, value: value))
317
322
  end
318
323
 
@@ -323,6 +328,11 @@ module StatsD
323
328
  # @return (see #collect_metric)
324
329
  # @note Supported by the datadog implementation only.
325
330
  def histogram(key, value, *metric_options)
331
+ if value.is_a?(Hash) && metric_options.empty?
332
+ metric_options = [value]
333
+ value = value.fetch(:value, nil)
334
+ end
335
+
326
336
  collect_metric(hash_argument(metric_options).merge(type: :h, name: key, value: value))
327
337
  end
328
338
 
@@ -333,6 +343,11 @@ module StatsD
333
343
  # @return (see #collect_metric)
334
344
  # @note Supported by the statsite implementation only.
335
345
  def key_value(key, value, *metric_options)
346
+ if value.is_a?(Hash) && metric_options.empty?
347
+ metric_options = [value]
348
+ value = value.fetch(:value, nil)
349
+ end
350
+
336
351
  collect_metric(hash_argument(metric_options).merge(type: :kv, name: key, value: value))
337
352
  end
338
353
 
@@ -343,6 +358,11 @@ module StatsD
343
358
  # @return (see #collect_metric)
344
359
  # @note Supported by the datadog implementation only.
345
360
  def set(key, value, *metric_options)
361
+ if value.is_a?(Hash) && metric_options.empty?
362
+ metric_options = [value]
363
+ value = value.fetch(:value, nil)
364
+ end
365
+
346
366
  collect_metric(hash_argument(metric_options).merge(type: :s, name: key, value: value))
347
367
  end
348
368
 
@@ -1,5 +1,5 @@
1
1
  require 'rspec/expectations'
2
- require 'rspec/version'
2
+ require 'rspec/core/version'
3
3
 
4
4
  module StatsD::Instrument::Matchers
5
5
  CUSTOM_MATCHERS = {
@@ -12,7 +12,7 @@ module StatsD::Instrument::Matchers
12
12
  }
13
13
 
14
14
  class Matcher
15
- include RSpec::Matchers::Composable if RSpec::Version::STRING.start_with?('3')
15
+ include RSpec::Matchers::Composable if RSpec::Core::Version::STRING.start_with?('3')
16
16
  include StatsD::Instrument::Helpers
17
17
 
18
18
  def initialize(metric_type, metric_name, options = {})
@@ -1,5 +1,5 @@
1
1
  module StatsD
2
2
  module Instrument
3
- VERSION = "2.0.12"
3
+ VERSION = "2.1.0"
4
4
  end
5
5
  end
data/test/statsd_test.rb CHANGED
@@ -17,12 +17,25 @@ class StatsDTest < Minitest::Test
17
17
  assert_equal :ms, metric.type
18
18
  end
19
19
 
20
+ def test_statsd_measure_with_explicit_value_as_keyword_argument
21
+ result = nil
22
+ metric = capture_statsd_call { result = StatsD.measure('values.foobar', value: 42) }
23
+ assert_equal metric, result
24
+ assert_equal 'values.foobar', metric.name
25
+ assert_equal 42, metric.value
26
+ assert_equal :ms, metric.type
27
+ end
28
+
29
+ def test_statsd_measure_without_value_or_block
30
+ assert_raises(ArgumentError) { StatsD.measure('values.foobar', tags: 123) }
31
+ end
32
+
20
33
  def test_statsd_measure_with_explicit_value_and_sample_rate
21
34
  metric = capture_statsd_call { StatsD.measure('values.foobar', 42, :sample_rate => 0.1) }
22
35
  assert_equal 0.1, metric.sample_rate
23
36
  end
24
37
 
25
- def test_statsd_measure_with_benchmarked_duration
38
+ def test_statsd_measure_with_benchmarked_block_duration
26
39
  StatsD::Instrument.stubs(:duration).returns(1.12)
27
40
  metric = capture_statsd_call do
28
41
  StatsD.measure('values.foobar') { 'foo' }
@@ -51,6 +64,12 @@ class StatsDTest < Minitest::Test
51
64
  assert_equal 1, metric.value
52
65
  end
53
66
 
67
+ def test_statsd_increment_with_value_as_keyword_argument
68
+ metric = capture_statsd_call { StatsD.increment('values.foobar', :value => 2) }
69
+ assert_equal StatsD.default_sample_rate, metric.sample_rate
70
+ assert_equal 2, metric.value
71
+ end
72
+
54
73
  def test_statsd_increment_with_multiple_arguments
55
74
  metric = capture_statsd_call { StatsD.increment('values.foobar', 12, nil, ['test']) }
56
75
  assert_equal StatsD.default_sample_rate, metric.sample_rate
@@ -67,6 +86,19 @@ class StatsDTest < Minitest::Test
67
86
  assert_equal 12, metric.value
68
87
  end
69
88
 
89
+ def test_statsd_gauge_with_keyword_argument
90
+ result = nil
91
+ metric = capture_statsd_call { result = StatsD.gauge('values.foobar', value: 13) }
92
+ assert_equal metric, result
93
+ assert_equal :g, metric.type
94
+ assert_equal 'values.foobar', metric.name
95
+ assert_equal 13, metric.value
96
+ end
97
+
98
+ def test_statsd_gauge_without_value
99
+ assert_raises(ArgumentError) { StatsD.gauge('values.foobar', tags: 123) }
100
+ end
101
+
70
102
  def test_statsd_set
71
103
  result = nil
72
104
  metric = capture_statsd_call { result = StatsD.set('values.foobar', 'unique_identifier') }
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.0.12
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jesse Storimer
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2016-05-20 00:00:00.000000000 Z
13
+ date: 2016-06-16 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rake
@@ -161,7 +161,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
161
161
  version: '0'
162
162
  requirements: []
163
163
  rubyforge_project:
164
- rubygems_version: 2.2.3
164
+ rubygems_version: 2.4.5.1
165
165
  signing_key:
166
166
  specification_version: 4
167
167
  summary: A StatsD client for Ruby apps