inst_statsd 2.2.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,120 +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 'appends the hostname to stat names by default' do
14
- allow(InstStatsd::Statsd).to receive(:hostname).and_return('testhost')
15
- statsd = double
16
- allow(InstStatsd::Statsd).to receive(:instance).and_return(statsd)
17
- allow(InstStatsd::Statsd).to receive(:append_hostname?).and_return(true)
18
- METHODS.each do |method|
19
- expect(statsd).to receive(method).with('test.name.testhost', 'test')
20
- InstStatsd::Statsd.send(method, 'test.name', 'test')
16
+ it "includes the events module" do
17
+ expect(described_class).to respond_to :event
18
+ end
19
+
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")
21
26
  end
22
- expect(statsd).to receive('timing').with('test.name.testhost', anything, anything)
23
- 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"
24
29
  end
25
30
 
26
- it 'sending tags should not break statsd' do
27
- default_tags = {app: 'canvas', env: 'prod'}
28
- short_stat = 'test2'
31
+ it "sending tags should not break statsd" do
32
+ default_tags = { app: "canvas", env: "prod" }
33
+ short_stat = "test2"
29
34
  env = {
30
- 'INST_DOG_TAGS' => '{"app": "canvas", "env": "prod"}',
35
+ "INST_DOG_TAGS" => '{"app": "canvas", "env": "prod"}'
31
36
  }
32
37
  InstStatsd.env_settings(env)
33
- allow(InstStatsd::Statsd).to receive(:hostname).and_return('testhost')
34
- allow(InstStatsd::Statsd).to receive(:short_stat).and_return(short_stat)
35
- statsd = double
36
- allow(InstStatsd::Statsd).to receive(:instance).and_return(statsd)
37
- allow(InstStatsd::Statsd).to receive(:data_dog?).and_return(false)
38
- allow(InstStatsd::Statsd).to receive(:append_hostname?).and_return(true)
39
- METHODS.each do |method|
40
- expect(statsd).to receive(method).with('test.name.testhost', 'test') # no short stat or tags
41
- 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)
42
47
  end
43
- expect(statsd).to receive('timing').with('test.name.testhost', anything, anything) # no short stat or tags
44
- 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"
45
50
  end
46
51
 
47
- it 'adds default dog tags default' do
48
- default_tags = {app: 'canvas', env: 'prod'}
52
+ it "adds default dog tags default" do
53
+ default_tags = { app: "canvas", env: "prod" }
49
54
  converted_tags = ["app:canvas", "env:prod", "host:"]
50
- short_stat = 'test2'
51
- allow(InstStatsd::Statsd).to receive(:dog_tags).and_return(default_tags)
52
- allow(InstStatsd::Statsd).to receive(:short_stat).and_return(short_stat)
53
- statsd = double
54
- allow(InstStatsd::Statsd).to receive(:instance).and_return(statsd)
55
- allow(InstStatsd::Statsd).to receive(:data_dog?).and_return(true)
56
- allow(InstStatsd::Statsd).to receive(:append_hostname?).and_return(false)
57
- METHODS.each do |method|
58
- expect(statsd).to receive(method).with(short_stat, 'test', tags: converted_tags)
59
- 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)
60
68
  end
61
- expect(statsd).to receive('timing').with(short_stat, anything, sample_rate: anything, tags: converted_tags)
62
- 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"
63
71
  end
64
72
 
65
- it 'uses regular stat name when short_stat is omitted on data dog' do
66
- 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" }
67
75
  converted_tags = ["app:canvas", "env:prod", "host:"]
68
- allow(InstStatsd::Statsd).to receive(:dog_tags).and_return(default_tags)
69
- statsd = double
70
- allow(InstStatsd::Statsd).to receive(:instance).and_return(statsd)
71
- allow(InstStatsd::Statsd).to receive(:data_dog?).and_return(true)
72
- allow(InstStatsd::Statsd).to receive(:append_hostname?).and_return(false)
73
- METHODS.each do |method|
74
- expect(statsd).to receive(method).with('test.name', 'test', tags: converted_tags)
75
- 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)
76
87
  end
