inst_statsd 2.4.0 → 3.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,124 +1,159 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'spec_helper'
3
+ require "spec_helper"
4
+
5
+ require "datadog/statsd"
4
6
 
5
7
  describe InstStatsd::Statsd do
6
- METHODS = %w[increment decrement count gauge timing].freeze
8
+ let(:methods) { %w[increment decrement count gauge timing].freeze }
9
+ let(:increment_decrement) { %w[increment decrement].freeze }
7
10
 
8
11
  after do
9
12
  InstStatsd.settings = {}
10
13
  InstStatsd::Statsd.reset_instance
11
14
  end
12
15
 
13
- it 'includes the events module' do
16
+ it "includes the events module" do
14
17
  expect(described_class).to respond_to :event
15
18
  end
16
19
 
17
- it 'appends the hostname to stat names by default' do
18
- allow(InstStatsd::Statsd).to receive(:hostname).and_return('testhost')
19
- statsd = double
20
- allow(InstStatsd::Statsd).to receive(:instance).and_return(statsd)
21
- allow(InstStatsd::Statsd).to receive(:append_hostname?).and_return(true)
22
- METHODS.each do |method|
23
- expect(statsd).to receive(method).with('test.name.testhost', 'test')
24
- InstStatsd::Statsd.send(method, 'test.name', 'test')
20
+ it "appends the hostname to stat names by default" do
21
+ statsd = instance_double(Datadog::Statsd)
22
+ allow(InstStatsd::Statsd).to receive_messages(hostname: "testhost", instance: statsd, append_hostname?: true)
23
+ methods.each do |method|
24
+ expect(statsd).to receive(method).with("test.name.testhost", "test")
25
+ InstStatsd::Statsd.send(method, "test.name", "test")
25
26
  end
26
- expect(statsd).to receive('timing').with('test.name.testhost', anything, anything)
27
- expect(InstStatsd::Statsd.time('test.name') { 'test' }).to eq 'test'
27
+ expect(statsd).to receive("timing").with("test.name.testhost", anything, anything)
28
+ expect(InstStatsd::Statsd.time("test.name") { "test" }).to eq "test"
28
29
  end
29
30
 
30
- it 'sending tags should not break statsd' do
31
- default_tags = {app: 'canvas', env: 'prod'}
32
- short_stat = 'test2'
31
+ it "sending tags should not break statsd" do
32
+ default_tags = { app: "canvas", env: "prod" }
33
+ short_stat = "test2"
33
34
  env = {
34
- 'INST_DOG_TAGS' => '{"app": "canvas", "env": "prod"}',
35
+ "INST_DOG_TAGS" => '{"app": "canvas", "env": "prod"}'
35
36
  }
36
37
  InstStatsd.env_settings(env)
37
- allow(InstStatsd::Statsd).to receive(:hostname).and_return('testhost')
38
- allow(InstStatsd::Statsd).to receive(:short_stat).and_return(short_stat)
39
- statsd = double
40
- allow(InstStatsd::Statsd).to receive(:instance).and_return(statsd)
41
- allow(InstStatsd::Statsd).to receive(:data_dog?).and_return(false)
42
- allow(InstStatsd::Statsd).to receive(:append_hostname?).and_return(true)
43
- METHODS.each do |method|
44
- expect(statsd).to receive(method).with('test.name.testhost', 'test') # no short stat or tags
45
- InstStatsd::Statsd.send(method, 'test.name', 'test', short_stat: short_stat, tags: default_tags)
38
+ statsd = instance_double(Datadog::Statsd)
39
+ allow(InstStatsd::Statsd).to receive_messages(hostname: "testhost",
40
+ short_stat: short_stat,
41
+ instance: statsd,
42
+ data_dog?: false,
43
+ append_hostname?: true)
44
+ methods.each do |method|
45
+ expect(statsd).to receive(method).with("test.name.testhost", "test") # no short stat or tags
46
+ InstStatsd::Statsd.send(method, "test.name", "test", short_stat: short_stat, tags: default_tags)
46
47
  end
47
- expect(statsd).to receive('timing').with('test.name.testhost', anything, anything) # no short stat or tags
48
- expect(InstStatsd::Statsd.time('test.name') { 'test' }).to eq 'test'
48
+ expect(statsd).to receive("timing").with("test.name.testhost", anything, anything) # no short stat or tags
49
+ expect(InstStatsd::Statsd.time("test.name") { "test" }).to eq "test"
49
50
  end
