elastic-transport 8.3.2 → 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.
- checksums.yaml +4 -4
- data/.github/workflows/license.yml +2 -2
- data/.github/workflows/otel.yml +3 -3
- data/.github/workflows/tests.yml +6 -7
- data/CHANGELOG.md +47 -0
- data/CONTRIBUTING.md +7 -1
- data/Gemfile +7 -6
- data/Gemfile-faraday1.gemfile +3 -3
- data/lib/elastic/transport/client.rb +24 -19
- data/lib/elastic/transport/meta_header.rb +12 -1
- data/lib/elastic/transport/opentelemetry.rb +36 -29
- data/lib/elastic/transport/transport/base.rb +3 -3
- data/lib/elastic/transport/transport/serializer/multi_json.rb +3 -3
- data/lib/elastic/transport/version.rb +1 -1
- data/spec/elastic/transport/client_spec.rb +33 -0
- data/test/unit/adapters_test.rb +17 -1
- data/test/unit/connection_test.rb +35 -37
- metadata +3 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 88698d9c25a84a6242bfb875623c2bca0bd9a0e5c40244272e88fe291b06a9e0
|
4
|
+
data.tar.gz: 90aff86e0a0f301908c888877d97a72ac926e9b5f7f48b23ad447813a729824d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3a235c8813516864b3b661790c56c9eeb6c8ee8b44a208d70a3309faca0075e9b45f25890be47d56ed29b845a70c5d3f6cd45c617592543993a0c6d788eb7211
|
7
|
+
data.tar.gz: 9cd571ba906d3e841f63f8bf3ea018820d0d9e2eddb9171f01785b6787df5ed19fecbeb0b05e494428af8853d2040c78c32f25a370c612d55a4a69ed77798682
|
@@ -4,10 +4,10 @@ jobs:
|
|
4
4
|
build:
|
5
5
|
runs-on: ubuntu-latest
|
6
6
|
steps:
|
7
|
-
- uses: actions/checkout@
|
7
|
+
- uses: actions/checkout@v4
|
8
8
|
- uses: ruby/setup-ruby@v1
|
9
9
|
with:
|
10
|
-
ruby-version: 3
|
10
|
+
ruby-version: '3.4'
|
11
11
|
- name: Check license headers
|
12
12
|
run: |
|
13
13
|
ruby ./.github/check_license_headers.rb
|
data/.github/workflows/otel.yml
CHANGED
@@ -16,11 +16,11 @@ jobs:
|
|
16
16
|
strategy:
|
17
17
|
fail-fast: false
|
18
18
|
matrix:
|
19
|
-
ruby: ['3.
|
20
|
-
es_version: ['8.
|
19
|
+
ruby: ['3.4', 'jruby-9.4']
|
20
|
+
es_version: ['8.17.0-SNAPSHOT']
|
21
21
|
runs-on: ubuntu-latest
|
22
22
|
steps:
|
23
|
-
- uses: actions/checkout@
|
23
|
+
- uses: actions/checkout@v4
|
24
24
|
- name: Increase system limits
|
25
25
|
run: |
|
26
26
|
sudo swapoff -a
|
data/.github/workflows/tests.yml
CHANGED
@@ -15,11 +15,11 @@ jobs:
|
|
15
15
|
strategy:
|
16
16
|
fail-fast: false
|
17
17
|
matrix:
|
18
|
-
ruby: [
|
19
|
-
es_version: ['8.
|
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
20
|
runs-on: ubuntu-latest
|
21
21
|
steps:
|
22
|
-
- uses: actions/checkout@
|
22
|
+
- uses: actions/checkout@v4
|
23
23
|
- name: Increase system limits
|
24
24
|
run: |
|
25
25
|
sudo swapoff -a
|
@@ -53,11 +53,11 @@ jobs:
|
|
53
53
|
strategy:
|
54
54
|
fail-fast: false
|
55
55
|
matrix:
|
56
|
-
ruby: [
|
57
|
-
es_version: ['8.
|
56
|
+
ruby: ['3.0', '3.1', '3.2', '3.3', 'jruby-9.3']
|
57
|
+
es_version: ['8.16.0-SNAPSHOT']
|
58
58
|
runs-on: ubuntu-latest
|
59
59
|
steps:
|
60
|
-
- uses: actions/checkout@
|
60
|
+
- uses: actions/checkout@v4
|
61
61
|
- name: Increase system limits
|
62
62
|
run: |
|
63
63
|
sudo swapoff -a
|
@@ -76,7 +76,6 @@ jobs:
|
|
76
76
|
sudo apt-get update
|
77
77
|
sudo apt-get install libcurl4-openssl-dev
|
78
78
|
ruby -v
|
79
|
-
gem install bundler
|
80
79
|
BUNDLE_GEMFILE=./Gemfile-faraday1.gemfile bundle install
|
81
80
|
- name: faraday1 unit tests
|
82
81
|
run: BUNDLE_GEMFILE=./Gemfile-faraday1.gemfile bundle exec rake test:faraday1:unit
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,50 @@
|
|
1
|
+
## 8.4.0
|
2
|
+
|
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:
|
4
|
+
|
5
|
+
```ruby
|
6
|
+
require 'faraday/excon'
|
7
|
+
|
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.
|
37
|
+
|
38
|
+
## 8.3.5
|
39
|
+
|
40
|
+
- Small updates in source code documentation.
|
41
|
+
- Updates meta header for Elasticsearch Serverless.
|
42
|
+
- Fixes issues with ES_SERVERLESS_SERVICE_VERSION for backwards compatibility
|
43
|
+
|
44
|
+
## 8.3.3, 8.3.4 (yanked)
|
45
|
+
|
46
|
+
- Yanked due to errors.
|
47
|
+
|
1
48
|
## 8.3.2
|
2
49
|
|
3
50
|
- OpenTelemetry: In v8.3.0 and v8.3.1, the environment variable `OTEL_INSTRUMENTATION_ELASTICSEARCH_CAPTURE_SEARCH_QUERY` was available but is now deprecated in favor of `OTEL_RUBY_INSTRUMENTATION_ELASTICSEARCH_CAPTURE_SEARCH_QUERY`.
|
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
CHANGED
@@ -21,18 +21,19 @@ source 'https://rubygems.org'
|
|
21
21
|
gemspec
|
22
22
|
|
23
23
|
group :development, :test do
|
24
|
+
gem 'faraday-excon'
|
24
25
|
gem 'faraday-httpclient'
|
25
26
|
gem 'faraday-net_http_persistent'
|
26
|
-
gem 'faraday-patron' unless defined? JRUBY_VERSION
|
27
27
|
gem 'faraday-typhoeus'
|
28
|
-
gem '
|
29
|
-
gem '
|
28
|
+
gem 'mutex_m' if RUBY_VERSION >= '3.4'
|
29
|
+
gem 'opentelemetry-sdk', require: false if RUBY_VERSION >= '3.0'
|
30
30
|
if defined?(JRUBY_VERSION)
|
31
31
|
gem 'pry-nav'
|
32
32
|
else
|
33
|
+
gem 'async-http-faraday'
|
34
|
+
gem 'faraday-patron'
|
35
|
+
gem 'oj'
|
33
36
|
gem 'pry-byebug'
|
34
37
|
end
|
35
|
-
|
36
|
-
gem 'opentelemetry-sdk', require: false
|
37
|
-
end
|
38
|
+
gem 'rspec'
|
38
39
|
end
|
data/Gemfile-faraday1.gemfile
CHANGED
@@ -23,18 +23,18 @@ source 'https://rubygems.org'
|
|
23
23
|
# $ BUNDLE_GEMFILE=./Gemfile-faraday1.gemfile bundle exec rake test:faraday1:unit
|
24
24
|
|
25
25
|
gem 'faraday', '~> 1'
|
26
|
-
gemspec
|
26
|
+
gemspec
|
27
27
|
|
28
28
|
group :development, :test do
|
29
29
|
gem 'httpclient'
|
30
30
|
gem 'net-http-persistent'
|
31
|
-
gem 'patron' unless defined? JRUBY_VERSION
|
32
31
|
gem 'rspec'
|
33
32
|
gem 'typhoeus'
|
34
|
-
gem 'oj' unless defined? JRUBY_VERSION
|
35
33
|
if defined?(JRUBY_VERSION)
|
36
34
|
gem 'pry-nav'
|
37
35
|
else
|
38
36
|
gem 'pry-byebug'
|
37
|
+
gem 'oj'
|
38
|
+
gem 'patron'
|
39
39
|
end
|
40
40
|
end
|
@@ -83,7 +83,7 @@ module Elastic
|
|
83
83
|
#
|
84
84
|
# @option arguments [Integer] :sniffer_timeout Timeout for reloading connections in seconds (1 by default)
|
85
85
|
#
|
86
|
-
# @option arguments [Boolean,Number] :retry_on_failure Retry X times when request fails before raising
|
86
|
+
# @option arguments [Boolean,Number] :retry_on_failure Retry X times when request fails before raising an
|
87
87
|
# exception (false by default)
|
88
88
|
# @option arguments [Number] :delay_on_retry Delay in milliseconds between each retry (0 by default)
|
89
89
|
#
|
@@ -91,7 +91,8 @@ module Elastic
|
|
91
91
|
#
|
92
92
|
# @option arguments [Boolean] :reload_on_failure Reload connections after failure (false by default)
|
93
93
|
#
|
94
|
-
# @option arguments [Integer] :request_timeout The request timeout to be passed to transport in options
|
94
|
+
# @option arguments [Integer] :request_timeout The request timeout to be passed to transport in options in seconds
|
95
|
+
# (the default value is taken from the transport)
|
95
96
|
#
|
96
97
|
# @option arguments [Symbol] :adapter A specific adapter for Faraday (e.g. `:patron`)
|
97
98
|
#
|
@@ -110,7 +111,7 @@ module Elastic
|
|
110
111
|
#
|
111
112
|
# @option arguments [String] :send_get_body_as Specify the HTTP method to use for GET requests with a body.
|
112
113
|
# (Default: GET)
|
113
|
-
# @option arguments [
|
114
|
+
# @option arguments [Boolean] :compression Whether to compress requests. Gzip compression will be used.
|
114
115
|
# The default is false. Responses will automatically be inflated if they are compressed.
|
115
116
|
# If a custom transport object is used, it must handle the request compression and response inflation.
|
116
117
|
#
|
@@ -122,8 +123,8 @@ module Elastic
|
|
122
123
|
#
|
123
124
|
def initialize(arguments = {}, &block)
|
124
125
|
@arguments = arguments.transform_keys(&:to_sym)
|
125
|
-
@arguments[:logger] ||= @arguments[:log] ? DEFAULT_LOGGER.call
|
126
|
-
@arguments[:tracer] ||= @arguments[:trace] ? DEFAULT_TRACER.call
|
126
|
+
@arguments[:logger] ||= @arguments[:log] ? DEFAULT_LOGGER.call : nil
|
127
|
+
@arguments[:tracer] ||= @arguments[:trace] ? DEFAULT_TRACER.call : nil
|
127
128
|
@arguments[:reload_connections] ||= false
|
128
129
|
@arguments[:retry_on_failure] ||= false
|
129
130
|
@arguments[:delay_on_retry] ||= 0
|
@@ -133,13 +134,7 @@ module Elastic
|
|
133
134
|
@arguments[:http] ||= {}
|
134
135
|
@arguments[:enable_meta_header] = arguments.fetch(:enable_meta_header, true)
|
135
136
|
|
136
|
-
@hosts ||=
|
137
|
-
@arguments[:host] ||
|
138
|
-
@arguments[:url] ||
|
139
|
-
@arguments[:urls] ||
|
140
|
-
ENV['ELASTICSEARCH_URL'] ||
|
141
|
-
DEFAULT_HOST)
|
142
|
-
|
137
|
+
@hosts ||= extract_hosts
|
143
138
|
@send_get_body_as = @arguments[:send_get_body_as] || 'GET'
|
144
139
|
@ca_fingerprint = @arguments.delete(:ca_fingerprint)
|
145
140
|
|
@@ -152,7 +147,7 @@ module Elastic
|
|
152
147
|
else
|
153
148
|
@transport_class = @arguments[:transport_class] || DEFAULT_TRANSPORT_CLASS
|
154
149
|
@transport = if @transport_class == Transport::HTTP::Faraday
|
155
|
-
@arguments[:adapter] ||=
|
150
|
+
@arguments[:adapter] ||= auto_detect_adapter
|
156
151
|
set_meta_header # from include MetaHeader
|
157
152
|
@transport_class.new(hosts: @hosts, options: @arguments) do |faraday|
|
158
153
|
faraday.adapter(@arguments[:adapter])
|
@@ -172,7 +167,7 @@ module Elastic
|
|
172
167
|
# Performs a request through delegation to {#transport}.
|
173
168
|
#
|
174
169
|
def perform_request(method, path, params = {}, body = nil, headers = nil, opts = {})
|
175
|
-
method = @send_get_body_as if 'GET'
|
170
|
+
method = @send_get_body_as if method == 'GET' && body
|
176
171
|
validate_ca_fingerprints if @ca_fingerprint
|
177
172
|
if @otel
|
178
173
|
# If no endpoint is specified in the opts, use the HTTP method name
|
@@ -245,7 +240,7 @@ module Elastic
|
|
245
240
|
#
|
246
241
|
# @api private
|
247
242
|
#
|
248
|
-
def
|
243
|
+
def extract_hosts
|
249
244
|
hosts = case hosts_config
|
250
245
|
when String
|
251
246
|
hosts_config.split(',').map { |h| h.strip! || h }
|
@@ -256,12 +251,20 @@ module Elastic
|
|
256
251
|
else
|
257
252
|
Array(hosts_config)
|
258
253
|
end
|
259
|
-
|
260
|
-
host_list = hosts.map { |host| __parse_host(host) }
|
254
|
+
host_list = hosts.map { |host| parse_host(host) }
|
261
255
|
@arguments[:randomize_hosts] ? host_list.shuffle! : host_list
|
262
256
|
end
|
263
257
|
|
264
|
-
def
|
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)
|
265
268
|
host_parts = case host
|
266
269
|
when String
|
267
270
|
if host =~ /^[a-z]+\:\/\//
|
@@ -312,12 +315,14 @@ module Elastic
|
|
312
315
|
#
|
313
316
|
# @api private
|
314
317
|
#
|
315
|
-
def
|
318
|
+
def auto_detect_adapter
|
316
319
|
if Gem::Version.new(Faraday::VERSION) >= Gem::Version.new(2)
|
317
320
|
return :patron if defined?(Faraday::Adapter::Patron)
|
318
321
|
return :typhoeus if defined?(Faraday::Adapter::Typhoeus)
|
319
322
|
return :httpclient if defined?(Faraday::Adapter::HTTPClient)
|
320
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)
|
321
326
|
else
|
322
327
|
return :patron if defined?(::Patron)
|
323
328
|
return :typhoeus if defined?(::Typhoeus)
|
@@ -41,6 +41,12 @@ module Elastic
|
|
41
41
|
def meta_header_service_version
|
42
42
|
if enterprise_search?
|
43
43
|
Elastic::ENTERPRISE_SERVICE_VERSION
|
44
|
+
elsif serverless?
|
45
|
+
if defined?(Elastic::ES_SERVERLESS_SERVICE_VERSION)
|
46
|
+
Elastic::ES_SERVERLESS_SERVICE_VERSION
|
47
|
+
else
|
48
|
+
Elastic::ELASTICSEARCH_SERVICE_VERSION
|
49
|
+
end
|
44
50
|
elsif elasticsearch?
|
45
51
|
Elastic::ELASTICSEARCH_SERVICE_VERSION
|
46
52
|
elsif defined?(Elasticsearch::VERSION)
|
@@ -60,6 +66,11 @@ module Elastic
|
|
60
66
|
called_from?('elasticsearch')
|
61
67
|
end
|
62
68
|
|
69
|
+
def serverless?
|
70
|
+
defined?(ElasticsearchServerless::CLIENT_VERSION) &&
|
71
|
+
called_from?('elasticsearch-serverless')
|
72
|
+
end
|
73
|
+
|
63
74
|
def called_from?(service)
|
64
75
|
!caller.select { |c| c.match?(service) }.empty?
|
65
76
|
end
|
@@ -70,7 +81,7 @@ module Elastic
|
|
70
81
|
def client_meta_version(version)
|
71
82
|
regexp = /^([0-9]+\.[0-9]+\.[0-9]+)(\.?[a-z0-9.-]+)?$/
|
72
83
|
match = version.match(regexp)
|
73
|
-
return "#{match[1]}p" if
|
84
|
+
return "#{match[1]}p" if match[2]
|
74
85
|
|
75
86
|
version
|
76
87
|
end
|
@@ -21,70 +21,77 @@ module Elastic
|
|
21
21
|
#
|
22
22
|
# @api private
|
23
23
|
class OpenTelemetry
|
24
|
-
OTEL_TRACER_NAME = 'elasticsearch-api'
|
24
|
+
OTEL_TRACER_NAME = 'elasticsearch-api'.freeze
|
25
25
|
# Valid values for the enabled config are 'true' and 'false'. Default is 'true'.
|
26
|
-
ENV_VARIABLE_ENABLED = 'OTEL_RUBY_INSTRUMENTATION_ELASTICSEARCH_ENABLED'
|
26
|
+
ENV_VARIABLE_ENABLED = 'OTEL_RUBY_INSTRUMENTATION_ELASTICSEARCH_ENABLED'.freeze
|
27
27
|
# Describes how to handle search queries in the request body when assigned to
|
28
28
|
# a span attribute.
|
29
29
|
# Valid values are 'raw', 'omit', 'sanitize'. Default is 'omit'.
|
30
|
-
ENV_VARIABLE_BODY_STRATEGY = 'OTEL_RUBY_INSTRUMENTATION_ELASTICSEARCH_CAPTURE_SEARCH_QUERY'
|
31
|
-
ENV_VARIABLE_DEPRECATED_BODY_STRATEGY = 'OTEL_INSTRUMENTATION_ELASTICSEARCH_CAPTURE_SEARCH_QUERY'
|
32
|
-
DEFAULT_BODY_STRATEGY = 'omit'
|
30
|
+
ENV_VARIABLE_BODY_STRATEGY = 'OTEL_RUBY_INSTRUMENTATION_ELASTICSEARCH_CAPTURE_SEARCH_QUERY'.freeze
|
31
|
+
ENV_VARIABLE_DEPRECATED_BODY_STRATEGY = 'OTEL_INSTRUMENTATION_ELASTICSEARCH_CAPTURE_SEARCH_QUERY'.freeze
|
32
|
+
DEFAULT_BODY_STRATEGY = 'omit'.freeze
|
33
33
|
# A string list of keys whose values are redacted. This is only relevant if the body strategy is
|
34
34
|
# 'sanitize'. For example, a config 'sensitive-key,other-key' will redact the values at
|
35
35
|
# 'sensitive-key' and 'other-key' in addition to the default keys.
|
36
|
-
ENV_VARIABLE_BODY_SANITIZE_KEYS = 'OTEL_RUBY_INSTRUMENTATION_ELASTICSEARCH_SEARCH_QUERY_SANITIZE_KEYS'
|
36
|
+
ENV_VARIABLE_BODY_SANITIZE_KEYS = 'OTEL_RUBY_INSTRUMENTATION_ELASTICSEARCH_SEARCH_QUERY_SANITIZE_KEYS'.freeze
|
37
37
|
|
38
38
|
# A list of the Elasticsearch endpoints that qualify as "search" endpoints. The search query in
|
39
39
|
# the request body may be captured for these endpoints, depending on the body capture strategy.
|
40
40
|
SEARCH_ENDPOINTS = Set[
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
41
|
+
'search',
|
42
|
+
'async_search.submit',
|
43
|
+
'msearch',
|
44
|
+
'eql.search',
|
45
|
+
'terms_enum',
|
46
|
+
'search_template',
|
47
|
+
'msearch_template',
|
48
|
+
'render_search_template',
|
49
49
|
]
|
50
50
|
|
51
51
|
# Initialize the Open Telemetry wrapper object. Takes the options originally passed to
|
52
52
|
# Client#initialize.
|
53
53
|
def initialize(opts)
|
54
|
-
@tracer = (opts
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
DEFAULT_BODY_STRATEGY
|
54
|
+
@tracer = tracer_provider(opts).tracer(OTEL_TRACER_NAME, Elastic::Transport::VERSION)
|
55
|
+
@body_strategy = ENV[ENV_VARIABLE_DEPRECATED_BODY_STRATEGY] ||
|
56
|
+
ENV[ENV_VARIABLE_BODY_STRATEGY] ||
|
57
|
+
DEFAULT_BODY_STRATEGY
|
59
58
|
@sanitize_keys = ENV[ENV_VARIABLE_BODY_SANITIZE_KEYS]&.split(',')&.collect! do |pattern|
|
60
59
|
Regexp.new(pattern.gsub('*', '.*'))
|
61
60
|
end
|
62
61
|
end
|
63
62
|
attr_accessor :tracer
|
64
63
|
|
64
|
+
def tracer_provider(opts)
|
65
|
+
opts[:opentelemetry_tracer_provider] || ::OpenTelemetry.tracer_provider
|
66
|
+
end
|
67
|
+
|
65
68
|
# Process the request body. Applies the body strategy, which can be one of the following:
|
66
|
-
# 'omit': return nil
|
69
|
+
# 'omit' (DEFAULT_BODY_STRATEGY): return nil
|
67
70
|
# 'sanitize': redact values at the default list of keys + any additional keys provided in
|
68
71
|
# the OTEL_RUBY_INSTRUMENTATION_ELASTICSEARCH_SEARCH_QUERY_SANITIZE_KEYS env variable.
|
69
72
|
# 'raw': return the original body, unchanged
|
70
73
|
def process_body(body, endpoint)
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
74
|
+
return if @body_strategy == DEFAULT_BODY_STRATEGY || !search_endpoint?(endpoint)
|
75
|
+
|
76
|
+
if @body_strategy == 'sanitize'
|
77
|
+
Sanitizer.sanitize(body, @sanitize_keys).to_json
|
78
|
+
elsif @body_strategy == 'raw'
|
79
|
+
body.is_a?(String) ? body : body.to_json
|
77
80
|
end
|
78
81
|
end
|
79
82
|
|
83
|
+
def search_endpoint?(endpoint)
|
84
|
+
SEARCH_ENDPOINTS.include?(endpoint)
|
85
|
+
end
|
86
|
+
|
80
87
|
# Replaces values in a hash with 'REDACTED', given a set of keys to match on.
|
81
88
|
class Sanitizer
|
82
89
|
class << self
|
83
|
-
FILTERED = 'REDACTED'
|
90
|
+
FILTERED = 'REDACTED'.freeze
|
84
91
|
DEFAULT_KEY_PATTERNS =
|
85
92
|
%w[password passwd pwd secret *key *token* *session* *credit* *card* *auth* set-cookie].map! do |p|
|
86
|
-
|
87
|
-
|
93
|
+
Regexp.new(p.gsub('*', '.*'))
|
94
|
+
end
|
88
95
|
|
89
96
|
def sanitize(body, key_patterns = [])
|
90
97
|
patterns = DEFAULT_KEY_PATTERNS
|
@@ -83,7 +83,7 @@ module Elastic
|
|
83
83
|
# @return [Connections::Connection]
|
84
84
|
# @see Connections::Collection#get_connection
|
85
85
|
#
|
86
|
-
def get_connection(options={})
|
86
|
+
def get_connection(options = {})
|
87
87
|
resurrect_dead_connections! if Time.now > @last_request_at + @resurrect_after
|
88
88
|
|
89
89
|
@counter_mtx.synchronize { @counter += 1 }
|
@@ -120,7 +120,7 @@ module Elastic
|
|
120
120
|
# @return [Connections::Collection]
|
121
121
|
# @api private
|
122
122
|
#
|
123
|
-
def __rebuild_connections(arguments={})
|
123
|
+
def __rebuild_connections(arguments = {})
|
124
124
|
@state_mutex.synchronize do
|
125
125
|
@hosts = arguments[:hosts] || []
|
126
126
|
@options = arguments[:options] || {}
|
@@ -232,7 +232,7 @@ module Elastic
|
|
232
232
|
#
|
233
233
|
# @api private
|
234
234
|
#
|
235
|
-
def __convert_to_json(o=nil, options={})
|
235
|
+
def __convert_to_json(o = nil, options = {})
|
236
236
|
o.is_a?(String) ? o : serializer.dump(o, options)
|
237
237
|
end
|
238
238
|
|
@@ -24,7 +24,7 @@ module Elastic
|
|
24
24
|
module Base
|
25
25
|
# @param transport [Object] The instance of transport which uses this serializer
|
26
26
|
#
|
27
|
-
def initialize(transport=nil)
|
27
|
+
def initialize(transport = nil)
|
28
28
|
@transport = transport
|
29
29
|
end
|
30
30
|
end
|
@@ -36,13 +36,13 @@ module Elastic
|
|
36
36
|
|
37
37
|
# De-serialize a Hash from JSON string
|
38
38
|
#
|
39
|
-
def load(string, options={})
|
39
|
+
def load(string, options = {})
|
40
40
|
::MultiJson.load(string, options)
|
41
41
|
end
|
42
42
|
|
43
43
|
# Serialize a Hash to JSON string
|
44
44
|
#
|
45
|
-
def dump(object, options={})
|
45
|
+
def dump(object, options = {})
|
46
46
|
::MultiJson.dump(object, options)
|
47
47
|
end
|
48
48
|
end
|
@@ -225,6 +225,38 @@ describe Elastic::Transport::Client do
|
|
225
225
|
end
|
226
226
|
end unless jruby?
|
227
227
|
|
228
|
+
context 'when the adapter is excon' do
|
229
|
+
let(:adapter) do
|
230
|
+
client.transport.connections.all.first.connection.builder.adapter
|
231
|
+
end
|
232
|
+
|
233
|
+
let(:client) do
|
234
|
+
require 'faraday/excon'
|
235
|
+
|
236
|
+
described_class.new(adapter: :excon, enable_meta_header: false)
|
237
|
+
end
|
238
|
+
|
239
|
+
it 'uses Faraday with the adapter' do
|
240
|
+
expect(adapter).to eq Faraday::Adapter::Excon
|
241
|
+
end
|
242
|
+
end if is_faraday_v2?
|
243
|
+
|
244
|
+
context 'when the adapter is async-http' do
|
245
|
+
let(:adapter) do
|
246
|
+
client.transport.connections.all.first.connection.builder.adapter
|
247
|
+
end
|
248
|
+
|
249
|
+
let(:client) do
|
250
|
+
require 'async/http/faraday'
|
251
|
+
|
252
|
+
described_class.new(adapter: :async_http, enable_meta_header: false)
|
253
|
+
end
|
254
|
+
|
255
|
+
it 'uses Faraday with the adapter' do
|
256
|
+
expect(adapter).to eq Async::HTTP::Faraday::Adapter
|
257
|
+
end
|
258
|
+
end unless jruby? || !is_faraday_v2?
|
259
|
+
|
228
260
|
context 'when the adapter is specified as a string key' do
|
229
261
|
let(:adapter) do
|
230
262
|
client.transport.connections.all.first.connection.builder.adapter
|
@@ -1453,6 +1485,7 @@ describe Elastic::Transport::Client do
|
|
1453
1485
|
|
1454
1486
|
context 'when using the HTTPClient adapter' do
|
1455
1487
|
require 'faraday/httpclient'
|
1488
|
+
require 'mutex_m' if RUBY_VERSION >= '3.4'
|
1456
1489
|
|
1457
1490
|
let(:client) do
|
1458
1491
|
described_class.new(hosts: ELASTICSEARCH_HOSTS, compression: true, adapter: :httpclient, enable_meta_header: false)
|
data/test/unit/adapters_test.rb
CHANGED
@@ -72,6 +72,22 @@ class Elastic::Transport::ClientAdaptersUnitTest < Minitest::Test
|
|
72
72
|
end
|
73
73
|
end
|
74
74
|
|
75
|
+
should 'use Excon Faraday adapter' do
|
76
|
+
fork do
|
77
|
+
require 'faraday/excon'
|
78
|
+
client = Elastic::Transport::Client.new
|
79
|
+
assert_equal(client.transport.connections.first.connection.adapter, Faraday::Adapter::Excon)
|
80
|
+
end
|
81
|
+
end if is_faraday_v2?
|
82
|
+
|
83
|
+
should 'use Async HTTP Faraday adapter' do
|
84
|
+
fork do
|
85
|
+
require 'async/http/faraday'
|
86
|
+
client = Elastic::Transport::Client.new
|
87
|
+
assert_equal(client.transport.connections.first.connection.adapter, Async::HTTP::Faraday::Adapter)
|
88
|
+
end
|
89
|
+
end if is_faraday_v2?
|
90
|
+
|
75
91
|
should 'use HTTPClient Faraday adapter' do
|
76
92
|
fork do
|
77
93
|
if is_faraday_v2?
|
@@ -81,7 +97,7 @@ class Elastic::Transport::ClientAdaptersUnitTest < Minitest::Test
|
|
81
97
|
end
|
82
98
|
|
83
99
|
client = Elastic::Transport::Client.new
|
84
|
-
assert_equal(
|
100
|
+
assert_equal(client.transport.connections.first.connection.adapter, Faraday::Adapter::HTTPClient)
|
85
101
|
end
|
86
102
|
end
|
87
103
|
end unless jruby?
|
@@ -20,66 +20,66 @@ require 'test_helper'
|
|
20
20
|
class Elastic::Transport::Transport::Connections::ConnectionTest < Minitest::Test
|
21
21
|
include Elastic::Transport::Transport::Connections
|
22
22
|
|
23
|
-
context
|
24
|
-
should
|
23
|
+
context 'Connection' do
|
24
|
+
should 'be initialized with :host, :connection, and :options' do
|
25
25
|
c = Connection.new :host => 'x', :connection => 'y', :options => {}
|
26
26
|
assert_equal 'x', c.host
|
27
27
|
assert_equal 'y', c.connection
|
28
28
|
assert_instance_of Hash, c.options
|
29
29
|
end
|
30
30
|
|
31
|
-
should
|
31
|
+
should 'return full path' do
|
32
32
|
c = Connection.new
|
33
33
|
assert_equal '_search', c.full_path('_search')
|
34
34
|
assert_equal '_search', c.full_path('_search', {})
|
35
|
-
assert_equal '_search?foo=bar', c.full_path('_search', {:
|
36
|
-
assert_equal '_search?foo=bar+bam', c.full_path('_search', {:
|
35
|
+
assert_equal '_search?foo=bar', c.full_path('_search', {foo: 'bar'})
|
36
|
+
assert_equal '_search?foo=bar+bam', c.full_path('_search', {foo: 'bar bam'})
|
37
37
|
end
|
38
38
|
|
39
|
-
should
|
40
|
-
c = Connection.new :
|
41
|
-
assert_equal 'http://localhost:9200/_search?foo=bar', c.full_url('_search', {:
|
39
|
+
should 'return full url' do
|
40
|
+
c = Connection.new host: { protocol: 'http', host: 'localhost', port: '9200' }
|
41
|
+
assert_equal 'http://localhost:9200/_search?foo=bar', c.full_url('_search', { foo: 'bar' })
|
42
42
|
end
|
43
43
|
|
44
|
-
should
|
45
|
-
c = Connection.new :
|
46
|
-
assert_equal 'http://U:P@localhost:9200/_search?foo=bar', c.full_url('_search', {:
|
44
|
+
should 'return full url with credentials' do
|
45
|
+
c = Connection.new host: { protocol: 'http', user: 'U', password: 'P', host: 'localhost', port: '9200' }
|
46
|
+
assert_equal 'http://U:P@localhost:9200/_search?foo=bar', c.full_url('_search', { foo: 'bar' })
|
47
47
|
end
|
48
48
|
|
49
|
-
should
|
50
|
-
c = Connection.new :
|
51
|
-
assert_equal 'http://U%24%24%24:P%5E%5E%5E@localhost:9200/_search?foo=bar', c.full_url('_search', {:
|
49
|
+
should 'return full url with escaped credentials' do
|
50
|
+
c = Connection.new host: { protocol: 'http', user: 'U$$$', password: 'P^^^', host: 'localhost', port: '9200' }
|
51
|
+
assert_equal 'http://U%24%24%24:P%5E%5E%5E@localhost:9200/_search?foo=bar', c.full_url('_search', { foo: 'bar' })
|
52
52
|
end
|
53
53
|
|
54
|
-
should
|
55
|
-
c = Connection.new :
|
56
|
-
assert_equal 'http://localhost:9200/foo/_search?foo=bar', c.full_url('_search', {:
|
54
|
+
should 'return full url with path' do
|
55
|
+
c = Connection.new host: { protocol: 'http', host: 'localhost', port: '9200', path: '/foo' }
|
56
|
+
assert_equal 'http://localhost:9200/foo/_search?foo=bar', c.full_url('_search', { foo: 'bar' })
|
57
57
|
end
|
58
58
|
|
59
|
-
should
|
60
|
-
c = Connection.new :
|
61
|
-
assert_equal 'http://localhost:9200/foo/_search?foo=bar', c.full_url('/_search', {:
|
59
|
+
should 'return right full url with path when path starts with /' do
|
60
|
+
c = Connection.new host: { protocol: 'http', host: 'localhost', port: '9200', path: '/foo' }
|
61
|
+
assert_equal 'http://localhost:9200/foo/_search?foo=bar', c.full_url('/_search', { foo: 'bar' })
|
62
62
|
end
|
63
63
|
|
64
|
-
should
|
65
|
-
c = Connection.new
|
64
|
+
should 'have a string representation' do
|
65
|
+
c = Connection.new(host: 'x')
|
66
66
|
assert_match(/host: x/, c.to_s)
|
67
67
|
assert_match(/alive/, c.to_s)
|
68
68
|
end
|
69
69
|
|
70
|
-
should
|
70
|
+
should 'not be dead by default' do
|
71
71
|
c = Connection.new
|
72
72
|
assert ! c.dead?
|
73
73
|
end
|
74
74
|
|
75
|
-
should
|
75
|
+
should 'be dead when marked' do
|
76
76
|
c = Connection.new.dead!
|
77
77
|
assert c.dead?
|
78
78
|
assert_equal 1, c.failures
|
79
79
|
assert_in_delta c.dead_since, Time.now, 1
|
80
80
|
end
|
81
81
|
|
82
|
-
should
|
82
|
+
should 'be alive when marked' do
|
83
83
|
c = Connection.new.dead!
|
84
84
|
assert c.dead?
|
85
85
|
assert_equal 1, c.failures
|
@@ -90,7 +90,7 @@ class Elastic::Transport::Transport::Connections::ConnectionTest < Minitest::Tes
|
|
90
90
|
assert_equal 1, c.failures
|
91
91
|
end
|
92
92
|
|
93
|
-
should
|
93
|
+
should 'be healthy when marked' do
|
94
94
|
c = Connection.new.dead!
|
95
95
|
assert c.dead?
|
96
96
|
assert_equal 1, c.failures
|
@@ -101,35 +101,33 @@ class Elastic::Transport::Transport::Connections::ConnectionTest < Minitest::Tes
|
|
101
101
|
assert_equal 0, c.failures
|
102
102
|
end
|
103
103
|
|
104
|
-
should
|
104
|
+
should 'be resurrected if timeout passed' do
|
105
105
|
c = Connection.new.dead!
|
106
106
|
|
107
107
|
now = Time.now + 60
|
108
108
|
Time.stubs(:now).returns(now)
|
109
109
|
|
110
|
-
assert
|
111
|
-
assert
|
110
|
+
assert(c.resurrect!, c.inspect)
|
111
|
+
assert(!c.dead?, c.inspect)
|
112
112
|
end
|
113
113
|
|
114
|
-
should
|
114
|
+
should 'be resurrected if timeout passed for multiple failures' do
|
115
115
|
c = Connection.new.dead!.dead!
|
116
116
|
|
117
|
-
now = Time.now + 60*2
|
117
|
+
now = Time.now + 60 * 2
|
118
118
|
Time.stubs(:now).returns(now)
|
119
119
|
|
120
120
|
assert c.resurrect!, c.inspect
|
121
121
|
assert ! c.dead?, c.inspect
|
122
122
|
end
|
123
123
|
|
124
|
-
should
|
125
|
-
c1 = Connection.new(:
|
126
|
-
c2 = Connection.new(:
|
127
|
-
c3 = Connection.new(:
|
124
|
+
should 'implement the equality operator' do
|
125
|
+
c1 = Connection.new(host: { protocol: 'http', host: 'foo', port: 123 })
|
126
|
+
c2 = Connection.new(host: { protocol: 'http', host: 'foo', port: 123 })
|
127
|
+
c3 = Connection.new(host: { protocol: 'http', host: 'foo', port: 456 })
|
128
128
|
|
129
129
|
assert c1 == c2, "Connection #{c1} should be equal to #{c2}"
|
130
130
|
assert c2 != c3, "Connection #{c2} should NOT be equal to #{c3}"
|
131
131
|
end
|
132
|
-
|
133
132
|
end
|
134
|
-
|
135
133
|
end
|
metadata
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: elastic-transport
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 8.
|
4
|
+
version: 8.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Elastic Client Library Maintainers
|
8
|
-
autorequire:
|
9
8
|
bindir: bin
|
10
9
|
cert_chain: []
|
11
|
-
date:
|
10
|
+
date: 2025-02-18 00:00:00.000000000 Z
|
12
11
|
dependencies:
|
13
12
|
- !ruby/object:Gem::Dependency
|
14
13
|
name: faraday
|
@@ -324,7 +323,6 @@ metadata:
|
|
324
323
|
changelog_uri: https://github.com/elastic/elastic-transport-ruby/blob/master/CHANGELOG.md
|
325
324
|
source_code_uri: https://github.com/elastic/elastic-transport-ruby
|
326
325
|
bug_tracker_uri: https://github.com/elastic/elastic-transport-ruby/issues
|
327
|
-
post_install_message:
|
328
326
|
rdoc_options:
|
329
327
|
- "--charset=UTF-8"
|
330
328
|
require_paths:
|
@@ -340,8 +338,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
340
338
|
- !ruby/object:Gem::Version
|
341
339
|
version: '0'
|
342
340
|
requirements: []
|
343
|
-
rubygems_version: 3.
|
344
|
-
signing_key:
|
341
|
+
rubygems_version: 3.6.2
|
345
342
|
specification_version: 4
|
346
343
|
summary: Low level Ruby client for Elastic services.
|
347
344
|
test_files:
|