77
- expect(statsd).to receive('timing').with('test.name', anything, sample_rate: anything, tags: converted_tags)
78
- 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"
79
90
  end
80
91
 
81
- it 'omits hostname if specified in config' do
82
- expect(InstStatsd::Statsd).to receive(:hostname).never
83
- statsd = double
84
- allow(InstStatsd::Statsd).to receive(:instance).and_return(statsd)
85
- allow(InstStatsd::Statsd).to receive(:append_hostname?).and_return(false)
86
- METHODS.each do |method|
87
- expect(statsd).to receive(method).with('test.name', 'test')
88
- 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"
89
130
  end
90
- expect(statsd).to receive('timing').with('test.name', anything, anything)
91
- expect(InstStatsd::Statsd.time('test.name') { 'test' }).to eq 'test'
92
131
  end
93
132
 
94
133
  it "ignores all calls if statsd isn't enabled" do
95
134
  allow(InstStatsd::Statsd).to receive(:instance).and_return(nil)
96
- METHODS.each do |method|
97
- 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
98
137
  end
99
- expect(InstStatsd::Statsd.time('test.name') { 'test' }).to eq 'test'
138
+ expect(InstStatsd::Statsd.time("test.name") { "test" }).to eq "test"
100
139
  end
101
140
 
102
- it 'configures a statsd instance' do
141
+ it "configures a statsd instance" do
103
142
  expect(InstStatsd::Statsd.instance).to be_nil
104
143
 
105
- InstStatsd.settings = { host: 'localhost', namespace: 'test', port: 1234 }
144
+ InstStatsd.settings = { host: "localhost", namespace: "test", port: 1234 }
106
145
  InstStatsd::Statsd.reset_instance
107
146
 
108
147
  instance = InstStatsd::Statsd.instance
109
- expect(instance).to be_a ::Statsd
110
- expect(instance.host).to eq 'localhost'
148
+ expect(instance).to be_a Statsd
149
+ expect(instance.host).to eq "localhost"
111
150
  expect(instance.port).to eq 1234
112
- expect(instance.namespace).to eq 'test'
151
+ expect(instance.namespace).to eq "test"
113
152
  end
114
153
 
115
- describe '.batch' do
116
- it 'is properly reentrant' do
117
- 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 }
118
157
  InstStatsd::Statsd.reset_instance
119
158
 
120
159
  statsd = InstStatsd::Statsd.instance
@@ -122,9 +161,9 @@ describe InstStatsd::Statsd do
122
161
  batch1 = InstStatsd::Statsd.instance
123
162
  InstStatsd::Statsd.batch do
124
163
  batch2 = InstStatsd::Statsd.instance
125
- expect(statsd).to be_a ::Statsd
126
- expect(batch1).to be_a ::Statsd::Batch
127
- 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
128
167
  expect(batch1).not_to eq batch2
129
168
  end
130
169
  expect(InstStatsd::Statsd.instance).to eq batch1
@@ -133,21 +172,21 @@ describe InstStatsd::Statsd do
133
172
  end
134
173
  end
135
174
 
136
- describe '.escape' do
137
- it 'replaces any dots in str with a _ when no replacment given' do
138
- result = InstStatsd::Statsd.escape('lots.of.dots')
139
- 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"
140
179
  end
141
180
 
142
- it 'replaces any dots in str with replacement arg' do
143
- result = InstStatsd::Statsd.escape('lots.of.dots', '/')
144
- 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"
145
184
  end
146
185
 
147
- 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
148
187
  result = InstStatsd::Statsd.escape(nil)
149
- expect(result).to eq nil
150
- hash = { foo: 'bar' }
188
+ expect(result).to be_nil
189
+ hash = { foo: "bar" }
151
190
  result = InstStatsd::Statsd.escape(hash)