50
51
 
51
- it 'adds default dog tags default' do
52
- default_tags = {app: 'canvas', env: 'prod'}
52
+ it "adds default dog tags default" do
53
+ default_tags = { app: "canvas", env: "prod" }
53
54
  converted_tags = ["app:canvas", "env:prod", "host:"]
54
- short_stat = 'test2'
55
- allow(InstStatsd::Statsd).to receive(:dog_tags).and_return(default_tags)
56
- allow(InstStatsd::Statsd).to receive(:short_stat).and_return(short_stat)
57
- statsd = double
58
- allow(InstStatsd::Statsd).to receive(:instance).and_return(statsd)
59
- allow(InstStatsd::Statsd).to receive(:data_dog?).and_return(true)
60
- allow(InstStatsd::Statsd).to receive(:append_hostname?).and_return(false)
61
- METHODS.each do |method|
62
- expect(statsd).to receive(method).with(short_stat, 'test', tags: converted_tags)
63
- InstStatsd::Statsd.send(method, 'test.name', 'test', short_stat: short_stat)
55
+ short_stat = "test2"
56
+ statsd = instance_double(Datadog::Statsd)
57
+ allow(InstStatsd::Statsd).to receive_messages(dog_tags: default_tags,
58
+ short_stat: short_stat,
59
+ instance: statsd,
60
+ data_dog?: true,
61
+ append_hostname?: false)
62
+ methods.each do |method|
63
+ args = [short_stat]
64
+ args << "test" unless increment_decrement.include?(method)
65
+
66
+ expect(statsd).to receive(method).with(*args, { tags: converted_tags })
67
+ InstStatsd::Statsd.send(method, *args, short_stat: short_stat)
64
68
  end
65
- expect(statsd).to receive('timing').with(short_stat, anything, sample_rate: anything, tags: converted_tags)
66
- expect(InstStatsd::Statsd.time('test.name', short_stat: short_stat) {'test'}).to eq 'test'
69
+ expect(statsd).to receive("timing").with(short_stat, anything, { sample_rate: anything, tags: converted_tags })
70
+ expect(InstStatsd::Statsd.time("test.name", short_stat: short_stat) { "test" }).to eq "test"
67
71
  end
68
72
 
69
- it 'uses regular stat name when short_stat is omitted on data dog' do
70
- default_tags = {app: 'canvas', env: 'prod'}
73
+ it "uses regular stat name when short_stat is omitted on data dog" do
74
+ default_tags = { app: "canvas", env: "prod" }
71
75
  converted_tags = ["app:canvas", "env:prod", "host:"]
72
- allow(InstStatsd::Statsd).to receive(:dog_tags).and_return(default_tags)
73
- statsd = double
74
- allow(InstStatsd::Statsd).to receive(:instance).and_return(statsd)
75
- allow(InstStatsd::Statsd).to receive(:data_dog?).and_return(true)
76
- allow(InstStatsd::Statsd).to receive(:append_hostname?).and_return(false)
77
- METHODS.each do |method|
78
- expect(statsd).to receive(method).with('test.name', 'test', tags: converted_tags)
79
- InstStatsd::Statsd.send(method, 'test.name', 'test')
76
+ statsd = instance_double(Datadog::Statsd)
77
+ allow(InstStatsd::Statsd).to receive_messages(dog_tags: default_tags,
78
+ instance: statsd,
79
+ data_dog?: true,
80
+ append_hostname?: false)
81
+ methods.each do |method|
82
+ args = ["test.name"]
83
+ args << "test" unless increment_decrement.include?(method)
84
+
85
+ expect(statsd).to receive(method).with(*args, { tags: converted_tags })
86
+ InstStatsd::Statsd.send(method, *args)
80
87
  end
81
- expect(statsd).to receive('timing').with('test.name', anything, sample_rate: anything, tags: converted_tags)
82
- expect(InstStatsd::Statsd.time('test.name') {'test'}).to eq 'test'
88
+ expect(statsd).to receive("timing").with("test.name", anything, { sample_rate: anything, tags: converted_tags })
89
+ expect(InstStatsd::Statsd.time("test.name") { "test" }).to eq "test"
83
90
  end
84
91
 
