statsd-instrument 2.0.11 → 2.0.12

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: 2b3d5d77001c8868328c05e1f62406ab13b92c03
4
- data.tar.gz: 32b5ba8a24354acfb72f73ce2e514146e9e3773c
3
+ metadata.gz: 63dfe410622af6e685d7a2f6614f528152b36357
4
+ data.tar.gz: 104d234cfd0350fcd4f079bec5baf965f86da6f3
5
5
  SHA512:
6
- metadata.gz: a94d925a45d26e5b5ebd366cc8aa2d2e61e06a577b79e5f4af908d1114598dad047cd24b0206d7864964be93f6a7e571f6f2d601ed68c26458433151cde8f540
7
- data.tar.gz: d1bab44e9942aa4a7e1be4d1af6f88bcf33bf82106d7f8c3c5cfcb957579be583942693f30662f837a26e37f9a7adbadcebeea7a3c980ac06ae14e6931aa9bbc
6
+ metadata.gz: 69206e0b5124e2223184895448be069458c95023ff85bb684897bd9ff369d70f8b91e8dfbcec3cbf2f9e13c081612ef615fa1cfb21311a46ddea9fd5ad72aa6d
7
+ data.tar.gz: 471d932952f69c70e1f73e92e2e8ce08841d91f054353690002d2e4017571b866cc1c6cb86028eee3830f97ab7ce2080fe001acb20c97be85565c64d675f7971
data/CHANGELOG.md CHANGED
@@ -7,6 +7,7 @@ please at an entry to the "unreleased changes" section below.
7
7
 
8
8
  - Drop support for Ruby 1.9.3.
9
9
  - Add support for Ruby 2.2.
10
+ - Make library compatible with RSpec 2.
10
11
 
11
12
  ### Version 2.0.6
12
13
 
@@ -39,28 +39,36 @@ module StatsD::Instrument::Assertions
39
39
  metrics = metrics.select { |m| m.type == metric_type && m.name == metric_name }
40
40
  assert metrics.length > 0, "No StatsD calls for metric #{metric_name} were made."
41
41
  assert options[:times] === metrics.length, "The amount of StatsD calls for metric #{metric_name} was unexpected. Expected #{options[:times].inspect}, found #{metrics.length}"
42
- metric = metrics.first
43
42
 
44
- assert_equal options[:sample_rate], metric.sample_rate, "Unexpected StatsD sample rate for metric #{metric_name}" if options[:sample_rate]
45
- assert_equal options[:value], metric.value, "Unexpected value submitted for StatsD metric #{metric_name}" if options[:value]
43
+ metrics.each do |metric|
46
44
 
47
- if options[:tags]
48
- expected_tags = Set.new(StatsD::Instrument::Metric.normalize_tags(options[:tags]))
49
- actual_tags = Set.new(metric.tags)
45
+ assert within_numeric_range?(metric.sample_rate), "Unexpected sample rate type for metric #{metric_name}, must be numeric"
46
+ assert_equal options[:sample_rate], metric.sample_rate, "Unexpected StatsD sample rate for metric #{metric_name}" if options[:sample_rate]
47
+ assert_equal options[:value], metric.value, "Unexpected value submitted for StatsD metric #{metric_name}" if options[:value]
50
48
 
51
- if options[:ignore_tags]
52
- ignored_tags = Set.new(StatsD::Instrument::Metric.normalize_tags(options[:ignore_tags])) - expected_tags
53
- actual_tags -= ignored_tags
49
+ if options[:tags]
54
50
 
55
- if options[:ignore_tags].is_a?(Array)
56
- actual_tags.delete_if{ |key| options[:ignore_tags].include?(key.split(":").first) }
51
+ expected_tags = Set.new(StatsD::Instrument::Metric.normalize_tags(options[:tags]))
52
+ actual_tags = Set.new(metric.tags)
53
+
54
+ if options[:ignore_tags]
55
+ ignored_tags = Set.new(StatsD::Instrument::Metric.normalize_tags(options[:ignore_tags])) - expected_tags
56
+ actual_tags -= ignored_tags
57
+
58
+ if options[:ignore_tags].is_a?(Array)
59
+ actual_tags.delete_if{ |key| options[:ignore_tags].include?(key.split(":").first) }
60
+ end
57
61
  end
62
+
63
+ assert_equal expected_tags, actual_tags,
64
+ "Unexpected StatsD tags for metric #{metric_name}. Expected: #{expected_tags.inspect}, actual: #{actual_tags.inspect}"
58
65
  end
