Skip to content

Commit f49b710

Browse files
authored
Set x-elastic-product-origin header for ES requests (#211)
* 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. * Prep 4.20.5 release Update version and add CHANGELOG entry.
1 parent 4fec6d8 commit f49b710

File tree

4 files changed

+18
-1
lines changed

4 files changed

+18
-1
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## 4.20.5
2+
- Add `x-elastic-product-origin` header to Elasticsearch requests [#211](https://github.com/logstash-plugins/logstash-input-elasticsearch/pull/211)
3+
14
## 4.20.4
25
- Fix issue where the `index` parameter was being ignored when using `response_type => aggregations` [#209](https://github.com/logstash-plugins/logstash-input-elasticsearch/pull/209)
36

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()})

logstash-input-elasticsearch.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Gem::Specification.new do |s|
22

33
s.name = 'logstash-input-elasticsearch'
4-
s.version = '4.20.4'
4+
s.version = '4.20.5'
55
s.licenses = ['Apache License (2.0)']
66
s.summary = "Reads query results from an Elasticsearch cluster"
77
s.description = "This gem is a Logstash plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/logstash-plugin install gemname. This gem is not a stand-alone program"

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)