librato-metrics 1.3.2 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
data.tar.gz.sig CHANGED
Binary file
data/CHANGELOG.md CHANGED
@@ -1,5 +1,8 @@
1
1
  ## Changelog
2
2
 
3
+ ### Version 1.4.0
4
+ * Add support for snapshots
5
+
3
6
  ### Version 1.3.2
4
7
  * Fix queue autosubmission to fire if needed after #merge! calls
5
8
 
data/README.md CHANGED
@@ -287,4 +287,4 @@ We also maintain a set of [examples of common uses](https://github.com/librato/l
287
287
 
288
288
  ## Copyright
289
289
 
290
- Copyright (c) 2011-2013 [Librato Inc.](http://librato.com) See LICENSE for details.
290
+ Copyright (c) 2011-2014 [Librato Inc.](http://librato.com) See LICENSE for details.
@@ -80,6 +80,7 @@ module Librato
80
80
  :delete_metrics, :update_metric, :update_metrics,
81
81
  :submit,
82
82
  :sources, :get_source, :update_source,
83
+ :create_snapshot, :get_snapshot,
83
84
  # Deprecated metrics methods
84
85
  :fetch, :list, :delete, :update
85
86
 
@@ -387,6 +387,38 @@ module Librato
387
387
  end
388
388
  end
389
389
 
390
+ # Create a snapshot of an instrument
391
+ #
392
+ # @example Take a snapshot of the instrument at https://metrics-api.librato.com/v1/instruments/42 using a
393
+ # duration of 3 hours and ending at now.
394
+ # Librato::Metrics.snapshot(subject: {instrument: {href: "https://metrics-api.librato.com/v1/instruments/42"}},
395
+ # duration: 3.hours, end_time: Time.now)
396
+ #
397
+ # @param Hash options Params for the snapshot
398
+ # @options options [Hash] :subject An object representing the subject of the snapshot. For now, only instruments are supported
399
+ # @options options [Numeric] :duration Time interval over which to take the snapshot, defaults to 1 hour
400
+ # @options options [Numeric, Time] :end_time Snapshot the time period of the duration, ending with end_time. Default is "now".
401
+ def create_snapshot(options = {})
402
+ url = "snapshots"
403
+ response = connection.post do |request|
404
+ request.url connection.build_url(url)
405
+ request.body = SmartJSON.write(options)
406
+ end
407
+ parsed = SmartJSON.read(response.body)
408
+ end
409
+
410
+ # Retrive a snapshot, to check its progress or find its image_href
411
+ #
412
+ # @example Get a snapshot identified by 42
413
+ # Librato::Metrics.get_snapshot 42
414
+ #
415
+ # @param [Integer|String] id
416
+ def get_snapshot(id)
417
+ url = "snapshots/#{id}"
418
+ response = connection.get(url)
419
+ parsed = SmartJSON.read(response.body)
420
+ end
421
+
390
422
  private
391
423
 
392
424
  def default_faraday_adapter
@@ -1,5 +1,5 @@
1
1
  module Librato
2
2
  module Metrics
3
- VERSION = "1.3.2"
3
+ VERSION = "1.4.0"
4
4
  end
5
5
  end
@@ -355,5 +355,35 @@ module Librato
355
355
 
356
356
  end
357
357
 
358
+ describe "Snapshots API" do
359
+
360
+ let(:instrument_id) do
361
+ instrument_options = {name: "Snapshot test subject"}
362
+ conn = Metrics.connection
363
+ resp = conn.post do |req|
364
+ req.url conn.build_url("/v1/instruments")
365
+ req.body = Librato::Metrics::SmartJSON.write(instrument_options)
366
+ end
367
+ instrument_id = Librato::Metrics::SmartJSON.read(resp.body)["id"]
368
+ end
369
+
370
+ let(:subject) do
371
+ {instrument: {href: "http://api.librato.dev/v1/instruments/#{instrument_id}"}}
372
+ end
373
+
374
+ it "should #create_snapshot" do
375
+ result = Metrics.create_snapshot(subject: subject)
376
+ result["href"].should =~ /snapshots\/\d+$/
377
+ end
378
+
379
+ it "should #get_snapshot" do
380
+ result = Metrics.create_snapshot(subject: subject)
381
+ snapshot_id = result["href"][/(\d+)$/]
382
+
383
+ result = Metrics.get_snapshot(snapshot_id)
384
+ result["href"].should =~ /snapshots\/\d+$/
385
+ end
386
+ end
387
+
358
388
  end
359
389
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: librato-metrics
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.2
4
+ version: 1.4.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -37,7 +37,7 @@ cert_chain:
37
37
  bktaNmhlblFBRjFDSDk2WmNxY0pIMTc5UzJ0SWlLRE04a2VlUklVT1BDM1dU
38
38
  MGZhb2svMgpnQTJvemRyODUxYy9uQT09Ci0tLS0tRU5EIENFUlRJRklDQVRF
39
39
  LS0tLS0K
40
- date: 2014-04-14 00:00:00.000000000 Z
40
+ date: 2014-05-21 00:00:00.000000000 Z
41
41
  dependencies:
42
42
  - !ruby/object:Gem::Dependency
43
43
  name: faraday
@@ -251,7 +251,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
251
251
  version: '0'
252
252
  segments:
253
253
  - 0
254
- hash: -3482606803820656168
254
+ hash: -879066088464311398
255
255
  required_rubygems_version: !ruby/object:Gem::Requirement
256
256
  none: false
257
257
  requirements:
metadata.gz.sig CHANGED
Binary file