85
- it 'omits hostname if specified in config' do
86
- expect(InstStatsd::Statsd).to receive(:hostname).never
87
- statsd = double
88
- allow(InstStatsd::Statsd).to receive(:instance).and_return(statsd)
89
- allow(InstStatsd::Statsd).to receive(:append_hostname?).and_return(false)
90
- METHODS.each do |method|
91
- expect(statsd).to receive(method).with('test.name', 'test')
92
- InstStatsd::Statsd.send(method, 'test.name', 'test')
92
+ it "omits hostname if specified in config" do
93
+ expect(InstStatsd::Statsd).not_to receive(:hostname)
94
+ statsd = instance_double(Datadog::Statsd)
95
+ allow(InstStatsd::Statsd).to receive_messages(instance: statsd, append_hostname?: false)
96
+ methods.each do |method|
97
+ expect(statsd).to receive(method).with("test.name", "test")
98
+ InstStatsd::Statsd.send(method, "test.name", "test")
99
+ end
100
+ expect(statsd).to receive("timing").with("test.name", anything, anything)
101
+ expect(InstStatsd::Statsd.time("test.name") { "test" }).to eq "test"
102
+ end
103
+
104
+ context "with datadog enabled" do
105
+ it "handles being called with an array of stat names" do
106
+ converted_tags = %w[tag:value host:]
107
+ statsd = instance_double(Datadog::Statsd)
108
+ allow(InstStatsd::Statsd).to receive_messages(instance: statsd, append_hostname?: false, data_dog?: true)
109
+ methods.each do |method|
110
+ args = []
111
+ args << "values" unless increment_decrement.include?(method)
112
+
113
+ expect(statsd).to receive(method).once.with("test.one", *args, { tags: converted_tags })
114
+ expect(statsd).to receive(method).once.with("test.two", *args, { tags: converted_tags })
115
+ InstStatsd::Statsd.send(method,
116
+ %w[test.one test.two],
117
+ *args,
118
+ tags: { tag: "value" },
119
+ short_stat: "short_stat")
120
+ end
121
+ expect(statsd).to receive("timing").once.with("test.one",
122
+ anything,
123
+ { tags: converted_tags, sample_rate: anything })
124
+ expect(statsd).to receive("timing").once.with("test.two",
125
+ anything,
126
+ { tags: converted_tags, sample_rate: anything })
127
+ expect(InstStatsd::Statsd.time(%w[test.one test.two], tags: { tag: "value" }, short_stat: "short_stat") do
128
+ "test"
129
+ end).to eq "test"
93
130
  end
94
- expect(statsd).to receive('timing').with('test.name', anything, anything)
95
- expect(InstStatsd::Statsd.time('test.name') { 'test' }).to eq 'test'
96
131
  end
97
132
 
98
133
  it "ignores all calls if statsd isn't enabled" do
99
134
  allow(InstStatsd::Statsd).to receive(:instance).and_return(nil)
100
- METHODS.each do |method|
101
- expect(InstStatsd::Statsd.send(method, 'test.name')).to be_nil
135
+ methods.each do |method|
136
+ expect(InstStatsd::Statsd.send(method, "test.name")).to be_nil
102
137
  end
103
- expect(InstStatsd::Statsd.time('test.name') { 'test' }).to eq 'test'
138
+ expect(InstStatsd::Statsd.time("test.name") { "test" }).to eq "test"
104
139
  end
105
140
 
106
- it 'configures a statsd instance' do
141
+ it "configures a statsd instance" do
107
142
  expect(InstStatsd::Statsd.instance).to be_nil
108
143
 
109
- InstStatsd.settings = { host: 'localhost', namespace: 'test', port: 1234 }
144
+ InstStatsd.settings = { host: "localhost", namespace: "test", port: 1234 }
110
145
  InstStatsd::Statsd.reset_instance
111
146
 
112
147
  instance = InstStatsd::Statsd.instance
113
- expect(instance).to be_a ::Statsd
114
- expect(instance.host).to eq 'localhost'
148
+ expect(instance).to be_a Statsd
149
+ expect(instance.host).to eq "localhost"
115
150
  expect(instance.port).to eq 1234
116
- expect(instance.namespace).to eq 'test'
151
+ expect(instance.namespace).to eq "test"
117
152
  end
118
153
 
119
- describe '.batch' do
120
- it 'is properly reentrant' do
121
- InstStatsd.settings = { host: 'localhost', namespace: 'test', port: 1234 }
154
+ describe ".batch" do
155
+ it "is properly reentrant" do
156
+ InstStatsd.settings = { host: "localhost", namespace: "test", port: 1234 }
122
157
  InstStatsd::Statsd.reset_instance
