elasticsearch-transport 6.8.3 → 7.0.0.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +17 -0
  3. data/LICENSE.txt +199 -10
  4. data/README.md +32 -86
  5. data/Rakefile +23 -4
  6. data/elasticsearch-transport.gemspec +78 -45
  7. data/lib/elasticsearch-transport.rb +16 -3
  8. data/lib/elasticsearch/transport.rb +17 -3
  9. data/lib/elasticsearch/transport/client.rb +70 -174
  10. data/lib/elasticsearch/transport/redacted.rb +5 -9
  11. data/lib/elasticsearch/transport/transport/base.rb +63 -55
  12. data/lib/elasticsearch/transport/transport/connections/collection.rb +16 -3
  13. data/lib/elasticsearch/transport/transport/connections/connection.rb +16 -3
  14. data/lib/elasticsearch/transport/transport/connections/selector.rb +16 -3
  15. data/lib/elasticsearch/transport/transport/errors.rb +16 -3
  16. data/lib/elasticsearch/transport/transport/http/curb.rb +18 -5
  17. data/lib/elasticsearch/transport/transport/http/faraday.rb +18 -5
  18. data/lib/elasticsearch/transport/transport/http/manticore.rb +17 -4
  19. data/lib/elasticsearch/transport/transport/loggable.rb +85 -0
  20. data/lib/elasticsearch/transport/transport/response.rb +16 -3
  21. data/lib/elasticsearch/transport/transport/serializer/multi_json.rb +16 -3
  22. data/lib/elasticsearch/transport/transport/sniffer.rb +17 -5
  23. data/lib/elasticsearch/transport/version.rb +17 -4
  24. data/spec/elasticsearch/transport/base_spec.rb +8 -187
  25. data/spec/elasticsearch/transport/client_spec.rb +29 -163
  26. data/spec/elasticsearch/transport/sniffer_spec.rb +19 -0
  27. data/spec/spec_helper.rb +2 -11
  28. data/test/integration/transport_test.rb +18 -5
  29. data/test/profile/client_benchmark_test.rb +16 -3
  30. data/test/test_helper.rb +63 -14
  31. data/test/unit/connection_collection_test.rb +17 -4
  32. data/test/unit/connection_selector_test.rb +17 -4
  33. data/test/unit/connection_test.rb +17 -4
  34. data/test/unit/response_test.rb +18 -5
  35. data/test/unit/serializer_test.rb +17 -4
  36. data/test/unit/transport_base_test.rb +21 -8
  37. data/test/unit/transport_curb_test.rb +17 -4
  38. data/test/unit/transport_faraday_test.rb +17 -4
  39. data/test/unit/transport_manticore_test.rb +24 -6
  40. metadata +61 -86
  41. data/spec/elasticsearch/transport/meta_header_spec.rb +0 -214
