elasticsearch-transport 7.4.0 → 7.17.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 +4 -4
- data/Gemfile +30 -13
- data/Gemfile-faraday1.gemfile +47 -0
- data/README.md +159 -64
- data/Rakefile +63 -13
- data/elasticsearch-transport.gemspec +55 -63
- data/lib/elasticsearch/transport/client.rb +184 -59
- data/lib/elasticsearch/transport/meta_header.rb +135 -0
- data/lib/elasticsearch/transport/redacted.rb +16 -3
- data/lib/elasticsearch/transport/transport/base.rb +69 -30
- data/lib/elasticsearch/transport/transport/connections/collection.rb +18 -8
- data/lib/elasticsearch/transport/transport/connections/connection.rb +25 -9
- data/lib/elasticsearch/transport/transport/connections/selector.rb +16 -3
- data/lib/elasticsearch/transport/transport/errors.rb +17 -3
- data/lib/elasticsearch/transport/transport/http/curb.rb +60 -35
- data/lib/elasticsearch/transport/transport/http/faraday.rb +32 -9
- data/lib/elasticsearch/transport/transport/http/manticore.rb +57 -32
- data/lib/elasticsearch/transport/transport/loggable.rb +16 -3
- data/lib/elasticsearch/transport/transport/response.rb +17 -5
- data/lib/elasticsearch/transport/transport/serializer/multi_json.rb +16 -3
- data/lib/elasticsearch/transport/transport/sniffer.rb +35 -15
- data/lib/elasticsearch/transport/version.rb +17 -4
- data/lib/elasticsearch/transport.rb +35 -33
- data/lib/elasticsearch-transport.rb +16 -3
- data/spec/elasticsearch/connections/collection_spec.rb +28 -3
- data/spec/elasticsearch/connections/selector_spec.rb +16 -3
- data/spec/elasticsearch/transport/base_spec.rb +107 -49
- data/spec/elasticsearch/transport/client_spec.rb +734 -164
- data/spec/elasticsearch/transport/http/curb_spec.rb +126 -0
- data/spec/elasticsearch/transport/http/faraday_spec.rb +141 -0
- data/spec/elasticsearch/transport/http/manticore_spec.rb +161 -0
- data/spec/elasticsearch/transport/meta_header_spec.rb +301 -0
- data/spec/elasticsearch/transport/sniffer_spec.rb +16 -16
- data/spec/spec_helper.rb +32 -6
- data/test/integration/jruby_test.rb +43 -0
- data/test/integration/transport_test.rb +109 -46
- data/test/profile/client_benchmark_test.rb +16 -3
- data/test/test_helper.rb +26 -25
- data/test/unit/adapters_test.rb +88 -0
- data/test/unit/connection_test.rb +23 -5
- data/test/unit/response_test.rb +18 -5
- data/test/unit/serializer_test.rb +16 -3
- data/test/unit/transport_base_test.rb +33 -11
- data/test/unit/transport_curb_test.rb +16 -4
- data/test/unit/transport_faraday_test.rb +18 -5
- data/test/unit/transport_manticore_test.rb +258 -158
- metadata +64 -76
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 9e0c37098be528ebc37efec244285f3601ba8251c355195d5d64b5d3d6146b01
         | 
| 4 | 
            +
              data.tar.gz: 7dd46af46b3ae346e4f76a6f8cae669e27964cddd8cd9e91ca4329cf34f8fb74
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 7c1d381899e45182eb000f45f1e014c2944741f817276424cefcbce05e26878da524ecc0c8d64c2dba3b290e755b30a7428b11fb6d65fd417528d92007418ed6
         | 
| 7 | 
            +
              data.tar.gz: f2639368b74d2884376420cccb89e591dae6ecbfdc4632224d1f073ba34000ea54c498e5cb6256a60dda8f9a9a02a218158fbef64d62e1b6118b13b6912a2334
         | 
    
        data/Gemfile
    CHANGED
    
    | @@ -1,25 +1,42 @@ | |
| 1 | 
            -
            # Licensed to Elasticsearch B.V under one or more  | 
| 2 | 
            -
            #  | 
| 3 | 
            -
            #  | 
| 1 | 
            +
            # Licensed to Elasticsearch B.V. under one or more contributor
         | 
| 2 | 
            +
            # license agreements. See the NOTICE file distributed with
         | 
| 3 | 
            +
            # this work for additional information regarding copyright
         | 
| 4 | 
            +
            # ownership. Elasticsearch B.V. licenses this file to you under
         | 
| 5 | 
            +
            # the Apache License, Version 2.0 (the "License"); you may
         | 
| 6 | 
            +
            # not use this file except in compliance with the License.
         | 
| 7 | 
            +
            # You may obtain a copy of the License at
         | 
| 8 | 
            +
            #
         | 
| 9 | 
            +
            #   http://www.apache.org/licenses/LICENSE-2.0
         | 
| 10 | 
            +
            #
         | 
| 11 | 
            +
            # Unless required by applicable law or agreed to in writing,
         | 
