File tree Expand file tree Collapse file tree 8 files changed +43
-6
lines changed Expand file tree Collapse file tree 8 files changed +43
-6
lines changed Original file line number Diff line number Diff line change @@ -29,6 +29,7 @@ Configure the Slate client
29
29
``` ruby
30
30
client = Slate .configure do |config |
31
31
config.endpoint = " http://your.graphite-server.com"
32
+ config.timeout = 30 # In seconds (default: 10)
32
33
end
33
34
```
34
35
Original file line number Diff line number Diff line change 1
1
require "slate/version"
2
+ require "slate/error"
2
3
require "slate/client"
3
4
require "slate/target"
4
5
require "slate/graph"
Original file line number Diff line number Diff line change 1
1
module Slate
2
2
class Client
3
3
# Public: Gets/Sets the URL endpoint of the Graphite server.
4
- attr_accessor :endpoint
4
+ attr_accessor :endpoint , :timeout
5
5
end
6
6
end
Original file line number Diff line number Diff line change
1
+ module Slate
2
+ module Error
3
+ class TimeoutError < StandardError ; end
4
+ end
5
+ end
Original file line number Diff line number Diff line change 1
1
require 'cgi'
2
- require 'rest-client '
2
+ require 'faraday '
3
3
4
4
module Slate
5
5
class Graph
@@ -65,11 +65,20 @@ def url(format=:png)
65
65
# download(:json)
66
66
# # => '{"targets":[]}'
67
67
def download ( format = :png )
68
- RestClient . get url ( format )
68
+ connection . get ( url ( format ) ) . body
69
+ rescue Faraday ::Error ::TimeoutError
70
+ raise Slate ::Error ::TimeoutError
69
71
end
70
72
71
73
private
72
74
75
+ def connection
76
+ @connection ||= Faraday . new do |faraday |
77
+ faraday . options [ :timeout ] = @client . timeout || 10
78
+ faraday . adapter Faraday . default_adapter
79
+ end
80
+ end
81
+
73
82
def url_options
74
83
options = [ ]
75
84
options += @targets . map { |t | [ "target" , t . to_s ] }
Original file line number Diff line number Diff line change @@ -17,10 +17,10 @@ Gem::Specification.new do |gem|
17
17
gem . test_files = gem . files . grep ( %r{^(test|spec|features)/} )
18
18
gem . require_paths = [ "lib" ]
19
19
20
- gem . add_dependency "rest-client " , "~> 1.6.7 "
21
- gem . add_dependency "json" , "~> 1.7.5 "
20
+ gem . add_dependency "faraday " , "~> 0.8 "
21
+ gem . add_dependency "json" , "~> 1.8 "
22
22
gem . add_dependency "jruby-openssl" if RUBY_PLATFORM == 'java'
23
- gem . add_dependency "treetop" , "~> 1.4.12 "
23
+ gem . add_dependency "treetop" , "~> 1.4"
24
24
25
25
gem . add_development_dependency "rake"
26
26
gem . add_development_dependency "rspec"
Original file line number Diff line number Diff line change 124
124
graph . download ( :json ) . should eq ( @json_stub )
125
125
graph . download ( :svg ) . should eq ( @svg_stub )
126
126
end
127
+
128
+ it "should respect the configured timeout" do
129
+ stub_request ( :get , "http://graphite/render?format=png&target=app.server01.timeout" ) .
130
+ to_timeout
131
+
132
+ target = Slate ::Target . build ( "app.server01.timeout" )
133
+ graph = Slate ::Graph . new ( @client )
134
+ graph << target
135
+
136
+ expect {
137
+ graph . download ( :png ) . should eq ( @png_stub )
138
+ } . to raise_error ( Slate ::Error ::TimeoutError )
139
+ end
127
140
end
128
141
129
142
def stub_download ( format , body = "" )
Original file line number Diff line number Diff line change 8
8
9
9
client . endpoint . should == "http://graphite"
10
10
end
11
+
12
+ it "should be able to configure the request timeout" do
13
+ client = Slate . configure do |c |
14
+ c . timeout = 30
15
+ end
16
+
17
+ client . timeout . should == 30
18
+ end
11
19
end
You can’t perform that action at this time.
0 commit comments