inst_statsd 3.0.2 → 3.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,142 +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")
93
99
  end
94
- expect(statsd).to receive('timing').with('test.name', anything, anything)
95
- expect(InstStatsd::Statsd.time('test.name') { 'test' }).to eq 'test'
100
+ expect(statsd).to receive("timing").with("test.name", anything, anything)
101
+ expect(InstStatsd::Statsd.time("test.name") { "test" }).to eq "test"
96
102
  end
97
103
 
98
- context 'with datadog enabled' do
99
- it 'handles being called with an array of stat names' do
104
+ context "with datadog enabled" do
105
+ it "handles being called with an array of stat names" do
100
106
  converted_tags = %w[tag:value host:]
101
- statsd = double
102
- allow(InstStatsd::Statsd).to receive(:instance).and_return(statsd)
103
- allow(InstStatsd::Statsd).to receive(:append_hostname?).and_return(false)
104
- allow(InstStatsd::Statsd).to receive(:data_dog?).and_return(true)
105
- METHODS.each do |method|
106
- expect(statsd).to receive(method).once.with('test.one', 'value', tags: converted_tags)
107
- expect(statsd).to receive(method).once.with('test.two', 'value', tags: converted_tags)
108
- InstStatsd::Statsd.send(method, %w[test.one test.two], 'value', tags: {tag: 'value'}, short_stat: 'short_stat')
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")
109
120
  end
110
- expect(statsd).to receive('timing').once.with('test.one', anything, tags: converted_tags, sample_rate: anything)
111
- expect(statsd).to receive('timing').once.with('test.two', anything, tags: converted_tags, sample_rate: anything)
112
- expect(InstStatsd::Statsd.time(%w[test.one test.two], tags: {tag: 'value'}, short_stat: 'short_stat') { 'test' }).to eq 'test'
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"
113
130
  end
114
131
  end
115
132
 
116
133
  it "ignores all calls if statsd isn't enabled" do
117
134
  allow(InstStatsd::Statsd).to receive(:instance).and_return(nil)
118
- METHODS.each do |method|
119
- 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
120
137
  end
121
- expect(InstStatsd::Statsd.time('test.name') { 'test' }).to eq 'test'
138
+ expect(InstStatsd::Statsd.time("test.name") { "test" }).to eq "test"
122
139
  end
123
140
 
124
- it 'configures a statsd instance' do
141
+ it "configures a statsd instance" do
125
142
  expect(InstStatsd::Statsd.instance).to be_nil
126
143
 
127
- InstStatsd.settings = { host: 'localhost', namespace: 'test', port: 1234 }
144
+ InstStatsd.settings = { host: "localhost", namespace: "test", port: 1234 }
128
145
  InstStatsd::Statsd.reset_instance
129
146
 
130
147
  instance = InstStatsd::Statsd.instance
131
- expect(instance).to be_a ::Statsd
132
- expect(instance.host).to eq 'localhost'
148
+ expect(instance).to be_a Statsd
149
+ expect(instance.host).to eq "localhost"
133
150
  expect(instance.port).to eq 1234
134
- expect(instance.namespace).to eq 'test'
151
+ expect(instance.namespace).to eq "test"
135
152
  end
136
153
 
137
- describe '.batch' do
138
- it 'is properly reentrant' do
139
- 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 }
140
157
  InstStatsd::Statsd.reset_instance
141
158
 
142
159
  statsd = InstStatsd::Statsd.instance
@@ -144,9 +161,9 @@ describe InstStatsd::Statsd do
144
161
  batch1 = InstStatsd::Statsd.instance
145
162
  InstStatsd::Statsd.batch do
146
163
  batch2 = InstStatsd::Statsd.instance
147
- expect(statsd).to be_a ::Statsd
148
- expect(batch1).to be_a ::Statsd::Batch
149
- 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
150
167
  expect(batch1).not_to eq batch2
151
168
  end
152
169
  expect(InstStatsd::Statsd.instance).to eq batch1
@@ -155,21 +172,21 @@ describe InstStatsd::Statsd do
155
172
  end
156
173
  end
157
174
 
158
- describe '.escape' do
159
- it 'replaces any dots in str with a _ when no replacment given' do
160
- result = InstStatsd::Statsd.escape('lots.of.dots')
161
- 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"
162
179
  end
163
180
 
164
- it 'replaces any dots in str with replacement arg' do
165
- result = InstStatsd::Statsd.escape('lots.of.dots', '/')
166
- 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"
167
184
  end
168
185
 
169
- 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
170
187
  result = InstStatsd::Statsd.escape(nil)
171
- expect(result).to eq nil
172
- hash = { foo: 'bar' }
188
+ expect(result).to be_nil
189
+ hash = { foo: "bar" }
173
190
  result = InstStatsd::Statsd.escape(hash)
174
191
  expect(result).to eq hash
