statsd-instrument 3.1.1 → 3.1.2

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
  SHA256:
3
- metadata.gz: feb99d0537663296eacb1c2f0c6d090f37430afc04d886b60a9aaf322f86a114
4
- data.tar.gz: 0ed9a90c182d52d11a70490b78c369ba2ec9cdc1b4cf90c86d306199061d5dc9
3
+ metadata.gz: 85b73b161dac9bc8839c3b820e9ea038d05078519fca692e971a48be7077e799
4
+ data.tar.gz: e2d5bfa763a5d53537494c8a5006327a93967d4d2b63f74a685094c551815c81
5
5
  SHA512:
6
- metadata.gz: bba9e06ddabc9ec50fcc6586f53376d5c5a97ddd1745265d76130544b07ebe603375b964bb1d2ede8e32f03963d098df3bca774873a610cee20fad7df11d537c
7
- data.tar.gz: b60faf4b9164f883592109a04e64ffb7aaa60972460c26545526c43ad16d2c3ed4a897d9a537a3b285cae4c6435dae8afd96a3303cf7aa2b818afceca65cf17b
6
+ metadata.gz: e6db90f921635692d1d19145e3b346029886022c679649fac3e6f5641411ddc557fcd2028baff7be4e0b47a23e53f97e4afe9af4ecb7e537dc0850b32352fbec
7
+ data.tar.gz: 6c8f12361a70596d49dc84b3feb6637bc0ff7e9d62f1e6e7876ec02111cc94a2b561947ac4bfda045f612f57951f9789e578447e67a0b8bda4beec4f0fc76576
@@ -13,7 +13,7 @@ jobs:
13
13
  - name: Setup Ruby
14
14
  uses: actions/setup-ruby@v1
15
15
  with:
16
- ruby-version: 2.6
16
+ ruby-version: 2.7
17
17
 
18
18
  - name: Install dependencies
19
19
  run: gem install bundler && bundle install --jobs 4 --retry 3
data/.rubocop.yml CHANGED
@@ -5,8 +5,9 @@ require:
5
5
  - ./lib/statsd/instrument/rubocop.rb
6
6
 
7
7
  AllCops:
8
- TargetRubyVersion: 2.6
8
+ TargetRubyVersion: 2.7
9
9
  UseCache: true
10
+ SuggestExtensions: false
10
11
  CacheRootDirectory: tmp/rubocop
11
12
  Exclude:
12
13
  - statsd-instrument.gemspec
data/CHANGELOG.md CHANGED
@@ -8,6 +8,10 @@ section below.
8
8
 
9
9
  _Nothing yet_
10
10
 
11
+ ## Version 3.1.2
12
+
13
+ - Fix bug when passing custom client to expectation.
14
+
11
15
  ## Version 3.1.1
12
16
 
13
17
  - Improved flushing of buffered datagrams on process exit when using UDP batching.
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # StatsD client for Ruby apps
2
2
 
