Skip to content

Commit 9fce225

Browse files
committed
Set x-elastic-product-origin header for ES requests
This commit updates the `Elasticsearch::Client` used to make requests to ES to send along a header identifying the request as originating from an internal component.
1 parent ef8874c commit 9fce225

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

lib/logstash/inputs/elasticsearch.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,7 @@ class LogStash::Inputs::Elasticsearch < LogStash::Inputs::Base
271271

272272
BUILD_FLAVOR_SERVERLESS = 'serverless'.freeze
273273
DEFAULT_EAV_HEADER = { "Elastic-Api-Version" => "2023-10-31" }.freeze
274+
INTERNAL_ORIGIN_HEADER = { 'x-elastic-product-origin' => 'logstash-input-elasticsearch'}.freeze
274275

275276
def initialize(params={})
276277
super(params)
@@ -300,6 +301,7 @@ def register
300301
fill_user_password_from_cloud_auth
301302

302303
transport_options = {:headers => {}}
304+
transport_options[:headers].merge!(INTERNAL_ORIGIN_HEADER)
303305
transport_options[:headers].merge!(setup_basic_auth(user, password))
304306
transport_options[:headers].merge!(setup_api_key(api_key))
305307
transport_options[:headers].merge!({'user-agent' => prepare_user_agent()})

spec/inputs/elasticsearch_spec.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@
5050
client = plugin.send(:client)
5151
expect( extract_transport(client).options[:transport_options][:headers] ).not_to match hash_including("Elastic-Api-Version" => "2023-10-31")
5252
end
53+
54+
it "sets an x-elastic-product-origin header identifying this as an internal plugin request" do
55+
plugin.register
56+
client = plugin.send(:client)
57+
expect( extract_transport(client).options[:transport_options][:headers] ).to match hash_including("x-elastic-product-origin"=>"logstash-input-elasticsearch")
58+
end
5359
end
5460

5561
context "against not authentic Elasticsearch" do
@@ -90,6 +96,12 @@
9096
client = plugin.send(:client)
9197
expect( extract_transport(client).options[:transport_options][:headers] ).to match hash_including("Elastic-Api-Version" => "2023-10-31")
9298
end
99+
100+
it "sets an x-elastic-product-origin header identifying this as an internal plugin request" do
101+
plugin.register
102+
client = plugin.send(:client)
103+
expect( extract_transport(client).options[:transport_options][:headers] ).to match hash_including("x-elastic-product-origin"=>"logstash-input-elasticsearch")
104+
end
93105
end
94106
end
95107

0 commit comments

Comments
 (0)