@@ -1,214 +0,0 @@
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 'spec_helper'
19
-
20
- describe Elasticsearch::Transport::Client do
21
- context 'meta-header' do
22
- let(:subject) { client.transport.connections.first.connection.headers }
23
- let(:client) { described_class.new }
24
- let(:regexp) { /^[a-z]{1,}=[a-z0-9.\-]{1,}(?:,[a-z]{1,}=[a-z0-9._\-]+)*$/ }
25
- let(:adapter) { :net_http }
26
- let(:adapter_code) { "nh=#{defined?(Net::HTTP::VERSION) ? Net::HTTP::VERSION : Net::HTTP::HTTPVersion}" }
27
- let(:meta_header) do
28
- if jruby?
29
- "es=#{meta_version},rb=#{RUBY_VERSION},t=#{Elasticsearch::Transport::VERSION},jv=#{ENV_JAVA['java.version']},jr=#{JRUBY_VERSION},fd=#{Faraday::VERSION},#{adapter_code}"
30
- else
31
- "es=#{meta_version},rb=#{RUBY_VERSION},t=#{Elasticsearch::Transport::VERSION},fd=#{Faraday::VERSION},#{adapter_code}"
32
- end
33
- end
34
-
35
- context 'client_meta_version_' do
36
- let(:version) { ['7.1.0-alpha', '7.11.0.pre.1', '8.0.0-beta', '8.0.0.beta.2']}
37
-
38
- it 'converts the version to X.X.Xp' do
39
- expect(client.send(:client_meta_version, '7.0.0-alpha')).to eq('7.0.0p')
40
- expect(client.send(:client_meta_version, '7.11.0.pre.1')).to eq('7.11.0p')
41
- expect(client.send(:client_meta_version, '8.1.0-beta')).to eq('8.1.0p')
42
- expect(client.send(:client_meta_version, '8.0.0.beta.2')).to eq('8.0.0p')
43
- expect(client.send(:client_meta_version, '12.16.4.pre')).to eq('12.16.4p')
44
- end
45
- end
46
-
47
- # We are testing this method in the previous block, so now using it inside the test to make the
48
- # Elasticsearch version in the meta header string dynamic
49
- def meta_version
50
- client.send(:client_meta_version, Elasticsearch::VERSION)
51
- end
52
-
53
- context 'single use of meta header' do
54
- let(:client) do
55
- described_class.new(adapter: adapter).tap do |klient|
56
- allow(klient).to receive(:__build_connections)
57
- end
58
- end
59
-
60
- it 'x-elastic-client-header value matches regexp' do
61
- expect(subject['x-elastic-client-meta']).to match(regexp)
62
- expect(subject).to include('x-elastic-client-meta' => meta_header)
63
- end
64
- end
65
-
66
- context 'when using user-agent headers' do
67
- let(:client) do
68
- transport_options = { headers: { user_agent: 'My Ruby App' } }
69
- described_class.new(transport_options: transport_options, adapter: adapter).tap do |klient|
70
- allow(klient).to receive(:__build_connections)
71
- end
72
- end
73
-
74
- it 'is friendly to previously set headers' do
75
- expect(subject).to include(user_agent: 'My Ruby App')
76
- expect(subject['x-elastic-client-meta']).to match(regexp)
77
- expect(subject).to include('x-elastic-client-meta' => meta_header)
78
- end
79
- end
80
-
81
- context 'when using API Key' do
82
- let(:client) do
83
- described_class.new(api_key: 'an_api_key', adapter: adapter)
84
- end
85
-
86
- let(:authorization_header) do
87
- client.transport.connections.first.connection.headers['Authorization']
88
- end
89
-
90
- it 'adds the ApiKey header to the connection' do
91
- expect(authorization_header).to eq('ApiKey an_api_key')
92
- expect(subject['x-elastic-client-meta']).to match(regexp)
93
- expect(subject).to include('x-elastic-client-meta' => meta_header)
94
- end
95
- end
96
-
97
- context 'adapters' do
98
- let(:meta_header) do
99
- if jruby?
100
- "es=#{meta_version},rb=#{RUBY_VERSION},t=#{Elasticsearch::Transport::VERSION},jv=#{ENV_JAVA['java.version']},jr=#{JRUBY_VERSION},fd=#{Faraday::VERSION}"
101
- else
102
- "es=#{meta_version},rb=#{RUBY_VERSION},t=#{Elasticsearch::Transport::VERSION},fd=#{Faraday::VERSION}"
103
- end
104
- end
105
- let(:client) { described_class.new(adapter: adapter) }
106
- let(:headers) { client.transport.connections.first.connection.headers }
107
-
108
- context 'using net/http/persistent' do
109
- let(:adapter) { :net_http_persistent }
110
-
111
- it 'sets adapter in the meta header' do
112
- require 'net/http/persistent'
113
- expect(headers['x-elastic-client-meta']).to match(regexp)
114
- meta = "#{meta_header},np=#{Net::HTTP::Persistent::VERSION}"
115
- expect(headers).to include('x-elastic-client-meta' => meta)
116
- end
117
- end
118
-
119
- context 'using httpclient' do
120
- let(:adapter) { :httpclient }
121
-
122
- it 'sets adapter in the meta header' do
123
- require 'httpclient'
124
- expect(headers['x-elastic-client-meta']).to match(regexp)
125
- meta = "#{meta_header},hc=#{HTTPClient::VERSION}"
126
- expect(headers).to include('x-elastic-client-meta' => meta)
127
- end
128
- end
129
-
130
- context 'using typhoeus' do
131
- let(:adapter) { :typhoeus }
132
-
133
- it 'sets adapter in the meta header' do
134
- require 'typhoeus'
135
- expect(headers['x-elastic-client-meta']).to match(regexp)
136
- meta = "#{meta_header},ty=#{Typhoeus::VERSION}"
137
- expect(headers).to include('x-elastic-client-meta' => meta)
138
- end
139
- end
140
-
141
- unless defined?(JRUBY_VERSION)
142
- let(:adapter) { :patron }
143
-
144
- context 'using patron' do
145
- it 'sets adapter in the meta header' do
146
- require 'patron'
147
- expect(headers['x-elastic-client-meta']).to match(regexp)
148
- meta = "#{meta_header},pt=#{Patron::VERSION}"
149
- expect(headers).to include('x-elastic-client-meta' => meta)
150
- end
151
- end
152
- end
153
- end
154
-
155
- if defined?(JRUBY_VERSION)
156
- context 'when using manticore' do
157
- let(:client) do
158
- Elasticsearch::Client.new(transport_class: Elasticsearch::Transport::Transport::HTTP::Manticore)
159
- end
160
- let(:subject) { client.transport.connections.first.connection.instance_variable_get("@options")[:headers]}
161
-
162
- it 'sets manticore in the metaheader' do
163
- expect(subject['x-elastic-client-meta']).to match(regexp)
164
- expect(subject['x-elastic-client-meta']).to match(/mc=[0-9.]+/)
165
- end
166
- end
167
- else
168
- context 'when using curb' do
169
- let(:client) do
170
- Elasticsearch::Client.new(transport_class: Elasticsearch::Transport::Transport::HTTP::Curb)
171
- end
172
-
173
- it 'sets curb in the metaheader' do
174
- expect(subject['x-elastic-client-meta']).to match(regexp)
175
- expect(subject['x-elastic-client-meta']).to match(/cl=[0-9.]+/)
176
- end
177
- end
178
- end
179
-
180
- context 'when using custom transport implementation' do
181
- class MyTransport
182
- include Elasticsearch::Transport::Transport::Base
183
- def initialize(args); end
184
- end
185
- let(:client) { Elasticsearch::Client.new(transport_class: MyTransport) }
186
- let(:subject){ client.instance_variable_get("@arguments")[:transport_options][:headers] }
187
- let(:meta_header) do
188
- if jruby?
189
- "es=#{meta_version},rb=#{RUBY_VERSION},t=#{Elasticsearch::Transport::VERSION},jv=#{ENV_JAVA['java.version']},jr=#{JRUBY_VERSION}"
190
- else
191
- "es=#{meta_version},rb=#{RUBY_VERSION},t=#{Elasticsearch::Transport::VERSION}"
192
- end
193
- end
194
-
195
- it 'doesnae set any info about the implementation in the metaheader' do
196
- expect(subject['x-elastic-client-meta']).to match(regexp)
197
- expect(subject).to include('x-elastic-client-meta' => meta_header)
198
- end
199
- end
200
-
201
- context 'when using a different service version' do
202
- before do
203
- stub_const("Elastic::META_HEADER_SERVICE_VERSION", [:ent, '8.0.0'])
204
- end
205
-
206
- let(:client) { Elasticsearch::Client.new }
207
-
208
- it 'sets the service version in the metaheader' do
209
- expect(subject['x-elastic-client-meta']).to match(regexp)
210
- expect(subject['x-elastic-client-meta']).to start_with('ent=8.0.0')
211
- end
212
- end
213
- end
214
- end