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
@@ -14,15 +14,15 @@ module Librato::Metrics
|
|
14
14
|
# annotator.add :deployments, 'deployed v45'
|
15
15
|
#
|
16
16
|
# @example Annotation with start and end times
|
17
|
-
# annotator.add :deployments, 'deployed v56', :
|
18
|
-
# :
|
17
|
+
# annotator.add :deployments, 'deployed v56', start_time: start,
|
18
|
+
# end_time: end_time
|
19
19
|
#
|
20
20
|
# @example Annotation with a specific source
|
21
|
-
# annotator.add :deployments, 'deployed v60', :
|
21
|
+
# annotator.add :deployments, 'deployed v60', source: 'app12'
|
22
22
|
#
|
23
23
|
# @example Annotation with a description
|
24
24
|
# annotator.add :deployments, 'deployed v61',
|
25
|
-
# :
|
25
|
+
# description: '9b562b2: shipped new feature foo!'
|
26
26
|
#
|
27
27
|
# @example Annotate with automatic start and end times
|
28
28
|
# annotator.add(:deployments, 'deployed v62') do
|
@@ -41,7 +41,7 @@ module Librato::Metrics
|
|
41
41
|
event = SmartJSON.read(response.body)
|
42
42
|
if block_given?
|
43
43
|
yield
|
44
|
-
update_event stream, event['id'], :
|
44
|
+
update_event stream, event['id'], end_time: Time.now.to_i
|
45
45
|
# need to get updated representation
|
46
46
|
event = fetch_event stream, event['id']
|
47
47
|
end
|
@@ -85,12 +85,12 @@ module Librato::Metrics
|
|
85
85
|
# annotator.fetch :deployments
|
86
86
|
#
|
87
87
|
# @example Get events on 'deployments' between start and end times
|
88
|
-
# annotator.fetch :deployments, :
|
89
|
-
# :
|
88
|
+
# annotator.fetch :deployments, start_time: start,
|
89
|
+
# end_time: end_time
|
90
90
|
#
|
91
91
|
# @example Source-limited listing
|
92
|
-
# annotator.fetch :deployments, :
|
93
|
-
# :
|
92
|
+
# annotator.fetch :deployments, sources: ['foo','bar','baz'],
|
93
|
+
# start_time: start, end_time: end_time
|
94
94
|
#
|
95
95
|
def fetch(stream, options={})
|
96
96
|
response = connection.get("annotations/#{stream}", options)
|
@@ -113,7 +113,7 @@ module Librato::Metrics
|
|
113
113
|
# streams = annotator.list
|
114
114
|
#
|
115
115
|
# @example List annotator streams with 'deploy' in the name
|
116
|
-
# deploy_streams = annotator.list :
|
116
|
+
# deploy_streams = annotator.list name: 'deploy'
|
117
117
|
#
|
118
118
|
def list(options={})
|
119
119
|
response = connection.get("annotations", options)
|
@@ -123,7 +123,7 @@ module Librato::Metrics
|
|
123
123
|
# Update an event's properties
|
124
124
|
#
|
125
125
|
# @example Set an end time for a previously submitted event
|
126
|
-
# annotator.update_event 'deploys', 'v24', :
|
126
|
+
# annotator.update_event 'deploys', 'v24', end_time: end_time
|
127
127
|
#
|
128
128
|
def update_event(stream, id, options={})
|
129
129
|
url = "annotations/#{stream}/#{id}"
|
@@ -31,7 +31,7 @@ module Librato
|
|
31
31
|
end
|
32
32
|
|
33
33
|
def annotator
|
34
|
-
@annotator ||= Annotator.new(:
|
34
|
+
@annotator ||= Annotator.new(client: self)
|
35
35
|
end
|
36
36
|
|
37
37
|
# API endpoint to use for queries and direct
|
@@ -65,8 +65,8 @@ module Librato
|
|
65
65
|
def connection
|
66
66
|
# prevent successful creation if no credentials set
|
67
67
|
raise CredentialsMissing unless (self.email and self.api_key)
|
68
|
-
@connection ||= Connection.new(:
|
69
|
-
:
|
68
|
+
@connection ||= Connection.new(client: self, api_endpoint: api_endpoint,
|
69
|
+
adapter: faraday_adapter, proxy: self.proxy)
|
70
70
|
end
|
71
71
|
|
72
72
|
# Overrride user agent for this client's connections. If you
|
@@ -92,14 +92,14 @@ module Librato
|
|
92
92
|
# Librato::Metrics.delete_metrics :foo, :bar
|
93
93
|
#
|
94
94
|
# @example Delete metrics that start with 'foo' except 'foobar'
|
95
|
-
# Librato::Metrics.delete_metrics :
|
95
|
+
# Librato::Metrics.delete_metrics names: 'foo*', exclude: ['foobar']
|
96
96
|
#
|
97
97
|
def delete_metrics(*metric_names)
|
98
98
|
raise(NoMetricsProvided, 'Metric name missing.') if metric_names.empty?
|
99
99
|
if metric_names[0].respond_to?(:keys) # hash form
|
100
100
|
params = metric_names[0]
|
101
101
|
else
|
102
|
-
params = { :
|
102
|
+
params = { names: metric_names.map(&:to_s) }
|
103
103
|
end
|
104
104
|
connection.delete do |request|
|
105
105
|
request.url connection.build_url("metrics")
|
@@ -109,12 +109,6 @@ module Librato
|
|
109
109
|
true
|
110
110
|
end
|
111
111
|
|
112
|
-
# Completely delete metrics with the given names. Be
|
113
|
-
# careful with this, this is instant and permanent.
|
114
|
-
#
|
115
|
-
# @deprecated Use {#delete_metrics} instead
|
116
|
-
def delete(*metric_names); delete_metrics(*metric_names); end
|
117
|
-
|
118
112
|
# Return current adapter this client will use.
|
119
113
|
# Defaults to Metrics.faraday_adapter if set, otherwise
|
120
114
|
# Faraday.default_adapter
|
@@ -127,42 +121,6 @@ module Librato
|
|
127
121
|
@faraday_adapter = adapter
|
128
122
|
end
|
129
123
|
|
130
|
-
# Query metric data
|
131
|
-
#
|
132
|
-
# @deprecated Use {#get_metric} or {#get_measurements} instead.
|
133
|
-
#
|
134
|
-
# @example Get attributes for a metric
|
135
|
-
# attrs = Librato::Metrics.fetch :temperature
|
136
|
-
#
|
137
|
-
# @example Get 20 most recent data points for metric
|
138
|
-
# data = Librato::Metrics.fetch :temperature, :count => 20
|
139
|
-
#
|
140
|
-
# @example Get 20 most recent data points for a specific source
|
141
|
-
# data = Librato::Metrics.fetch :temperature, :count => 20,
|
142
|
-
# :source => 'app1'
|
143
|
-
#
|
144
|
-
# @example Get the 20 most recent 15 minute data point rollups
|
145
|
-
# data = Librato::Metrics.fetch :temperature, :count => 20,
|
146
|
-
# :resolution => 900
|
147
|
-
#
|
148
|
-
# @example Get data points for the last hour
|
149
|
-
# data = Librato::Metrics.fetch :start_time => Time.now-3600
|
150
|
-
#
|
151
|
-
# @example Get 15 min data points from two hours to an hour ago
|
152
|
-
# data = Librato::Metrics.fetch :start_time => Time.now-7200,
|
153
|
-
# :end_time => Time.now-3600,
|
154
|
-
# :resolution => 900
|
155
|
-
#
|
156
|
-
# A full list of query parameters can be found in the API
|
157
|
-
# documentation: {http://dev.librato.com/v1/get/metrics/:name}
|
158
|
-
#
|
159
|
-
# @param [Symbol|String] metric Metric name
|
160
|
-
# @param [Hash] options Query options
|
161
|
-
def fetch(metric, options={})
|
162
|
-
metric = get_metric(metric, options)
|
163
|
-
options.empty? ? metric : metric["measurements"]
|
164
|
-
end
|
165
|
-
|
166
124
|
# Retrieve measurements for a given composite metric definition.
|
167
125
|
# :start_time and :resolution are required options, :end_time is
|
168
126
|
# optional.
|
@@ -170,7 +128,7 @@ module Librato
|
|
170
128
|
# @example Get 5m moving average of 'foo'
|
171
129
|
# measurements = Librato::Metrics.get_composite
|
172
130
|
# 'moving_average(mean(series("foo", "*"), {size: "5"}))',
|
173
|
-
# :
|
131
|
+
# start_time: Time.now.to_i - 60*60, resolution: 300
|
174
132
|
#
|
175
133
|
# @param [String] definition Composite definition
|
176
134
|
# @param [hash] options Query options
|
@@ -193,7 +151,7 @@ module Librato
|
|
193
151
|
# metric = Librato::Metrics.get_metric :temperature
|
194
152
|
#
|
195
153
|
# @example Get a metric and its 20 most recent data points
|
196
|
-
# metric = Librato::Metrics.get_metric :temperature, :
|
154
|
+
# metric = Librato::Metrics.get_metric :temperature, count: 20
|
197
155
|
# metric['measurements'] # => {...}
|
198
156
|
#
|
199
157
|
# A full list of query parameters can be found in the API
|
@@ -223,23 +181,23 @@ module Librato
|
|
223
181
|
# Retrieve data points for a specific metric
|
224
182
|
#
|
225
183
|
# @example Get 20 most recent data points for metric
|
226
|
-
# data = Librato::Metrics.get_measurements :temperature, :
|
184
|
+
# data = Librato::Metrics.get_measurements :temperature, count: 20
|
227
185
|
#
|
228
186
|
# @example Get 20 most recent data points for a specific source
|
229
|
-
# data = Librato::Metrics.get_measurements :temperature, :
|
230
|
-
# :
|
187
|
+
# data = Librato::Metrics.get_measurements :temperature, count: 20,
|
188
|
+
# source: 'app1'
|
231
189
|
#
|
232
190
|
# @example Get the 20 most recent 15 minute data point rollups
|
233
|
-
# data = Librato::Metrics.get_measurements :temperature, :
|
234
|
-
# :
|
191
|
+
# data = Librato::Metrics.get_measurements :temperature, count: 20,
|
192
|
+
# resolution: 900
|
235
193
|
#
|
236
194
|
# @example Get data points for the last hour
|
237
|
-
# data = Librato::Metrics.get_measurements :
|
195
|
+
# data = Librato::Metrics.get_measurements start_time: Time.now-3600
|
238
196
|
#
|
239
197
|
# @example Get 15 min data points from two hours to an hour ago
|
240
|
-
# data = Librato::Metrics.get_measurements :
|
241
|
-
# :
|
242
|
-
# :
|
198
|
+
# data = Librato::Metrics.get_measurements start_time: Time.now-7200,
|
199
|
+
# end_time: Time.now-3600,
|
200
|
+
# resolution: 900
|
243
201
|
#
|
244
202
|
# A full list of query parameters can be found in the API
|
245
203
|
# documentation: {http://dev.librato.com/v1/get/metrics/:name}
|
@@ -265,7 +223,7 @@ module Librato
|
|
265
223
|
# Librato::Metrics.metrics
|
266
224
|
#
|
267
225
|
# @example List metrics with 'foo' in the name
|
268
|
-
# Librato::Metrics.metrics :
|
226
|
+
# Librato::Metrics.metrics name: 'foo'
|
269
227
|
#
|
270
228
|
# @param [Hash] options
|
271
229
|
def metrics(options={})
|
@@ -276,11 +234,6 @@ module Librato
|
|
276
234
|
Collection.paginated_metrics(connection, path, query)
|
277
235
|
end
|
278
236
|
|
279
|
-
# List currently existing metrics
|
280
|
-
#
|
281
|
-
# @deprecated Use {#metrics} instead
|
282
|
-
def list(options={}); metrics(options); end
|
283
|
-
|
284
237
|
# Create a new queue which uses this client.
|
285
238
|
#
|
286
239
|
# @return [Queue]
|
@@ -312,9 +265,9 @@ module Librato
|
|
312
265
|
# Submit all queued metrics.
|
313
266
|
#
|
314
267
|
def submit(args)
|
315
|
-
@queue ||= Queue.new(:
|
316
|
-
:
|
317
|
-
:
|
268
|
+
@queue ||= Queue.new(client: self,
|
269
|
+
skip_measurement_times: true,
|
270
|
+
clear_failures: true)
|
318
271
|
@queue.add args
|
319
272
|
@queue.submit
|
320
273
|
end
|
@@ -322,10 +275,10 @@ module Librato
|
|
322
275
|
# Update a single metric with new attributes.
|
323
276
|
#
|
324
277
|
# @example Update metric 'temperature'
|
325
|
-
# Librato::Metrics.update_metric :temperature, :
|
278
|
+
# Librato::Metrics.update_metric :temperature, period: 15, attributes: { color: 'F00' }
|
326
279
|
#
|
327
280
|
# @example Update metric 'humidity', creating it if it doesn't exist
|
328
|
-
# Librato::Metrics.update_metric 'humidity', :
|
281
|
+
# Librato::Metrics.update_metric 'humidity', type: :gauge, period: 60, display_name: 'Humidity'
|
329
282
|
#
|
330
283
|
def update_metric(metric, options = {})
|
331
284
|
url = "metrics/#{metric}"
|
@@ -338,10 +291,10 @@ module Librato
|
|
338
291
|
# Update multiple metrics.
|
339
292
|
#
|
340
293
|
# @example Update multiple metrics by name
|
341
|
-
# Librato::Metrics.update_metrics :
|
294
|
+
# Librato::Metrics.update_metrics names: ["foo", "bar"], period: 60
|
342
295
|
#
|
343
296
|
# @example Update all metrics that start with 'foo' that aren't 'foobar'
|
344
|
-
# Librato::Metrics.update_metrics :
|
297
|
+
# Librato::Metrics.update_metrics names: 'foo*', exclude: ['foobar'], display_min: 0
|
345
298
|
#
|
346
299
|
def update_metrics(metrics)
|
347
300
|
url = "metrics" # update multiple metrics
|
@@ -351,26 +304,6 @@ module Librato
|
|
351
304
|
end
|
352
305
|
end
|
353
306
|
|
354
|
-
# Update one or more metrics. Note that attributes are specified in
|
355
|
-
# their own hash for updating a single metric but are included inline
|
356
|
-
# when updating multiple metrics.
|
357
|
-
#
|
358
|
-
# @deprecated Use {#update_metric} or {#update_metrics} instead
|
359
|
-
def update(metric, options={})
|
360
|
-
if metric.respond_to?(:each)
|
361
|
-
update_metrics(metric)
|
362
|
-
else
|
363
|
-
update_metric(metric, options)
|
364
|
-
end
|
365
|
-
end
|
366
|
-
|
367
|
-
# Update one or more metrics. Note that attributes are specified in
|
368
|
-
# their own hash for updating a single metric but are included inline
|
369
|
-
# when updating multiple metrics.
|
370
|
-
#
|
371
|
-
# @deprecated Use #update_metric instead
|
372
|
-
alias update update_metric
|
373
|
-
|
374
307
|
# List sources, optionally limited by a name. See http://dev.librato.com/v1/sources
|
375
308
|
# and http://dev.librato.com/v1/get/sources
|
376
309
|
#
|
@@ -31,8 +31,8 @@ module Librato
|
|
31
31
|
def transport
|
32
32
|
raise(NoClientProvided, "No client provided.") unless @client
|
33
33
|
@transport ||= Faraday::Connection.new(
|
34
|
-
:
|
35
|
-
:
|
34
|
+
url: api_endpoint + "/v1/",
|
35
|
+
request: {open_timeout: 20, timeout: 30}) do |f|
|
36
36
|
|
37
37
|
f.use Librato::Metrics::Middleware::RequestBody
|
38
38
|
f.use Librato::Metrics::Middleware::Retry
|
@@ -16,7 +16,7 @@ module Librato
|
|
16
16
|
env[:body] = request_body # after failure is set to response body
|
17
17
|
@app.call(env)
|
18
18
|
rescue Librato::Metrics::ServerError, Timeout::Error,
|
19
|
-
Faraday::ConnectionFailed
|
19
|
+
Faraday::Error::ConnectionFailed
|
20
20
|
if retries > 0
|
21
21
|
retries -= 1 and retry
|
22
22
|
end
|
@@ -30,7 +30,7 @@ module Librato
|
|
30
30
|
# @return Boolean
|
31
31
|
def submit
|
32
32
|
return true if self.queued.empty?
|
33
|
-
options = {:
|
33
|
+
options = {per_request: @per_request}
|
34
34
|
if persister.persist(self.client, self.queued, options)
|
35
35
|
@last_submit_time = Time.now
|
36
36
|
clear and return true
|
@@ -54,7 +54,7 @@ module Librato
|
|
54
54
|
# end
|
55
55
|
#
|
56
56
|
# @example Queue API request response time w/ source
|
57
|
-
# queue.time :api_request_time, :
|
57
|
+
# queue.time :api_request_time, source: 'app1' do
|
58
58
|
# # API request..
|
59
59
|
# end
|
60
60
|
#
|
@@ -64,7 +64,7 @@ module Librato
|
|
64
64
|
start = Time.now
|
65
65
|
yield.tap do
|
66
66
|
duration = (Time.now - start) * 1000.0 # milliseconds
|
67
|
-
metric = {name => options.merge({:
|
67
|
+
metric = {name => options.merge({value: duration})}
|
68
68
|
add metric
|
69
69
|
end
|
70
70
|
end
|
@@ -1,25 +1,36 @@
|
|
1
|
-
require 'multi_json'
|
2
|
-
|
3
1
|
module Librato
|
4
2
|
module Metrics
|
5
3
|
class SmartJSON
|
6
|
-
JSON_HANDLER = MultiJson
|
7
4
|
extend SingleForwardable
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
5
|
+
|
6
|
+
if defined?(::MultiJson)
|
7
|
+
# MultiJSON >= 1.3.0
|
8
|
+
if MultiJson.respond_to?(:load)
|
9
|
+
def_delegator MultiJson, :load, :read
|
10
|
+
else
|
11
|
+
def_delegator MultiJson, :decode, :read
|
12
|
+
end
|
13
|
+
|
14
|
+
# MultiJSON <= 1.2.0
|
15
|
+
if MultiJson.respond_to?(:dump)
|
16
|
+
def_delegator MultiJson, :dump, :write
|
17
|
+
else
|
18
|
+
def_delegator MultiJson, :encode, :write
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.handler
|
22
|
+
:multi_json
|
23
|
+
end
|
19
24
|
else
|
20
|
-
|
21
|
-
end
|
25
|
+
require "json"
|
22
26
|
|
27
|
+
def_delegator JSON, :parse, :read
|
28
|
+
def_delegator JSON, :generate, :write
|
29
|
+
|
30
|
+
def self.handler
|
31
|
+
:json
|
32
|
+
end
|
33
|
+
end
|
23
34
|
end
|
24
35
|
end
|
25
36
|
end
|
data/librato-metrics.gemspec
CHANGED
@@ -7,6 +7,7 @@ Gem::Specification.new do |s|
|
|
7
7
|
s.specification_version = 2 if s.respond_to? :specification_version=
|
8
8
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
9
9
|
s.rubygems_version = '1.3.5'
|
10
|
+
s.required_ruby_version = '>= 1.9'
|
10
11
|
|
11
12
|
s.name = 'librato-metrics'
|
12
13
|
s.version = Librato::Metrics::VERSION
|
@@ -25,8 +26,7 @@ Gem::Specification.new do |s|
|
|
25
26
|
s.extra_rdoc_files = %w[LICENSE]
|
26
27
|
|
27
28
|
## runtime dependencies
|
28
|
-
s.add_dependency 'faraday'
|
29
|
-
s.add_dependency 'multi_json'
|
29
|
+
s.add_dependency 'faraday'
|
30
30
|
s.add_dependency 'aggregate', '~> 0.2.2'
|
31
31
|
|
32
32
|
# omitting for now because jruby-19mode can't handle
|
@@ -8,135 +8,135 @@ module Librato
|
|
8
8
|
before(:each) { delete_all_annotations }
|
9
9
|
|
10
10
|
describe "#add" do
|
11
|
-
it "
|
11
|
+
it "creates new annotation" do
|
12
12
|
subject.add :deployment, "deployed v68"
|
13
|
-
annos = subject.fetch(:deployment, :
|
14
|
-
annos["events"]["unassigned"].length.
|
15
|
-
annos["events"]["unassigned"][0]["title"].
|
16
|
-
end
|
17
|
-
it "
|
18
|
-
subject.add :deployment, 'deployed v69', :
|
19
|
-
annos = subject.fetch(:deployment, :
|
20
|
-
annos["events"]["box1"].length.
|
13
|
+
annos = subject.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
|
+
end
|
17
|
+
it "supports sources" do
|
18
|
+
subject.add :deployment, 'deployed v69', source: 'box1'
|
19
|
+
annos = subject.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
|
-
subject.add :deployment, 'deployed v70', :
|
28
|
-
:
|
29
|
-
annos = subject.fetch(:deployment, :
|
30
|
-
annos["events"]["unassigned"].length.
|
27
|
+
subject.add :deployment, 'deployed v70', start_time: start_time,
|
28
|
+
end_time: end_time
|
29
|
+
annos = subject.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'].
|
35
|
-
end
|
36
|
-
it "
|
37
|
-
subject.add :deployment, 'deployed v71', :
|
38
|
-
annos = subject.fetch(:deployment, :
|
39
|
-
annos["events"]["unassigned"].length.
|
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
|
+
end
|
36
|
+
it "supports description" do
|
37
|
+
subject.add :deployment, 'deployed v71', description: 'deployed foobar!'
|
38
|
+
annos = subject.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
|
-
it "
|
44
|
+
it "has an id for further use" do
|
45
45
|
annotation = subject.add :deployment, "deployed v23"
|
46
|
-
annotation['id'].
|
46
|
+
expect(annotation['id']).not_to be_nil
|
47
47
|
end
|
48
48
|
|
49
49
|
context "with a block" do
|
50
|
-
it "
|
50
|
+
it "sets both start and end times" do
|
51
51
|
annotation = subject.add 'deploys', 'v345' do
|
52
52
|
sleep 1.0
|
53
53
|
end
|
54
54
|
data = subject.fetch_event 'deploys', annotation['id']
|
55
|
-
data['start_time'].
|
56
|
-
data['end_time'].
|
55
|
+
expect(data['start_time']).not_to be_nil
|
56
|
+
expect(data['end_time']).not_to be_nil
|
57
57
|
end
|
58
58
|
end
|
59
59
|
end
|
60
60
|
|
61
61
|
describe "#delete" do
|
62
|
-
it "
|
62
|
+
it "removes annotation streams" do
|
63
63
|
subject.add :deployment, "deployed v45"
|
64
64
|
subject.fetch :deployment # should exist
|
65
65
|
subject.delete :deployment
|
66
|
-
|
66
|
+
expect {
|
67
67
|
subject.fetch(:deployment)
|
68
|
-
}.
|
68
|
+
}.to raise_error(Metrics::NotFound)
|
69
69
|
end
|
70
70
|
end
|
71
71
|
|
72
72
|
describe "#delete_event" do
|
73
|
-
it "
|
73
|
+
it "removes an annotation event" do
|
74
74
|
subject.add :deployment, 'deployed v46'
|
75
75
|
subject.add :deployment, 'deployed v47'
|
76
|
-
events = subject.fetch(:deployment, :
|
76
|
+
events = subject.fetch(:deployment, start_time: Time.now.to_i-60)
|
77
77
|
events = events['events']['unassigned']
|
78
78
|
ids = events.reduce({}) do |hash, event|
|
79
79
|
hash[event['title']] = event['id']
|
80
80
|
hash
|
81
81
|
end
|
82
82
|
subject.delete_event :deployment, ids['deployed v47']
|
83
|
-
events = subject.fetch(:deployment, :
|
83
|
+
events = subject.fetch(:deployment, start_time: Time.now.to_i-60)
|
84
84
|
events = events['events']['unassigned']
|
85
|
-
events.length.
|
86
|
-
events[0]['title'].
|
85
|
+
expect(events.length).to eq(1)
|
86
|
+
expect(events[0]['title']).to eq('deployed v46')
|
87
87
|
end
|
88
88
|
end
|
89
89
|
|
90
90
|
describe "#fetch" do
|
91
91
|
context "without a time frame" do
|
92
|
-
it "
|
92
|
+
it "returns stream properties" do
|
93
93
|
subject.add :backups, "backup 21"
|
94
94
|
properties = subject.fetch :backups
|
95
|
-
properties['name'].
|
95
|
+
expect(properties['name']).to eq('backups')
|
96
96
|
end
|
97
97
|
end
|
98
98
|
|
99
99
|
context "with a time frame" do
|
100
|
-
it "
|
100
|
+
it "returns set of annotations" do
|
101
101
|
subject.add :backups, "backup 22"
|
102
102
|
subject.add :backups, "backup 23"
|
103
|
-
annos = subject.fetch :backups, :
|
103
|
+
annos = subject.fetch :backups, start_time: Time.now.to_i-60
|
104
104
|
events = annos['events']['unassigned']
|
105
|
-
events[0]['title'].
|
106
|
-
events[1]['title'].
|
105
|
+
expect(events[0]['title']).to eq('backup 22')
|
106
|
+
expect(events[1]['title']).to eq('backup 23')
|
107
107
|
end
|
108
|
-
it "
|
109
|
-
subject.add :backups, "backup 24", :
|
110
|
-
subject.add :backups, "backup 25", :
|
111
|
-
subject.add :backups, "backup 26", :
|
112
|
-
annos = subject.fetch :backups, :
|
113
|
-
:
|
114
|
-
annos['events']['server_1'].
|
115
|
-
annos['events']['server_2'].
|
116
|
-
annos['events']['server_3'].
|
108
|
+
it "respects source limits" do
|
109
|
+
subject.add :backups, "backup 24", source: 'server_1'
|
110
|
+
subject.add :backups, "backup 25", source: 'server_2'
|
111
|
+
subject.add :backups, "backup 26", source: 'server_3'
|
112
|
+
annos = subject.fetch :backups, start_time: Time.now.to_i-60,
|
113
|
+
sources: %w{server_1 server_3}
|
114
|
+
expect(annos['events']['server_1']).not_to be_nil
|
115
|
+
expect(annos['events']['server_2']).to be_nil
|
116
|
+
expect(annos['events']['server_3']).not_to be_nil
|
117
117
|
end
|
118
118
|
end
|
119
119
|
|
120
|
-
it "
|
121
|
-
|
120
|
+
it "returns exception if annotation is missing" do
|
121
|
+
expect {
|
122
122
|
subject.fetch :backups
|
123
|
-
}.
|
123
|
+
}.to raise_error(Metrics::NotFound)
|
124
124
|
end
|
125
125
|
end
|
126
126
|
|
127
127
|
describe "#fetch_event" do
|
128
128
|
context "with existing event" do
|
129
|
-
it "
|
129
|
+
it "returns event properties" do
|
130
130
|
annotation = subject.add 'deploys', 'v69'
|
131
131
|
data = subject.fetch_event 'deploys', annotation['id']
|
132
|
-
data['title'].
|
132
|
+
expect(data['title']).to eq('v69')
|
133
133
|
end
|
134
134
|
end
|
135
135
|
context "when event doesn't exist" do
|
136
|
-
it "
|
137
|
-
|
136
|
+
it "raises NotFound" do
|
137
|
+
expect {
|
138
138
|
data = subject.fetch_event 'deploys', 324
|
139
|
-
}.
|
139
|
+
}.to raise_error(Metrics::NotFound)
|
140
140
|
end
|
141
141
|
end
|
142
142
|
end
|
@@ -148,35 +148,35 @@ module Librato
|
|
148
148
|
end
|
149
149
|
|
150
150
|
context "without arguments" do
|
151
|
-
it "
|
151
|
+
it "lists annotation streams" do
|
152
152
|
streams = subject.list
|
153
|
-
streams['annotations'].length.
|
153
|
+
expect(streams['annotations'].length).to eq(2)
|
154
154
|
streams = streams['annotations'].map{|i| i['name']}
|
155
|
-
streams.
|
156
|
-
streams.
|
155
|
+
expect(streams).to include('backups')
|
156
|
+
expect(streams).to include('deployment')
|
157
157
|
end
|
158
158
|
end
|
159
159
|
context "with an argument" do
|
160
|
-
it "
|
161
|
-
streams = subject.list :
|
162
|
-
streams['annotations'].length.
|
160
|
+
it "lists annotation streams which match" do
|
161
|
+
streams = subject.list name: 'back'
|
162
|
+
expect(streams['annotations'].length).to eq(1)
|
163
163
|
streams = streams['annotations'].map{|i| i['name']}
|
164
|
-
streams.
|
164
|
+
expect(streams).to include('backups')
|
165
165
|
end
|
166
166
|
end
|
167
167
|
end
|
168
168
|
|
169
169
|
describe "#update_event" do
|
170
170
|
context "when event exists" do
|
171
|
-
it "
|
171
|
+
it "updates event" do
|
172
172
|
end_time = (Time.now + 60).to_i
|
173
173
|
annotation = subject.add 'deploys', 'v24'
|
174
174
|
subject.update_event 'deploys', annotation['id'],
|
175
|
-
:
|
175
|
+
end_time: end_time, title: 'v28'
|
176
176
|
data = subject.fetch_event 'deploys', annotation['id']
|
177
177
|
|
178
|
-
data['title'].
|
179
|
-
data['end_time'].
|
178
|
+
expect(data['title']).to eq('v28')
|
179
|
+
expect(data['end_time']).to eq(end_time)
|
180
180
|
end
|
181
181
|
end
|
182
182
|
context "when event does not exist" do
|