librato-metrics 0.7.4 → 0.7.5
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 +5 -1
- data/lib/librato/metrics.rb +3 -2
- data/lib/librato/metrics/client.rb +22 -1
- data/lib/librato/metrics/connection.rb +2 -1
- data/lib/librato/metrics/middleware/retry.rb +2 -2
- data/lib/librato/metrics/version.rb +1 -1
- data/spec/unit/metrics/client_spec.rb +17 -0
- data/spec/unit/metrics/queue_spec.rb +1 -1
- data/spec/unit/metrics_spec.rb +18 -5
- metadata +3 -3
data/CHANGELOG.md
CHANGED
@@ -1,8 +1,12 @@
|
|
1
1
|
## Changelog
|
2
2
|
|
3
|
+
### Version 0.7.5
|
4
|
+
* Catch a broader range of connection failures for retrying
|
5
|
+
* Add Metrics.faraday_adapter config option (Mathieu Ravaux)_
|
6
|
+
|
3
7
|
### Version 0.7.4
|
4
8
|
* Support global measure_time option for Queues/Aggregators
|
5
|
-
* Support all versions of multi_json so we can relax version
|
9
|
+
* Support all versions of multi_json so we can relax version constraint
|
6
10
|
|
7
11
|
### Version 0.7.3
|
8
12
|
* Allow prefixes to be changed after instantiation on Queues/Aggregators
|
data/lib/librato/metrics.rb
CHANGED
@@ -71,8 +71,9 @@ module Librato
|
|
71
71
|
#
|
72
72
|
def_delegators :client, :agent_identifier, :api_endpoint,
|
73
73
|
:api_endpoint=, :authenticate, :connection, :delete,
|
74
|
-
:
|
75
|
-
:submit,
|
74
|
+
:faraday_adapter, :faraday_adapter=, :fetch, :list,
|
75
|
+
:persistence, :persistence=, :persister, :submit,
|
76
|
+
:update
|
76
77
|
|
77
78
|
# The Librato::Metrics::Client being used by module-level
|
78
79
|
# access.
|
@@ -57,7 +57,8 @@ module Librato
|
|
57
57
|
def connection
|
58
58
|
# prevent successful creation if no credentials set
|
59
59
|
raise CredentialsMissing unless (self.email and self.api_key)
|
60
|
-
@connection ||= Connection.new(:client => self, :api_endpoint => api_endpoint
|
60
|
+
@connection ||= Connection.new(:client => self, :api_endpoint => api_endpoint,
|
61
|
+
:adapter => faraday_adapter)
|
61
62
|
end
|
62
63
|
|
63
64
|
# Overrride user agent for this client's connections. If you
|
@@ -93,6 +94,18 @@ module Librato
|
|
93
94
|
# otherwise.
|
94
95
|
true
|
95
96
|
end
|
97
|
+
|
98
|
+
# Return current adapter this client will use.
|
99
|
+
# Defaults to Metrics.faraday_adapter if set, otherwise
|
100
|
+
# Faraday.default_adapter
|
101
|
+
def faraday_adapter
|
102
|
+
@faraday_adapter ||= default_faraday_adapter
|
103
|
+
end
|
104
|
+
|
105
|
+
# Set faraday adapter this client will use
|
106
|
+
def faraday_adapter=(adapter)
|
107
|
+
@faraday_adapter = adapter
|
108
|
+
end
|
96
109
|
|
97
110
|
# Query metric data
|
98
111
|
#
|
@@ -221,6 +234,14 @@ module Librato
|
|
221
234
|
end
|
222
235
|
|
223
236
|
private
|
237
|
+
|
238
|
+
def default_faraday_adapter
|
239
|
+
if Metrics.client == self
|
240
|
+
Faraday.default_adapter
|
241
|
+
else
|
242
|
+
Metrics.faraday_adapter
|
243
|
+
end
|
244
|
+
end
|
224
245
|
|
225
246
|
def flush_persistence
|
226
247
|
@persistence = nil
|
@@ -18,6 +18,7 @@ module Librato
|
|
18
18
|
def initialize(options={})
|
19
19
|
@client = options[:client]
|
20
20
|
@api_endpoint = options[:api_endpoint]
|
21
|
+
@adapter = options[:adapter]
|
21
22
|
end
|
22
23
|
|
23
24
|
# API endpoint that will be used for requests.
|
@@ -37,7 +38,7 @@ module Librato
|
|
37
38
|
f.use Librato::Metrics::Middleware::ExpectsStatus
|
38
39
|
#f.use FaradayMiddleware::ParseJson, :content_type => /\bjson$/
|
39
40
|
|
40
|
-
f.adapter
|
41
|
+
f.adapter @adapter || Metrics.faraday_adapter
|
41
42
|
end.tap do |transport|
|
42
43
|
transport.headers[:user_agent] = user_agent
|
43
44
|
transport.headers[:content_type] = 'application/json'
|
@@ -1,4 +1,3 @@
|
|
1
|
-
# borrowed from faraday 0.8, will use official once final
|
2
1
|
module Librato
|
3
2
|
module Metrics
|
4
3
|
module Middleware
|
@@ -14,7 +13,8 @@ module Librato
|
|
14
13
|
retries = @retries
|
15
14
|
begin
|
16
15
|
@app.call(env)
|
17
|
-
rescue Librato::Metrics::ServerError, Timeout::Error
|
16
|
+
rescue Librato::Metrics::ServerError, Timeout::Error,
|
17
|
+
Faraday::Error::ConnectionFailed
|
18
18
|
if retries > 0
|
19
19
|
retries -= 1 and retry
|
20
20
|
end
|
@@ -67,6 +67,23 @@ module Librato
|
|
67
67
|
lambda{ subject.connection }.should raise_error(Librato::Metrics::CredentialsMissing)
|
68
68
|
end
|
69
69
|
end
|
70
|
+
|
71
|
+
describe "#faraday_adapter" do
|
72
|
+
it "should default to Metrics default adapter" do
|
73
|
+
Metrics.faraday_adapter = :typhoeus
|
74
|
+
Client.new.faraday_adapter.should == Metrics.faraday_adapter
|
75
|
+
Metrics.faraday_adapter = nil
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
describe "#faraday_adapter=" do
|
80
|
+
it "should allow setting of faraday adapter" do
|
81
|
+
subject.faraday_adapter = :excon
|
82
|
+
subject.faraday_adapter.should == :excon
|
83
|
+
subject.faraday_adapter = :patron
|
84
|
+
subject.faraday_adapter.should == :patron
|
85
|
+
end
|
86
|
+
end
|
70
87
|
|
71
88
|
describe "#new_queue" do
|
72
89
|
it "should return a new queue with client set" do
|
data/spec/unit/metrics_spec.rb
CHANGED
@@ -5,7 +5,6 @@ module Librato
|
|
5
5
|
describe Metrics do
|
6
6
|
|
7
7
|
describe "#authorize" do
|
8
|
-
|
9
8
|
context "when given two arguments" do
|
10
9
|
it "should store them on simple" do
|
11
10
|
Metrics.authenticate 'tester@librato.com', 'api_key'
|
@@ -13,16 +12,31 @@ module Librato
|
|
13
12
|
Metrics.client.api_key.should == 'api_key'
|
14
13
|
end
|
15
14
|
end
|
16
|
-
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "#faraday_adapter" do
|
18
|
+
it "should return current default adapter" do
|
19
|
+
Metrics.faraday_adapter.should_not be nil
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe "#faraday_adapter=" do
|
24
|
+
before(:all) { @current_adapter = Metrics.faraday_adapter }
|
25
|
+
after(:all) { Metrics.faraday_adapter = @current_adapter }
|
26
|
+
|
27
|
+
it "should allow setting of faraday adapter" do
|
28
|
+
Metrics.faraday_adapter = :excon
|
29
|
+
Metrics.faraday_adapter.should == :excon
|
30
|
+
Metrics.faraday_adapter = :patron
|
31
|
+
Metrics.faraday_adapter.should == :patron
|
32
|
+
end
|
17
33
|
end
|
18
34
|
|
19
35
|
describe "#persistence" do
|
20
|
-
|
21
36
|
it "should allow configuration of persistence method" do
|
22
37
|
Metrics.persistence = :test
|
23
38
|
Metrics.persistence.should == :test
|
24
39
|
end
|
25
|
-
|
26
40
|
end
|
27
41
|
|
28
42
|
describe "#submit" do
|
@@ -43,7 +57,6 @@ module Librato
|
|
43
57
|
expected = {:gauges => [{:name => 'foo', :value => 123}, {:name => 'bar', :value => 456}]}
|
44
58
|
Librato::Metrics.persister.persisted.should equal_unordered(expected)
|
45
59
|
end
|
46
|
-
|
47
60
|
end
|
48
61
|
|
49
62
|
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.7.
|
4
|
+
version: 0.7.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-11-
|
12
|
+
date: 2012-11-27 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: faraday
|
@@ -216,7 +216,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
216
216
|
version: '0'
|
217
217
|
segments:
|
218
218
|
- 0
|
219
|
-
hash: -
|
219
|
+
hash: -366569108077334223
|
220
220
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
221
221
|
none: false
|
222
222
|
requirements:
|