librato-metrics 0.3.1 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +4 -0
- data/README.md +1 -1
- data/lib/librato/metrics.rb +3 -3
- data/lib/librato/metrics/errors.rb +1 -0
- data/lib/librato/metrics/simple.rb +34 -3
- data/lib/librato/metrics/version.rb +1 -1
- data/spec/spec_helper.rb +9 -0
- data/spec/unit/metrics/simple_spec.rb +46 -1
- metadata +15 -15
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -125,7 +125,7 @@ This is an early release and as such is lacking some capabilities slated for fut
|
|
125
125
|
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
|
126
126
|
* Fork the project and submit a pull request from a feature or bugfix branch.
|
127
127
|
* Please include specs. This is important so we don't break your changes unintentionally in a future version.
|
128
|
-
* Please don't modify the Rakefile, version, or
|
128
|
+
* Please don't modify the gemspec, Rakefile, version, or changelog. If you do change these files, please isolate a separate commit so we can cherry-pick around it.
|
129
129
|
|
130
130
|
## Copyright
|
131
131
|
|
data/lib/librato/metrics.rb
CHANGED
@@ -26,9 +26,9 @@ module Librato
|
|
26
26
|
# Expose class methods of Simple via Metrics itself.
|
27
27
|
#
|
28
28
|
# TODO: Explain exposed interface with examples.
|
29
|
-
def_delegators Librato::Metrics::Simple, :
|
30
|
-
:authenticate, :connection, :persistence,
|
31
|
-
:persister, :submit
|
29
|
+
def_delegators Librato::Metrics::Simple, :agent_identifier, :api_endpoint,
|
30
|
+
:api_endpoint=, :authenticate, :connection, :persistence,
|
31
|
+
:persistence=, :persister, :submit
|
32
32
|
|
33
33
|
# Query metric data
|
34
34
|
#
|
@@ -17,6 +17,28 @@ module Librato
|
|
17
17
|
# class instance vars
|
18
18
|
attr_accessor :email, :api_key
|
19
19
|
|
20
|
+
# Provide agent identifier for the developer program. See:
|
21
|
+
# http://support.metrics.librato.com/knowledgebase/articles/53548-developer-program
|
22
|
+
#
|
23
|
+
# @example Have the gem build your identifier string
|
24
|
+
# Librato::Metrics.agent_identifier 'flintstone', '0.5', 'fred'
|
25
|
+
#
|
26
|
+
# @example Provide your own identifier string
|
27
|
+
# Librato::Metrics.agent_identifier 'flintstone/0.5 (dev_id:fred)'
|
28
|
+
#
|
29
|
+
# @example Remove identifier string
|
30
|
+
# Librato::Metrics.agent_identifier ''
|
31
|
+
def agent_identifier(*args)
|
32
|
+
if args.length == 1
|
33
|
+
@agent_identifier = args.first
|
34
|
+
elsif args.length == 3
|
35
|
+
@agent_identifier = "#{args[0]}/#{args[1]} (dev_id:#{args[2]})"
|
36
|
+
elsif ![0,1,3].include?(args.length)
|
37
|
+
raise ArgumentError, 'invalid arguments, see method documentation'
|
38
|
+
end
|
39
|
+
@agent_identifier ||= ''
|
40
|
+
end
|
41
|
+
|
20
42
|
# API endpoint to use for queries and direct
|
21
43
|
# persistence.
|
22
44
|
#
|
@@ -71,11 +93,12 @@ module Librato
|
|
71
93
|
@persistence = persist_method
|
72
94
|
end
|
73
95
|
|
96
|
+
# Current persister object.
|
74
97
|
def persister
|
75
98
|
@queue ? @queue.persister : nil
|
76
99
|
end
|
77
100
|
|
78
|
-
# Submit all queued metrics
|
101
|
+
# Submit all queued metrics.
|
79
102
|
#
|
80
103
|
def submit(args)
|
81
104
|
@queue ||= Queue.new(:skip_measurement_times => true)
|
@@ -83,9 +106,17 @@ module Librato
|
|
83
106
|
@queue.submit
|
84
107
|
end
|
85
108
|
|
109
|
+
# User-agent used when making requests.
|
110
|
+
#
|
86
111
|
def user_agent
|
87
|
-
|
88
|
-
|
112
|
+
ua_chunks = []
|
113
|
+
if agent_identifier && !agent_identifier.empty?
|
114
|
+
ua_chunks << agent_identifier
|
115
|
+
end
|
116
|
+
ua_chunks << "librato-metrics/#{Metrics::VERSION}"
|
117
|
+
ua_chunks << "(#{ruby_engine}; #{RUBY_VERSION}p#{RUBY_PATCHLEVEL}; #{RUBY_PLATFORM})"
|
118
|
+
ua_chunks << "direct-excon/#{Excon::VERSION}"
|
119
|
+
ua_chunks.join(' ')
|
89
120
|
end
|
90
121
|
|
91
122
|
private
|
data/spec/spec_helper.rb
CHANGED
@@ -26,4 +26,13 @@ RSpec.configure do |config|
|
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
|
+
end
|
30
|
+
|
31
|
+
# Ex: 'foobar'.should start_with('foo') #=> true
|
32
|
+
#
|
33
|
+
RSpec::Matchers.define :start_with do |start_string|
|
34
|
+
match do |string|
|
35
|
+
start_length = start_string.length
|
36
|
+
string[0..start_length-1] == start_string
|
37
|
+
end
|
29
38
|
end
|
@@ -5,6 +5,35 @@ module Librato
|
|
5
5
|
|
6
6
|
describe Simple do
|
7
7
|
|
8
|
+
describe "#agent_identifier" do
|
9
|
+
context "when given a single string argument" do
|
10
|
+
it "should set agent_identifier" do
|
11
|
+
Simple.agent_identifier 'mycollector/0.1 (dev_id:foo)'
|
12
|
+
Simple.agent_identifier.should == 'mycollector/0.1 (dev_id:foo)'
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
context "when given three arguments" do
|
17
|
+
it "should compose an agent string" do
|
18
|
+
Simple.agent_identifier('test_app', '0.5', 'foobar')
|
19
|
+
Simple.agent_identifier.should == 'test_app/0.5 (dev_id:foobar)'
|
20
|
+
end
|
21
|
+
|
22
|
+
context "when given an empty string" do
|
23
|
+
it "should set to empty" do
|
24
|
+
Simple.agent_identifier ''
|
25
|
+
Simple.agent_identifier.should == ''
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
context "when given two arguments" do
|
31
|
+
it "should raise error" do
|
32
|
+
lambda { Simple.agent_identifier('test_app', '0.5') }.should raise_error(ArgumentError)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
8
37
|
describe "#api_endpoint" do
|
9
38
|
it "should default to metrics" do
|
10
39
|
Simple.api_endpoint.should == 'https://metrics-api.librato.com/v1/'
|
@@ -75,7 +104,23 @@ module Librato
|
|
75
104
|
end
|
76
105
|
end
|
77
106
|
|
107
|
+
describe "#user_agent" do
|
108
|
+
context "without an agent_identifier" do
|
109
|
+
it "should render standard string" do
|
110
|
+
Simple.agent_identifier('')
|
111
|
+
Simple.user_agent.should start_with('librato-metrics')
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
context "with an agent_identifier" do
|
116
|
+
it "should render agent_identifier first" do
|
117
|
+
Simple.agent_identifier('foo', '0.5', 'bar')
|
118
|
+
Simple.user_agent.should start_with('foo/0.5')
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
78
123
|
end
|
79
124
|
|
80
125
|
end
|
81
|
-
end
|
126
|
+
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: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-03-06 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: excon
|
16
|
-
requirement: &
|
16
|
+
requirement: &70302139720560 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 0.9.5
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70302139720560
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: multi_json
|
27
|
-
requirement: &
|
27
|
+
requirement: &70302139720160 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70302139720160
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rake
|
38
|
-
requirement: &
|
38
|
+
requirement: &70302139719700 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70302139719700
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: rspec
|
49
|
-
requirement: &
|
49
|
+
requirement: &70302139719200 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ~>
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: 2.6.0
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70302139719200
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: yard
|
60
|
-
requirement: &
|
60
|
+
requirement: &70302139718780 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: '0'
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *70302139718780
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rdiscount
|
71
|
-
requirement: &
|
71
|
+
requirement: &70302139718320 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ! '>='
|
@@ -76,7 +76,7 @@ dependencies:
|
|
76
76
|
version: '0'
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *70302139718320
|
80
80
|
description: An easy to use ruby wrapper for Librato's Metrics API
|
81
81
|
email: matt@librato.com
|
82
82
|
executables: []
|
@@ -127,7 +127,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
127
127
|
version: '0'
|
128
128
|
requirements: []
|
129
129
|
rubyforge_project:
|
130
|
-
rubygems_version: 1.8.
|
130
|
+
rubygems_version: 1.8.16
|
131
131
|
signing_key:
|
132
132
|
specification_version: 2
|
133
133
|
summary: Ruby wrapper for Librato's Metrics API
|