inst_statsd 2.0.4 → 2.1.0
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.
- checksums.yaml +5 -5
- data/lib/inst_statsd.rb +11 -3
- data/lib/inst_statsd/block_stat.rb +8 -3
- data/lib/inst_statsd/block_tracking.rb +2 -2
- data/lib/inst_statsd/counter.rb +1 -1
- data/lib/inst_statsd/request_stat.rb +9 -1
- data/lib/inst_statsd/statsd.rb +45 -7
- data/spec/inst_statsd/block_tracking_spec.rb +29 -18
- data/spec/inst_statsd/inst_statsd_spec.rb +18 -0
- data/spec/inst_statsd/request_stat_spec.rb +32 -18
- data/spec/inst_statsd/statsd_spec.rb +52 -0
- metadata +17 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 1a9bd14115668f4b354ae740b4ff35cb5b551c09e7a6795986faafb35c379826
|
4
|
+
data.tar.gz: 4811158906ecebf02185c5ebb4bb67f691e9f61ec3f369903d1cfa502438a554
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8d0c8ac4747069dbe6da16c798044d585fa6a32a871730f41bf80fc5cfd0064ddad967789af655e5b3cbd6138f7c169402e43cc563bd3f0748970820cb3e622b
|
7
|
+
data.tar.gz: d0a88767195a8febc5e2c002d02ba9dd6da3438a4830f9c97f8fa013b325d8b8ee00835bcaf63ad2299af1f9db8479664ae55ae1e789208e16b6fcca515eb242
|
data/lib/inst_statsd.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
require 'statsd'
|
2
2
|
|
3
3
|
module InstStatsd
|
4
|
-
VALID_SETTINGS = %i[host port namespace append_hostname mask negative_mask batch_size batch_byte_size
|
4
|
+
VALID_SETTINGS = %i[host port namespace append_hostname mask negative_mask batch_size batch_byte_size
|
5
|
+
dog_tags].freeze
|
5
6
|
|
6
7
|
class ConfigurationError < StandardError; end
|
7
8
|
|
@@ -45,11 +46,18 @@ module InstStatsd
|
|
45
46
|
host: env.fetch('INST_STATSD_HOST', nil),
|
46
47
|
port: env.fetch('INST_STATSD_PORT', nil),
|
47
48
|
namespace: env.fetch('INST_STATSD_NAMESPACE', nil),
|
48
|
-
append_hostname: env.fetch('INST_STATSD_APPEND_HOSTNAME', nil)
|
49
|
+
append_hostname: env.fetch('INST_STATSD_APPEND_HOSTNAME', nil),
|
50
|
+
dog_tags: env.fetch('INST_DOG_TAGS', nil)
|
49
51
|
}
|
50
52
|
config.delete_if { |_k, v| v.nil? }
|
51
53
|
convert_bool(config, :append_hostname)
|
52
|
-
config[:host]
|
54
|
+
if config[:host]
|
55
|
+
config
|
56
|
+
elsif config[:dog_tags]
|
57
|
+
config
|
58
|
+
else
|
59
|
+
{}
|
60
|
+
end
|
53
61
|
end
|
54
62
|
|
55
63
|
def convert_bool(hash, key)
|
@@ -3,9 +3,14 @@ module InstStatsd
|
|
3
3
|
|
4
4
|
attr_accessor :stats
|
5
5
|
attr_accessor :common_key
|
6
|
+
attr_accessor :short_stat
|
7
|
+
attr_accessor :tags
|
6
8
|
|
7
|
-
def initialize(common_key, statsd=InstStatsd::Statsd)
|
9
|
+
def initialize(common_key, statsd=InstStatsd::Statsd, tags: {}, short_stat: nil)
|
8
10
|
self.common_key = common_key
|
11
|
+
@tags = tags
|
12
|
+
@short_stat = short_stat
|
13
|
+
@short_stat ||= common_key
|
9
14
|
@statsd = statsd
|
10
15
|
@stats = {}
|
11
16
|
end
|
@@ -26,10 +31,10 @@ module InstStatsd
|
|
26
31
|
def report
|
27
32
|
if common_key
|
28
33
|
stats.each do |(key, value)|
|
29
|
-
@statsd.timing("#{common_key}.#{key}", value)
|
34
|
+
@statsd.timing("#{common_key}.#{key}", value, tags: @tags, short_stat: "#{@short_stat}.#{key}")
|
30
35
|
end
|
31
36
|
exclusive_stats&.each do |(key, value)|
|
32
|
-
@statsd.timing("#{common_key}.exclusive.#{key}", value)
|
37
|
+
@statsd.timing("#{common_key}.exclusive.#{key}", value, tags: @tags, short_stat: "#{@short_stat}.exclusive.#{key}")
|
33
38
|
end
|
34
39
|
end
|
35
40
|
end
|
@@ -17,7 +17,7 @@ module InstStatsd
|
|
17
17
|
RUBY
|
18
18
|
end
|
19
19
|
|
20
|
-
def track(key, category: nil, statsd: InstStatsd::Statsd, only: nil)
|
20
|
+
def track(key, category: nil, statsd: InstStatsd::Statsd, only: nil, tags: {}, short_stat: nil)
|
21
21
|
return yield if mask && mask !~ key
|
22
22
|
return yield if negative_mask && negative_mask =~ key
|
23
23
|
|
@@ -26,7 +26,7 @@ module InstStatsd
|
|
26
26
|
else
|
27
27
|
Counter.counters.map { |(name, counter)| [name, counter.start] }
|
28
28
|
end
|
29
|
-
block_stat = InstStatsd::BlockStat.new(key, statsd)
|
29
|
+
block_stat = InstStatsd::BlockStat.new(key, statsd, tags: tags, short_stat: short_stat)
|
30
30
|
stack(category).push(block_stat) if category
|
31
31
|
|
32
32
|
result = nil
|
data/lib/inst_statsd/counter.rb
CHANGED
@@ -7,12 +7,20 @@ module InstStatsd
|
|
7
7
|
@finish = finish
|
8
8
|
@id = id
|
9
9
|
@payload = payload
|
10
|
+
@statsd = statsd
|
10
11
|
end
|
11
12
|
|
12
13
|
def common_key
|
13
14
|
common_key = super
|
14
15
|
return common_key if common_key
|
15
|
-
|
16
|
+
if @statsd.data_dog?
|
17
|
+
self.common_key = "request"
|
18
|
+
self.short_stat = "request"
|
19
|
+
self.tags[:controller] = controller if controller
|
20
|
+
self.tags[:action] = action if action
|
21
|
+
else
|
22
|
+
self.common_key = "request.#{controller}.#{action}" if controller && action
|
23
|
+
end
|
16
24
|
end
|
17
25
|
|
18
26
|
def report
|
data/lib/inst_statsd/statsd.rb
CHANGED
@@ -15,6 +15,9 @@
|
|
15
15
|
# So if the namespace is "canvas" and the hostname is "app01", the final stat name of "my_stat" would be "stats.canvas.my_stat.app01"
|
16
16
|
# (assuming the default statsd/graphite configuration)
|
17
17
|
#
|
18
|
+
# If dog_tags is set in statsd.yml, it'll use the tags param and will use
|
19
|
+
# Data Dog instead of Statsd
|
20
|
+
#
|
18
21
|
# If statsd isn't configured and enabled, then calls to InstStatsd::Statsd.* will do nothing and return nil
|
19
22
|
|
20
23
|
module InstStatsd
|
@@ -28,13 +31,17 @@ module InstStatsd
|
|
28
31
|
@hostname ||= Socket.gethostname.split('.').first
|
29
32
|
end
|
30
33
|
|
34
|
+
def self.dog_tags
|
35
|
+
@dog_tags ||= {}
|
36
|
+
end
|
37
|
+
|
31
38
|
%w[increment decrement count gauge timing].each do |method|
|
32
39
|
class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
33
|
-
def self.#{method}(stat, *args)
|
40
|
+
def self.#{method}(stat, *args, tags: {}, short_stat: nil)
|
34
41
|
if self.instance
|
35
42
|
if Array === stat
|
36
43
|
stat.each do |st|
|
37
|
-
self.#{method}(st, *args)
|
44
|
+
self.#{method}(st, *args, tags: {}, short_stat: nil)
|
38
45
|
end
|
39
46
|
return
|
40
47
|
end
|
@@ -44,7 +51,16 @@ module InstStatsd
|
|
44
51
|
else
|
45
52
|
stat_name = stat.to_s
|
46
53
|
end
|
47
|
-
|
54
|
+
|
55
|
+
if data_dog?
|
56
|
+
tags.merge!(dog_tags) if tags.is_a? Hash
|
57
|
+
tags = convert_tags(tags)
|
58
|
+
tags << 'host:' unless self.append_hostname?
|
59
|
+
short_stat ||= stat_name
|
60
|
+
self.instance.#{method}(short_stat, *args, tags: tags)
|
61
|
+
else
|
62
|
+
self.instance.#{method}(stat_name, *args)
|
63
|
+
end
|
48
64
|
else
|
49
65
|
nil
|
50
66
|
end
|
@@ -52,10 +68,22 @@ module InstStatsd
|
|
52
68
|
RUBY
|
53
69
|
end
|
54
70
|
|
55
|
-
def self.
|
71
|
+
def self.convert_tags(tags)
|
72
|
+
new_tags = []
|
73
|
+
if tags.is_a? Hash
|
74
|
+
tags.each do |tag, v|
|
75
|
+
new_tags << "#{tag}:#{v}"
|
76
|
+
end
|
77
|
+
else
|
78
|
+
return tags
|
79
|
+
end
|
80
|
+
new_tags
|
81
|
+
end
|
82
|
+
|
83
|
+
def self.time(stat, sample_rate = 1, tags: {}, short_stat: nil)
|
56
84
|
start = Time.now
|
57
85
|
result = yield
|
58
|
-
timing(stat, ((Time.now - start) * 1000).round, sample_rate)
|
86
|
+
timing(stat, ((Time.now - start) * 1000).round, sample_rate, tags: tags, short_stat: short_stat)
|
59
87
|
result
|
60
88
|
end
|
61
89
|
|
@@ -75,8 +103,14 @@ module InstStatsd
|
|
75
103
|
|
76
104
|
unless defined?(@statsd)
|
77
105
|
statsd_settings = InstStatsd.settings
|
78
|
-
|
79
|
-
|
106
|
+
if statsd_settings.key?(:dog_tags)
|
107
|
+
@data_dog = true
|
108
|
+
host = statsd_settings[:host] || 'localhost'
|
109
|
+
port = statsd_settings[:port] || 8125
|
110
|
+
@statsd = Datadog::Statsd.new(host, port)
|
111
|
+
@statsd.dog_tags = statsd_settings[:dog_tags] || {}
|
112
|
+
@append_hostname = !statsd_settings.key?(:append_hostname) || !!statsd_settings[:append_hostname]
|
113
|
+
elsif statsd_settings && statsd_settings[:host]
|
80
114
|
@statsd = ::Statsd.new(statsd_settings[:host])
|
81
115
|
@statsd.port = statsd_settings[:port] if statsd_settings[:port]
|
82
116
|
@statsd.namespace = statsd_settings[:namespace] if statsd_settings[:namespace]
|
@@ -94,6 +128,10 @@ module InstStatsd
|
|
94
128
|
@append_hostname
|
95
129
|
end
|
96
130
|
|
131
|
+
def self.data_dog?
|
132
|
+
@data_dog
|
133
|
+
end
|
134
|
+
|
97
135
|
def self.reset_instance
|
98
136
|
remove_instance_variable(:@statsd) if defined?(@statsd)
|
99
137
|
Thread.current[:inst_statsd] = nil
|
@@ -7,28 +7,39 @@ describe InstStatsd::BlockTracking do
|
|
7
7
|
|
8
8
|
it "works" do
|
9
9
|
statsd = double()
|
10
|
-
allow(statsd).to receive(:timing).with('mykey.total', anything)
|
11
|
-
expect(statsd).to receive(:timing).with("mykey.sql.read", 1)
|
10
|
+
allow(statsd).to receive(:timing).with('mykey.total', anything, {short_stat: "mykey.total", tags: {}})
|
11
|
+
expect(statsd).to receive(:timing).with("mykey.sql.read", 1, {short_stat: "mykey.sql.read", tags: {}})
|
12
12
|
|
13
13
|
InstStatsd::BlockTracking.track("mykey", statsd: statsd, only: 'sql.read') do
|
14
14
|
ActiveSupport::Notifications.instrument('sql.active_record', name: "LOAD", sql: "SELECT * FROM users") {}
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
|
+
it "works for data_dog" do
|
19
|
+
statsd = double()
|
20
|
+
allow(statsd).to receive(:data_dog?).and_return true
|
21
|
+
allow(statsd).to receive(:timing).with('mykey.total', anything, {short_stat: "mykey.total", tags: {app: "canvas", env: "prod"}})
|
22
|
+
expect(statsd).to receive(:timing).with("mykey.sql.read", 1, {short_stat: "mykey.sql.read", tags: {app: "canvas", env: "prod"}})
|
23
|
+
|
24
|
+
InstStatsd::BlockTracking.track("mykey", statsd: statsd, only: 'sql.read', tags: {app: 'canvas', env: 'prod'}, short_stat: 'mykey') do
|
25
|
+
ActiveSupport::Notifications.instrument('sql.active_record', name: "LOAD", sql: "SELECT * FROM users") {}
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
18
29
|
it "keeps track of exclusive stats too" do
|
19
30
|
statsd = double()
|
20
|
-
expect(statsd).to receive(:timing).with("mykey.sql.read", 2).ordered
|
21
|
-
expect(statsd).to receive(:timing).with('mykey.total', anything).ordered
|
22
|
-
expect(statsd).to receive(:timing).with("mykey.exclusive.sql.read", 2).ordered
|
23
|
-
expect(statsd).to receive(:timing).with('mykey.exclusive.total', anything).ordered
|
24
|
-
expect(statsd).to receive(:timing).with("mykey.sql.read", 2).ordered
|
25
|
-
expect(statsd).to receive(:timing).with('mykey.total', anything).ordered
|
26
|
-
expect(statsd).to receive(:timing).with("mykey.exclusive.sql.read", 2).ordered
|
27
|
-
expect(statsd).to receive(:timing).with('mykey.exclusive.total', anything).ordered
|
28
|
-
expect(statsd).to receive(:timing).with("mykey.sql.read", 5).ordered
|
29
|
-
expect(statsd).to receive(:timing).with('mykey.total', anything).ordered
|
30
|
-
expect(statsd).to receive(:timing).with("mykey.exclusive.sql.read", 1).ordered
|
31
|
-
expect(statsd).to receive(:timing).with('mykey.exclusive.total', anything).ordered
|
31
|
+
expect(statsd).to receive(:timing).with("mykey.sql.read", 2, {short_stat: "mykey.sql.read", tags: {}}).ordered
|
32
|
+
expect(statsd).to receive(:timing).with('mykey.total', anything, {short_stat: "mykey.total", tags: {}}).ordered
|
33
|
+
expect(statsd).to receive(:timing).with("mykey.exclusive.sql.read", 2, {short_stat: "mykey.exclusive.sql.read", tags: {}}).ordered
|
34
|
+
expect(statsd).to receive(:timing).with('mykey.exclusive.total', anything, {short_stat: "mykey.exclusive.total", tags: {}}).ordered
|
35
|
+
expect(statsd).to receive(:timing).with("mykey.sql.read", 2, {short_stat: "mykey.sql.read", tags: {}}).ordered
|
36
|
+
expect(statsd).to receive(:timing).with('mykey.total', anything, {short_stat: "mykey.total", tags: {}}).ordered
|
37
|
+
expect(statsd).to receive(:timing).with("mykey.exclusive.sql.read", 2, {short_stat: "mykey.exclusive.sql.read", tags: {}}).ordered
|
38
|
+
expect(statsd).to receive(:timing).with('mykey.exclusive.total', anything, {short_stat: "mykey.exclusive.total", tags: {}}).ordered
|
39
|
+
expect(statsd).to receive(:timing).with("mykey.sql.read", 5, {short_stat: "mykey.sql.read", tags: {}}).ordered
|
40
|
+
expect(statsd).to receive(:timing).with('mykey.total', anything, {short_stat: "mykey.total", tags: {}}).ordered
|
41
|
+
expect(statsd).to receive(:timing).with("mykey.exclusive.sql.read", 1, {short_stat: "mykey.exclusive.sql.read", tags: {}}).ordered
|
42
|
+
expect(statsd).to receive(:timing).with('mykey.exclusive.total', anything, {short_stat: "mykey.exclusive.total", tags: {}}).ordered
|
32
43
|
|
33
44
|
InstStatsd::BlockTracking.track("mykey", category: :nested, statsd: statsd, only: 'sql.read') do
|
34
45
|
ActiveSupport::Notifications.instrument('sql.active_record', name: "LOAD", sql: "SELECT * FROM users") {}
|
@@ -52,8 +63,8 @@ describe InstStatsd::BlockTracking do
|
|
52
63
|
it "only tracks keys that match the mask" do
|
53
64
|
InstStatsd::BlockTracking.mask = /mykey/
|
54
65
|
statsd = double()
|
55
|
-
allow(statsd).to receive(:timing).with('mykey.total', anything)
|
56
|
-
expect(statsd).to receive(:timing).with("mykey.sql.read", 1)
|
66
|
+
allow(statsd).to receive(:timing).with('mykey.total', anything, {short_stat: "mykey.total", tags: {}})
|
67
|
+
expect(statsd).to receive(:timing).with("mykey.sql.read", 1, {short_stat: "mykey.sql.read", tags: {}})
|
57
68
|
|
58
69
|
InstStatsd::BlockTracking.track("mykey", statsd: statsd, only: 'sql.read') do
|
59
70
|
InstStatsd::BlockTracking.track("ignoreme", statsd: statsd, only: 'sql.read') do
|
@@ -65,8 +76,8 @@ describe InstStatsd::BlockTracking do
|
|
65
76
|
it "doesn't track keys that match the negative mask" do
|
66
77
|
InstStatsd::BlockTracking.negative_mask = /ignoreme/
|
67
78
|
statsd = double()
|
68
|
-
allow(statsd).to receive(:timing).with('mykey.total', anything)
|
69
|
-
expect(statsd).to receive(:timing).with("mykey.sql.read", 1)
|
79
|
+
allow(statsd).to receive(:timing).with('mykey.total', anything, {short_stat: "mykey.total", tags: {}})
|
80
|
+
expect(statsd).to receive(:timing).with("mykey.sql.read", 1, {short_stat: "mykey.sql.read", tags: {}})
|
70
81
|
|
71
82
|
InstStatsd::BlockTracking.track("mykey", statsd: statsd, only: 'sql.read') do
|
72
83
|
InstStatsd::BlockTracking.track("ignoreme", statsd: statsd, only: 'sql.read') do
|
@@ -11,6 +11,7 @@ describe InstStatsd do
|
|
11
11
|
'INST_STATSD_NAMESPACE',
|
12
12
|
'INST_STATSD_PORT',
|
13
13
|
'INST_STATSD_APPEND_HOST_NAME',
|
14
|
+
'INST_DOG_TAGS'
|
14
15
|
].each {|k| ENV.delete k}
|
15
16
|
end
|
16
17
|
|
@@ -111,6 +112,23 @@ describe InstStatsd do
|
|
111
112
|
expect(InstStatsd.env_settings(env)).to eq({})
|
112
113
|
end
|
113
114
|
|
115
|
+
it 'returns empty hash when missing dog tags' do
|
116
|
+
env = {
|
117
|
+
'INST_DOG_API_KEY' => 'SEKRET KEY'
|
118
|
+
}
|
119
|
+
expect(InstStatsd.env_settings(env)).to eq({})
|
120
|
+
end
|
121
|
+
|
122
|
+
it 'builds settings hash with dog environment vars' do
|
123
|
+
env = {
|
124
|
+
'INST_DOG_TAGS' => {app: 'canvas', env: 'prod'},
|
125
|
+
}
|
126
|
+
expected = {
|
127
|
+
dog_tags: {app: 'canvas', env: 'prod'},
|
128
|
+
}
|
129
|
+
expect(InstStatsd.env_settings(env)).to eq(expected)
|
130
|
+
end
|
131
|
+
|
114
132
|
it 'builds settings hash from environment vars' do
|
115
133
|
env = {
|
116
134
|
'INST_STATSD_HOST' => 'statsd.example.org',
|
@@ -69,7 +69,7 @@ describe InstStatsd::RequestStat do
|
|
69
69
|
end
|
70
70
|
|
71
71
|
describe '#total' do
|
72
|
-
it 'correctly
|
72
|
+
it 'correctly calculates milliseconds from start, finish' do
|
73
73
|
rs = create_subject({params: {}})
|
74
74
|
# start and finish are in seconds
|
75
75
|
expect(rs.total).to eq 1000
|
@@ -85,14 +85,14 @@ describe InstStatsd::RequestStat do
|
|
85
85
|
|
86
86
|
describe '#report' do
|
87
87
|
it 'doesnt send stats when no controller or action' do
|
88
|
-
statsd =
|
88
|
+
statsd = InstStatsd::Statsd
|
89
89
|
rs = create_subject({params: {}}, statsd)
|
90
|
-
expect(statsd).to_not receive(:timing).with('request.foo.index', 1000)
|
90
|
+
expect(statsd).to_not receive(:timing).with('request.foo.index', 1000, {short_stat: nil, tags: {}})
|
91
91
|
rs.report
|
92
92
|
end
|
93
93
|
|
94
94
|
it 'sends total timing when controller && action are present, doesnt send db, or view if they are not' do
|
95
|
-
statsd =
|
95
|
+
statsd = InstStatsd::Statsd
|
96
96
|
payload = {
|
97
97
|
params: {
|
98
98
|
'controller' => 'foo',
|
@@ -100,12 +100,26 @@ describe InstStatsd::RequestStat do
|
|
100
100
|
}
|
101
101
|
}
|
102
102
|
rs = create_subject(payload, statsd)
|
103
|
-
expect(statsd).to receive(:timing).with('request.foo.index.total', 1000)
|
103
|
+
expect(statsd).to receive(:timing).with('request.foo.index.total', 1000, {short_stat: ".total", tags: {}})
|
104
|
+
rs.report
|
105
|
+
end
|
106
|
+
|
107
|
+
it 'sends total timing when controller && action are present as tags for data dog' do
|
108
|
+
statsd = InstStatsd::Statsd
|
109
|
+
expect(statsd).to receive(:data_dog?).and_return true
|
110
|
+
payload = {
|
111
|
+
params: {
|
112
|
+
'controller' => 'foo',
|
113
|
+
'action' => 'index'
|
114
|
+
}
|
115
|
+
}
|
116
|
+
rs = create_subject(payload, statsd)
|
117
|
+
expect(statsd).to receive(:timing).with('request.total', 1000, {short_stat: 'request.total', tags: {action: "index", controller: "foo"}} )
|
104
118
|
rs.report
|
105
119
|
end
|
106
120
|
|
107
121
|
it 'sends view_runtime and db_runtime when present' do
|
108
|
-
statsd =
|
122
|
+
statsd = InstStatsd::Statsd
|
109
123
|
payload = {
|
110
124
|
view_runtime: 70.1,
|
111
125
|
db_runtime: 100.2,
|
@@ -115,14 +129,14 @@ describe InstStatsd::RequestStat do
|
|
115
129
|
}
|
116
130
|
}
|
117
131
|
rs = create_subject(payload, statsd)
|
118
|
-
allow(statsd).to receive(:timing).with('request.foo.index.total', 1000)
|
119
|
-
expect(statsd).to receive(:timing).with('request.foo.index.view', 70.1)
|
120
|
-
expect(statsd).to receive(:timing).with('request.foo.index.db', 100.2)
|
132
|
+
allow(statsd).to receive(:timing).with('request.foo.index.total', 1000, {short_stat: ".total", tags: {}})
|
133
|
+
expect(statsd).to receive(:timing).with('request.foo.index.view', 70.1, {short_stat: ".view", tags: {}})
|
134
|
+
expect(statsd).to receive(:timing).with('request.foo.index.db', 100.2, {short_stat: ".db", tags: {}})
|
121
135
|
rs.report
|
122
136
|
end
|
123
137
|
|
124
138
|
it 'sends cache_read_count when present' do
|
125
|
-
statsd =
|
139
|
+
statsd = InstStatsd::Statsd
|
126
140
|
payload = {
|
127
141
|
params: {
|
128
142
|
'controller' => 'foo',
|
@@ -134,7 +148,7 @@ describe InstStatsd::RequestStat do
|
|
134
148
|
describe 'sql stats' do
|
135
149
|
|
136
150
|
before :each do
|
137
|
-
@statsd =
|
151
|
+
@statsd = InstStatsd::Statsd
|
138
152
|
payload = {
|
139
153
|
params: {
|
140
154
|
'controller' => 'foo',
|
@@ -143,21 +157,21 @@ describe InstStatsd::RequestStat do
|
|
143
157
|
}
|
144
158
|
@rs = create_subject(payload, @statsd)
|
145
159
|
@rs.stats['cache.read'] = 25
|
146
|
-
expect(@statsd).to receive(:timing).with('request.foo.index.cache.read', 25)
|
160
|
+
expect(@statsd).to receive(:timing).with('request.foo.index.cache.read', 25, {short_stat: ".cache.read", tags: {}})
|
147
161
|
end
|
148
162
|
|
149
163
|
it 'doesnt send sql stats when they dont exist' do
|
150
|
-
allow(@statsd).to receive(:timing).with('request.foo.index.total', 1000)
|
151
|
-
expect(@statsd).to_not receive(:timing).with('request.foo.index.sql.read', kind_of(Numeric))
|
152
|
-
expect(@statsd).to_not receive(:timing).with('request.foo.index.sql.write', kind_of(Numeric))
|
153
|
-
expect(@statsd).to_not receive(:timing).with('request.foo.index.sql.cache', kind_of(Numeric))
|
164
|
+
allow(@statsd).to receive(:timing).with('request.foo.index.total', 1000, {short_stat: nil, tags: {}})
|
165
|
+
expect(@statsd).to_not receive(:timing).with('request.foo.index.sql.read', kind_of(Numeric), {short_stat: ".sql.read", tags: {}})
|
166
|
+
expect(@statsd).to_not receive(:timing).with('request.foo.index.sql.write', kind_of(Numeric), {short_stat: ".sql.write", tags: {}})
|
167
|
+
expect(@statsd).to_not receive(:timing).with('request.foo.index.sql.cache', kind_of(Numeric), {short_stat: ".sql.cache", tags: {}})
|
154
168
|
@rs.report
|
155
169
|
end
|
156
170
|
|
157
171
|
it 'sends sql_read_count when present' do
|
158
172
|
@rs.stats['sql.read'] = 10
|
159
|
-
allow(@statsd).to receive(:timing).with('request.foo.index.total', 1000)
|
160
|
-
expect(@statsd).to receive(:timing).with('request.foo.index.sql.read', 10)
|
173
|
+
allow(@statsd).to receive(:timing).with('request.foo.index.total', 1000, {short_stat: ".total", tags: {}})
|
174
|
+
expect(@statsd).to receive(:timing).with('request.foo.index.sql.read', 10, {short_stat: ".sql.read", tags: {}})
|
161
175
|
@rs.report
|
162
176
|
end
|
163
177
|
end
|
@@ -21,6 +21,58 @@ describe InstStatsd::Statsd do
|
|
21
21
|
expect(InstStatsd::Statsd.time('test.name') { 'test' }).to eq 'test'
|
22
22
|
end
|
23
23
|
|
24
|
+
it 'sending tags should not break statsd' do
|
25
|
+
default_tags = {app: 'canvas', env: 'prod'}
|
26
|
+
short_stat = 'test2'
|
27
|
+
allow(InstStatsd::Statsd).to receive(:hostname).and_return('testhost')
|
28
|
+
allow(InstStatsd::Statsd).to receive(:dog_tags).and_return(default_tags)
|
29
|
+
allow(InstStatsd::Statsd).to receive(:short_stat).and_return(short_stat)
|
30
|
+
statsd = double
|
31
|
+
allow(InstStatsd::Statsd).to receive(:instance).and_return(statsd)
|
32
|
+
allow(InstStatsd::Statsd).to receive(:data_dog?).and_return(false)
|
33
|
+
allow(InstStatsd::Statsd).to receive(:append_hostname?).and_return(true)
|
34
|
+
METHODS.each do |method|
|
35
|
+
expect(statsd).to receive(method).with('test.name.testhost', 'test') # no short stat or tags
|
36
|
+
InstStatsd::Statsd.send(method, 'test.name', 'test', short_stat: short_stat, tags: default_tags)
|
37
|
+
end
|
38
|
+
expect(statsd).to receive('timing').with('test.name.testhost', anything, anything) # no short stat or tags
|
39
|
+
expect(InstStatsd::Statsd.time('test.name') { 'test' }).to eq 'test'
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'adds default dog tags default' do
|
43
|
+
default_tags = {app: 'canvas', env: 'prod'}
|
44
|
+
converted_tags = ["app:canvas", "env:prod", "host:"]
|
45
|
+
short_stat = 'test2'
|
46
|
+
allow(InstStatsd::Statsd).to receive(:dog_tags).and_return(default_tags)
|
47
|
+
allow(InstStatsd::Statsd).to receive(:short_stat).and_return(short_stat)
|
48
|
+
statsd = double
|
49
|
+
allow(InstStatsd::Statsd).to receive(:instance).and_return(statsd)
|
50
|
+
allow(InstStatsd::Statsd).to receive(:data_dog?).and_return(true)
|
51
|
+
allow(InstStatsd::Statsd).to receive(:append_hostname?).and_return(false)
|
52
|
+
METHODS.each do |method|
|
53
|
+
expect(statsd).to receive(method).with(short_stat, 'test', tags: converted_tags)
|
54
|
+
InstStatsd::Statsd.send(method, 'test.name', 'test', short_stat: short_stat)
|
55
|
+
end
|
56
|
+
expect(statsd).to receive('timing').with(short_stat, anything, anything, tags: converted_tags)
|
57
|
+
expect(InstStatsd::Statsd.time('test.name', short_stat: short_stat) {'test'}).to eq 'test'
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'uses regular stat name when short_stat is omitted on data dog' do
|
61
|
+
default_tags = {app: 'canvas', env: 'prod'}
|
62
|
+
converted_tags = ["app:canvas", "env:prod", "host:"]
|
63
|
+
allow(InstStatsd::Statsd).to receive(:dog_tags).and_return(default_tags)
|
64
|
+
statsd = double
|
65
|
+
allow(InstStatsd::Statsd).to receive(:instance).and_return(statsd)
|
66
|
+
allow(InstStatsd::Statsd).to receive(:data_dog?).and_return(true)
|
67
|
+
allow(InstStatsd::Statsd).to receive(:append_hostname?).and_return(false)
|
68
|
+
METHODS.each do |method|
|
69
|
+
expect(statsd).to receive(method).with('test.name', 'test', tags: converted_tags)
|
70
|
+
InstStatsd::Statsd.send(method, 'test.name', 'test')
|
71
|
+
end
|
72
|
+
expect(statsd).to receive('timing').with('test.name', anything, anything, tags: converted_tags)
|
73
|
+
expect(InstStatsd::Statsd.time('test.name') {'test'}).to eq 'test'
|
74
|
+
end
|
75
|
+
|
24
76
|
it 'omits hostname if specified in config' do
|
25
77
|
expect(InstStatsd::Statsd).to receive(:hostname).never
|
26
78
|
statsd = double
|
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.0
|
4
|
+
version: 2.1.0
|
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:
|
12
|
+
date: 2019-02-20 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: dogstatsd-ruby
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - "~>"
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '3.3'
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - "~>"
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '3.3'
|
14
28
|
- !ruby/object:Gem::Dependency
|
15
29
|
name: statsd-ruby
|
16
30
|
requirement: !ruby/object:Gem::Requirement
|
@@ -147,7 +161,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
147
161
|
version: '0'
|
148
162
|
requirements: []
|
149
163
|
rubyforge_project:
|
150
|
-
rubygems_version: 2.6
|
164
|
+
rubygems_version: 2.7.6
|
151
165
|
signing_key:
|
152
166
|
specification_version: 4
|
153
167
|
summary: Statsd for Instructure
|