59
66
 
60
- assert_equal expected_tags, actual_tags,
61
- "Unexpected StatsD tags for metric #{metric_name}. Expected: #{expected_tags.inspect}, actual: #{actual_tags.inspect}"
67
+ metric
62
68
  end
69
+ end
63
70
 
64
- metric
71
+ def within_numeric_range?(object)
72
+ object.kind_of?(Numeric) && (0.0..1.0).cover?(object)
65
73
  end
66
74
  end
@@ -1,12 +1,17 @@
1
+ require 'monitor'
2
+
1
3
  module StatsD::Instrument::Backends
2
4
  class UDPBackend < StatsD::Instrument::Backend
3
5
 
4
6
  DEFAULT_IMPLEMENTATION = :statsd
5
7
 
8
+ include MonitorMixin
9
+
6
10
  attr_reader :host, :port
7
11
  attr_accessor :implementation
8
12
 
9
13
  def initialize(server = nil, implementation = nil)
14
+ super()
10
15
  self.server = server || "localhost:8125"
11
16
  self.implementation = (implementation || DEFAULT_IMPLEMENTATION).to_sym
12
17
  end
@@ -76,7 +81,9 @@ module StatsD::Instrument::Backends
76
81
  end
77
82
 
78
83
  def write_packet(command)
79
- socket.send(command, 0) > 0
84
+ synchronize do
85
+ socket.send(command, 0) > 0
86
+ end
80
87
  rescue SocketError, IOError, SystemCallError => e
81
88
  StatsD.logger.error "[StatsD] #{e.class.name}: #{e.message}"
82
89
  end
@@ -1,4 +1,5 @@
1
1
  require 'rspec/expectations'
2
+ require 'rspec/version'
2
3
 
3
4
  module StatsD::Instrument::Matchers
4
5
  CUSTOM_MATCHERS = {
@@ -11,7 +12,7 @@ module StatsD::Instrument::Matchers
11
12
  }
12
13
 
13
14
  class Matcher
14
- include RSpec::Matchers::Composable
15
+ include RSpec::Matchers::Composable if RSpec::Version::STRING.start_with?('3')
15
16
  include StatsD::Instrument::Helpers
16
17
 
17
18
  def initialize(metric_type, metric_name, options = {})
@@ -1,5 +1,5 @@
1
1
  module StatsD
2
2
  module Instrument
3
- VERSION = "2.0.11"
3
+ VERSION = "2.0.12"
4
4
  end
5
5
  end
@@ -80,6 +80,20 @@ class AssertionsTest < Minitest::Test
80
80
  end
81
81
  end
82
82
 
83
+ assert_no_assertion_triggered do
84
+ @test_case.assert_statsd_increment('counter', times: 2, tags: ['foo:1']) do
85
+ StatsD.increment('counter', tags: { foo: 1 })
86
+ StatsD.increment('counter', tags: { foo: 1 })
87
+ end
88
+ end
89
+
90
+ assert_assertion_triggered do
91
+ @test_case.assert_statsd_increment('counter', times: 2, tags: ['foo:1']) do
92
+ StatsD.increment('counter', tags: { foo: 1 })
93
+ StatsD.increment('counter', tags: { foo: 2 })
94
+ end
95
+ end
96
+
83
97
  assert_no_assertion_triggered do
84
98
  @test_case.assert_statsd_increment('counter', sample_rate: 0.5, tags: ['a', 'b']) do
85
99
  StatsD.increment('counter', sample_rate: 0.5, tags: ['a', 'b'])
@@ -149,6 +163,14 @@ class AssertionsTest < Minitest::Test
149
163
  end
150
164
  end
151
165
 
166
+ def test_assert_statsd_call_with_wrong_sample_rate_type
167
+ assert_assertion_triggered "Unexpected sample rate type for metric counter, must be numeric" do
168
+ @test_case.assert_statsd_increment('counter', tags: ['a', 'b']) do
169
+ StatsD.increment('counter', sample_rate: 'abc', tags: ['a', 'b'])
170
+ end
171
+ end
172
+ end
173
+
152
174
  def test_nested_assertions
153
175
  assert_no_assertion_triggered do
154
176
  @test_case.assert_statsd_increment('counter1') do
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.11
4
+ version: 2.0.12
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-02-18 00:00:00.000000000 Z
13
+ date: 2016-05-20 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rake