elasticsearch-transport 1.0.9 → 1.0.10

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 85aa43e17d7dbb5e43514c2c6c8d61030db7bf0f
4
- data.tar.gz: 7220157362dbd60f5f003fbe457cb97d5f03983f
3
+ metadata.gz: daee16fc525cec703b65be13c6ef73521ef246ed
4
+ data.tar.gz: 8cbc0e8fb197177c69ee2c9eae1f2ce5a3c97eb6
5
5
  SHA512:
6
- metadata.gz: e86b6d6fdd5d38114b5a8ff506c114a0270d6ee8bccade584badb9bb5aac51c59f181afa162cfb8cfb5da01b9967507a513dafa1a3e157eed20874253424fd4d
7
- data.tar.gz: 44569f981a390c4ad0f1a4bb5a3cb766bd03f5fd114f384c4a705c5b59bf69d73759b0e75b445ecd5b4ca7e67a0e9239f4ae8faad76d4228ac281626657dff12
6
+ metadata.gz: deebc659d3b87ba4c8eaa6333f8f98f7d946c71aabfcf4833dfbdca0afdc9af998b119aaccdc2730667981cacf48f2274d79a75490a2f14a7adb7066f703fb31
7
+ data.tar.gz: 170dee5bd767cf824e2c69b8233ff642213b3d0a49dbac53931f3287289cca566f7a15818d83492a6420e3b0b3eb887356348d22919bd9927171d1c87bd36a16
data/README.md CHANGED
@@ -155,6 +155,15 @@ You can pass the client any conforming logger implementation:
155
155
 
156
156
  client = Elasticsearch::Client.new logger: log
157
157
 
158
+ ### Setting Timeouts
159
+
160
+ For many operations in Elasticsearch, the default timeouts of HTTP libraries are too low.
161
+ To increase the timeout, you can use the `request_timeout` parameter:
162
+
163
+ Elasticsearch::Client.new request_timeout: 5*60
164
+
165
+ You can also use the `transport_options` argument documented below.
166
+
158
167
  ### Randomizing Hosts
159
168
 
160
169
  If you pass multiple hosts to the client, it rotates across them in a round-robin fashion, by default.
@@ -59,6 +59,8 @@ module Elasticsearch
59
59
  #
60
60
  # @option arguments [Boolean] :reload_on_failure Reload connections after failure (false by default)
61
61
  #
62
+ # @option arguments [Integer] :request_timeout The request timeout to be passed to transport in options
63
+ #
62
64
  # @option arguments [Symbol] :adapter A specific adapter for Faraday (e.g. `:patron`)
63
65
  #
64
66
  # @option arguments [Hash] :transport_options Options to be passed to the `Faraday::Connection` constructor
@@ -92,6 +94,8 @@ module Elasticsearch
92
94
  arguments[:randomize_hosts] ||= false
93
95
  arguments[:transport_options] ||= {}
94
96
 
97
+ arguments[:transport_options].update(request: { timeout: arguments[:request_timeout] } ) if arguments[:request_timeout]
98
+
95
99
  @send_get_body_as = arguments[:send_get_body_as] || 'GET'
96
100
 
97
101
  transport_class = arguments[:transport_class] || DEFAULT_TRANSPORT_CLASS
@@ -13,7 +13,9 @@ module Elasticsearch
13
13
  DEFAULT_SERIALIZER_CLASS = Serializer::MultiJson
14
14
 
15
15
  attr_reader :hosts, :options, :connections, :counter, :last_request_at, :protocol
16
- attr_accessor :serializer, :sniffer, :logger, :tracer, :reload_after, :resurrect_after, :max_retries
16
+ attr_accessor :serializer, :sniffer, :logger, :tracer,
17
+ :reload_connections, :reload_after,
18
+ :resurrect_after, :max_retries
17
19
 
18
20
  # Creates a new transport object.
19
21
  #
@@ -40,6 +42,7 @@ module Elasticsearch
40
42
  @sniffer = options[:sniffer_class] ? options[:sniffer_class].new(self) : Sniffer.new(self)
41
43
  @counter = 0
42
44
  @last_request_at = Time.now
45
+ @reload_connections = options[:reload_connections]
43
46
  @reload_after = options[:reload_connections].is_a?(Fixnum) ? options[:reload_connections] : DEFAULT_RELOAD_AFTER
44
47
  @resurrect_after = options[:resurrect_after] || DEFAULT_RESURRECT_AFTER
45
48
  @max_retries = options[:retry_on_failure].is_a?(Fixnum) ? options[:retry_on_failure] : DEFAULT_MAX_RETRIES
@@ -59,7 +62,7 @@ module Elasticsearch
59
62
  connection = connections.get_connection(options)
60
63
  @counter += 1
61
64
 
