Skip to content

Commit 8e8f4f1

Browse files
authored
Set x-elastic-product-origin header for ES requests (#1195)
* 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 11.22.10 release * Update integration test expectations Update integration tests to expect new headers where needed.
1 parent 8f9ecff commit 8e8f4f1

File tree

6 files changed

+19
-6
lines changed

6 files changed

+19
-6
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## 11.22.10
2+
- Add `x-elastic-product-origin` header to Elasticsearch requests [#1194](https://github.com/logstash-plugins/logstash-output-elasticsearch/pull/1194)
3+
14
## 11.22.9
25
- Vendor ECS template for Elasticsearch 9.x in built gem [#1188](https://github.com/logstash-plugins/logstash-output-elasticsearch/pull/1188)
36

lib/logstash/outputs/elasticsearch/http_client/manticore_adapter.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
require 'cgi'
33

44
module LogStash; module Outputs; class ElasticSearch; class HttpClient;
5-
DEFAULT_HEADERS = { "Content-Type" => "application/json" }
5+
DEFAULT_HEADERS = { "Content-Type" => "application/json", 'x-elastic-product-origin' => 'logstash-output-elasticsearch' }
66

77
class ManticoreAdapter
88
attr_reader :manticore, :logger

logstash-output-elasticsearch.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Gem::Specification.new do |s|
22
s.name = 'logstash-output-elasticsearch'
3-
s.version = '11.22.9'
3+
s.version = '11.22.10'
44
s.licenses = ['apache-2.0']
55
s.summary = "Stores logs in Elasticsearch"
66
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/integration/outputs/compressed_indexing_spec.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,13 @@
3232
let(:http_client) do
3333
Manticore::Client.new(http_client_options)
3434
end
35+
let(:expected_headers) {
36+
{
37+
"Content-Encoding" => "gzip",
38+
"Content-Type" => "application/json",
39+
'x-elastic-product-origin' => 'logstash-output-elasticsearch'
40+
}
41+
}
3542

3643
before do
3744
subject.register
@@ -64,7 +71,7 @@
6471

6572
it "sets the correct content-encoding header and body is compressed" do
6673
expect(subject.client.pool.adapter.client).to receive(:send).
67-
with(anything, anything, {:headers=>{"Content-Encoding"=>"gzip", "Content-Type"=>"application/json"}, :body => a_valid_gzip_encoded_string}).
74+
with(anything, anything, {:headers=> expected_headers, :body => a_valid_gzip_encoded_string}).
6875
and_call_original
6976
subject.multi_receive(events)
7077
end

spec/integration/outputs/index_spec.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,10 +214,13 @@ def curl_and_get_json_response(url, method: :get, retrieve_err_payload: false);
214214
end
215215

216216
it "sets the correct content-type header" do
217-
expected_manticore_opts = {:headers => {"Content-Type" => "application/json"}, :body => anything}
217+
expected_manticore_opts = {
218+
:headers => {"Content-Type" => "application/json", 'x-elastic-product-origin' => 'logstash-output-elasticsearch'},
219+
:body => anything
220+
}
218221
if secure
219222
expected_manticore_opts = {
220-
:headers => {"Content-Type" => "application/json"},
223+
:headers => {"Content-Type" => "application/json", 'x-elastic-product-origin' => 'logstash-output-elasticsearch'},
221224
:body => anything,
222225
:auth => {
223226
:user => user,

spec/unit/outputs/elasticsearch/http_client/manticore_adapter_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434

3535
expect(subject.manticore).to receive(:get).
3636
with(expected_uri.to_s, {
37-
:headers => {"Content-Type" => "application/json"},
37+
:headers => LogStash::Outputs::ElasticSearch::HttpClient::DEFAULT_HEADERS,
3838
:auth => {
3939
:user => user,
4040
:password => password,

0 commit comments

Comments
 (0)