175
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: 3.0.2
4
+ version: 3.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Cloward
@@ -9,8 +9,22 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2023-08-17 00:00:00.000000000 Z
12
+ date: 2023-09-08 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
@@ -52,21 +66,35 @@ dependencies:
52
66
  - !ruby/object:Gem::Version
53
67
  version: '1.0'
54
68
  - !ruby/object:Gem::Dependency
55
- name: aroi
69
+ name: appraisal
56
70
  requirement: !ruby/object:Gem::Requirement
57
71
  requirements:
58
72
  - - ">="
59
73
  - !ruby/object:Gem::Version
60
- version: 0.0.7
61
- type: :runtime
74
+ version: '0'
75
+ type: :development
62
76
  prerelease: false
63
77
  version_requirements: !ruby/object:Gem::Requirement
64
78
  requirements:
65
79
  - - ">="
66
80
  - !ruby/object:Gem::Version
67
- version: 0.0.7
81
+ version: '0'
68
82
  - !ruby/object:Gem::Dependency
69
- name: appraisal
83
+ name: bundler
84
+ requirement: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '1.5'
89
+ type: :development
90
+ prerelease: false
91
+ version_requirements: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '1.5'
96
+ - !ruby/object:Gem::Dependency
97
+ name: byebug
70
98
  requirement: !ruby/object:Gem::Requirement
71
99
  requirements:
72
100
  - - ">="
@@ -80,21 +108,21 @@ dependencies:
80
108
  - !ruby/object:Gem::Version
81
109
  version: '0'
82
110
  - !ruby/object:Gem::Dependency
83
- name: bundler
111
+ name: rake
84
112
  requirement: !ruby/object:Gem::Requirement
85
113
  requirements:
86
114
  - - ">="
87
115
  - !ruby/object:Gem::Version
88
- version: '1.5'
116
+ version: '0'
89
117
  type: :development
90
118
  prerelease: false
91
119
  version_requirements: !ruby/object:Gem::Requirement
92
120
  requirements:
93
121
  - - ">="
94
122
  - !ruby/object:Gem::Version
95
- version: '1.5'
123
+ version: '0'
96
124
  - !ruby/object:Gem::Dependency
97
- name: byebug
125
+ name: rspec
98
126
  requirement: !ruby/object:Gem::Requirement
99
127
  requirements:
100
128
  - - ">="
@@ -108,7 +136,7 @@ dependencies:
108
136
  - !ruby/object:Gem::Version
109
137
  version: '0'
110
138
  - !ruby/object:Gem::Dependency
111
- name: rake
139
+ name: rubocop-inst
112
140
  requirement: !ruby/object:Gem::Requirement
113
141
  requirements:
114
142
  - - ">="
@@ -122,7 +150,21 @@ dependencies:
122
150
  - !ruby/object:Gem::Version
123
151
  version: '0'
124
152
  - !ruby/object:Gem::Dependency
125
- name: rspec
153
+ name: rubocop-rake
154
+ requirement: !ruby/object:Gem::Requirement
155
+ requirements:
156
+ - - ">="
157
+ - !ruby/object:Gem::Version
158
+ version: '0'
159
+ type: :development
160
+ prerelease: false
161
+ version_requirements: !ruby/object:Gem::Requirement
162
+ requirements:
163
+ - - ">="
164
+ - !ruby/object:Gem::Version
165
+ version: '0'
166
+ - !ruby/object:Gem::Dependency
167
+ name: rubocop-rspec
126
168
  requirement: !ruby/object:Gem::Requirement
127
169
  requirements:
128
170
  - - ">="
@@ -173,7 +215,8 @@ files:
173
215
  homepage: https://github.com/instructure/inst_statsd
174
216
  licenses:
175
217
  - MIT
176
- metadata: {}
218
+ metadata:
219
+ rubygems_mfa_required: 'true'
177
220
  post_install_message:
178
221
  rdoc_options: []
179
222
  require_paths:
@@ -193,17 +236,4 @@ rubygems_version: 3.2.6
193
236
  signing_key:
194
237
  specification_version: 4
195
238
  summary: Statsd for Instructure
196
- test_files:
197
- - spec/inst_statsd/block_stat_spec.rb
198
- - spec/inst_statsd/block_tracking_spec.rb
199
- - spec/inst_statsd/counter_spec.rb
200
- - spec/inst_statsd/event_spec.rb
201
- - spec/inst_statsd/inst_statsd_spec.rb
202
- - spec/inst_statsd/null_logger_spec.rb
203
- - spec/inst_statsd/request_logger_spec.rb
204
- - spec/inst_statsd/request_stat_spec.rb
205
- - spec/inst_statsd/request_tracking_spec.rb
206
- - spec/inst_statsd/sql_tracker_spec.rb
207
- - spec/inst_statsd/statsd_spec.rb
208
- - spec/spec_helper.rb
209
- - spec/support/test.log
239
+ test_files: []