123
158
 
124
159
  statsd = InstStatsd::Statsd.instance
@@ -126,9 +161,9 @@ describe InstStatsd::Statsd do
126
161
  batch1 = InstStatsd::Statsd.instance
127
162
  InstStatsd::Statsd.batch do
128
163
  batch2 = InstStatsd::Statsd.instance
129
- expect(statsd).to be_a ::Statsd
130
- expect(batch1).to be_a ::Statsd::Batch
131
- expect(batch2).to be_a ::Statsd::Batch
164
+ expect(statsd).to be_a Statsd
165
+ expect(batch1).to be_a Statsd::Batch
166
+ expect(batch2).to be_a Statsd::Batch
132
167
  expect(batch1).not_to eq batch2
133
168
  end
134
169
  expect(InstStatsd::Statsd.instance).to eq batch1
@@ -137,21 +172,21 @@ describe InstStatsd::Statsd do
137
172
  end
138
173
  end
139
174
 
140
- describe '.escape' do
141
- it 'replaces any dots in str with a _ when no replacment given' do
142
- result = InstStatsd::Statsd.escape('lots.of.dots')
143
- expect(result).to eq 'lots_of_dots'
175
+ describe ".escape" do
176
+ it "replaces any dots in str with a _ when no replacment given" do
177
+ result = InstStatsd::Statsd.escape("lots.of.dots")
178
+ expect(result).to eq "lots_of_dots"
144
179
  end
145
180
 
146
- it 'replaces any dots in str with replacement arg' do
147
- result = InstStatsd::Statsd.escape('lots.of.dots', '/')
148
- expect(result).to eq 'lots/of/dots'
181
+ it "replaces any dots in str with replacement arg" do
182
+ result = InstStatsd::Statsd.escape("lots.of.dots", "/")
183
+ expect(result).to eq "lots/of/dots"
149
184
  end
150
185
 
151
- it 'returns str when given a str that doesnt respond to gsub' do
186
+ it "returns str when given a str that doesnt respond to gsub" do
152
187
  result = InstStatsd::Statsd.escape(nil)
153
- expect(result).to eq nil
154
- hash = { foo: 'bar' }
188
+ expect(result).to be_nil
189
+ hash = { foo: "bar" }
155
190
  result = InstStatsd::Statsd.escape(hash)
156
191
  expect(result).to eq hash
157
192
  end
data/spec/spec_helper.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'inst_statsd'
3
+ require "inst_statsd"
4
4
 
5
5
  RSpec.configure do |config|
6
6
  config.run_all_when_everything_filtered = true
@@ -8,5 +8,5 @@ RSpec.configure do |config|
8
8
 
9
9
  config.raise_errors_for_deprecations!
10
10
 
11
- config.order = 'random'
11
+ config.order = "random"
12
12
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: inst_statsd
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.4.0
4
+ version: 3.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Cloward
@@ -9,22 +9,48 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2023-06-13 00:00:00.000000000 Z
12
+ date: 2023-09-19 00:00:00.000000000 Z
13
13
  dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: aroi
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ">="
19
+ - !ruby/object:Gem::Version
20
+ version: 0.0.7
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ version: 0.0.7
14
28
  - !ruby/object:Gem::Dependency
15
29
  name: dogstatsd-ruby
16
30
  requirement: !ruby/object:Gem::Requirement
17
31
  requirements:
18
- - - "~>"
32
+ - - ">="
19
33
  - !ruby/object:Gem::Version
20
34
  version: '4.2'
35
+ - - "<"
36
+ - !ruby/object:Gem::Version
37
+ version: '6.0'
38
+ - - "!="
39
+ - !ruby/object:Gem::Version
40
+ version: 5.0.0
21
41
  type: :runtime
22
42
  prerelease: false
23
43
  version_requirements: !ruby/object:Gem::Requirement
24
44
  requirements:
25
- - - "~>"
45
+ - - ">="
26
46
  - !ruby/object:Gem::Version
27
47
  version: '4.2'
48
+ - - "<"
49
+ - !ruby/object:Gem::Version
50
+ version: '6.0'
51
+ - - "!="
52
+ - !ruby/object:Gem::Version
53
+ version: 5.0.0
28
54
  - !ruby/object:Gem::Dependency
29
55
  name: statsd-ruby
30
56
  requirement: !ruby/object:Gem::Requirement
