librato-rack 1.1.1 → 2.0.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.
- data/CHANGELOG.md +3 -0
- data/README.md +43 -20
- data/lib/librato/collector/aggregator.rb +45 -25
- data/lib/librato/collector/counter_cache.rb +38 -24
- data/lib/librato/collector.rb +9 -3
- data/lib/librato/rack/configuration.rb +24 -16
- data/lib/librato/rack/errors.rb +2 -0
- data/lib/librato/rack/tracker.rb +11 -16
- data/lib/librato/rack/validating_queue.rb +8 -6
- data/lib/librato/rack/version.rb +1 -1
- data/lib/librato/rack.rb +6 -12
- data/test/apps/custom.ru +5 -1
- data/test/integration/custom_test.rb +20 -6
- data/test/integration/no_stats_test.rb +2 -3
- data/test/integration/no_suites_test.rb +4 -5
- data/test/integration/queue_wait_test.rb +4 -10
- data/test/integration/request_test.rb +20 -23
- data/test/integration/suites_test.rb +5 -7
- data/test/remote/tracker_test.rb +53 -45
- data/test/support/environment_helpers.rb +1 -1
- data/test/test_helper.rb +1 -1
- data/test/unit/collector/aggregator_test.rb +70 -31
- data/test/unit/collector/counter_cache_test.rb +73 -33
- data/test/unit/collector/group_test.rb +20 -16
- data/test/unit/collector_test.rb +6 -5
- data/test/unit/rack/configuration_test.rb +19 -8
- data/test/unit/rack/tracker_test.rb +41 -5
- data.tar.gz.sig +0 -0
- metadata +83 -42
- metadata.gz.sig +1 -0
- checksums.yaml +0 -7
@@ -5,7 +5,8 @@ module Librato
|
|
5
5
|
class AggregatorTest < Minitest::Test
|
6
6
|
|
7
7
|
def setup
|
8
|
-
@
|
8
|
+
@tags = { hostname: "metrics-web-stg-1" }
|
9
|
+
@agg = Aggregator.new(default_tags: @tags)
|
9
10
|
end
|
10
11
|
|
11
12
|
def test_adding_timings
|
@@ -32,17 +33,17 @@ module Librato
|
|
32
33
|
[0.1, 0.2, 0.3].each do |val|
|
33
34
|
@agg.timing 'a.sample.thing', val, percentile: 50
|
34
35
|
end
|
35
|
-
assert_equal 0.2, @agg.fetch(
|
36
|
-
|
36
|
+
assert_equal 0.2, @agg.fetch("a.sample.thing", percentile: 50, tags: @tags),
|
37
|
+
"can calculate percentile"
|
37
38
|
|
38
39
|
# multiple percentiles
|
39
40
|
[0.2, 0.35].each do |val|
|
40
41
|
@agg.timing 'a.sample.thing', val, percentile: [80, 95]
|
41
42
|
end
|
42
|
-
assert_equal 0.31, @agg.fetch(
|
43
|
-
|
44
|
-
assert_equal 0.35, @agg.fetch(
|
45
|
-
|
43
|
+
assert_equal 0.31, @agg.fetch("a.sample.thing", percentile: 65, tags: @tags),
|
44
|
+
"can calculate another percentile simultaneously"
|
45
|
+
assert_equal 0.35, @agg.fetch("a.sample.thing", percentile: 95, tags: @tags),
|
46
|
+
"can calculate another percentile simultaneously"
|
46
47
|
|
47
48
|
# ensure storage is efficient: this is a little gross because we
|
48
49
|
# have to inquire past the public interface, but important to verify
|
@@ -62,13 +63,13 @@ module Librato
|
|
62
63
|
}
|
63
64
|
end
|
64
65
|
|
65
|
-
def
|
66
|
+
def test_percentiles_with_tags
|
66
67
|
Array(1..10).each do |val|
|
67
|
-
@agg.timing
|
68
|
+
@agg.timing "a.sample.thing", val, percentile: 50
|
68
69
|
end
|
69
70
|
assert_equal 5.5,
|
70
|
-
@agg.fetch(
|
71
|
-
|
71
|
+
@agg.fetch("a.sample.thing", tags: @tags, percentile: 50),
|
72
|
+
"can calculate percentile with tags"
|
72
73
|
end
|
73
74
|
|
74
75
|
# Todo: mult percentiles, block form, with source, invalid percentile
|
@@ -84,42 +85,51 @@ module Librato
|
|
84
85
|
assert_equal 'bar', timing
|
85
86
|
end
|
86
87
|
|
87
|
-
def
|
88
|
-
|
88
|
+
def test_custom_tags
|
89
|
+
tags_1 = { hostname: "douglas_adams" }
|
90
|
+
# tags are kept separate
|
89
91
|
@agg.measure 'meaning.of.life', 1
|
90
|
-
@agg.measure
|
92
|
+
@agg.measure "meaning.of.life", 42, tags: tags_1
|
91
93
|
assert_equal 1.0, @agg.fetch('meaning.of.life')[:sum]
|
92
|
-
assert_equal 42.0, @agg.fetch(
|
94
|
+
assert_equal 42.0, @agg.fetch("meaning.of.life", tags: tags_1)[:sum]
|
93
95
|
|
94
|
-
|
95
|
-
|
96
|
+
tags_2 = { hostname: "mine" }
|
97
|
+
# tags work with time blocks
|
98
|
+
@agg.timing "mytiming", tags: tags_2 do
|
96
99
|
sleep 0.02
|
97
100
|
end
|
98
|
-
assert_in_delta @agg.fetch(
|
101
|
+
assert_in_delta @agg.fetch("mytiming", tags: tags_2)[:sum], 20, 10
|
102
|
+
end
|
103
|
+
|
104
|
+
def test_legacy_source
|
105
|
+
legacy_agg = Aggregator.new
|
106
|
+
legacy_agg.measure "feature_flag.check", 5, source: "new_feature"
|
107
|
+
assert_equal 5, legacy_agg.fetch("feature_flag.check", tags: { source: "new_feature" })[:sum]
|
99
108
|
end
|
100
109
|
|
101
110
|
def test_flush
|
111
|
+
tags = { hostname: "douglas_adams" }
|
102
112
|
@agg.measure 'meaning.of.life', 1
|
103
|
-
@agg.measure
|
113
|
+
@agg.measure "meaning.of.life", 42, tags: tags
|
104
114
|
|
105
115
|
q = Librato::Metrics::Queue.new
|
106
116
|
@agg.flush_to(q)
|
107
117
|
|
108
118
|
expected = Set.new([
|
109
|
-
{:name=>"meaning.of.life", :count=>1, :sum=>1.0, :min=>1.0, :max=>1.0},
|
110
|
-
{:name=>"meaning.of.life", :count=>1, :sum=>42.0, :min=>42.0, :max=>42.0, :
|
119
|
+
{:name=>"meaning.of.life", :count=>1, :sum=>1.0, :min=>1.0, :max=>1.0, :tags=>@tags},
|
120
|
+
{:name=>"meaning.of.life", :count=>1, :sum=>42.0, :min=>42.0, :max=>42.0, :tags=>tags}
|
111
121
|
])
|
112
|
-
assert_equal expected, Set.new(q.queued[:
|
122
|
+
assert_equal expected, Set.new(q.queued[:measurements])
|
113
123
|
end
|
114
124
|
|
115
125
|
def test_flush_percentiles
|
116
126
|
[1,2,3].each { |i| @agg.timing 'a.timing', i, percentile: 95 }
|
117
|
-
[1,2,3].each { |i| @agg.timing
|
127
|
+
[1,2,3].each { |i| @agg.timing "b.timing", i, tags: { hostname: "f" }, percentile: [50, 99.9] }
|
118
128
|
|
119
|
-
q = Librato::Metrics::Queue.new
|
129
|
+
q = Librato::Metrics::Queue.new(tags: { region: "us-east-1" })
|
120
130
|
@agg.flush_to(q)
|
121
131
|
|
122
|
-
queued = q.queued[:
|
132
|
+
queued = q.queued[:measurements]
|
123
133
|
a_timing = queued.detect{ |q| q[:name] == 'a.timing.p95' }
|
124
134
|
b_timing_50 = queued.detect{ |q| q[:name] == 'b.timing.p50' }
|
125
135
|
b_timing_999 = queued.detect{ |q| q[:name] == 'b.timing.p999' }
|
@@ -132,15 +142,44 @@ module Librato
|
|
132
142
|
assert_equal 2, b_timing_50[:value]
|
133
143
|
assert_equal 3, b_timing_999[:value]
|
134
144
|
|
135
|
-
|
136
|
-
assert_equal
|
137
|
-
assert_equal 'f', b_timing_999[:source], 'proper source set'
|
145
|
+
assert_equal "f", b_timing_50[:tags][:hostname], "proper tags set"
|
146
|
+
assert_equal "f", b_timing_999[:tags][:hostname], "proper tags set"
|
138
147
|
|
139
148
|
# flushing clears percentages to track
|
140
|
-
|
141
|
-
assert_equal 0,
|
149
|
+
measurement = @agg.send(:fetch_percentile_store, 'a.timing', tags: @tags)
|
150
|
+
assert_equal 0, measurement[:percs].length, 'clears percentiles'
|
151
|
+
end
|
152
|
+
|
153
|
+
def test_default_tags
|
154
|
+
default_tags = { queue: 'priority' }
|
155
|
+
agg = Aggregator.new(default_tags: default_tags)
|
156
|
+
agg.measure 'jobs.queued', 1
|
157
|
+
|
158
|
+
assert_equal 1, agg['jobs.queued'][:sum]
|
159
|
+
assert_equal default_tags, agg['jobs.queued'][:tags]
|
160
|
+
end
|
161
|
+
|
162
|
+
def test_tags_option
|
163
|
+
default_tags = { queue: 'priority' }
|
164
|
+
tags_option = { worker: 'worker.12' }
|
165
|
+
agg = Aggregator.new(default_tags: default_tags)
|
166
|
+
agg.measure 'jobs.queued', 1, tags: tags_option
|
167
|
+
|
168
|
+
assert_equal 1, agg.fetch('jobs.queued', tags: tags_option)[:sum]
|
169
|
+
assert_equal tags_option, agg.fetch('jobs.queued', tags: tags_option)[:tags]
|
170
|
+
end
|
171
|
+
|
172
|
+
def test_inherit_tags
|
173
|
+
default_tags = { queue: 'priority' }
|
174
|
+
tags_option = { worker: 'worker.12' }
|
175
|
+
merged_tags = default_tags.merge(tags_option)
|
176
|
+
agg = Aggregator.new(default_tags: default_tags)
|
177
|
+
agg.measure 'jobs.queued', 1, tags: tags_option, inherit_tags: true
|
178
|
+
|
179
|
+
assert_equal 1, agg.fetch('jobs.queued', tags: merged_tags)[:sum]
|
180
|
+
assert_equal merged_tags, agg.fetch('jobs.queued', tags: merged_tags)[:tags]
|
142
181
|
end
|
143
182
|
|
144
183
|
end
|
145
184
|
end
|
146
|
-
end
|
185
|
+
end
|
@@ -5,67 +5,75 @@ module Librato
|
|
5
5
|
class CounterCacheTest < Minitest::Test
|
6
6
|
|
7
7
|
def test_basic_operations
|
8
|
-
cc = CounterCache.new
|
8
|
+
cc = CounterCache.new(default_tags: { host: 'metricsweb-stagevpc-1' })
|
9
9
|
cc.increment :foo
|
10
|
-
assert_equal 1, cc[:foo]
|
10
|
+
assert_equal 1, cc[:foo][:value]
|
11
11
|
|
12
12
|
# accepts optional argument
|
13
13
|
cc.increment :foo, :by => 5
|
14
|
-
assert_equal 6, cc[:foo]
|
14
|
+
assert_equal 6, cc[:foo][:value]
|
15
15
|
|
16
16
|
# legacy style
|
17
17
|
cc.increment :foo, 2
|
18
|
-
assert_equal 8, cc[:foo]
|
18
|
+
assert_equal 8, cc[:foo][:value]
|
19
19
|
|
20
20
|
# strings or symbols work
|
21
21
|
cc.increment 'foo'
|
22
|
-
assert_equal 9, cc['foo']
|
22
|
+
assert_equal 9, cc['foo'][:value]
|
23
23
|
end
|
24
24
|
|
25
|
-
def
|
25
|
+
def test_custom_tags
|
26
26
|
cc = CounterCache.new
|
27
27
|
|
28
|
-
cc.increment :foo, :
|
29
|
-
assert_equal 1, cc.fetch(:foo, :
|
28
|
+
cc.increment :foo, tags: { hostname: "bar" }
|
29
|
+
assert_equal 1, cc.fetch(:foo, tags: { hostname: "bar" })[:value]
|
30
30
|
|
31
31
|
# symbols also work
|
32
|
-
cc.increment :foo, :
|
33
|
-
assert_equal 1, cc.fetch(:foo, :
|
32
|
+
cc.increment :foo, tags: { hostname: :baz }
|
33
|
+
assert_equal 1, cc.fetch(:foo, tags: { hostname: :baz })[:value]
|
34
34
|
|
35
35
|
# strings and symbols are interchangable
|
36
|
-
cc.increment :foo, :
|
37
|
-
assert_equal 2, cc.fetch(:foo, :
|
36
|
+
cc.increment :foo, tags: { hostname: :bar }
|
37
|
+
assert_equal 2, cc.fetch(:foo, tags: { hostname: "bar" })[:value]
|
38
38
|
|
39
39
|
# custom source and custom increment
|
40
|
-
cc.increment :foo, :
|
41
|
-
assert_equal 10, cc.fetch(:foo, :
|
40
|
+
cc.increment :foo, tags: { hostname: "boombah" }, by: 10
|
41
|
+
assert_equal 10, cc.fetch(:foo, tags: { hostname: "boombah" })[:value]
|
42
42
|
end
|
43
43
|
|
44
|
-
def
|
44
|
+
def test_legacy_source
|
45
45
|
cc = CounterCache.new
|
46
46
|
|
47
|
+
cc.increment :foo, source: "bar"
|
48
|
+
|
49
|
+
assert_equal 1, cc.fetch(:foo, tags: { source: "bar" })[:value]
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_sporadic
|
53
|
+
cc = CounterCache.new(default_tags: { host: 'metricsweb-stagevpc-1' })
|
54
|
+
|
47
55
|
cc.increment :foo
|
48
|
-
cc.increment :foo, :
|
56
|
+
cc.increment :foo, tags: { hostname: "bar" }
|
49
57
|
|
50
58
|
cc.increment :baz, :sporadic => true
|
51
|
-
cc.increment :baz, :
|
52
|
-
assert_equal 1, cc[:baz]
|
53
|
-
assert_equal 1, cc.fetch(:baz, :
|
59
|
+
cc.increment :baz, tags: { hostname: 118 }, sporadic: true
|
60
|
+
assert_equal 1, cc[:baz][:value]
|
61
|
+
assert_equal 1, cc.fetch(:baz, tags: { hostname: 118 })[:value]
|
54
62
|
|
55
63
|
# persist values once
|
56
64
|
cc.flush_to(Librato::Metrics::Queue.new)
|
57
65
|
|
58
66
|
# normal values persist
|
59
|
-
assert_equal 0, cc[:foo]
|
60
|
-
assert_equal 0, cc.fetch(:foo, :
|
67
|
+
assert_equal 0, cc[:foo][:value]
|
68
|
+
assert_equal 0, cc.fetch(:foo, tags: { hostname: "bar" })[:value]
|
61
69
|
|
62
70
|
# sporadic do not
|
63
71
|
assert_nil cc[:baz]
|
64
|
-
assert_nil cc.fetch(:baz, :
|
72
|
+
assert_nil cc.fetch(:baz, tags: { hostname: 118 })
|
65
73
|
|
66
74
|
# add a different sporadic metric
|
67
75
|
cc.increment :bazoom, :sporadic => true
|
68
|
-
assert_equal 1, cc[:bazoom]
|
76
|
+
assert_equal 1, cc[:bazoom][:value]
|
69
77
|
|
70
78
|
# persist values again
|
71
79
|
cc.flush_to(Librato::Metrics::Queue.new)
|
@@ -73,24 +81,56 @@ module Librato
|
|
73
81
|
end
|
74
82
|
|
75
83
|
def test_flushing
|
76
|
-
|
84
|
+
default_tags = { host: 'metricsweb-stagevpc-1' }
|
85
|
+
cc = CounterCache.new(default_tags: default_tags)
|
86
|
+
tags = { hostname: "foobar" }
|
77
87
|
|
78
88
|
cc.increment :foo
|
79
89
|
cc.increment :bar, :by => 2
|
80
|
-
cc.increment :foo, :
|
81
|
-
cc.increment :foo, :
|
90
|
+
cc.increment :foo, tags: tags
|
91
|
+
cc.increment :foo, tags: tags, by: 3
|
82
92
|
|
83
|
-
q = Librato::Metrics::Queue.new
|
93
|
+
q = Librato::Metrics::Queue.new(tags: { region: "us-east-1" })
|
84
94
|
cc.flush_to(q)
|
85
95
|
|
86
|
-
expected = Set.new [{:name=>"foo", :value=>1},
|
87
|
-
{:name=>"foo", :value=>4, :
|
88
|
-
{:name=>"bar", :value=>2}]
|
89
|
-
queued = Set.new(q.
|
90
|
-
queued.each { |hash| hash.delete(:
|
96
|
+
expected = Set.new [{:name=>"foo", :value=>1, :tags=>default_tags},
|
97
|
+
{:name=>"foo", :value=>4, :tags=>tags},
|
98
|
+
{:name=>"bar", :value=>2, :tags=>default_tags}]
|
99
|
+
queued = Set.new(q.measurements)
|
100
|
+
queued.each { |hash| hash.delete(:time) }
|
91
101
|
assert_equal queued, expected
|
92
102
|
end
|
93
103
|
|
104
|
+
def test_default_tags
|
105
|
+
default_tags = { host: 'metricsweb-stagevpc-1' }
|
106
|
+
cc = CounterCache.new(default_tags: default_tags)
|
107
|
+
cc.increment 'user.signup'
|
108
|
+
|
109
|
+
assert_equal 1, cc.fetch('user.signup')[:value]
|
110
|
+
assert_equal default_tags, cc.fetch('user.signup')[:tags]
|
111
|
+
end
|
112
|
+
|
113
|
+
def test_tags_option
|
114
|
+
default_tags = { host: 'metricsweb-stagevpc-1' }
|
115
|
+
tags_option = { plan: 'developer' }
|
116
|
+
cc = CounterCache.new(default_tags: default_tags)
|
117
|
+
cc.increment 'user.signup', tags: tags_option
|
118
|
+
|
119
|
+
assert_equal 1, cc.fetch('user.signup', tags: tags_option)[:value]
|
120
|
+
assert_equal tags_option, cc.fetch('user.signup', tags: tags_option)[:tags]
|
121
|
+
end
|
122
|
+
|
123
|
+
def test_inherit_tags
|
124
|
+
default_tags = { host: 'metricsweb-stagevpc-1' }
|
125
|
+
tags_option = { plan: 'developer' }
|
126
|
+
merged_tags = default_tags.merge(tags_option)
|
127
|
+
cc = CounterCache.new(default_tags: default_tags)
|
128
|
+
cc.increment 'user.signup', tags: tags_option, inherit_tags: true
|
129
|
+
|
130
|
+
assert_equal 1, cc.fetch('user.signup', tags: merged_tags)[:value]
|
131
|
+
assert_equal merged_tags, cc.fetch('user.signup', tags: merged_tags)[:tags]
|
132
|
+
end
|
133
|
+
|
94
134
|
end
|
95
135
|
end
|
96
|
-
end
|
136
|
+
end
|
@@ -4,52 +4,56 @@ module Librato
|
|
4
4
|
class Collector
|
5
5
|
class GroupTest < Minitest::Test
|
6
6
|
|
7
|
+
def setup
|
8
|
+
@tags = { region: "us-east-1" }
|
9
|
+
end
|
10
|
+
|
7
11
|
def test_increment
|
8
|
-
collector = Collector.new
|
12
|
+
collector = Collector.new(tags: { host: 'metricsweb-stagevpc-1' })
|
9
13
|
collector.group 'foo' do |g|
|
10
14
|
g.increment :bar
|
11
|
-
g.increment :baz, :
|
15
|
+
g.increment :baz, tags: @tags
|
12
16
|
end
|
13
|
-
assert_equal 1, collector.counters['foo.bar']
|
14
|
-
assert_equal 1, collector.counters.fetch(
|
17
|
+
assert_equal 1, collector.counters['foo.bar'][:value]
|
18
|
+
assert_equal 1, collector.counters.fetch("foo.baz", tags: @tags)[:value]
|
15
19
|
end
|
16
20
|
|
17
21
|
def test_measure
|
18
|
-
collector = Collector.new
|
22
|
+
collector = Collector.new(tags: { host: 'metricsweb-stagevpc-1' })
|
19
23
|
collector.group 'foo' do |g|
|
20
|
-
g.measure :baz, 23
|
24
|
+
g.measure :baz, 23, tags: @tags
|
21
25
|
end
|
22
|
-
assert_equal 23, collector.aggregate
|
26
|
+
assert_equal 23, collector.aggregate.fetch("foo.baz", tags: @tags)[:sum]
|
23
27
|
end
|
24
28
|
|
25
29
|
def test_timing
|
26
|
-
collector = Collector.new
|
30
|
+
collector = Collector.new(tags: { host: 'metricsweb-stagevpc-1' })
|
27
31
|
collector.group 'foo' do |g|
|
28
|
-
g.timing :bam, 32.0
|
32
|
+
g.timing :bam, 32.0, tags: @tags
|
29
33
|
end
|
30
|
-
assert_equal 32.0, collector.aggregate
|
34
|
+
assert_equal 32.0, collector.aggregate.fetch("foo.bam", tags: @tags)[:sum]
|
31
35
|
end
|
32
36
|
|
33
37
|
def test_timing_block
|
34
|
-
collector = Collector.new
|
38
|
+
collector = Collector.new(tags: { host: 'metricsweb-stagevpc-1' })
|
35
39
|
collector.group 'foo' do |g|
|
36
|
-
g.timing :bak do
|
40
|
+
g.timing :bak, tags: @tags do
|
37
41
|
sleep 0.01
|
38
42
|
end
|
39
43
|
end
|
40
|
-
assert_in_delta 10.0, collector.aggregate
|
44
|
+
assert_in_delta 10.0, collector.aggregate.fetch("foo.bak", tags: @tags)[:sum], 2
|
41
45
|
end
|
42
46
|
|
43
47
|
def test_nesting
|
44
|
-
collector = Collector.new
|
48
|
+
collector = Collector.new(tags: { host: 'metricsweb-stagevpc-1' })
|
45
49
|
collector.group 'foo' do |g|
|
46
50
|
g.group :bar do |b|
|
47
51
|
b.increment :baz, 2
|
48
52
|
end
|
49
53
|
end
|
50
|
-
assert_equal 2, collector.counters['foo.bar.baz']
|
54
|
+
assert_equal 2, collector.counters['foo.bar.baz'][:value]
|
51
55
|
end
|
52
56
|
|
53
57
|
end
|
54
58
|
end
|
55
|
-
end
|
59
|
+
end
|
data/test/unit/collector_test.rb
CHANGED
@@ -10,14 +10,15 @@ module Librato
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def test_basic_grouping
|
13
|
-
collector = Collector.new
|
13
|
+
collector = Collector.new(tags: { host: 'metricsweb-stagevpc-1' })
|
14
|
+
tags = { region: "us-east-1" }
|
14
15
|
collector.group 'foo' do |g|
|
15
16
|
g.increment :bar
|
16
|
-
g.measure :baz, 23
|
17
|
+
g.measure :baz, 23, tags: tags
|
17
18
|
end
|
18
|
-
assert_equal 1, collector.counters[
|
19
|
-
assert_equal 23, collector.aggregate
|
19
|
+
assert_equal 1, collector.counters["foo.bar"][:value]
|
20
|
+
assert_equal 23, collector.aggregate.fetch("foo.baz", tags: tags)[:sum]
|
20
21
|
end
|
21
22
|
|
22
23
|
end
|
23
|
-
end
|
24
|
+
end
|
@@ -13,18 +13,20 @@ module Librato
|
|
13
13
|
assert_equal 60, config.flush_interval
|
14
14
|
assert_equal Librato::Metrics.api_endpoint, config.api_endpoint
|
15
15
|
assert_equal '', config.suites
|
16
|
+
assert_equal Hash.new, config.tags
|
16
17
|
end
|
17
18
|
|
18
19
|
def test_environment_variable_config
|
19
20
|
ENV['LIBRATO_USER'] = 'foo@bar.com'
|
20
21
|
ENV['LIBRATO_TOKEN'] = 'api_key'
|
21
|
-
ENV[
|
22
|
+
ENV["LIBRATO_TAGS"] = "hostname=metrics-web-stg-1"
|
22
23
|
ENV['LIBRATO_PROXY'] = 'http://localhost:8080'
|
23
24
|
ENV['LIBRATO_SUITES'] = 'foo,bar'
|
25
|
+
expected_tags = { hostname: "metrics-web-stg-1" }
|
24
26
|
config = Configuration.new
|
25
27
|
assert_equal 'foo@bar.com', config.user
|
26
28
|
assert_equal 'api_key', config.token
|
27
|
-
assert_equal
|
29
|
+
assert_equal expected_tags, config.tags
|
28
30
|
assert_equal 'http://localhost:8080', config.proxy
|
29
31
|
assert_equal 'foo,bar', config.suites
|
30
32
|
#assert Librato::Rails.explicit_source, 'source is explicit'
|
@@ -36,13 +38,22 @@ module Librato
|
|
36
38
|
assert_equal 'http://localhost:8888', config.proxy
|
37
39
|
end
|
38
40
|
|
39
|
-
def
|
41
|
+
def test_has_tags
|
40
42
|
config = Configuration.new
|
41
|
-
assert !config.
|
42
|
-
config.
|
43
|
-
assert config.
|
44
|
-
config.
|
45
|
-
assert !config.
|
43
|
+
assert !config.has_tags?
|
44
|
+
config.tags = { hostname: "tessaract" }
|
45
|
+
assert config.has_tags?
|
46
|
+
config.tags = nil
|
47
|
+
assert !config.has_tags?, "tags are not valid when nil"
|
48
|
+
config.tags = {}
|
49
|
+
assert !config.has_tags?, "tags are not valid when empty"
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_invalid_tags_env_var
|
53
|
+
ENV["LIBRATO_TAGS"] = "loljk"
|
54
|
+
assert_raises Librato::Rack::InvalidTagConfiguration do
|
55
|
+
config = Configuration.new
|
56
|
+
end
|
46
57
|
end
|
47
58
|
|
48
59
|
def test_prefix_change_notification
|
@@ -15,7 +15,7 @@ module Librato
|
|
15
15
|
assert_equal 'second', tracker.collector.prefix
|
16
16
|
end
|
17
17
|
|
18
|
-
def
|
18
|
+
def test_requires_tags_on_heroku
|
19
19
|
config = Configuration.new
|
20
20
|
config.user, config.token = 'foo', 'bar'
|
21
21
|
@buffer = StringIO.new
|
@@ -24,10 +24,10 @@ module Librato
|
|
24
24
|
tracker.on_heroku = true
|
25
25
|
|
26
26
|
assert_equal false, tracker.send(:should_start?),
|
27
|
-
'should not start with implicit
|
28
|
-
assert buffer_lines[0].index(
|
27
|
+
'should not start with implicit tags on heroku'
|
28
|
+
assert buffer_lines[0].index("tags must be provided")
|
29
29
|
|
30
|
-
config.
|
30
|
+
config.tags = { hostname: "myapp" }
|
31
31
|
new_tracker = Tracker.new(config)
|
32
32
|
assert_equal true, new_tracker.send(:should_start?)
|
33
33
|
end
|
@@ -46,6 +46,42 @@ module Librato
|
|
46
46
|
ENV.delete('LIBRATO_AUTORUN')
|
47
47
|
end
|
48
48
|
|
49
|
+
def test_invalid_tags_can_prevent_startup
|
50
|
+
config = Configuration.new
|
51
|
+
config.user, config.token = "foo", "bar"
|
52
|
+
@buffer = StringIO.new
|
53
|
+
config.log_target = @buffer
|
54
|
+
config.tags = { hostname: "!!!" }
|
55
|
+
tracker_1 = Tracker.new(config)
|
56
|
+
|
57
|
+
assert_equal false, tracker_1.send(:should_start?)
|
58
|
+
assert buffer_lines.to_s.include?("invalid tags")
|
59
|
+
|
60
|
+
config.tags = { "!!!" => "metrics-web-stg-1" }
|
61
|
+
tracker_2 = Tracker.new(config)
|
62
|
+
|
63
|
+
assert_equal false, tracker_2.send(:should_start?)
|
64
|
+
assert buffer_lines.to_s.include?("invalid tags")
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_exceeding_default_tags_limit_can_prevent_startup
|
68
|
+
config = Configuration.new
|
69
|
+
config.user, config.token = "foo", "bar"
|
70
|
+
@buffer = StringIO.new
|
71
|
+
config.log_target = @buffer
|
72
|
+
config.tags = { a: 1, b: 2, c: 3, d: 4 }
|
73
|
+
tracker_1 = Tracker.new(config)
|
74
|
+
|
75
|
+
assert_equal true, tracker_1.send(:should_start?)
|
76
|
+
|
77
|
+
config.tags = { a: 1, b: 2, c: 3, d: 4, e: 5 }
|
78
|
+
|
79
|
+
tracker_2 = Tracker.new(config)
|
80
|
+
|
81
|
+
assert_equal false, tracker_2.send(:should_start?)
|
82
|
+
assert buffer_lines.to_s.include?("cannot exceed default tags limit")
|
83
|
+
end
|
84
|
+
|
49
85
|
def test_suite_configured
|
50
86
|
ENV['LIBRATO_SUITES'] = 'abc,prq'
|
51
87
|
|
@@ -66,4 +102,4 @@ module Librato
|
|
66
102
|
|
67
103
|
end
|
68
104
|
end
|
69
|
-
end
|
105
|
+
end
|
data.tar.gz.sig
ADDED
Binary file
|