62
- reload_connections! if @options[:reload_connections] && counter % reload_after == 0
65
+ reload_connections! if reload_connections && counter % reload_after == 0
63
66
  connection
64
67
  end
65
68
 
@@ -211,7 +214,7 @@ module Elasticsearch
211
214
  end
212
215
 
213
216
  rescue Exception => e
214
- logger.fatal "[#{e.class}] #{e.message} (#{connection.host.inspect})" if logger
217
+ logger.fatal "[#{e.class}] #{e.message} (#{connection.host.inspect if connection})" if logger
215
218
  raise e
216
219
  end
217
220
 
@@ -84,7 +84,8 @@ module Elasticsearch
84
84
  @request_options[:headers] = options[:headers]
85
85
  end
86
86
 
87
- client_options = {:ssl => options[:ssl] || {}}
87
+ client_options = options[:transport_options] || {}
88
+ client_options[:ssl] = options[:ssl] || {}
88
89
 
89
90
  Connections::Collection.new \
90
91
  :connections => hosts.map { |host|
@@ -1,5 +1,5 @@
1
1
  module Elasticsearch
2
2
  module Transport
3
- VERSION = "1.0.9"
3
+ VERSION = "1.0.10"
4
4
  end
5
5
  end
@@ -49,6 +49,16 @@ class Elasticsearch::Transport::ClientIntegrationTest < Elasticsearch::Test::Int
49
49
  end
50
50
  end
51
51
 
52
+ should "pass options to the transport" do
53
+ @client = Elasticsearch::Client.new \
54
+ host: "localhost:#{@port}",
55
+ logger: (ENV['QUIET'] ? nil : @logger),
56
+ transport_options: { headers: { content_type: 'application/yaml' } }
57
+
58
+ response = @client.perform_request 'GET', '_cluster/health'
59
+ assert_match /---\ncluster_name:/, response.body.to_s
60
+ end
61
+
52
62
  context "with round robin selector" do
53
63
  setup do
54
64
  @client = Elasticsearch::Client.new \
@@ -63,6 +63,16 @@ class Elasticsearch::Transport::ClientTest < Test::Unit::TestCase
63
63
  assert_match /Faraday/, client.transport.connections.first.connection.headers['User-Agent']
64
64
  end
65
65
 
66
+ should "pass options to the transport" do
67
+ client = Elasticsearch::Transport::Client.new :transport_options => { :foo => 'bar' }
68
+ assert_equal 'bar', client.transport.options[:transport_options][:foo]
69
+ end
70
+
71
+ should "merge request_timeout to the transport options" do
72
+ client = Elasticsearch::Transport::Client.new :request_timeout => 120
73
+ assert_equal 120, client.transport.options[:transport_options][:request][:timeout]
74
+ end
75
+
66
76
  context "when passed hosts" do
67
77
  should "have localhost by default" do
68
78
  c = Elasticsearch::Transport::Client.new
@@ -100,6 +100,24 @@ class Elasticsearch::Transport::Transport::BaseTest < Test::Unit::TestCase
100
100
  12.times { @transport.get_connection }
101
101
  assert_equal 12, @transport.counter
102
102
  end
103
+
104
+ should "not reload connections by default" do
105
+ @transport = DummyTransportPerformer.new
106
+ @transport.stubs(:connections).returns(stub :get_connection => Object.new)
107
+ @transport.expects(:reload_connections!).never
108
+
109
+ 10_010.times { @transport.get_connection }
110
+ assert_equal 10_010, @transport.counter
111
+ end
112
+
113
+ should "not reload connections when the option is set to false" do
114
+ @transport = DummyTransportPerformer.new :options => { :reload_connections => false }
115
+ @transport.stubs(:connections).returns(stub :get_connection => Object.new)
116
+ @transport.expects(:reload_connections!).never
117
+
118
+ 10_010.times { @transport.get_connection }
119
+ assert_equal 10_010, @transport.counter
120
+ end
103
121
  end
104
122
 
105
123
  context "performing a request" do
@@ -102,6 +102,15 @@ else
102
102
  ::Manticore::Client.expects(:new).with(options)
103
103
  transport = Manticore.new :hosts => [ { :host => 'foobar', :port => 1234 } ], :options => options
104
104
  end
105
+
106
+ should "pass :transport_options to Manticore::Client" do
107
+ options = {
108
+ :transport_options => { :potatoes => 1 }
109
+ }
110
+
111
+ ::Manticore::Client.expects(:new).with(:potatoes => 1, :ssl => {})
112
+ transport = Manticore.new :hosts => [ { :host => 'foobar', :port => 1234 } ], :options => options
113
+ end
105
114
  end
106
115
 
107
116
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: elasticsearch-transport
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.9
4
+ version: 1.0.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Karel Minarik
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-14 00:00:00.000000000 Z
11
+ date: 2015-05-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: multi_json