librato-metrics 1.6.2 → 2.0.0.beta
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 +13 -5
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +2 -0
- data/.rspec +2 -1
- data/.travis.yml +2 -3
- data/CHANGELOG.md +6 -2
- data/Gemfile +3 -2
- data/README.md +33 -33
- data/Rakefile +3 -4
- data/certs/librato-public.pem +18 -18
- data/examples/simple.rb +5 -5
- data/lib/librato/metrics.rb +9 -12
- data/lib/librato/metrics/aggregator.rb +6 -6
- data/lib/librato/metrics/annotator.rb +11 -11
- data/lib/librato/metrics/client.rb +24 -91
- data/lib/librato/metrics/connection.rb +2 -2
- data/lib/librato/metrics/middleware/retry.rb +1 -1
- data/lib/librato/metrics/processor.rb +3 -3
- data/lib/librato/metrics/queue.rb +1 -1
- data/lib/librato/metrics/smart_json.rb +27 -16
- data/lib/librato/metrics/version.rb +1 -1
- data/librato-metrics.gemspec +2 -2
- data/spec/integration/metrics/annotator_spec.rb +73 -73
- data/spec/integration/metrics/middleware/count_requests_spec.rb +8 -8
- data/spec/integration/metrics/queue_spec.rb +28 -28
- data/spec/integration/metrics_spec.rb +137 -137
- data/spec/spec_helper.rb +6 -10
- data/spec/unit/metrics/aggregator_spec.rb +130 -130
- data/spec/unit/metrics/client_spec.rb +37 -37
- data/spec/unit/metrics/connection_spec.rb +30 -30
- data/spec/unit/metrics/queue/autosubmission_spec.rb +25 -25
- data/spec/unit/metrics/queue_spec.rb +178 -179
- data/spec/unit/metrics/smart_json_spec.rb +79 -0
- data/spec/unit/metrics_spec.rb +21 -21
- metadata +48 -42
- metadata.gz.sig +0 -0
- data/spec/integration/deprecated_methods_spec.rb +0 -85
@@ -7,18 +7,18 @@ module Librato
|
|
7
7
|
describe CountRequests do
|
8
8
|
before(:all) { prep_integration_tests }
|
9
9
|
|
10
|
-
it "
|
10
|
+
it "counts requests" do
|
11
11
|
CountRequests.reset
|
12
|
-
Metrics.submit :
|
13
|
-
Metrics.submit :
|
14
|
-
CountRequests.total_requests.
|
12
|
+
Metrics.submit foo: 123
|
13
|
+
Metrics.submit foo: 135
|
14
|
+
expect(CountRequests.total_requests).to eq(2)
|
15
15
|
end
|
16
16
|
|
17
|
-
it "
|
18
|
-
Metrics.submit :
|
19
|
-
CountRequests.total_requests.
|
17
|
+
it "is resettable" do
|
18
|
+
Metrics.submit foo: 123
|
19
|
+
expect(CountRequests.total_requests).to be > 0
|
20
20
|
CountRequests.reset
|
21
|
-
CountRequests.total_requests.
|
21
|
+
expect(CountRequests.total_requests).to eq(0)
|
22
22
|
end
|
23
23
|
|
24
24
|
end
|
@@ -8,42 +8,42 @@ module Librato
|
|
8
8
|
before(:each) { delete_all_metrics }
|
9
9
|
|
10
10
|
context "with a large number of metrics" do
|
11
|
-
it "
|
11
|
+
it "submits them in multiple requests" do
|
12
12
|
Middleware::CountRequests.reset
|
13
|
-
queue = Queue.new(:
|
13
|
+
queue = Queue.new(per_request: 3)
|
14
14
|
(1..10).each do |i|
|
15
15
|
queue.add "gauge_#{i}" => 1
|
16
16
|
end
|
17
17
|
queue.submit
|
18
|
-
Middleware::CountRequests.total_requests.
|
18
|
+
expect(Middleware::CountRequests.total_requests).to eq(4)
|
19
19
|
end
|
20
20
|
|
21
|
-
it "
|
22
|
-
queue = Queue.new(:
|
21
|
+
it "persists all metrics" do
|
22
|
+
queue = Queue.new(per_request: 2)
|
23
23
|
(1..5).each do |i|
|
24
24
|
queue.add "gauge_#{i}" => i
|
25
25
|
end
|
26
26
|
(1..3).each do |i|
|
27
|
-
queue.add "counter_#{i}" => {:
|
27
|
+
queue.add "counter_#{i}" => {type: :counter, value: i}
|
28
28
|
end
|
29
29
|
queue.submit
|
30
30
|
|
31
|
-
metrics = Metrics.
|
32
|
-
metrics.length.
|
33
|
-
counter = Metrics.get_measurements :counter_3, :
|
34
|
-
counter['unassigned'][0]['value'].
|
35
|
-
gauge = Metrics.get_measurements :gauge_5, :
|
36
|
-
gauge['unassigned'][0]['value'].
|
31
|
+
metrics = Metrics.metrics
|
32
|
+
expect(metrics.length).to eq(8)
|
33
|
+
counter = Metrics.get_measurements :counter_3, count: 1
|
34
|
+
expect(counter['unassigned'][0]['value']).to eq(3)
|
35
|
+
gauge = Metrics.get_measurements :gauge_5, count: 1
|
36
|
+
expect(gauge['unassigned'][0]['value']).to eq(5)
|
37
37
|
end
|
38
38
|
|
39
|
-
it "
|
39
|
+
it "applies globals to each request" do
|
40
40
|
source = 'yogi'
|
41
41
|
measure_time = Time.now.to_i-3
|
42
42
|
queue = Queue.new(
|
43
|
-
:
|
44
|
-
:
|
45
|
-
:
|
46
|
-
:
|
43
|
+
per_request: 3,
|
44
|
+
source: source,
|
45
|
+
measure_time: measure_time,
|
46
|
+
skip_measurement_times: true
|
47
47
|
)
|
48
48
|
(1..5).each do |i|
|
49
49
|
queue.add "gauge_#{i}" => 1
|
@@ -51,23 +51,23 @@ module Librato
|
|
51
51
|
queue.submit
|
52
52
|
|
53
53
|
# verify globals have persisted for all requests
|
54
|
-
gauge = Metrics.get_measurements :gauge_5, :
|
55
|
-
gauge[source][0]["value"].
|
56
|
-
gauge[source][0]["measure_time"].
|
54
|
+
gauge = Metrics.get_measurements :gauge_5, count: 1
|
55
|
+
expect(gauge[source][0]["value"]).to eq(1.0)
|
56
|
+
expect(gauge[source][0]["measure_time"]).to eq(measure_time)
|
57
57
|
end
|
58
58
|
end
|
59
59
|
|
60
|
-
it "
|
61
|
-
queue = Queue.new(:
|
62
|
-
queue.add :
|
63
|
-
queue.add :
|
60
|
+
it "respects default and individual sources" do
|
61
|
+
queue = Queue.new(source: 'default')
|
62
|
+
queue.add foo: 123
|
63
|
+
queue.add bar: {value: 456, source: 'barsource'}
|
64
64
|
queue.submit
|
65
65
|
|
66
|
-
foo = Metrics.get_measurements :foo, :
|
67
|
-
foo['default'][0]['value'].
|
66
|
+
foo = Metrics.get_measurements :foo, count: 2
|
67
|
+
expect(foo['default'][0]['value']).to eq(123)
|
68
68
|
|
69
|
-
bar = Metrics.get_measurements :bar, :
|
70
|
-
bar['barsource'][0]['value'].
|
69
|
+
bar = Metrics.get_measurements :bar, count: 2
|
70
|
+
expect(bar['barsource'][0]['value']).to eq(456)
|
71
71
|
end
|
72
72
|
|
73
73
|
end
|
@@ -8,67 +8,67 @@ module Librato
|
|
8
8
|
before(:all) { @annotator = Metrics::Annotator.new }
|
9
9
|
before(:each) { delete_all_annotations }
|
10
10
|
|
11
|
-
it "
|
11
|
+
it "creates new annotation" do
|
12
12
|
Metrics.annotate :deployment, "deployed v68"
|
13
|
-
annos = @annotator.fetch(:deployment, :
|
14
|
-
annos["events"]["unassigned"].length.
|
15
|
-
annos["events"]["unassigned"][0]["title"].
|
13
|
+
annos = @annotator.fetch(:deployment, start_time: Time.now.to_i-60)
|
14
|
+
expect(annos["events"]["unassigned"].length).to eq(1)
|
15
|
+
expect(annos["events"]["unassigned"][0]["title"]).to eq('deployed v68')
|
16
16
|
end
|
17
|
-
it "
|
18
|
-
Metrics.annotate :deployment, 'deployed v69', :
|
19
|
-
annos = @annotator.fetch(:deployment, :
|
20
|
-
annos["events"]["box1"].length.
|
17
|
+
it "supports sources" do
|
18
|
+
Metrics.annotate :deployment, 'deployed v69', source: 'box1'
|
19
|
+
annos = @annotator.fetch(:deployment, start_time: Time.now.to_i-60)
|
20
|
+
expect(annos["events"]["box1"].length).to eq(1)
|
21
21
|
first = annos["events"]["box1"][0]
|
22
|
-
first['title'].
|
22
|
+
expect(first['title']).to eq('deployed v69')
|
23
23
|
end
|
24
|
-
it "
|
24
|
+
it "supports start and end times" do
|
25
25
|
start_time = Time.now.to_i-120
|
26
26
|
end_time = Time.now.to_i-30
|
27
|
-
Metrics.annotate :deployment, 'deployed v70', :
|
28
|
-
:
|
29
|
-
annos = @annotator.fetch(:deployment, :
|
30
|
-
annos["events"]["unassigned"].length.
|
27
|
+
Metrics.annotate :deployment, 'deployed v70', start_time: start_time,
|
28
|
+
end_time: end_time
|
29
|
+
annos = @annotator.fetch(:deployment, start_time: Time.now.to_i-180)
|
30
|
+
expect(annos["events"]["unassigned"].length).to eq(1)
|
31
31
|
first = annos["events"]["unassigned"][0]
|
32
|
-
first['title'].
|
33
|
-
first['start_time'].
|
34
|
-
first['end_time'].
|
32
|
+
expect(first['title']).to eq('deployed v70')
|
33
|
+
expect(first['start_time']).to eq(start_time)
|
34
|
+
expect(first['end_time']).to eq(end_time)
|
35
35
|
end
|
36
|
-
it "
|
37
|
-
Metrics.annotate :deployment, 'deployed v71', :
|
38
|
-
annos = @annotator.fetch(:deployment, :
|
39
|
-
annos["events"]["unassigned"].length.
|
36
|
+
it "supports description" do
|
37
|
+
Metrics.annotate :deployment, 'deployed v71', description: 'deployed foobar!'
|
38
|
+
annos = @annotator.fetch(:deployment, start_time: Time.now.to_i-180)
|
39
|
+
expect(annos["events"]["unassigned"].length).to eq(1)
|
40
40
|
first = annos["events"]["unassigned"][0]
|
41
|
-
first['title'].
|
42
|
-
first['description'].
|
41
|
+
expect(first['title']).to eq('deployed v71')
|
42
|
+
expect(first['description']).to eq('deployed foobar!')
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
46
46
|
describe "#delete_metrics" do
|
47
47
|
before(:each) { delete_all_metrics }
|
48
48
|
|
49
|
-
context '
|
49
|
+
context 'with names' do
|
50
50
|
|
51
51
|
context "with a single argument" do
|
52
|
-
it "
|
53
|
-
Metrics.submit :
|
54
|
-
Metrics.metrics(:
|
52
|
+
it "deletes named metric" do
|
53
|
+
Metrics.submit foo: 123
|
54
|
+
expect(Metrics.metrics(name: :foo)).not_to be_empty
|
55
55
|
Metrics.delete_metrics :foo
|
56
|
-
Metrics.metrics(:
|
56
|
+
expect(Metrics.metrics(name: :foo)).to be_empty
|
57
57
|
end
|
58
58
|
end
|
59
59
|
|
60
60
|
context "with multiple arguments" do
|
61
|
-
it "
|
62
|
-
Metrics.submit :
|
61
|
+
it "deletes named metrics" do
|
62
|
+
Metrics.submit foo: 123, bar: 345, baz: 567
|
63
63
|
Metrics.delete_metrics :foo, :bar
|
64
|
-
Metrics.metrics(:
|
65
|
-
Metrics.metrics(:
|
66
|
-
Metrics.metrics(:
|
64
|
+
expect(Metrics.metrics(name: :foo)).to be_empty
|
65
|
+
expect(Metrics.metrics(name: :bar)).to be_empty
|
66
|
+
expect(Metrics.metrics(name: :baz)).not_to be_empty
|
67
67
|
end
|
68
68
|
end
|
69
69
|
|
70
70
|
context "with missing metric" do
|
71
|
-
it "
|
71
|
+
it "runs cleanly" do
|
72
72
|
# the API currently returns success even if
|
73
73
|
# the metric has already been deleted or is absent.
|
74
74
|
Metrics.delete_metrics :missing
|
@@ -76,24 +76,24 @@ module Librato
|
|
76
76
|
end
|
77
77
|
|
78
78
|
context "with no arguments" do
|
79
|
-
it "
|
80
|
-
|
79
|
+
it "does not make request" do
|
80
|
+
expect {
|
81
81
|
Metrics.delete_metrics
|
82
|
-
}.
|
82
|
+
}.to raise_error(Metrics::NoMetricsProvided)
|
83
83
|
end
|
84
84
|
end
|
85
85
|
|
86
86
|
end
|
87
87
|
|
88
|
-
context '
|
89
|
-
it "
|
90
|
-
Metrics.submit :
|
91
|
-
Metrics.delete_metrics :
|
88
|
+
context 'with patterns' do
|
89
|
+
it "filters properly" do
|
90
|
+
Metrics.submit foo: 1, foobar: 2, foobaz: 3, bar: 4
|
91
|
+
Metrics.delete_metrics names: 'fo*', exclude: ['foobar']
|
92
92
|
|
93
93
|
%w{foo foobaz}.each do |name|
|
94
|
-
|
94
|
+
expect {
|
95
95
|
Metrics.get_metric name
|
96
|
-
}.
|
96
|
+
}.to raise_error(Librato::Metrics::NotFound)
|
97
97
|
end
|
98
98
|
|
99
99
|
%w{foobar bar}.each do |name|
|
@@ -106,48 +106,48 @@ module Librato
|
|
106
106
|
describe "#get_metric" do
|
107
107
|
before(:all) do
|
108
108
|
delete_all_metrics
|
109
|
-
Metrics.submit :
|
109
|
+
Metrics.submit my_counter: {type: :counter, value: 0, measure_time: Time.now.to_i-60}
|
110
110
|
1.upto(2).each do |i|
|
111
111
|
measure_time = Time.now.to_i - (5+i)
|
112
|
-
opts = {:
|
113
|
-
Metrics.submit :
|
114
|
-
Metrics.submit :
|
112
|
+
opts = {measure_time: measure_time, type: :counter}
|
113
|
+
Metrics.submit my_counter: opts.merge(value: i)
|
114
|
+
Metrics.submit my_counter: opts.merge(source: 'baz', value: i+1)
|
115
115
|
end
|
116
116
|
end
|
117
117
|
|
118
118
|
context "without arguments" do
|
119
|
-
it "
|
119
|
+
it "gets metric attributes" do
|
120
120
|
metric = Metrics.get_metric :my_counter
|
121
|
-
metric['name'].
|
122
|
-
metric['type'].
|
121
|
+
expect(metric['name']).to eq('my_counter')
|
122
|
+
expect(metric['type']).to eq('counter')
|
123
123
|
end
|
124
124
|
end
|
125
125
|
|
126
126
|
context "with a start_time" do
|
127
|
-
it "
|
127
|
+
it "returns entries since that time" do
|
128
128
|
# 1 hr ago
|
129
|
-
metric = Metrics.get_metric :my_counter, :
|
129
|
+
metric = Metrics.get_metric :my_counter, start_time: Time.now-3600
|
130
130
|
data = metric['measurements']
|
131
|
-
data['unassigned'].length.
|
132
|
-
data['baz'].length.
|
131
|
+
expect(data['unassigned'].length).to eq(3)
|
132
|
+
expect(data['baz'].length).to eq(2)
|
133
133
|
end
|
134
134
|
end
|
135
135
|
|
136
136
|
context "with a count limit" do
|
137
|
-
it "
|
138
|
-
metric = Metrics.get_metric :my_counter, :
|
137
|
+
it "returns that number of entries per source" do
|
138
|
+
metric = Metrics.get_metric :my_counter, count: 2
|
139
139
|
data = metric['measurements']
|
140
|
-
data['unassigned'].length.
|
141
|
-
data['baz'].length.
|
140
|
+
expect(data['unassigned'].length).to eq(2)
|
141
|
+
expect(data['baz'].length).to eq(2)
|
142
142
|
end
|
143
143
|
end
|
144
144
|
|
145
145
|
context "with a source limit" do
|
146
|
-
it "
|
147
|
-
metric = Metrics.get_metric :my_counter, :
|
146
|
+
it "only returns that source" do
|
147
|
+
metric = Metrics.get_metric :my_counter, source: 'baz', start_time: Time.now-3600
|
148
148
|
data = metric['measurements']
|
149
|
-
data['baz'].length.
|
150
|
-
data['unassigned'].
|
149
|
+
expect(data['baz'].length).to eq(2)
|
150
|
+
expect(data['unassigned']).to be_nil
|
151
151
|
end
|
152
152
|
end
|
153
153
|
|
@@ -156,20 +156,20 @@ module Librato
|
|
156
156
|
describe "#metrics" do
|
157
157
|
before(:all) do
|
158
158
|
delete_all_metrics
|
159
|
-
Metrics.submit :
|
159
|
+
Metrics.submit foo: 123, bar: 345, baz: 678, foo_2: 901
|
160
160
|
end
|
161
161
|
|
162
162
|
context "without arguments" do
|
163
|
-
it "
|
163
|
+
it "lists all metrics" do
|
164
164
|
metric_names = Metrics.metrics.map { |metric| metric['name'] }
|
165
|
-
metric_names.sort.
|
165
|
+
expect(metric_names.sort).to eq(%w{foo bar baz foo_2}.sort)
|
166
166
|
end
|
167
167
|
end
|
168
168
|
|
169
169
|
context "with a name argument" do
|
170
|
-
it "
|
171
|
-
metric_names = Metrics.metrics(:
|
172
|
-
metric_names.sort.
|
170
|
+
it "lists metrics that match" do
|
171
|
+
metric_names = Metrics.metrics(name: 'foo').map { |metric| metric['name'] }
|
172
|
+
expect(metric_names.sort).to eq(%w{foo foo_2}.sort)
|
173
173
|
end
|
174
174
|
end
|
175
175
|
|
@@ -180,18 +180,18 @@ module Librato
|
|
180
180
|
context "with a gauge" do
|
181
181
|
before(:all) do
|
182
182
|
delete_all_metrics
|
183
|
-
Metrics.submit :
|
183
|
+
Metrics.submit foo: 123
|
184
184
|
end
|
185
185
|
|
186
|
-
it "
|
186
|
+
it "creates the metrics" do
|
187
187
|
metric = Metrics.metrics[0]
|
188
|
-
metric['name'].
|
189
|
-
metric['type'].
|
188
|
+
expect(metric['name']).to eq('foo')
|
189
|
+
expect(metric['type']).to eq('gauge')
|
190
190
|
end
|
191
191
|
|
192
|
-
it "
|
193
|
-
data = Metrics.get_measurements :foo, :
|
194
|
-
data.
|
192
|
+
it "stores their data" do
|
193
|
+
data = Metrics.get_measurements :foo, count: 1
|
194
|
+
expect(data).not_to be_empty
|
195
195
|
data['unassigned'][0]['value'] == 123.0
|
196
196
|
end
|
197
197
|
end
|
@@ -199,31 +199,31 @@ module Librato
|
|
199
199
|
context "with a counter" do
|
200
200
|
before(:all) do
|
201
201
|
delete_all_metrics
|
202
|
-
Metrics.submit :
|
202
|
+
Metrics.submit bar: {type: :counter, source: 'baz', value: 456}
|
203
203
|
end
|
204
204
|
|
205
|
-
it "
|
205
|
+
it "creates the metrics" do
|
206
206
|
metric = Metrics.metrics[0]
|
207
|
-
metric['name'].
|
208
|
-
metric['type'].
|
207
|
+
expect(metric['name']).to eq('bar')
|
208
|
+
expect(metric['type']).to eq('counter')
|
209
209
|
end
|
210
210
|
|
211
|
-
it "
|
212
|
-
data = Metrics.get_measurements :bar, :
|
213
|
-
data.
|
211
|
+
it "stores their data" do
|
212
|
+
data = Metrics.get_measurements :bar, count: 1
|
213
|
+
expect(data).not_to be_empty
|
214
214
|
data['baz'][0]['value'] == 456.0
|
215
215
|
end
|
216
216
|
end
|
217
217
|
|
218
|
-
it "
|
218
|
+
it "does not retain errors" do
|
219
219
|
delete_all_metrics
|
220
|
-
Metrics.submit :
|
221
|
-
|
222
|
-
Metrics.submit :
|
223
|
-
}.
|
224
|
-
|
225
|
-
Metrics.submit :
|
226
|
-
}.
|
220
|
+
Metrics.submit foo: {type: :counter, value: 12}
|
221
|
+
expect {
|
222
|
+
Metrics.submit foo: 15 # submitting as gauge
|
223
|
+
}.to raise_error
|
224
|
+
expect {
|
225
|
+
Metrics.submit foo: {type: :counter, value: 17}
|
226
|
+
}.not_to raise_error
|
227
227
|
end
|
228
228
|
|
229
229
|
end
|
@@ -234,46 +234,46 @@ module Librato
|
|
234
234
|
context "with an existing metric" do
|
235
235
|
before do
|
236
236
|
delete_all_metrics
|
237
|
-
Metrics.submit :
|
237
|
+
Metrics.submit foo: 123
|
238
238
|
end
|
239
239
|
|
240
|
-
it "
|
241
|
-
Metrics.update_metric :foo, :
|
242
|
-
:
|
243
|
-
:
|
244
|
-
:
|
240
|
+
it "updates the metric" do
|
241
|
+
Metrics.update_metric :foo, display_name: "Foo Metric",
|
242
|
+
period: 15,
|
243
|
+
attributes: {
|
244
|
+
display_max: 1000
|
245
245
|
}
|
246
246
|
foo = Metrics.get_metric :foo
|
247
|
-
foo['display_name'].
|
248
|
-
foo['period'].
|
249
|
-
foo['attributes']['display_max'].
|
247
|
+
expect(foo['display_name']).to eq('Foo Metric')
|
248
|
+
expect(foo['period']).to eq(15)
|
249
|
+
expect(foo['attributes']['display_max']).to eq(1000)
|
250
250
|
end
|
251
251
|
end
|
252
252
|
|
253
253
|
context "without an existing metric" do
|
254
|
-
it "
|
254
|
+
it "creates the metric if type specified" do
|
255
255
|
delete_all_metrics
|
256
|
-
Metrics.update_metric :foo, :
|
257
|
-
:
|
258
|
-
:
|
259
|
-
:
|
260
|
-
:
|
256
|
+
Metrics.update_metric :foo, display_name: "Foo Metric",
|
257
|
+
type: 'gauge',
|
258
|
+
period: 15,
|
259
|
+
attributes: {
|
260
|
+
display_max: 1000
|
261
261
|
}
|
262
262
|
foo = Metrics.get_metric :foo
|
263
|
-
foo['display_name'].
|
264
|
-
foo['period'].
|
265
|
-
foo['attributes']['display_max'].
|
263
|
+
expect(foo['display_name']).to eq('Foo Metric')
|
264
|
+
expect(foo['period']).to eq(15)
|
265
|
+
expect(foo['attributes']['display_max']).to eq(1000)
|
266
266
|
end
|
267
267
|
|
268
|
-
it "
|
268
|
+
it "raises error if no type specified" do
|
269
269
|
delete_all_metrics
|
270
|
-
|
271
|
-
Metrics.update_metric :foo, :
|
272
|
-
:
|
273
|
-
:
|
274
|
-
:
|
270
|
+
expect {
|
271
|
+
Metrics.update_metric :foo, display_name: "Foo Metric",
|
272
|
+
period: 15,
|
273
|
+
attributes: {
|
274
|
+
display_max: 1000
|
275
275
|
}
|
276
|
-
}.
|
276
|
+
}.to raise_error
|
277
277
|
end
|
278
278
|
end
|
279
279
|
|
@@ -285,27 +285,27 @@ module Librato
|
|
285
285
|
Metrics.submit 'my.1' => 1, 'my.2' => 2, 'my.3' => 3, 'my.4' => 4
|
286
286
|
end
|
287
287
|
|
288
|
-
it "
|
288
|
+
it "supports named list" do
|
289
289
|
names = ['my.1', 'my.3']
|
290
|
-
Metrics.update_metrics :
|
290
|
+
Metrics.update_metrics names: names, period: 60
|
291
291
|
|
292
292
|
names.each do |name|
|
293
293
|
metric = Metrics.get_metric name
|
294
|
-
metric['period'].
|
294
|
+
expect(metric['period']).to eq(60)
|
295
295
|
end
|
296
296
|
end
|
297
297
|
|
298
|
-
it "
|
299
|
-
Metrics.update_metrics :
|
300
|
-
:
|
298
|
+
it "supports patterns" do
|
299
|
+
Metrics.update_metrics names: 'my.*', exclude: ['my.3'],
|
300
|
+
display_max: 100
|
301
301
|
|
302
302
|
%w{my.1 my.2 my.4}.each do |name|
|
303
303
|
metric = Metrics.get_metric name
|
304
|
-
metric['attributes']['display_max'].
|
304
|
+
expect(metric['attributes']['display_max']).to eq(100)
|
305
305
|
end
|
306
306
|
|
307
307
|
excluded = Metrics.get_metric 'my.3'
|
308
|
-
excluded['attributes']['display_max'].
|
308
|
+
expect(excluded['attributes']['display_max']).not_to eq(100)
|
309
309
|
end
|
310
310
|
end
|
311
311
|
end
|
@@ -316,45 +316,45 @@ module Librato
|
|
316
316
|
end
|
317
317
|
|
318
318
|
describe "#sources" do
|
319
|
-
it "
|
319
|
+
it "works" do
|
320
320
|
sources = Metrics.sources
|
321
|
-
sources.
|
321
|
+
expect(sources).to be_an(Array)
|
322
322
|
test_source = sources.detect { |s| s["name"] == "sources_api_test" }
|
323
|
-
test_source["display_name"].
|
323
|
+
expect(test_source["display_name"]).to eq("Sources Api Test")
|
324
324
|
end
|
325
325
|
|
326
|
-
it "
|
326
|
+
it "allows filtering by name" do
|
327
327
|
sources = Metrics.sources name: 'sources_api_test'
|
328
|
-
sources.all? {|s| s['name'] =~ /sources_api_test/}.
|
328
|
+
expect(sources.all? {|s| s['name'] =~ /sources_api_test/}).to be_truthy
|
329
329
|
end
|
330
330
|
end
|
331
331
|
|
332
332
|
describe "#get_source" do
|
333
|
-
it "
|
333
|
+
it "works" do
|
334
334
|
test_source = Metrics.get_source("sources_api_test")
|
335
|
-
test_source["display_name"].
|
335
|
+
expect(test_source["display_name"]).to eq("Sources Api Test")
|
336
336
|
end
|
337
337
|
end
|
338
338
|
|
339
339
|
describe "#update_source" do
|
340
|
-
it "
|
340
|
+
it "updates an existing source" do
|
341
341
|
Metrics.update_source("sources_api_test", display_name: "Updated Source Name")
|
342
342
|
|
343
343
|
test_source = Metrics.get_source("sources_api_test")
|
344
|
-
test_source["display_name"].
|
344
|
+
expect(test_source["display_name"]).to eq("Updated Source Name")
|
345
345
|
end
|
346
346
|
|
347
|
-
it "
|
347
|
+
it "creates new sources" do
|
348
348
|
source_name = "sources_api_test_#{Time.now.to_f}"
|
349
|
-
|
349
|
+
expect {
|
350
350
|
no_source = Metrics.get_source(source_name)
|
351
|
-
}.
|
351
|
+
}.to raise_error(Librato::Metrics::NotFound)
|
352
352
|
|
353
353
|
Metrics.update_source(source_name, display_name: "New Source")
|
354
354
|
|
355
355
|
test_source = Metrics.get_source(source_name)
|
356
|
-
test_source.
|
357
|
-
test_source["display_name"].
|
356
|
+
expect(test_source).not_to be_nil
|
357
|
+
expect(test_source["display_name"]).to eq("New Source")
|
358
358
|
end
|
359
359
|
end
|
360
360
|
|