152
191
  expect(result).to eq hash
153
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,30 +1,56 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: inst_statsd
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.0
4
+ version: 3.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Cloward
8
8
  - Jason Madsen
9
- autorequire:
9
+ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2021-07-29 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,7 @@ dependencies:
110
136
  - !ruby/object:Gem::Version
111
137
  version: '0'
112
138
  - !ruby/object:Gem::Dependency
113
- name: rspec
139
+ name: rubocop-rake
114
140
  requirement: !ruby/object:Gem::Requirement
115
141
  requirements:
116
142
  - - ">="
@@ -123,7 +149,21 @@ dependencies:
123
149
  - - ">="
124
150
  - !ruby/object:Gem::Version
125
151
  version: '0'
126
- description:
152
+ - !ruby/object:Gem::Dependency
153
+ name: rubocop-rspec
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
+ description:
127
167
  email:
128
168
  - ncloward@instructure.com
129
169
  - jmadsen@instructure.com
@@ -136,15 +176,18 @@ files:
136
176
  - lib/inst_statsd/block_tracking.rb
137
177
  - lib/inst_statsd/counter.rb
138
178
  - lib/inst_statsd/default_tracking.rb
179
+ - lib/inst_statsd/event.rb
139
180
  - lib/inst_statsd/null_logger.rb
140
181
  - lib/inst_statsd/request_logger.rb
141
182
  - lib/inst_statsd/request_stat.rb
142
183
  - lib/inst_statsd/request_tracking.rb
143
184
  - lib/inst_statsd/sql_tracker.rb
144
185
  - lib/inst_statsd/statsd.rb
186
+ - lib/inst_statsd/version.rb
145
187
  - spec/inst_statsd/block_stat_spec.rb
146
188
  - spec/inst_statsd/block_tracking_spec.rb
147
189
  - spec/inst_statsd/counter_spec.rb
190
+ - spec/inst_statsd/event_spec.rb
148
191
  - spec/inst_statsd/inst_statsd_spec.rb
149
192
  - spec/inst_statsd/null_logger_spec.rb
150
193
  - spec/inst_statsd/request_logger_spec.rb
@@ -158,8 +201,9 @@ files:
158
201
  homepage: https://github.com/instructure/inst_statsd
159
202
  licenses:
160
203
  - MIT
161
- metadata: {}
162
- post_install_message:
204
+ metadata:
205
+ rubygems_mfa_required: 'true'
206
+ post_install_message:
163
207
  rdoc_options: []
164
208
  require_paths:
165
209
  - lib
@@ -167,27 +211,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
167
211
  requirements:
168
212
  - - ">="
169
213
  - !ruby/object:Gem::Version
170
- version: '2.3'
214
+ version: '2.7'
171
215
  required_rubygems_version: !ruby/object:Gem::Requirement
172
216
  requirements:
173
217
  - - ">="
174
218
  - !ruby/object:Gem::Version
175
219
  version: '0'
176
220
  requirements: []
177
- rubygems_version: 3.2.24
178
- signing_key:
221
+ rubygems_version: 3.2.6
222
+ signing_key:
179
223
  specification_version: 4
180
224
  summary: Statsd for Instructure
181
- test_files:
182
- - spec/inst_statsd/block_stat_spec.rb
183
- - spec/inst_statsd/block_tracking_spec.rb
184
- - spec/inst_statsd/counter_spec.rb
185
- - spec/inst_statsd/inst_statsd_spec.rb
186
- - spec/inst_statsd/null_logger_spec.rb
187
- - spec/inst_statsd/request_logger_spec.rb
188
- - spec/inst_statsd/request_stat_spec.rb
189
- - spec/inst_statsd/request_tracking_spec.rb
190
- - spec/inst_statsd/sql_tracker_spec.rb
191
- - spec/inst_statsd/statsd_spec.rb
192
- - spec/spec_helper.rb
193
- - spec/support/test.log
225
+ test_files: []