File tree Expand file tree Collapse file tree 4 files changed +42
-1
lines changed
lib/elasticsearch/transport
spec/elasticsearch/transport Expand file tree Collapse file tree 4 files changed +42
-1
lines changed Original file line number Diff line number Diff line change @@ -209,8 +209,10 @@ def add_header(header)
209209 def set_meta_header
210210 return if @arguments [ :enable_meta_header ] == false
211211
212+ service , version = meta_header_service_version
213+
212214 meta_headers = {
213- es : Elasticsearch :: VERSION , # TODO - es|ent
215+ service . to_sym => version ,
214216 rb : RUBY_VERSION ,
215217 t : Elasticsearch ::Transport ::VERSION
216218 }
@@ -220,6 +222,16 @@ def set_meta_header
220222 add_header ( { 'x-elastic-client-meta' => meta_headers . map { |k , v | "#{ k } =#{ v } " } . join ( ',' ) } )
221223 end
222224
225+ def meta_header_service_version
226+ if defined? ( Elastic ::META_HEADER_SERVICE_VERSION )
227+ Elastic ::META_HEADER_SERVICE_VERSION
228+ elsif defined? ( Elasticsearch ::VERSION )
229+ [ 'es' , Elasticsearch ::VERSION ]
230+ else
231+ [ 'es' , Elasticsearch ::Transport ::VERSION ]
232+ end
233+ end
234+
223235 def meta_header_engine
224236 case RUBY_ENGINE
225237 when 'ruby'
Original file line number Diff line number Diff line change @@ -178,5 +178,26 @@ def initialize(args); end
178178 expect ( subject ) . to include ( 'x-elastic-client-meta' => meta_header )
179179 end
180180 end
181+
182+ context 'when using a different service version' do
183+ before do
184+ module Elastic
185+ META_HEADER_SERVICE_VERSION = [ :ent , '8.0.0' ]
186+ end
187+ end
188+
189+ after do
190+ module Elastic
191+ META_HEADER_SERVICE_VERSION = [ :es , Elasticsearch ::VERSION ]
192+ end
193+ end
194+
195+ let ( :client ) { Elasticsearch ::Client . new }
196+
197+ it 'sets the service version in the metaheader' do
198+ expect ( subject [ 'x-elastic-client-meta' ] ) . to match ( regexp )
199+ expect ( subject [ 'x-elastic-client-meta' ] ) . to start_with ( 'ent=8.0.0' )
200+ end
201+ end
181202 end
182203end
Original file line number Diff line number Diff line change @@ -27,3 +27,7 @@ class Client
2727 end
2828 end
2929end
30+ module Elastic
31+ # Constant for elasticsearch-transport meta-header
32+ META_HEADER_SERVICE_VERSION = [ :es , Elasticsearch ::VERSION ]
33+ end
Original file line number Diff line number Diff line change @@ -70,6 +70,10 @@ class ClientIntegrationTest < Elasticsearch::Test::IntegrationTestCase
7070 end
7171 end
7272
73+ should 'report the right meta header' do
74+ headers = @client . transport . connections . first . connection . headers
75+ assert_match /^es=#{ Elasticsearch ::VERSION } / , headers [ 'x-elastic-client-meta' ]
76+ end
7377 end
7478 end
7579 end
You can’t perform that action at this time.
0 commit comments