elastic-transport 8.3.7 → 8.4.0

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.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/.github/check_license_headers.rb +33 -0
  3. data/.github/license-header.txt +16 -0
  4. data/.github/workflows/license.yml +13 -0
  5. data/.github/workflows/otel.yml +48 -0
  6. data/.github/workflows/tests.yml +85 -0
  7. data/.gitignore +19 -0
  8. data/CHANGELOG.md +33 -9
  9. data/CONTRIBUTING.md +7 -1
  10. data/Gemfile +39 -0
  11. data/Gemfile-faraday1.gemfile +40 -0
  12. data/Rakefile +133 -0
  13. data/elastic-transport.gemspec +71 -0
  14. data/lib/elastic/transport/client.rb +19 -15
  15. data/lib/elastic/transport/opentelemetry.rb +36 -29
  16. data/lib/elastic/transport/transport/base.rb +6 -10
  17. data/lib/elastic/transport/transport/errors.rb +0 -2
  18. data/lib/elastic/transport/transport/http/curb.rb +9 -13
  19. data/lib/elastic/transport/transport/http/manticore.rb +5 -7
  20. data/lib/elastic/transport/transport/serializer/multi_json.rb +2 -16
  21. data/lib/elastic/transport/transport/sniffer.rb +0 -2
  22. data/lib/elastic/transport/version.rb +1 -1
  23. data/lib/elastic/transport.rb +1 -0
  24. data/spec/elastic/connections/collection_spec.rb +266 -0
  25. data/spec/elastic/connections/selector_spec.rb +166 -0
  26. data/spec/elastic/transport/base_spec.rb +265 -0
  27. data/spec/elastic/transport/client_spec.rb +1805 -0
  28. data/spec/elastic/transport/http/curb_spec.rb +126 -0
  29. data/spec/elastic/transport/http/faraday_spec.rb +141 -0
  30. data/spec/elastic/transport/http/manticore_spec.rb +164 -0
  31. data/spec/elastic/transport/meta_header_spec.rb +289 -0
  32. data/spec/elastic/transport/opentelemetry_spec.rb +325 -0
  33. data/spec/elastic/transport/sniffer_spec.rb +293 -0
  34. data/spec/spec_helper.rb +105 -0
  35. data/test/integration/jruby_test.rb +46 -0
  36. data/test/integration/transport_test.rb +144 -0
  37. data/test/profile/client_benchmark_test.rb +132 -0
  38. data/test/test_helper.rb +86 -0
  39. data/test/unit/adapters_test.rb +104 -0
  40. data/test/unit/connection_test.rb +133 -0
  41. data/test/unit/response_test.rb +30 -0
  42. data/test/unit/serializer_test.rb +33 -0
  43. data/test/unit/transport_base_test.rb +663 -0
  44. data/test/unit/transport_curb_test.rb +134 -0
  45. data/test/unit/transport_faraday_test.rb +228 -0
  46. data/test/unit/transport_manticore_test.rb +268 -0
  47. metadata +79 -9
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6c74ecb8b5f87503b024bd292d35e9f090d5de7cb4974354af36b566f9866b2f
4
- data.tar.gz: fab6e1f899769073a83692e677be0904c819c4660f4d21908ed6068f0eb5d774
3
+ metadata.gz: 88698d9c25a84a6242bfb875623c2bca0bd9a0e5c40244272e88fe291b06a9e0
4
+ data.tar.gz: 90aff86e0a0f301908c888877d97a72ac926e9b5f7f48b23ad447813a729824d
5
5
  SHA512:
6
- metadata.gz: 4d79595ce41082119444253c1ea940e81ce4beef9c80c7ec7e7b9b7f780f514ffd1ac264455bea49616fa064d2b69c95a1f5977edd93c63ea19cfd5a4c6117d5
7
- data.tar.gz: 3c10b49555b514cac6d7c8fe7638d5047e8636114e089e2354032cf39af088247fb0661fb0fae1199c87a59df772991961188df91006912c7b7920ee5d0394a6
6
+ metadata.gz: 3a235c8813516864b3b661790c56c9eeb6c8ee8b44a208d70a3309faca0075e9b45f25890be47d56ed29b845a70c5d3f6cd45c617592543993a0c6d788eb7211
7
+ data.tar.gz: 9cd571ba906d3e841f63f8bf3ea018820d0d9e2eddb9171f01785b6787df5ed19fecbeb0b05e494428af8853d2040c78c32f25a370c612d55a4a69ed77798682
@@ -0,0 +1,33 @@
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
+ LICENSE = File.read('./.github/license-header.txt')
19
+ files = `git ls-files | grep -E '\.rb|Rakefile|\.rake|\.erb|Gemfile|gemspec'`.split("\n")
20
+ errors = []
21
+
22
+ files.each do |file|
23
+ unless File.read(file).include?(LICENSE)
24
+ errors << file
25
+ puts "#{file} doesn't contain the correct license header"
26
+ end
27
+ end
28
+
29
+ if errors.empty?
30
+ puts 'All checked files have the correct license header'
31
+ else
32
+ exit 1
33
+ end
@@ -0,0 +1,16 @@
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.
@@ -0,0 +1,13 @@
1
+ name: License headers
2
+ on: [pull_request]
3
+ jobs:
4
+ build:
5
+ runs-on: ubuntu-latest
6
+ steps:
7
+ - uses: actions/checkout@v4
8
+ - uses: ruby/setup-ruby@v1
9
+ with:
10
+ ruby-version: '3.4'
11
+ - name: Check license headers
12
+ run: |
13
+ ruby ./.github/check_license_headers.rb
@@ -0,0 +1,48 @@
1
+ name: opentelemetry
2
+ on:
3
+ push:
4
+ branches:
5
+ - main
6
+ pull_request:
7
+ branches:
8
+ - main
9
+ jobs:
10
+ test-otel:
11
+ name: 'Test Open Telemetry'
12
+ env:
13
+ TEST_ES_SERVER: http://localhost:9250
14
+ PORT: 9250
15
+ TEST_WITH_OTEL: true
16
+ strategy:
17
+ fail-fast: false
18
+ matrix:
19
+ ruby: ['3.4', 'jruby-9.4']
20
+ es_version: ['8.17.0-SNAPSHOT']
21
+ runs-on: ubuntu-latest
22
+ steps:
23
+ - uses: actions/checkout@v4
24
+ - name: Increase system limits
25
+ run: |
26
+ sudo swapoff -a
27
+ sudo sysctl -w vm.swappiness=1
28
+ sudo sysctl -w fs.file-max=262144
29
+ sudo sysctl -w vm.max_map_count=262144
30
+ - uses: elastic/elastic-github-actions/elasticsearch@master
31
+ with:
32
+ stack-version: ${{ matrix.es_version }}
33
+ security-enabled: false
34
+ - uses: ruby/setup-ruby@v1
35
+ with:
36
+ ruby-version: ${{ matrix.ruby }}
37
+ - name: Build and test with Rake
38
+ run: |
39
+ sudo apt-get update
40
+ sudo apt-get install libcurl4-openssl-dev
41
+ ruby -v
42
+ bundle install
43
+ - name: unit tests
44
+ run: bundle exec rake test:unit
45
+ - name: specs
46
+ run: bundle exec rake test:spec
47
+ - name: integration tests
48
+ run: bundle exec rake test:integration
@@ -0,0 +1,85 @@
1
+ name: main tests
2
+ on:
3
+ push:
4
+ branches:
5
+ - main
6
+ pull_request:
7
+ branches:
8
+ - main
9
+ jobs:
10
+ test:
11
+ name: 'Main tests'
12
+ env:
13
+ TEST_ES_SERVER: http://localhost:9250
14
+ PORT: 9250
15
+ strategy:
16
+ fail-fast: false
17
+ matrix:
18
+ ruby: ['3.1', '3.2', '3.3', '3.4', 'jruby-9.3', 'jruby-9.4']
19
+ es_version: ['8.16.0-SNAPSHOT', '8.17.0-SNAPSHOT', '8.18.0-SNAPSHOT']
20
+ runs-on: ubuntu-latest
21
+ steps:
22
+ - uses: actions/checkout@v4
23
+ - name: Increase system limits
24
+ run: |
25
+ sudo swapoff -a
26
+ sudo sysctl -w vm.swappiness=1
27
+ sudo sysctl -w fs.file-max=262144
28
+ sudo sysctl -w vm.max_map_count=262144
29
+ - uses: elastic/elastic-github-actions/elasticsearch@master
30
+ with:
31
+ stack-version: ${{ matrix.es_version }}
32
+ security-enabled: false
33
+ - uses: ruby/setup-ruby@v1
34
+ with:
35
+ ruby-version: ${{ matrix.ruby }}
36
+ - name: Build and test with Rake
37
+ run: |
38
+ sudo apt-get update
39
+ sudo apt-get install libcurl4-openssl-dev
40
+ ruby -v
41
+ bundle install
42
+ - name: unit tests
43
+ run: bundle exec rake test:unit
44
+ - name: specs
45
+ run: bundle exec rake test:spec
46
+ - name: integration tests
47
+ run: bundle exec rake test:integration
48
+ test-faraday1:
49
+ name: 'Test Faraday 1'
50
+ env:
51
+ TEST_ES_SERVER: http://localhost:9250
52
+ PORT: 9250
53
+ strategy:
54
+ fail-fast: false
55
+ matrix:
56
+ ruby: ['3.0', '3.1', '3.2', '3.3', 'jruby-9.3']
57
+ es_version: ['8.16.0-SNAPSHOT']
58
+ runs-on: ubuntu-latest
59
+ steps:
60
+ - uses: actions/checkout@v4
61
+ - name: Increase system limits
62
+ run: |
63
+ sudo swapoff -a
64
+ sudo sysctl -w vm.swappiness=1
65
+ sudo sysctl -w fs.file-max=262144
66
+ sudo sysctl -w vm.max_map_count=262144
67
+ - uses: elastic/elastic-github-actions/elasticsearch@master
68
+ with:
69
+ stack-version: ${{ matrix.es_version }}
70
+ security-enabled: false
71
+ - uses: ruby/setup-ruby@v1
72
+ with:
73
+ ruby-version: ${{ matrix.ruby }}
74
+ - name: Build and test with Rake
75
+ run: |
76
+ sudo apt-get update
77
+ sudo apt-get install libcurl4-openssl-dev
78
+ ruby -v
79
+ BUNDLE_GEMFILE=./Gemfile-faraday1.gemfile bundle install
80
+ - name: faraday1 unit tests
81
+ run: BUNDLE_GEMFILE=./Gemfile-faraday1.gemfile bundle exec rake test:faraday1:unit
82
+ - name: specs
83
+ run: BUNDLE_GEMFILE=./Gemfile-faraday1.gemfile bundle exec rake test:faraday1:spec
84
+ - name: integration tests
85
+ run: BUNDLE_GEMFILE=./Gemfile-faraday1.gemfile bundle exec rake test:faraday1:integration
data/.gitignore ADDED
@@ -0,0 +1,19 @@
1
+ *.gem
2
+ *.rbc
3
+ *.log
4
+ .byebug_history
5
+ .bundle
6
+ .config
7
+ .yardoc
8
+ Gemfile*.lock
9
+ InstalledFiles
10
+ _yardoc
11
+ coverage
12
+ doc/
13
+ lib/bundler/man
14
+ pkg
15
+ rdoc
16
+ spec/reports
17
+ test/tmp
18
+ test/version_tmp
19
+ tmp
data/CHANGELOG.md CHANGED
@@ -1,15 +1,39 @@
1
- ## 8.3.7
1
+ ## 8.4.0
2
2
 
