canvas_statsd 1.0.3 → 1.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.
- checksums.yaml +4 -4
- data/lib/canvas_statsd.rb +13 -2
- data/spec/canvas_statsd/canvas_statsd_spec.rb +58 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7f93d09a249a24e64798dd4e4b1554b1132cf2e5
|
4
|
+
data.tar.gz: c104aae22f8fe8bf5f86d2e92aa2cda2218f1fb0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dfe9e66cff26fe7687e592d6d668295609577228dfa46ae7c3f81cdd2295585cbe9ec571f1547554e0df429012d02d3d68111fb9167ae2ecb63dc70380d3ebc8
|
7
|
+
data.tar.gz: ab4ffc4acf17efc36669900d9e26400a18fc59e547162e59974e15146599129edae89dd4ef190a5e46e62ce9dea43cfb0b1795e4e46fb6f6d774d2c67ca9c6aa
|
data/lib/canvas_statsd.rb
CHANGED
@@ -3,6 +3,8 @@ require "aroi" if defined?(ActiveRecord)
|
|
3
3
|
|
4
4
|
module CanvasStatsd
|
5
5
|
|
6
|
+
class ConfigurationError < StandardError; end
|
7
|
+
|
6
8
|
require "canvas_statsd/statsd"
|
7
9
|
require "canvas_statsd/request_stat"
|
8
10
|
require "canvas_statsd/counter"
|
@@ -27,11 +29,20 @@ module CanvasStatsd
|
|
27
29
|
append_hostname: env.fetch('CANVAS_STATSD_APPEND_HOSTNAME', nil),
|
28
30
|
}
|
29
31
|
config.delete_if {|k,v| v.nil?}
|
30
|
-
config
|
31
|
-
config[:append_hostname] = true if config[:append_hostname] == 'true';
|
32
|
+
convert_bool(config, :append_hostname)
|
32
33
|
config[:host] ? config : {}
|
33
34
|
end
|
34
35
|
|
36
|
+
def self.convert_bool(hash, key)
|
37
|
+
value = hash[key]
|
38
|
+
return if value.nil?
|
39
|
+
unless ['true', 'false', true, false].include?(value)
|
40
|
+
message = "#{key} must be a boolean, or the string representation of a boolean, got: #{value}"
|
41
|
+
raise CanvasStatsd::ConfigurationError, message
|
42
|
+
end
|
43
|
+
hash[key] = (value == 'true' || value == true) ? true : false
|
44
|
+
end
|
45
|
+
|
35
46
|
def self.track_default_metrics options={}
|
36
47
|
CanvasStatsd::DefaultTracking.track_default_metrics options
|
37
48
|
end
|
@@ -66,6 +66,39 @@ describe CanvasStatsd do
|
|
66
66
|
end
|
67
67
|
end
|
68
68
|
|
69
|
+
describe ".convert_bool" do
|
70
|
+
it 'sets string true values to boolean true' do
|
71
|
+
config = {potential_string_bool: 'true'}
|
72
|
+
CanvasStatsd.convert_bool(config, :potential_string_bool)
|
73
|
+
expect(config[:potential_string_bool]).to be(true)
|
74
|
+
end
|
75
|
+
it 'sets boolean true values to boolean true' do
|
76
|
+
config = {potential_string_bool: true}
|
77
|
+
CanvasStatsd.convert_bool(config, :potential_string_bool)
|
78
|
+
expect(config[:potential_string_bool]).to be(true)
|
79
|
+
end
|
80
|
+
it 'sets false strings to boolean false' do
|
81
|
+
config = {potential_string_bool: 'false'}
|
82
|
+
CanvasStatsd.convert_bool(config, :potential_string_bool)
|
83
|
+
expect(config[:potential_string_bool]).to be(false)
|
84
|
+
end
|
85
|
+
it 'sets false booleans to boolean false' do
|
86
|
+
config = {potential_string_bool: false}
|
87
|
+
CanvasStatsd.convert_bool(config, :potential_string_bool)
|
88
|
+
expect(config[:potential_string_bool]).to be(false)
|
89
|
+
end
|
90
|
+
it 'makes no change for nil values' do
|
91
|
+
config = {foo: 'bar'}
|
92
|
+
CanvasStatsd.convert_bool(config, :potential_string_bool)
|
93
|
+
expect(config).to eq({foo: 'bar'})
|
94
|
+
end
|
95
|
+
it 'raises error for non true or false strings or booleans' do
|
96
|
+
config = {potential_string_bool: 'trrruuue'}
|
97
|
+
expect{CanvasStatsd.convert_bool(config, :potential_string_bool)}.to raise_error(CanvasStatsd::ConfigurationError)
|
98
|
+
end
|
99
|
+
|
100
|
+
end
|
101
|
+
|
69
102
|
describe ".env_settings" do
|
70
103
|
it 'returns empty hash when no CANVAS_STATSD_HOST found' do
|
71
104
|
env = {
|
@@ -120,6 +153,31 @@ describe CanvasStatsd do
|
|
120
153
|
}
|
121
154
|
expect(CanvasStatsd.env_settings(env)).to eq(expected)
|
122
155
|
end
|
156
|
+
|
157
|
+
it 'keeps boolean false values for append_hostname' do
|
158
|
+
env = {
|
159
|
+
'CANVAS_STATSD_HOST' => 'statsd.example.org',
|
160
|
+
'CANVAS_STATSD_APPEND_HOSTNAME' => false,
|
161
|
+
}
|
162
|
+
expected = {
|
163
|
+
host: 'statsd.example.org',
|
164
|
+
append_hostname: false,
|
165
|
+
}
|
166
|
+
expect(CanvasStatsd.env_settings(env)).to eq(expected)
|
167
|
+
end
|
168
|
+
|
169
|
+
it 'keeps boolean true values for append_hostname' do
|
170
|
+
env = {
|
171
|
+
'CANVAS_STATSD_HOST' => 'statsd.example.org',
|
172
|
+
'CANVAS_STATSD_APPEND_HOSTNAME' => true,
|
173
|
+
}
|
174
|
+
expected = {
|
175
|
+
host: 'statsd.example.org',
|
176
|
+
append_hostname: true,
|
177
|
+
}
|
178
|
+
expect(CanvasStatsd.env_settings(env)).to eq(expected)
|
179
|
+
end
|
180
|
+
|
123
181
|
end
|
124
182
|
|
125
183
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: canvas_statsd
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nick Cloward
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-06-
|
11
|
+
date: 2015-06-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: statsd-ruby
|