@@ -40,21 +66,21 @@ dependencies:
40
66
  - !ruby/object:Gem::Version
41
67
  version: '1.0'
42
68
  - !ruby/object:Gem::Dependency
43
- name: aroi
69
+ name: bundler
44
70
  requirement: !ruby/object:Gem::Requirement
45
71
  requirements:
46
72
  - - ">="
47
73
  - !ruby/object:Gem::Version
48
- version: 0.0.7
49
- type: :runtime
74
+ version: '1.5'
75
+ type: :development
50
76
  prerelease: false
51
77
  version_requirements: !ruby/object:Gem::Requirement
52
78
  requirements:
53
79
  - - ">="
54
80
  - !ruby/object:Gem::Version
55
- version: 0.0.7
81
+ version: '1.5'
56
82
  - !ruby/object:Gem::Dependency
57
- name: appraisal
83
+ name: byebug
58
84
  requirement: !ruby/object:Gem::Requirement
59
85
  requirements:
60
86
  - - ">="
@@ -68,21 +94,21 @@ dependencies:
68
94
  - !ruby/object:Gem::Version
69
95
  version: '0'
70
96
  - !ruby/object:Gem::Dependency
71
- name: bundler
97
+ name: rake
72
98
  requirement: !ruby/object:Gem::Requirement
73
99
  requirements:
74
100
  - - ">="
75
101
  - !ruby/object:Gem::Version
76
- version: '1.5'
102
+ version: '0'
77
103
  type: :development
78
104
  prerelease: false
79
105
  version_requirements: !ruby/object:Gem::Requirement
80
106
  requirements:
81
107
  - - ">="
82
108
  - !ruby/object:Gem::Version
83
- version: '1.5'
109
+ version: '0'
84
110
  - !ruby/object:Gem::Dependency
85
- name: byebug
111
+ name: rspec
86
112
  requirement: !ruby/object:Gem::Requirement
87
113
  requirements:
88
114
  - - ">="
@@ -96,7 +122,7 @@ dependencies:
96
122
  - !ruby/object:Gem::Version
97
123
  version: '0'
98
124
  - !ruby/object:Gem::Dependency
99
- name: rake
125
+ name: rubocop-inst
100
126
  requirement: !ruby/object:Gem::Requirement
101
127
  requirements:
102
128
  - - ">="
@@ -110,7 +136,21 @@ dependencies:
110
136
  - !ruby/object:Gem::Version
111
137
  version: '0'
112
138
  - !ruby/object:Gem::Dependency
113
- name: rspec
139
+ name: rubocop-rake
140
+ requirement: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - ">="
143
+ - !ruby/object:Gem::Version
144
+ version: '0'
145
+ type: :development
146
+ prerelease: false
147
+ version_requirements: !ruby/object:Gem::Requirement
148
+ requirements:
149
+ - - ">="
150
+ - !ruby/object:Gem::Version
151
+ version: '0'
152
+ - !ruby/object:Gem::Dependency
153
+ name: rubocop-rspec
114
154
  requirement: !ruby/object:Gem::Requirement
115
155
  requirements:
116
156
  - - ">="
@@ -161,7 +201,8 @@ files:
161
201
  homepage: https://github.com/instructure/inst_statsd
162
202
  licenses:
163
203
  - MIT
164
- metadata: {}
204
+ metadata:
205
+ rubygems_mfa_required: 'true'
165
206
  post_install_message:
166
207
  rdoc_options: []
167
208
  require_paths:
@@ -181,17 +222,4 @@ rubygems_version: 3.2.6
181
222
  signing_key:
182
223
  specification_version: 4
183
224
  summary: Statsd for Instructure
184
- test_files:
185
- - spec/inst_statsd/block_stat_spec.rb
186
- - spec/inst_statsd/block_tracking_spec.rb
187
- - spec/inst_statsd/counter_spec.rb
188
- - spec/inst_statsd/event_spec.rb
189
- - spec/inst_statsd/inst_statsd_spec.rb
190
- - spec/inst_statsd/null_logger_spec.rb
191
- - spec/inst_statsd/request_logger_spec.rb
192
- - spec/inst_statsd/request_stat_spec.rb
193
- - spec/inst_statsd/request_tracking_spec.rb
194
- - spec/inst_statsd/sql_tracker_spec.rb
195
- - spec/inst_statsd/statsd_spec.rb
196
- - spec/spec_helper.rb
197
- - spec/support/test.log
225
+ test_files: []