inst_statsd 2.4.0 → 3.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/inst_statsd/block_stat.rb +14 -14
- data/lib/inst_statsd/block_tracking.rb +12 -13
- data/lib/inst_statsd/counter.rb +2 -4
- data/lib/inst_statsd/default_tracking.rb +30 -27
- data/lib/inst_statsd/event.rb +1 -1
- data/lib/inst_statsd/null_logger.rb +3 -4
- data/lib/inst_statsd/request_logger.rb +4 -6
- data/lib/inst_statsd/request_stat.rb +20 -20
- data/lib/inst_statsd/request_tracking.rb +19 -18
- data/lib/inst_statsd/sql_tracker.rb +9 -11
- data/lib/inst_statsd/statsd.rb +61 -52
- data/lib/inst_statsd/version.rb +2 -2
- data/lib/inst_statsd.rb +36 -29
- data/spec/inst_statsd/block_stat_spec.rb +2 -2
- data/spec/inst_statsd/block_tracking_spec.rb +66 -46
- data/spec/inst_statsd/counter_spec.rb +21 -23
- data/spec/inst_statsd/event_spec.rb +25 -24
- data/spec/inst_statsd/inst_statsd_spec.rb +85 -81
- data/spec/inst_statsd/null_logger_spec.rb +11 -13
- data/spec/inst_statsd/request_logger_spec.rb +43 -50
- data/spec/inst_statsd/request_stat_spec.rb +90 -93
- data/spec/inst_statsd/request_tracking_spec.rb +6 -7
- data/spec/inst_statsd/sql_tracker_spec.rb +29 -31
- data/spec/inst_statsd/statsd_spec.rb +123 -88
- data/spec/spec_helper.rb +2 -2
- metadata +58 -30
@@ -1,124 +1,159 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require "spec_helper"
|
4
|
+
|
5
|
+
require "datadog/statsd"
|
4
6
|
|
5
7
|
describe InstStatsd::Statsd do
|
6
|
-
|
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
|
16
|
+
it "includes the events module" do
|
14
17
|
expect(described_class).to respond_to :event
|
15
18
|
end
|
16
19
|
|
17
|
-
it
|
18
|
-
|
19
|
-
statsd
|
20
|
-
|
21
|
-
|
22
|
-
|
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(
|
27
|
-
expect(InstStatsd::Statsd.time(
|
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
|
31
|
-
default_tags = {app:
|
32
|
-
short_stat =
|
31
|
+
it "sending tags should not break statsd" do
|
32
|
+
default_tags = { app: "canvas", env: "prod" }
|
33
|
+
short_stat = "test2"
|
33
34
|
env = {
|
34
|
-
|
35
|
+
"INST_DOG_TAGS" => '{"app": "canvas", "env": "prod"}'
|
35
36
|
}
|
36
37
|
InstStatsd.env_settings(env)
|
37
|
-
|
38
|
-
allow(InstStatsd::Statsd).to
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
expect(statsd).to receive(method).with(
|
45
|
-
InstStatsd::Statsd.send(method,
|
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(
|
48
|
-
expect(InstStatsd::Statsd.time(
|
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
|
52
|
-
default_tags = {app:
|
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 =
|
55
|
-
|
56
|
-
allow(InstStatsd::Statsd).to
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
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(
|
66
|
-
expect(InstStatsd::Statsd.time(
|
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
|
70
|
-
default_tags = {app:
|
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
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
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(
|
82
|
-
expect(InstStatsd::Statsd.time(
|
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
|
86
|
-
expect(InstStatsd::Statsd).
|
87
|
-
statsd =
|
88
|
-
allow(InstStatsd::Statsd).to
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
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
|
-
|
101
|
-
expect(InstStatsd::Statsd.send(method,
|
135
|
+
methods.each do |method|
|
136
|
+
expect(InstStatsd::Statsd.send(method, "test.name")).to be_nil
|
102
137
|
end
|
103
|
-
expect(InstStatsd::Statsd.time(
|
138
|
+
expect(InstStatsd::Statsd.time("test.name") { "test" }).to eq "test"
|
104
139
|
end
|
105
140
|
|
106
|
-
it
|
141
|
+
it "configures a statsd instance" do
|
107
142
|
expect(InstStatsd::Statsd.instance).to be_nil
|
108
143
|
|
109
|
-
InstStatsd.settings = { host:
|
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
|
114
|
-
expect(instance.host).to eq
|
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
|
151
|
+
expect(instance.namespace).to eq "test"
|
117
152
|
end
|
118
153
|
|
119
|
-
describe
|
120
|
-
it
|
121
|
-
InstStatsd.settings = { host:
|
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
|
130
|
-
expect(batch1).to be_a
|
131
|
-
expect(batch2).to be_a
|
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
|
141
|
-
it
|
142
|
-
result = InstStatsd::Statsd.escape(
|
143
|
-
expect(result).to eq
|
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
|
147
|
-
result = InstStatsd::Statsd.escape(
|
148
|
-
expect(result).to eq
|
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
|
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
|
154
|
-
hash = { foo:
|
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
|
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 =
|
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:
|
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-
|
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:
|
69
|
+
name: bundler
|
44
70
|
requirement: !ruby/object:Gem::Requirement
|
45
71
|
requirements:
|
46
72
|
- - ">="
|
47
73
|
- !ruby/object:Gem::Version
|
48
|
-
version:
|
49
|
-
type: :
|
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:
|
81
|
+
version: '1.5'
|
56
82
|
- !ruby/object:Gem::Dependency
|
57
|
-
name:
|
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:
|
97
|
+
name: rake
|
72
98
|
requirement: !ruby/object:Gem::Requirement
|
73
99
|
requirements:
|
74
100
|
- - ">="
|
75
101
|
- !ruby/object:Gem::Version
|
76
|
-
version: '
|
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: '
|
109
|
+
version: '0'
|
84
110
|
- !ruby/object:Gem::Dependency
|
85
|
-
name:
|
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:
|
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:
|
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: []
|