3
- - Minor refactor to `curb` implementation.
4
- - Updated `yard` development dependency to `> 0.9.42`.
5
- - Fix `multi_json` deprecation warnings. Some deprecations [were introduced in `multi_json` 1.21.0](https://github.com/sferik/multi_json/blob/main/CHANGELOG.md#1210). Pull Request: [#112](https://github.com/elastic/elastic-transport-ruby/pull/112).
6
- - Reduced gem size. Pull Request: [#114](https://github.com/elastic/elastic-transport-ruby/pull/114).
7
- - Addresses duplicate `content-type` header in Manticore. Pull Request: [#115](https://github.com/elastic/elastic-transport-ruby/pull/115).
3
+ - Adds support for **[Excon](https://github.com/excon/excon)** Faraday adapter. You can use the Excon adapter by setting it in when initializing an Elasticsearch client:
8
4
 
9
- ## 8.3.6
5
+ ```ruby
6
+ require 'faraday/excon'
10
7
 
11
- - Moves `require 'timeout'` to the classes that use it. Closed [#79](https://github.com/elastic/elastic-transport-ruby/issues/79).
12
- - Sanitize url on OTEL spans, thanks @steve21168. Pull Request: [#98](https://github.com/elastic/elastic-transport-ruby/pull/98)
8
+ Elasticsearch::Client.new(
9
+ host: host,
10
+ transport_options: transport_options,
11
+ adapter: :excon
12
+ )
13
+ ```
14
+
15
+ Excon may need some specific configuration for HTTPS/SSL. You may see certificate verification errors when trying to connect to Elastic. Excon has certificates bundled, but these can be customized:
16
+
17
+ ```ruby
18
+ Excon.defaults[:ssl_ca_path] = path_to_certs
19
+ ENV['SSL_CERT_DIR'] = path_to_certs
20
+ Excon.defaults[:ssl_ca_file] = path_to_file
21
+ ENV['SSL_CERT_FILE'] = path_to_file
22
+ Excon.defaults[:ssl_verify_callback] = callback
23
+ # (see OpenSSL::SSL::SSLContext#verify_callback)
24
+ Excon.defaults[:ssl_verify_peer] = false` # (less secure).
25
+ ```
26
+
27
+ - Adds support for **[Async::HTTP::Faraday](https://github.com/socketry/async-http-faraday)**. You can use the adapter by setting it when initializing an Elasticsearch client:
28
+ ```ruby
29
+ require 'async-http-faraday'
30
+
31
+ Elasticsearch::Client.new(
32
+ host: host,
33
+ adapter: :async_http
34
+ )
35
+ ```
36
+ - Minor refactors, styling fixes.
13
37
 
14
38
  ## 8.3.5
15
39
 
data/CONTRIBUTING.md CHANGED
@@ -41,7 +41,13 @@ E.g.:
41
41
  $ rake docker:start[8.0.0-alpha1]
42
42
  ```
43
43
 
44
- You can find the available version in [Docker @ Elastic](https://www.docker.elastic.co/r/elasticsearch).
44
+ You can find the available version in [Docker @ Elastic](https://www.docker.elastic.co/r/elasticsearch). You can also run Elasticsearch and Kibana locally with Docker with `start-local`:
45
+
46
+ ```bash
47
+ curl -fsSL https://elastic.co/start-local | sh
48
+ ```
49
+
50
+ This will run Elasticsearch in http://localhost:9200 and Kibana in http://localhost:5601. More information is available [here](https://www.elastic.co/guide/en/elasticsearch/reference/current/run-elasticsearch-locally.html).
45
51
 
46
52
  # Contributing
47
53
 
data/Gemfile ADDED
@@ -0,0 +1,39 @@
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
+ # Specify your gem's dependencies in elasticsearch-transport.gemspec
21
+ gemspec
22
+
23
+ group :development, :test do
24
+ gem 'faraday-excon'
25
+ gem 'faraday-httpclient'
26
+ gem 'faraday-net_http_persistent'
27
+ gem 'faraday-typhoeus'
28
+ gem 'mutex_m' if RUBY_VERSION >= '3.4'
29
+ gem 'opentelemetry-sdk', require: false if RUBY_VERSION >= '3.0'
30
+ if defined?(JRUBY_VERSION)
31
+ gem 'pry-nav'
32
+ else
33
+ gem 'async-http-faraday'
34
+ gem 'faraday-patron'
35
+ gem 'oj'
36
+ gem 'pry-byebug'
37
+ end
38
+ gem 'rspec'
39
+ end
@@ -0,0 +1,40 @@
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
27
+
28
+ group :development, :test do
29
+ gem 'httpclient'
30
+ gem 'net-http-persistent'
31
+ gem 'rspec'
32
+ gem 'typhoeus'
33
+ if defined?(JRUBY_VERSION)
34
+ gem 'pry-nav'
35
+ else
36
+ gem 'pry-byebug'
37
+ gem 'oj'
38
+ gem 'patron'
39
+ end
40
+ end
data/Rakefile ADDED
@@ -0,0 +1,133 @@
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
+ require 'bundler/gem_tasks'
19
+ require 'mkmf'
20
+
21
+ desc 'Run unit tests'
22
+ task default: 'test:unit'
23
+ task test: 'test:unit'
24
+
25
+ # ----- Test tasks ------------------------------------------------------------
26
+ require 'rake/testtask'
27
+ require 'rspec/core/rake_task'
28
+ FARADAY1_GEMFILE = 'Gemfile-faraday1.gemfile'.freeze
29
+ GEMFILES = ['Gemfile', FARADAY1_GEMFILE].freeze
30
+
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
37
+
38
+ namespace :test do
39
+ RSpec::Core::RakeTask.new(:spec)
40
+
41
+ Rake::TestTask.new(:unit) do |test|
42
+ test.libs << 'lib' << 'test'
43
+ test.test_files = FileList['test/unit/**/*_test.rb']
44
+ test.verbose = false
45
+ test.warning = false
46
+ end
47
+
48
+ Rake::TestTask.new(:integration) do |test|
49
+ test.libs << 'lib' << 'test'
50
+ test.test_files = FileList['test/integration/**/*_test.rb']
51
+ test.verbose = false
52
+ test.warning = false
53
+ end
54
+
55
+ desc 'Run all tests'
56
+ task :all do
57
+ Rake::Task['test:unit'].invoke
58
+ Rake::Task['test:spec'].invoke
59
+ Rake::Task['test:integration'].invoke
60
+ end
61
+
62
+ Rake::TestTask.new(:profile) do |test|
63
+ test.libs << 'lib' << 'test'
64
+ test.test_files = FileList['test/profile/**/*_test.rb']
65
+ end
66
+
67
+ namespace :faraday1 do
68
+ desc 'Faraday 1: Run RSpec with dependency on Faraday 1'
69
+ task :spec do
70
+ sh "BUNDLE_GEMFILE=#{FARADAY1_GEMFILE} bundle exec rspec"
71
+ end
72
+
73
+ desc 'Faraday 1: Run unit tests with dependency on Faraday 1'
74
+ task :unit do
75
+ Dir.glob('./test/unit/**/**.rb').each do |test|
76
+ sh "BUNDLE_GEMFILE=#{FARADAY1_GEMFILE} ruby -Ilib:test #{test}"
77
+ end
78
+ end
79
+
80
+ desc 'Faraday 1: Run integration tests with dependency on Faraday 1'
81
+ task :integration do
82
+ Dir.glob('./test/integration/**/**.rb').each do |test|
83
+ sh "BUNDLE_GEMFILE=#{FARADAY1_GEMFILE} ruby -Ilib:test #{test}"
84
+ end
85
+ end
86
+
87
+ desc 'Faraday 1: Run all tests'
88
+ task :all do
89
+ Rake::Task['test:faraday1:unit'].invoke
90
+ Rake::Task['test:faraday1:spec'].invoke
91
+ Rake::Task['test:faraday1:integration'].invoke
92
+ end
93
+ end
94
+ end
95
+
96
+ namespace :docker do
97
+ desc <<~DOC
98
+ Start Elasticsearch in a Docker container. Credentials are 'elastic:changeme'.
99
+
100
+ Default:
101
+ rake docker:start[version]
102
+ E.g.:
103
+ rake docker:start[8.0.0-SNAPSHOT]
104
+ DOC
105
+ task :start, [:version] do |_, params|
106
+ abort 'Docker not installed' unless find_executable 'docker'
107
+ abort 'You need to set a version, e.g. rake docker:start[7.x-SNAPSHOT]' unless params[:version]
108
+
109
+ system("docker run -p 9200:9200 -p 9300:9300 -e 'discovery.type=single-node' -e ELASTIC_PASSWORD=changeme docker.elastic.co/elasticsearch/elasticsearch:#{params[:version]}")
110
+ end
111
+ end
112
+
113
+ desc 'Run Ruby console with the Elastic transport client libraries loaded'
114
+ task :console do
115
+ require 'irb'
116
+ require 'irb/completion'
117
+ require 'elastic-transport'
118
+ ARGV.clear
119
+ IRB.start
120
+ end
121
+
122
+ # ----- Documentation tasks ---------------------------------------------------
123
+ require 'yard'
124
+ YARD::Rake::YardocTask.new(:doc) do |t|
125
+ t.options = %w| --embed-mixins --markup=markdown |
126
+ end
127
+
128
+ # ----- Code analysis tasks ---------------------------------------------------
129
+ require 'cane/rake_task'
130
+ Cane::RakeTask.new(:quality) do |cane|
131
+ cane.abc_max = 15
132
+ cane.no_style = true
133
+ end
@@ -0,0 +1,71 @@
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
+ # coding: utf-8
19
+ lib = File.expand_path('../lib', __FILE__)
20
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
21
+ require 'elastic/transport/version'
22
+
23
+ Gem::Specification.new do |s|
24
+ s.name = "elastic-transport"
25
+ s.version = Elastic::Transport::VERSION
26
+ s.authors = ['Elastic Client Library Maintainers']
27
+ s.email = ['client-libs@elastic.co']
28
+ s.summary = 'Low level Ruby client for Elastic services.'
29
+ s.homepage = 'https://github.com/elastic/elastic-transport-ruby'
30
+ s.license = 'Apache-2.0'
31
+ s.metadata = {
32
+ 'homepage_uri' => 'https://github.com/elastic/elastic-transport-ruby',
33
+ 'changelog_uri' => 'https://github.com/elastic/elastic-transport-ruby/blob/master/CHANGELOG.md',
34
+ 'source_code_uri' => 'https://github.com/elastic/elastic-transport-ruby',
35
+ 'bug_tracker_uri' => 'https://github.com/elastic/elastic-transport-ruby/issues'
36
+ }
37
+ s.files = `git ls-files`.split($/)
38
+ s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
39
+ s.test_files = s.files.grep(%r{^(test|spec|features)/})
40
+ s.require_paths = ['lib']
41
+
42
+ s.extra_rdoc_files = ['README.md', 'LICENSE']
43
+ s.rdoc_options = [ '--charset=UTF-8' ]
44
+
45
+ s.required_ruby_version = '>= 2.5'
46
+
47
+ s.add_dependency 'faraday', '< 3'
48
+ s.add_dependency 'multi_json'
49
+
50
+ # Faraday Adapters
51
+ s.add_development_dependency 'manticore' if defined? JRUBY_VERSION
52
+ s.add_development_dependency 'curb' unless defined? JRUBY_VERSION
53
+ s.add_development_dependency 'bundler'
54
+ s.add_development_dependency 'cane'
55
+ s.add_development_dependency 'hashie'
56
+ s.add_development_dependency 'minitest'
57
+ s.add_development_dependency 'minitest-reporters'
58
+ s.add_development_dependency 'mocha'
59
+ s.add_development_dependency 'pry'
60
+ s.add_development_dependency 'rake', '~> 13'
61
+ s.add_development_dependency 'require-prof' unless defined?(JRUBY_VERSION) || defined?(Rubinius)
62
+ s.add_development_dependency 'ruby-prof' unless defined?(JRUBY_VERSION) || defined?(Rubinius)
63
+ s.add_development_dependency 'shoulda-context'
64
+ s.add_development_dependency 'simplecov'
65
+ s.add_development_dependency 'test-unit', '~> 2'
66
+ s.add_development_dependency 'yard'
67
+
68
+ s.description = <<-DESC.gsub(/^ /, '')
69
+ Low level Ruby client for Elastic. See the `elasticsearch` or `elastic-enterprise-search` gems for full integration.
70
+ DESC
71
+ end
@@ -123,8 +123,8 @@ module Elastic
123
123
  #
124
124
  def initialize(arguments = {}, &block)
125
125
  @arguments = arguments.transform_keys(&:to_sym)
126
- @arguments[:logger] ||= @arguments[:log] ? DEFAULT_LOGGER.call() : nil
127
- @arguments[:tracer] ||= @arguments[:trace] ? DEFAULT_TRACER.call() : nil
126
+ @arguments[:logger] ||= @arguments[:log] ? DEFAULT_LOGGER.call : nil
127
+ @arguments[:tracer] ||= @arguments[:trace] ? DEFAULT_TRACER.call : nil
128
128
  @arguments[:reload_connections] ||= false
129
129
  @arguments[:retry_on_failure] ||= false
130
130
  @arguments[:delay_on_retry] ||= 0
@@ -134,13 +134,7 @@ module Elastic
134
134
  @arguments[:http] ||= {}
135
135
  @arguments[:enable_meta_header] = arguments.fetch(:enable_meta_header, true)
136
136
 
137
- @hosts ||= __extract_hosts(@arguments[:hosts] ||
138
- @arguments[:host] ||
139
- @arguments[:url] ||
140
- @arguments[:urls] ||
141
- ENV['ELASTICSEARCH_URL'] ||
142
- DEFAULT_HOST)
143
-
137
+ @hosts ||= extract_hosts
144
138
  @send_get_body_as = @arguments[:send_get_body_as] || 'GET'
145
139
  @ca_fingerprint = @arguments.delete(:ca_fingerprint)
146
140
 
@@ -153,7 +147,7 @@ module Elastic
153
147
  else
154
148
  @transport_class = @arguments[:transport_class] || DEFAULT_TRANSPORT_CLASS
155
149
  @transport = if @transport_class == Transport::HTTP::Faraday
156
- @arguments[:adapter] ||= __auto_detect_adapter
150
+ @arguments[:adapter] ||= auto_detect_adapter
157
151
  set_meta_header # from include MetaHeader
158
152
  @transport_class.new(hosts: @hosts, options: @arguments) do |faraday|
159
153
  faraday.adapter(@arguments[:adapter])
@@ -246,7 +240,7 @@ module Elastic
246
240
  #
247
241
  # @api private
248
242
  #
249
- def __extract_hosts(hosts_config)
243
+ def extract_hosts
250
244
  hosts = case hosts_config
251
245
  when String
252
246
  hosts_config.split(',').map { |h| h.strip! || h }
@@ -257,12 +251,20 @@ module Elastic
257
251
  else
258
252
  Array(hosts_config)
259
253
  end
260
-
261
- host_list = hosts.map { |host| __parse_host(host) }
254
+ host_list = hosts.map { |host| parse_host(host) }
262
255
  @arguments[:randomize_hosts] ? host_list.shuffle! : host_list
263
256
  end
264
257
 
265
- def __parse_host(host)
258
+ def hosts_config
259
+ @arguments[:hosts] ||
260
+ @arguments[:host] ||
261
+ @arguments[:url] ||
262
+ @arguments[:urls] ||
263
+ ENV['ELASTICSEARCH_URL'] ||
264
+ DEFAULT_HOST
265
+ end
266
+
267
+ def parse_host(host)
266
268
  host_parts = case host
267
269
  when String
268
270
  if host =~ /^[a-z]+\:\/\//
@@ -313,12 +315,14 @@ module Elastic
313
315
  #
314
316
  # @api private
315
317
  #
316
- def __auto_detect_adapter
318
+ def auto_detect_adapter
317
319
  if Gem::Version.new(Faraday::VERSION) >= Gem::Version.new(2)
318
320
  return :patron if defined?(Faraday::Adapter::Patron)
319
321
  return :typhoeus if defined?(Faraday::Adapter::Typhoeus)
320
322
  return :httpclient if defined?(Faraday::Adapter::HTTPClient)
321
323
  return :net_http_persistent if defined?(Faraday::Adapter::NetHttpPersistent)
324
+ return :excon if defined?(Faraday::Adapter::Excon)
325
+ return :async_http if defined?(Async::HTTP::Faraday)
322
326
  else
323
327
  return :patron if defined?(::Patron)
324
328
  return :typhoeus if defined?(::Typhoeus)