Skip to content

Commit ef38c6e

Browse files
authored
Merge pull request #185 from donoghuc/GH-180-product-origin-header
Set x-elastic-product-origin header for ES requests
2 parents 8a0c4c6 + 1869656 commit ef38c6e

File tree

4 files changed

+12
-3
lines changed

4 files changed

+12
-3
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## 3.16.2
2+
- Add `x-elastic-product-origin` header to Elasticsearch requests [#185](https://github.com/logstash-plugins/logstash-filter-elasticsearch/pull/185)
3+
14
## 3.16.1
25
- Version bump to pick up doc fix in [#172](https://github.com/logstash-plugins/logstash-filter-elasticsearch/pull/172)
36

lib/logstash/filters/elasticsearch/client.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ class ElasticsearchClient
1212

1313
BUILD_FLAVOR_SERVERLESS = 'serverless'.freeze
1414
DEFAULT_EAV_HEADER = { "Elastic-Api-Version" => "2023-10-31" }.freeze
15+
INTERNAL_ORIGIN_HEADER = { 'x-elastic-product-origin' => 'logstash-filter-elasticsearch'}.freeze
1516

1617
def initialize(logger, hosts, options = {})
1718
user = options.fetch(:user, nil)
@@ -25,6 +26,7 @@ def initialize(logger, hosts, options = {})
2526
transport_options[:headers].merge!(setup_basic_auth(user, password))
2627
transport_options[:headers].merge!(setup_api_key(api_key))
2728
transport_options[:headers].merge!({ 'user-agent' => "#{user_agent}" })
29+
transport_options[:headers].merge!(INTERNAL_ORIGIN_HEADER)
2830

2931
transport_options[:pool_max] = 1000
3032
transport_options[:pool_max_per_route] = 100

logstash-filter-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-filter-elasticsearch'
4-
s.version = '3.16.1'
4+
s.version = '3.16.2'
55
s.licenses = ['Apache License (2.0)']
66
s.summary = "Copies fields from previous log events in Elasticsearch to current events "
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/filters/elasticsearch_spec.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -644,7 +644,7 @@ def wait_receive_request
644644
end
645645
end
646646

647-
describe "Elastic Api Header" do
647+
describe "Elastic Api and Product Origin Headers" do
648648
let(:config) { {"query" => "*"} }
649649
let(:plugin) { described_class.new(config) }
650650
let(:headers) {{'x-elastic-product' => 'Elasticsearch'}}
@@ -666,6 +666,8 @@ def wait_receive_request
666666
plugin.register
667667
client = plugin.send(:get_client).client
668668
expect( extract_transport(client).options[:transport_options][:headers] ).to match hash_including("Elastic-Api-Version" => "2023-10-31")
669+
expect( extract_transport(client).options[:transport_options][:headers] )
670+
.to match hash_including("x-elastic-product-origin" => "logstash-filter-elasticsearch")
669671
end
670672
end
671673

@@ -676,10 +678,12 @@ def wait_receive_request
676678
expect_any_instance_of(Elasticsearch::Client).to receive(:perform_request).with(any_args).and_return(mock_resp)
677679
end
678680

679-
it 'does not propagate header to es client' do
681+
it 'does not propagate Elastic-Api-Version header to es client' do
680682
plugin.register
681683
client = plugin.send(:get_client).client
682684
expect( extract_transport(client).options[:transport_options][:headers] ).to match hash_not_including("Elastic-Api-Version" => "2023-10-31")
685+
expect( extract_transport(client).options[:transport_options][:headers] )
686+
.to match hash_including("x-elastic-product-origin" => "logstash-filter-elasticsearch")
683687
end
684688
end
685689

0 commit comments

Comments
 (0)