3
- This is a ruby client for statsd (http://github.com/etsy/statsd). It provides
3
+ This is a ruby client for statsd (https://github.com/statsd/statsd). It provides
4
4
  a lightweight way to track and measure metrics in your application.
5
5
 
6
6
  We call out to statsd by sending data over a UDP socket. UDP sockets are fast,
@@ -10,8 +10,8 @@ because it means your code doesn't get bogged down trying to log statistics.
10
10
  We send data to statsd several times per request and haven't noticed a
11
11
  performance hit.
12
12
 
13
- For more information about StatsD, see the [README of the Etsy
14
- project](http://github.com/etsy/statsd).
13
+ For more information about StatsD, see the [README of the StatsD
14
+ project](https://github.com/statsd/statsd).
15
15
 
16
16
  ## Configuration
17
17
 
@@ -6,8 +6,8 @@ require "tmpdir"
6
6
  require "benchmark/ips"
7
7
 
8
8
  revision = %x(git rev-parse HEAD).rstrip
9
- master_revision = %x(git rev-parse origin/master).rstrip
10
- branch = if revision == master_revision
9
+ base_revision = %x(git rev-parse origin/master).rstrip
10
+ branch = if revision == base_revision
11
11
  "master"
12
12
  else
13
13
  %x(git rev-parse --abbrev-ref HEAD).rstrip
@@ -8,8 +8,8 @@ require "socket"
8
8
  require "statsd-instrument"
9
9
 
10
10
  revision = %x(git rev-parse HEAD).rstrip
11
- master_revision = %x(git rev-parse origin/master).rstrip
12
- branch = if revision == master_revision
11
+ base_revision = %x(git rev-parse origin/master).rstrip
12
+ branch = if revision == base_revision
13
13
  "master"
14
14
  else
15
15
  %x(git rev-parse --abbrev-ref HEAD).rstrip
@@ -74,7 +74,7 @@ module StatsD
74
74
  # @raise [Minitest::Assertion] If an exception occurs, or if the metric did
75
75
  # not occur as specified during the execution the block.
76
76
  def assert_statsd_increment(metric_name, value = nil, datagrams: nil, client: nil, **options, &block)
77
- expectation = StatsD::Instrument::Expectation.increment(metric_name, value, **options)
77
+ expectation = StatsD::Instrument::Expectation.increment(metric_name, value, client: client, **options)
78
78
  assert_statsd_expectation(expectation, datagrams: datagrams, client: client, &block)
79
79
  end
80
80
 
@@ -86,7 +86,7 @@ module StatsD
86
86
  # @return [void]
87
87
  # @raise (see #assert_statsd_increment)
88
88
  def assert_statsd_measure(metric_name, value = nil, datagrams: nil, client: nil, **options, &block)
89
- expectation = StatsD::Instrument::Expectation.measure(metric_name, value, **options)
89
+ expectation = StatsD::Instrument::Expectation.measure(metric_name, value, client: client, **options)
90
90
  assert_statsd_expectation(expectation, datagrams: datagrams, client: client, &block)
91
91
  end
92
92
 
@@ -98,7 +98,7 @@ module StatsD
98
98
  # @return [void]
99
99
  # @raise (see #assert_statsd_increment)
100
100
  def assert_statsd_gauge(metric_name, value = nil, datagrams: nil, client: nil, **options, &block)
101
- expectation = StatsD::Instrument::Expectation.gauge(metric_name, value, **options)
101
+ expectation = StatsD::Instrument::Expectation.gauge(metric_name, value, client: client, **options)
102
102
  assert_statsd_expectation(expectation, datagrams: datagrams, client: client, &block)
103
103
  end
104
104
 
@@ -110,7 +110,7 @@ module StatsD
110
110
  # @return [void]
111
111
  # @raise (see #assert_statsd_increment)
112
112
  def assert_statsd_histogram(metric_name, value = nil, datagrams: nil, client: nil, **options, &block)
113
- expectation = StatsD::Instrument::Expectation.histogram(metric_name, value, **options)
113
+ expectation = StatsD::Instrument::Expectation.histogram(metric_name, value, client: client, **options)
114
114
  assert_statsd_expectation(expectation, datagrams: datagrams, client: client, &block)
115
115
  end
116
116
 
@@ -122,7 +122,7 @@ module StatsD
122
122
  # @return [void]
123
123
  # @raise (see #assert_statsd_increment)
124
124
  def assert_statsd_distribution(metric_name, value = nil, datagrams: nil, client: nil, **options, &block)
125
- expectation = StatsD::Instrument::Expectation.distribution(metric_name, value, **options)
125
+ expectation = StatsD::Instrument::Expectation.distribution(metric_name, value, client: client, **options)
126
126
  assert_statsd_expectation(expectation, datagrams: datagrams, client: client, &block)
127
127
  end
128
128
 
@@ -134,7 +134,7 @@ module StatsD
134
134
  # @return [void]
135
135
  # @raise (see #assert_statsd_increment)
136
136
  def assert_statsd_set(metric_name, value = nil, datagrams: nil, client: nil, **options, &block)
137
- expectation = StatsD::Instrument::Expectation.set(metric_name, value, **options)
137
+ expectation = StatsD::Instrument::Expectation.set(metric_name, value, client: client, **options)
138
138
  assert_statsd_expectation(expectation, datagrams: datagrams, client: client, &block)
139
139
  end
140
140
 
@@ -29,7 +29,7 @@ module StatsD
29
29
  end
30
30
 
31
31
  def sample?(sample_rate)
32
- sample_rate == 1 || rand < sample_rate
32
+ sample_rate == 1.0 || rand < sample_rate
33
33
  end
34
34
 
35
35
  def <<(datagram)
@@ -5,18 +5,6 @@ module StatsD
5
5
  # @note This class is part of the new Client implementation that is intended
6
6
  # to become the new default in the next major release of this library.
7
7
  class DatagramBuilder
8
- unless Regexp.method_defined?(:match?) # for ruby 2.3
9
- module RubyBackports
10
- refine Regexp do
11
- def match?(str)
12
- match(str) != nil
13
- end
14
- end
15
- end
16
-
17
- using(RubyBackports)
18
- end
19
-
20
8
  def self.unsupported_datagram_types(*types)
21
9
  types.each do |type|
22
10
  define_method(type) do |_, _, _, _|
@@ -32,9 +32,10 @@ module StatsD
32
32
 
33
33
  attr_accessor :times, :type, :name, :value, :sample_rate, :tags
34
34
 
35
- def initialize(client: StatsD.singleton_client, type:, name:, value: nil,
35
+ def initialize(client: nil, type:, name:, value: nil,
36
36
  sample_rate: nil, tags: nil, no_prefix: false, times: 1)
37
37
 
38
+ client ||= StatsD.singleton_client
38
39
  @type = type
39
40
  @name = no_prefix || !client.prefix ? name : "#{client.prefix}.#{name}"
40
41
  @value = normalized_value_for_type(type, value) if value
@@ -78,19 +79,6 @@ module StatsD
78
79
 
79
80
  private
80
81
 
81
- # Needed for normalize_tags
82
- unless Regexp.method_defined?(:match?) # for ruby 2.3
83
- module RubyBackports
84
- refine Regexp do
85
- def match?(str)
86
- (self =~ str) != nil
87
- end
88
- end
89
- end
90
-
91
- using(RubyBackports)
92
- end
93
-
94
82
  # @private
95
83
  #
96
84
  # Utility function to convert tags to the canonical form.
@@ -19,7 +19,7 @@ module RuboCop
19
19
 
20
20
  MSG = "Do not use the return value of StatsD metric methods"
21
21
 
22
- INVALID_PARENTS = %i{lvasgn array pair send return yield}
22
+ INVALID_PARENTS = [:lvasgn, :array, :pair, :send, :return, :yield]
23
23
 
24
24
  def on_send(node)
25
25
  if metric_method?(node) && node.arguments.last&.type != :block_pass
@@ -3,34 +3,13 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module StatsD
6
- METRIC_METHODS = %i{
7
- increment
8
- gauge
9
- measure
10
- set
11
- histogram
12
- distribution
13
- key_value
14
- }
6
+ METRIC_METHODS = [:increment, :gauge, :measure, :set, :histogram, :distribution, :key_value]
15
7
 
16
- METAPROGRAMMING_METHODS = %i{
17
- statsd_measure
18
- statsd_distribution
19
- statsd_count_success
20
- statsd_count_if
21
- statsd_count
22
- }
8
+ METAPROGRAMMING_METHODS = [:statsd_measure, :statsd_distribution, :statsd_count_success, :statsd_count_if,
9
+ :statsd_count,]
23
10
 
24
- SINGLETON_CONFIGURATION_METHODS = %i{
25
- backend
26
- backend=
27
- prefix
28
- prefix=
29
- default_tags
30
- default_tags=
31
- default_sample_rate
32
- default_sample_rate=
33
- }
11
+ SINGLETON_CONFIGURATION_METHODS = [:backend, :"backend=", :prefix, :"prefix=", :default_tags, :"default_tags=",
12
+ :default_sample_rate, :"default_sample_rate=",]
34
13
 
35
14
  private
36
15
 
@@ -20,7 +20,7 @@ module StatsD
20
20
  end
21
21
 
22
22
  def sample?(sample_rate)
23
- sample_rate == 1 || rand < sample_rate
23
+ sample_rate == 1.0 || rand < sample_rate
24
24
  end
25
25
 
26
26
  def <<(datagram)
@@ -2,6 +2,6 @@
2
2
 
3
3
  module StatsD
4
4
  module Instrument
5
- VERSION = "3.1.1"
5
+ VERSION = "3.1.2"
6
6
  end
7
7
  end
@@ -440,4 +440,17 @@ class AssertionsTest < Minitest::Test
440
440
  StatsD.increment("incr", no_prefix: true)
441
441
  end
442
442
  end
443
+
444
+ def test_client_propagation_to_expectations
445
+ foo_1_metric = StatsD::Instrument::Expectation.increment("foo")
446
+ @test_case.assert_statsd_expectations([foo_1_metric]) do
447
+ StatsD.increment("foo")
448
+ end
449
+
450
+ client = StatsD::Instrument::Client.new(prefix: "prefix")
451
+ foo_2_metric = StatsD::Instrument::Expectation.increment("foo", client: client)
452
+ @test_case.assert_statsd_expectations([foo_2_metric]) do
453
+ StatsD.increment("prefix.foo")
454
+ end
455
+ end
443
456
  end
@@ -16,7 +16,7 @@ class DatagramBuilderTest < Minitest::Test
16
16
 
17
17
  def test_normalize_unsupported_tag_names
18
18
  assert_equal(["ign#ored"], @datagram_builder.send(:normalize_tags, ["ign#o|re,d"]))
19
- # Note: how this is interpreted by the backend is undefined.
19
+ # NOTE: how this is interpreted by the backend is undefined.
20
20
  # We rely on the user to not do stuff like this if they don't want to be surprised.
21
21
  # We do not want to take the performance hit of normalizing this.
22
22
  assert_equal(["lol::class:omg::lol"], @datagram_builder.send(:normalize_tags, "lol::class" => "omg::lol"))
@@ -345,7 +345,7 @@ class StatsDInstrumentationTest < Minitest::Test
345
345
  client = StatsD::Instrument::Client.new(prefix: "prefix")
346
346
 
347
347
  ActiveMerchant::Gateway.statsd_count(:ssl_post, "ActiveMerchant.Gateway.ssl_post", client: client)
348
- assert_statsd_increment("prefix.ActiveMerchant.Gateway.ssl_post", client: client) do
348
+ assert_statsd_increment("ActiveMerchant.Gateway.ssl_post", client: client) do
349
349
  ActiveMerchant::Gateway.new.purchase(true)
350
350
  end
351
351
  ensure
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: 3.1.1
4
+ version: 3.1.2
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: 2021-04-13 00:00:00.000000000 Z
13
+ date: 2021-09-02 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: concurrent-ruby
@@ -87,7 +87,6 @@ files:
87
87
  - statsd-instrument.gemspec
88
88
  - test/assertions_test.rb
89
89
  - test/benchmark/clock_gettime.rb
90
- - test/benchmark/default_tags.rb
91
90
  - test/benchmark/metrics.rb
92
91
  - test/benchmark/tags.rb
93
92
  - test/capture_sink_test.rb
@@ -135,14 +134,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
135
134
  - !ruby/object:Gem::Version
136
135
  version: '0'
137
136
  requirements: []
138
- rubygems_version: 3.0.3
137
+ rubygems_version: 3.2.20
139
138
  signing_key:
140
139
  specification_version: 4
141
140
  summary: A StatsD client for Ruby apps
142
141
  test_files:
143
142
  - test/assertions_test.rb
144
143
  - test/benchmark/clock_gettime.rb
145
- - test/benchmark/default_tags.rb
146
144
  - test/benchmark/metrics.rb
147
145
  - test/benchmark/tags.rb
148
146
  - test/capture_sink_test.rb
@@ -1,47 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "statsd-instrument"
4
- require "benchmark/ips"
5
-
6
- StatsD.logger = Logger.new(File::NULL)
7
-
8
- class Suite
9
- def warming(*args)
10
- StatsD.default_tags = if args[0] == "with default tags"
11
- { first_tag: "first_value", second_tag: "second_value" }
12
- end
13
- puts "warming with default tags: #{StatsD.default_tags}"
14
- end
15
-
16
- def running(*args)
17
- StatsD.default_tags = if args[0] == "with default tags"
18
- { first_tag: "first_value", second_tag: "second_value" }
19
- end
20
- puts "running with default tags: #{StatsD.default_tags}"
21
- end
22
-
23
- def warmup_stats(*)
24
- end
25
-
26
- def add_report(*)
27
- end
28
- end
29
-
30
- suite = Suite.new
31
-
32
- Benchmark.ips do |bench|
33
- bench.config(suite: suite)
34
- bench.report("without default tags") do
35
- StatsD.increment("GoogleBase.insert", tags: {
36
- first_tag: "first_value",
37
- second_tag: "second_value",
38
- third_tag: "third_value",
39
- })
40
- end
41
-
42
- bench.report("with default tags") do
43
- StatsD.increment("GoogleBase.insert", tags: { third_tag: "third_value" })
44
- end
45
-
46
- bench.compare!
47
- end