| 12 | 
            +
            # software distributed under the License is distributed on an
         | 
| 13 | 
            +
            # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
         | 
| 14 | 
            +
            # KIND, either express or implied.  See the License for the
         | 
| 15 | 
            +
            # specific language governing permissions and limitations
         | 
| 16 | 
            +
            # under the License.
         | 
| 4 17 |  | 
| 5 18 | 
             
            source 'https://rubygems.org'
         | 
| 6 19 |  | 
| 7 20 | 
             
            # Specify your gem's dependencies in elasticsearch-transport.gemspec
         | 
| 8 21 | 
             
            gemspec
         | 
| 9 22 |  | 
| 10 | 
            -
            if File.exist? File.expand_path( | 
| 11 | 
            -
              gem 'elasticsearch-api', : | 
| 23 | 
            +
            if File.exist? File.expand_path('../elasticsearch-api/elasticsearch-api.gemspec', __dir__)
         | 
| 24 | 
            +
              gem 'elasticsearch-api', path: File.expand_path('../elasticsearch-api', __dir__), require: false
         | 
| 12 25 | 
             
            end
         | 
| 13 26 |  | 
| 14 | 
            -
            if File.exist? File.expand_path( | 
| 15 | 
            -
              gem 'elasticsearch | 
| 27 | 
            +
            if File.exist? File.expand_path('../elasticsearch/elasticsearch.gemspec', __dir__)
         | 
| 28 | 
            +
              gem 'elasticsearch', path: File.expand_path('../elasticsearch', __dir__), require: false
         | 
| 16 29 | 
             
            end
         | 
| 17 30 |  | 
| 18 | 
            -
             | 
| 19 | 
            -
              gem ' | 
| 20 | 
            -
             | 
| 21 | 
            -
             | 
| 22 | 
            -
             | 
| 31 | 
            +
            group :development, :test do
         | 
| 32 | 
            +
              gem 'faraday-httpclient'
         | 
| 33 | 
            +
              gem 'faraday-net_http_persistent'
         | 
| 34 | 
            +
              gem 'faraday-patron' unless defined? JRUBY_VERSION
         | 
| 35 | 
            +
              gem 'faraday-typhoeus'
         | 
| 23 36 | 
             
              gem 'rspec'
         | 
| 24 | 
            -
               | 
| 37 | 
            +
              if defined?(JRUBY_VERSION)
         | 
| 38 | 
            +
                gem 'pry-nav'
         | 
| 39 | 
            +
              else
         | 
| 40 | 
            +
                gem 'pry-byebug', '~> 3.9'
         | 
| 41 | 
            +
              end
         | 
| 25 42 | 
             
            end
         | 
| @@ -0,0 +1,47 @@ | |
| 1 | 
            +
            # Licensed to Elasticsearch B.V. under one or more contributor
         | 
| 2 | 
            +
            # license agreements. See the NOTICE file distributed with
         | 
| 3 | 
            +
            # this work for additional information regarding copyright
         | 
| 4 | 
            +
            # ownership. Elasticsearch B.V. licenses this file to you under
         | 
| 5 | 
            +
            # the Apache License, Version 2.0 (the "License"); you may
         | 
| 6 | 
            +
            # not use this file except in compliance with the License.
         | 
| 7 | 
            +
            # You may obtain a copy of the License at
         | 
| 8 | 
            +
            #
         | 
| 9 | 
            +
            #   http://www.apache.org/licenses/LICENSE-2.0
         | 
| 10 | 
            +
            #
         | 
| 11 | 
            +
            # Unless required by applicable law or agreed to in writing,
         | 
| 12 | 
            +
            # software distributed under the License is distributed on an
         | 
| 13 | 
            +
            # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
         | 
| 14 | 
            +
            # KIND, either express or implied.  See the License for the
         | 
| 15 | 
            +
            # specific language governing permissions and limitations
         | 
| 16 | 
            +
            # under the License.
         | 
| 17 | 
            +
             | 
| 18 | 
            +
            source 'https://rubygems.org'
         | 
| 19 | 
            +
             | 
| 20 | 
            +
            # Usage:
         | 
| 21 | 
            +
            #
         | 
| 22 | 
            +
            # $ BUNDLE_GEMFILE=./Gemfile-faraday1.gemfile bundle install
         | 
| 23 | 
            +
            # $ BUNDLE_GEMFILE=./Gemfile-faraday1.gemfile bundle exec rake test:faraday1:unit
         | 
| 24 | 
            +
             | 
| 25 | 
            +
            gem 'faraday', '~> 1'
         | 
| 26 | 
            +
            gemspec path: './'
         | 
| 27 | 
            +
             | 
| 28 | 
            +
            if File.exist? File.expand_path('../elasticsearch-api/elasticsearch-api.gemspec', __dir__)
         | 
| 29 | 
            +
              gem 'elasticsearch-api', path: File.expand_path('../elasticsearch-api', __dir__), require: false
         | 
| 30 | 
            +
            end
         | 
| 31 | 
            +
             | 
| 32 | 
            +
            if File.exist? File.expand_path('../elasticsearch/elasticsearch.gemspec', __dir__)
         | 
| 33 | 
            +
              gem 'elasticsearch', path: File.expand_path('../elasticsearch', __dir__), require: false
         | 
| 34 | 
            +
            end
         | 
| 35 | 
            +
             | 
| 36 | 
            +
            group :development, :test do
         | 
| 37 | 
            +
              gem 'httpclient'
         | 
| 38 | 
            +
              gem 'net-http-persistent'
         | 
| 39 | 
            +
              gem 'patron' unless defined? JRUBY_VERSION
         | 
| 40 | 
            +
              gem 'typhoeus'
         | 
| 41 | 
            +
              gem 'rspec'
         | 
| 42 | 
            +
              if defined?(JRUBY_VERSION)
         | 
| 43 | 
            +
                gem 'pry-nav'
         | 
| 44 | 
            +
              else
         | 
| 45 | 
            +
                gem 'pry-byebug'
         | 
| 46 | 
            +
              end
         | 
| 47 | 
            +
            end
         | 
    
        data/README.md
    CHANGED
    
    | @@ -28,12 +28,16 @@ Features overview: | |
| 28 28 | 
             
            * Node reloading (based on cluster state) on errors or on demand
         | 
| 29 29 |  | 
| 30 30 | 
             
            For optimal performance, use a HTTP library which supports persistent ("keep-alive") connections,
         | 
| 31 | 
            -
            such as [Typhoeus](https://github.com/typhoeus/typhoeus).
         | 
| 32 | 
            -
            Just require the library (`require ' | 
| 33 | 
            -
             | 
| 34 | 
            -
             | 
| 35 | 
            -
            [ | 
| 36 | 
            -
            [ | 
| 31 | 
            +
            such as [patron](https://github.com/toland/patron) or [Typhoeus](https://github.com/typhoeus/typhoeus).
         | 
| 32 | 
            +
            Just require the library (`require 'patron'`) in your code, and it will be automatically used.
         | 
| 33 | 
            +
             | 
| 34 | 
            +
            Currently these libraries will be automatically detected and used:
         | 
| 35 | 
            +
            - [Patron](https://github.com/toland/patron)
         | 
| 36 | 
            +
            - [Typhoeus](https://github.com/typhoeus/typhoeus)
         | 
| 37 | 
            +
            - [HTTPClient](https://rubygems.org/gems/httpclient)
         | 
| 38 | 
            +
            - [Net::HTTP::Persistent](https://rubygems.org/gems/net-http-persistent)
         | 
| 39 | 
            +
             | 
| 40 | 
            +
            **Note on [Typhoeus](https://github.com/typhoeus/typhoeus)**: You need to use v1.4.0 or up since older versions are not compatible with Faraday 1.0.
         | 
| 37 41 |  | 
| 38 42 | 
             
            For detailed information, see example configurations [below](#transport-implementations).
         | 
| 39 43 |  | 
| @@ -69,6 +73,23 @@ Full documentation is available at <http://rubydoc.info/gems/elasticsearch-trans | |
| 69 73 |  | 
| 70 74 | 
             
            ## Configuration
         | 
| 71 75 |  | 
| 76 | 
            +
            * [Setting Hosts](#setting-hosts)
         | 
| 77 | 
            +
            * [Default port](#default-port)
         | 
| 78 | 
            +
            * [Connect using an Elastic Cloud ID](#connect-using-an-elastic-cloud-id)
         | 
| 79 | 
            +
            * [Authentication](#authentication)
         | 
| 80 | 
            +
            * [Logging](#logging)
         | 
| 81 | 
            +
            * [Custom HTTP Headers](#custom-http-headers)
         | 
| 82 | 
            +
            * [Identifying running tasks with X-Opaque-Id](#identifying-running-tasks-with-x-opaque-id)
         | 
| 83 | 
            +
            * [Setting Timeouts](#setting-timeouts)
         | 
| 84 | 
            +
            * [Randomizing Hosts](#randomizing-hosts)
         | 
| 85 | 
            +
            * [Retrying on Failures](#retrying-on-failures)
         | 
| 86 | 
            +
            * [Reloading Hosts](#reloading-hosts)
         | 
| 87 | 
            +
            * [Connection Selector](#connection-selector)
         | 
| 88 | 
            +
            * [Transport Implementations](#transport-implementations)
         | 
| 89 | 
            +
            * [Serializer implementations](#serializer-implementations)
         | 
| 90 | 
            +
            * [Exception Handling](#exception-handling)
         | 
| 91 | 
            +
            * [Development and Community](#development-and-community)
         | 
| 92 | 
            +
             | 
| 72 93 | 
             
            The client supports many configurations options for setting up and managing connections,
         | 
| 73 94 | 
             
            configuring logging, customizing the transport library, etc.
         | 
| 74 95 |  | 
| @@ -115,7 +136,7 @@ Please see below for an exception to this when connecting using an Elastic Cloud | |
| 115 136 |  | 
| 116 137 | 
             
            If you are using [Elastic Cloud](https://www.elastic.co/cloud), you can provide your cloud id to the client.
         | 
| 117 138 | 
             
            You must supply your username and password separately, and optionally a port. If no port is supplied,
         | 
| 118 | 
            -
            port  | 
| 139 | 
            +
            port 443 will be used.
         | 
| 119 140 |  | 
| 120 141 | 
             
            Note: Do not enable sniffing when using Elastic Cloud. The nodes are behind a load balancer so
         | 
| 121 142 | 
             
            Elastic Cloud will take care of everything for you.
         | 
| @@ -144,35 +165,114 @@ use the `transport_options` option: | |
| 144 165 | 
             
                Elasticsearch::Client.new url: 'https://username:password@example.com:9200',
         | 
| 145 166 | 
             
                                          transport_options: { ssl: { ca_file: '/path/to/cacert.pem' } }
         | 
| 146 167 |  | 
| 168 | 
            +
            You can also use [**API Key authentication**](https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-create-api-key.html):
         | 
| 169 | 
            +
             | 
| 170 | 
            +
            ``` ruby
         | 
| 171 | 
            +
            Elasticsearch::Client.new(
         | 
| 172 | 
            +
              host: host,
         | 
| 173 | 
            +
              transport_options: transport_options,
         | 
| 174 | 
            +
              api_key: credentials
         | 
| 175 | 
            +
            )
         | 
| 176 | 
            +
            ```
         | 
| 177 | 
            +
             | 
| 178 | 
            +
            Where credentials is either the base64 encoding of `id` and `api_key` joined by a colon or a hash with the `id` and `api_key`:
         | 
| 179 | 
            +
             | 
| 180 | 
            +
            ``` ruby
         | 
| 181 | 
            +
            Elasticsearch::Client.new(
         | 
| 182 | 
            +
              host: host,
         | 
| 183 | 
            +
              transport_options: transport_options,
         | 
| 184 | 
            +
              api_key: {id: 'my_id', api_key: 'my_api_key'}
         | 
| 185 | 
            +
            )
         | 
| 186 | 
            +
            ```
         | 
| 187 | 
            +
             | 
| 147 188 | 
             
            ### Logging
         | 
| 148 189 |  | 
| 149 | 
            -
            To log requests and responses to standard output with the default logger (an instance of Ruby's {::Logger} class),
         | 
| 150 | 
            -
             | 
| 190 | 
            +
            To log requests and responses to standard output with the default logger (an instance of Ruby's {::Logger} class), set the `log` argument to true:
         | 
| 191 | 
            +
             | 
| 192 | 
            +
            ```ruby
         | 
| 193 | 
            +
            Elasticsearch::Client.new(log: true)
         | 
| 194 | 
            +
            ```
         | 
| 195 | 
            +
             | 
| 196 | 
            +
            You can also use [ecs-logging](https://github.com/elastic/ecs-logging-ruby). `ecs-logging` is a set of libraries that allows you to transform your application logs to structured logs that comply with the [Elastic Common Schema (ECS)](https://www.elastic.co/guide/en/ecs/current/ecs-reference.html):
         | 
| 197 | 
            +
             | 
| 198 | 
            +
            ```ruby
         | 
| 199 | 
            +
            logger = EcsLogging::Logger.new($stdout)
         | 
| 200 | 
            +
            Elasticsearch::Client.new(logger: logger)
         | 
| 201 | 
            +
            ```
         | 
| 151 202 |  | 
| 152 | 
            -
                Elasticsearch::Client.new log: true
         | 
| 153 203 |  | 
| 154 204 | 
             
            To trace requests and responses in the _Curl_ format, set the `trace` argument:
         | 
| 155 205 |  | 
| 156 | 
            -
             | 
| 206 | 
            +
            ```ruby
         | 
| 207 | 
            +
            Elasticsearch::Client.new(trace: true)
         | 
| 208 | 
            +
            ```
         | 
| 157 209 |  | 
| 158 210 | 
             
            You can customize the default logger or tracer:
         | 
| 159 211 |  | 
| 212 | 
            +
            ```ruby
         | 
| 160 213 | 
             
                client.transport.logger.formatter = proc { |s, d, p, m| "#{s}: #{m}\n" }
         | 
| 161 214 | 
             
                client.transport.logger.level = Logger::INFO
         | 
| 215 | 
            +
            ```
         | 
| 162 216 |  | 
| 163 217 | 
             
            Or, you can use a custom `::Logger` instance:
         | 
| 164 218 |  | 
| 165 | 
            -
             | 
| 219 | 
            +
            ```ruby
         | 
| 220 | 
            +
            Elasticsearch::Client.new(logger: Logger.new(STDERR))
         | 
| 221 | 
            +
            ```
         | 
| 166 222 |  | 
| 167 223 | 
             
            You can pass the client any conforming logger implementation:
         | 
| 168 224 |  | 
| 169 | 
            -
             | 
| 225 | 
            +
            ```ruby
         | 
| 226 | 
            +
            require 'logging' # https://github.com/TwP/logging/
         | 
| 227 | 
            +
             | 
| 228 | 
            +
            log = Logging.logger['elasticsearch']
         | 
| 229 | 
            +
            log.add_appenders Logging.appenders.stdout
         | 
| 230 | 
            +
            log.level = :info
         | 
| 231 | 
            +
             | 
| 232 | 
            +
            client = Elasticsearch::Client.new(logger: log)
         | 
| 233 | 
            +
            ```
         | 
| 234 | 
            +
             | 
| 235 | 
            +
            ### Custom HTTP Headers
         | 
| 170 236 |  | 
| 171 | 
            -
             | 
| 172 | 
            -
                log.add_appenders Logging.appenders.stdout
         | 
| 173 | 
            -
                log.level = :info
         | 
| 237 | 
            +
            You can set a custom HTTP header on the client's initializer:
         | 
| 174 238 |  | 
| 175 | 
            -
             | 
| 239 | 
            +
            ```ruby
         | 
| 240 | 
            +
            client = Elasticsearch::Client.new(
         | 
| 241 | 
            +
              transport_options: {
         | 
| 242 | 
            +
                headers:
         | 
| 243 | 
            +
                  {user_agent: "My App"}
         | 
| 244 | 
            +
              }
         | 
| 245 | 
            +
            )
         | 
| 246 | 
            +
            ```
         | 
| 247 | 
            +
             | 
| 248 | 
            +
            You can also pass in `headers` as a parameter to any of the API Endpoints to set custom headers for the request:
         | 
| 249 | 
            +
             | 
| 250 | 
            +
            ```ruby
         | 
| 251 | 
            +
            client.search(index: 'myindex', q: 'title:test', headers: {user_agent: "My App"})
         | 
| 252 | 
            +
            ```
         | 
| 253 | 
            +
             | 
| 254 | 
            +
            ### Identifying running tasks with X-Opaque-Id
         | 
| 255 | 
            +
             | 
| 256 | 
            +
            The X-Opaque-Id header allows to track certain calls, or associate certain tasks with the client that started them ([more on the Elasticsearch docs](https://www.elastic.co/guide/en/elasticsearch/reference/master/tasks.html#_identifying_running_tasks)). To use this feature, you need to set an id for `opaque_id` on the client on each request. Example:
         | 
| 257 | 
            +
             | 
| 258 | 
            +
            ```ruby
         | 
| 259 | 
            +
            client = Elasticsearch::Client.new
         | 
| 260 | 
            +
            client.search(index: 'myindex', q: 'title:test', opaque_id: '123456')
         | 
| 261 | 
            +
            ```
         | 
| 262 | 
            +
            The search request will include the following HTTP Header:
         | 
| 263 | 
            +
            ```
         | 
| 264 | 
            +
            X-Opaque-Id: 123456
         | 
| 265 | 
            +
            ```
         | 
| 266 | 
            +
             | 
| 267 | 
            +
            You can also set a prefix for X-Opaque-Id when initializing the client. This will be prepended to the id you set before each request if you're using X-Opaque-Id. Example:
         | 
| 268 | 
            +
            ```ruby
         | 
| 269 | 
            +
            client = Elasticsearch::Client.new(opaque_id_prefix: 'eu-west1')
         | 
| 270 | 
            +
            client.search(index: 'myindex', q: 'title:test', opaque_id: '123456')
         | 
| 271 | 
            +
            ```
         | 
| 272 | 
            +
            The request will include the following HTTP Header:
         | 
| 273 | 
            +
            ```
         | 
| 274 | 
            +
            X-Opaque-Id: eu-west1_123456
         | 
| 275 | 
            +
            ```
         | 
| 176 276 |  | 
| 177 277 | 
             
            ### Setting Timeouts
         | 
| 178 278 |  | 
| @@ -199,11 +299,16 @@ on a different host: | |
| 199 299 |  | 
| 200 300 | 
             
                Elasticsearch::Client.new hosts: ['localhost:9200', 'localhost:9201'], retry_on_failure: true
         | 
| 201 301 |  | 
| 202 | 
            -
            You can specify how many times  | 
| 203 | 
            -
            (the default is 3 times):
         | 
| 302 | 
            +
            By default, the client will retry the request 3 times. You can specify how many times to retry before it raises an exception by passing a number to `retry_on_failure`:
         | 
| 204 303 |  | 
| 205 304 | 
             
                Elasticsearch::Client.new hosts: ['localhost:9200', 'localhost:9201'], retry_on_failure: 5
         | 
| 206 305 |  | 
| 306 | 
            +
            These two parameters can also be used together:
         | 
| 307 | 
            +
             | 
| 308 | 
            +
            ```ruby
         | 
| 309 | 
            +
            Elasticsearch::Client.new hosts: ['localhost:9200', 'localhost:9201'], retry_on_status: [502, 503], retry_on_failure: 10
         | 
| 310 | 
            +
            ```
         | 
| 311 | 
            +
             | 
| 207 312 | 
             
            ### Reloading Hosts
         | 
| 208 313 |  | 
| 209 314 | 
             
            Elasticsearch by default dynamically discovers new nodes in the cluster. You can leverage this
         | 
| @@ -268,25 +373,29 @@ preferring HTTP clients with support for persistent connections. | |
| 268 373 |  | 
| 269 374 | 
             
            To use the [_Patron_](https://github.com/toland/patron) HTTP, for example, just require it:
         | 
| 270 375 |  | 
| 271 | 
            -
             | 
| 376 | 
            +
            ```ruby
         | 
| 377 | 
            +
            require 'patron'
         | 
| 378 | 
            +
            ```
         | 
| 272 379 |  | 
| 273 380 | 
             
            Then, create a new client, and the _Patron_  gem will be used as the "driver":
         | 
| 274 381 |  | 
| 275 | 
            -
             | 
| 382 | 
            +
            ```ruby
         | 
| 383 | 
            +
            client = Elasticsearch::Client.new
         | 
| 276 384 |  | 
| 277 | 
            -
             | 
| 278 | 
            -
             | 
| 385 | 
            +
            client.transport.connections.first.connection.builder.adapter
         | 
| 386 | 
            +
            # => Faraday::Adapter::Patron
         | 
| 279 387 |  | 
| 280 | 
            -
             | 
| 281 | 
            -
             | 
| 282 | 
            -
             | 
| 283 | 
            -
             | 
| 284 | 
            -
             | 
| 388 | 
            +
            10.times do
         | 
| 389 | 
            +
              client.nodes.stats(metric: 'http')['nodes'].values.each do |n|
         | 
| 390 | 
            +
                puts "#{n['name']} : #{n['http']['total_opened']}"
         | 
| 391 | 
            +
              end
         | 
| 392 | 
            +
            end
         | 
| 285 393 |  | 
| 286 | 
            -
             | 
| 287 | 
            -
             | 
| 288 | 
            -
             | 
| 289 | 
            -
             | 
| 394 | 
            +
            # => Stiletoo : 24
         | 
| 395 | 
            +
            # => Stiletoo : 24
         | 
| 396 | 
            +
            # => Stiletoo : 24
         | 
| 397 | 
            +
            # => ...
         | 
| 398 | 
            +
            ```
         | 
| 290 399 |  | 
| 291 400 | 
             
            To use a specific adapter for _Faraday_, pass it as the `adapter` argument:
         | 
| 292 401 |  | 
| @@ -308,44 +417,32 @@ constructor, use the `transport_options` key: | |
| 308 417 |  | 
| 309 418 | 
             
            To configure the _Faraday_ instance directly, use a block:
         | 
| 310 419 |  | 
| 311 | 
            -
                require ' | 
| 312 | 
            -
                require 'typhoeus/adapters/faraday'
         | 
| 420 | 
            +
                require 'patron'
         | 
| 313 421 |  | 
| 314 422 | 
             
                client = Elasticsearch::Client.new(host: 'localhost', port: '9200') do |f|
         | 
| 315 423 | 
             
                  f.response :logger
         | 
| 316 | 
            -
                  f.adapter  : | 
| 424 | 
            +
                  f.adapter  :patron
         | 
| 317 425 | 
             
                end
         | 
| 318 426 |  | 
| 319 | 
            -
            You can use any standard Faraday middleware and plugins in the configuration block,
         | 
| 320 | 
            -
            for example sign the requests for the [AWS Elasticsearch service](https://aws.amazon.com/elasticsearch-service/):
         | 
| 427 | 
            +
            You can use any standard Faraday middleware and plugins in the configuration block. You can also initialize the transport class yourself, and pass it to the client constructor as the `transport` argument:
         | 
| 321 428 |  | 
| 322 | 
            -
             | 
| 429 | 
            +
            ```ruby
         | 
| 430 | 
            +
            require 'patron'
         | 
| 323 431 |  | 
| 324 | 
            -
             | 
| 325 | 
            -
             | 
| 326 | 
            -
             | 
| 327 | 
            -
             | 
| 328 | 
            -
                            region: 'us-east-1'
         | 
| 329 | 
            -
                end
         | 
| 330 | 
            -
             | 
| 331 | 
            -
            You can also initialize the transport class yourself, and pass it to the client constructor
         | 
| 332 | 
            -
            as the `transport` argument:
         | 
| 432 | 
            +
            transport_configuration = lambda do |f|
         | 
| 433 | 
            +
              f.response :logger
         | 
| 434 | 
            +
              f.adapter  :patron
         | 
| 435 | 
            +
            end
         | 
| 333 436 |  | 
| 334 | 
            -
             | 
| 335 | 
            -
             | 
| 437 | 
            +
            transport = Elasticsearch::Transport::Transport::HTTP::Faraday.new \
         | 
| 438 | 
            +
              hosts: [ { host: 'localhost', port: '9200' } ],
         | 
| 439 | 
            +
              &transport_configuration
         | 
| 336 440 |  | 
| 337 | 
            -
             | 
| 338 | 
            -
             | 
| 339 | 
            -
             | 
| 340 | 
            -
             | 
| 341 | 
            -
             | 
| 342 | 
            -
                transport = Elasticsearch::Transport::Transport::HTTP::Faraday.new \
         | 
| 343 | 
            -
                  hosts: [ { host: 'localhost', port: '9200' } ],
         | 
| 344 | 
            -
                  &transport_configuration
         | 
| 441 | 
            +
            # Pass the transport to the client
         | 
| 442 | 
            +
            #
         | 
| 443 | 
            +
            client = Elasticsearch::Client.new transport: transport
         | 
| 444 | 
            +
            ```
         | 
| 345 445 |  | 
| 346 | 
            -
                # Pass the transport to the client
         | 
| 347 | 
            -
                #
         | 
| 348 | 
            -
                client = Elasticsearch::Client.new transport: transport
         | 
| 349 446 |  | 
| 350 447 | 
             
            Instead of passing the transport to the constructor, you can inject it at run time:
         | 
| 351 448 |  | 
| @@ -461,16 +558,14 @@ Github's pull requests and issues are used to communicate, send bug reports and | |
| 461 558 | 
             
            To work on the code, clone and bootstrap the main repository first --
         | 
| 462 559 | 
             
            please see instructions in the main [README](../README.md#development).
         | 
| 463 560 |  | 
| 464 | 
            -
            To run tests, launch a testing cluster  | 
| 465 | 
            -
            in the main [README](../README.md#development) -- and use the Rake tasks:
         | 
| 561 | 
            +
            To run tests, launch a testing cluster and use the Rake tasks:
         | 
| 466 562 |  | 
| 467 563 | 
             
            ```
         | 
| 468 564 | 
             
            time rake test:unit
         | 
| 469 565 | 
             
            time rake test:integration
         | 
| 470 566 | 
             
            ```
         | 
| 471 567 |  | 
| 472 | 
            -
             | 
| 473 | 
            -
            can use Ruby 2.x syntax and features.
         | 
| 568 | 
            +
            Use `COVERAGE=true` before running a test task to check coverage with Simplecov.
         | 
| 474 569 |  | 
| 475 570 | 
             
            ## License
         | 
| 476 571 |  | 
    
        data/Rakefile
    CHANGED
    
    | @@ -1,6 +1,19 @@ | |
| 1 | 
            -
            # Licensed to Elasticsearch B.V under one or more  | 
| 2 | 
            -
            #  | 
| 3 | 
            -
            #  | 
| 1 | 
            +
            # Licensed to Elasticsearch B.V. under one or more contributor
         | 
| 2 | 
            +
            # license agreements. See the NOTICE file distributed with
         | 
| 3 | 
            +
            # this work for additional information regarding copyright
         | 
| 4 | 
            +
            # ownership. Elasticsearch B.V. licenses this file to you under
         | 
| 5 | 
            +
            # the Apache License, Version 2.0 (the "License"); you may
         | 
| 6 | 
            +
            # not use this file except in compliance with the License.
         | 
| 7 | 
            +
            # You may obtain a copy of the License at
         | 
| 8 | 
            +
            #
         | 
| 9 | 
            +
            #   http://www.apache.org/licenses/LICENSE-2.0
         | 
| 10 | 
            +
            #
         | 
| 11 | 
            +
            # Unless required by applicable law or agreed to in writing,
         | 
| 12 | 
            +
            # software distributed under the License is distributed on an
         | 
| 13 | 
            +
            # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
         | 
| 14 | 
            +
            # KIND, either express or implied.  See the License for the
         | 
| 15 | 
            +
            # specific language governing permissions and limitations
         | 
| 16 | 
            +
            # under the License.
         | 
| 4 17 |  | 
| 5 18 | 
             
            require "bundler/gem_tasks"
         | 
| 6 19 |  | 
| @@ -12,40 +25,77 @@ task :test    => 'test:unit' | |
| 12 25 |  | 
| 13 26 | 
             
            require 'rake/testtask'
         | 
| 14 27 | 
             
            require 'rspec/core/rake_task'
         | 
| 28 | 
            +
            FARADAY1_GEMFILE = 'Gemfile-faraday1.gemfile'.freeze
         | 
| 29 | 
            +
            GEMFILES = ['Gemfile', FARADAY1_GEMFILE].freeze
         | 
| 15 30 |  | 
| 16 | 
            -
             | 
| 31 | 
            +
            task :install do
         | 
| 32 | 
            +
              GEMFILES.each do |gemfile|
         | 
| 33 | 
            +
                gemfile = File.expand_path("../#{gemfile}", __FILE__)
         | 
| 34 | 
            +
                sh "bundle install --gemfile #{gemfile}"
         | 
| 35 | 
            +
              end
         | 
| 36 | 
            +
            end
         | 
| 17 37 |  | 
| 18 | 
            -
             | 
| 38 | 
            +
            namespace :test do
         | 
| 39 | 
            +
              desc 'Wait for Elasticsearch to be in a green state'
         | 
| 19 40 | 
             
              task :wait_for_green do
         | 
| 20 41 | 
             
                sh '../scripts/wait-cluster.sh'
         | 
| 21 42 | 
             
              end
         | 
| 22 43 |  | 
| 23 | 
            -
              task :spec => :wait_for_green
         | 
| 24 44 | 
             
              RSpec::Core::RakeTask.new(:spec)
         | 
| 25 45 |  | 
| 26 46 | 
             
              Rake::TestTask.new(:unit) do |test|
         | 
| 27 47 | 
             
                test.libs << 'lib' << 'test'
         | 
| 28 | 
            -
                test.test_files = FileList[ | 
| 48 | 
            +
                test.test_files = FileList['test/unit/**/*_test.rb']
         | 
| 29 49 | 
             
                test.verbose = false
         | 
| 30 50 | 
             
                test.warning = false
         | 
| 31 51 | 
             
              end
         | 
| 32 52 |  | 
| 33 53 | 
             
              Rake::TestTask.new(:integration) do |test|
         | 
| 34 54 | 
             
                test.libs << 'lib' << 'test'
         | 
| 35 | 
            -
                test.test_files = FileList[ | 
| 36 | 
            -
                test.deps = [ | 
| 55 | 
            +
                test.test_files = FileList['test/integration/**/*_test.rb']
         | 
| 56 | 
            +
                test.deps = ['test:wait_for_green', 'test:spec']
         | 
| 37 57 | 
             
                test.verbose = false
         | 
| 38 58 | 
             
                test.warning = false
         | 
| 39 59 | 
             
              end
         | 
| 40 60 |  | 
| 41 | 
            -
               | 
| 42 | 
            -
             | 
| 43 | 
            -
                 | 
| 61 | 
            +
              desc 'Run all tests'
         | 
| 62 | 
            +
              task :all do
         | 
| 63 | 
            +
                Rake::Task['test:unit'].invoke
         | 
| 64 | 
            +
                Rake::Task['test:spec'].invoke
         | 
| 65 | 
            +
                Rake::Task['test:integration'].invoke
         | 
| 44 66 | 
             
              end
         | 
| 45 67 |  | 
| 46 68 | 
             
              Rake::TestTask.new(:profile) do |test|
         | 
| 47 69 | 
             
                test.libs << 'lib' << 'test'
         | 
| 48 | 
            -
                test.test_files = FileList[ | 
| 70 | 
            +
                test.test_files = FileList['test/profile/**/*_test.rb']
         | 
| 71 | 
            +
              end
         | 
| 72 | 
            +
             | 
| 73 | 
            +
              namespace :faraday1 do
         | 
| 74 | 
            +
                desc 'Faraday 1: Run RSpec with dependency on Faraday 1'
         | 
| 75 | 
            +
                task :spec do
         | 
| 76 | 
            +
                  sh "BUNDLE_GEMFILE=#{FARADAY1_GEMFILE} bundle exec rspec"
         | 
| 77 | 
            +
                end
         | 
| 78 | 
            +
             | 
| 79 | 
            +
                desc 'Faraday 1: Run unit tests with dependency on Faraday 1'
         | 
| 80 | 
            +
                task :unit do
         | 
| 81 | 
            +
                  Dir.glob('./test/unit/**/**.rb').each do |test|
         | 
| 82 | 
            +
                    sh "BUNDLE_GEMFILE=#{FARADAY1_GEMFILE} ruby -Ilib:test #{test}"
         | 
| 83 | 
            +
                  end
         | 
| 84 | 
            +
                end
         | 
| 85 | 
            +
             | 
| 86 | 
            +
                desc 'Faraday 1: Run integration tests with dependency on Faraday 1'
         | 
| 87 | 
            +
                task :integration do
         | 
| 88 | 
            +
                  Dir.glob('./test/integration/**/**.rb').each do |test|
         | 
| 89 | 
            +
                    sh "BUNDLE_GEMFILE=#{FARADAY1_GEMFILE} ruby -Ilib:test #{test}"
         | 
| 90 | 
            +
                  end
         | 
| 91 | 
            +
                end
         | 
| 92 | 
            +
             | 
| 93 | 
            +
                desc 'Faraday 1: Run all tests'
         | 
| 94 | 
            +
                task :all do
         | 
| 95 | 
            +
                  Rake::Task['test:faraday1:unit'].invoke
         | 
| 96 | 
            +
                  Rake::Task['test:faraday1:spec'].invoke
         | 
| 97 | 
            +
                  Rake::Task['test:faraday1:integration'].invoke
         | 
| 98 | 
            +
                end
         | 
| 49 99 | 
             
              end
         | 
| 50 100 |  | 
| 51 101 | 
             
              namespace :cluster do
         |