mirror of
https://github.com/elastic/logstash.git
synced 2025-04-24 06:37:19 -04:00
Add x-elastic-product-origin
header to kibana requests (#16765)
This commit updates the Kibana client to add a `x-elastic-product-origin` header with the value `logstash` for any requests originating from logstash to indicate which internal product is using the API.
This commit is contained in:
parent
3954b61c9d
commit
625439b541
2 changed files with 34 additions and 1 deletions
|
@ -91,7 +91,12 @@ module LogStash module Modules class KibanaClient
|
|||
@endpoint = "#{@scheme}://#{@host}"
|
||||
|
||||
@client = client || Manticore::Client.new(client_options)
|
||||
@http_options = {:headers => {'Content-Type' => 'application/json'}}
|
||||
@http_options = {
|
||||
:headers => {
|
||||
'Content-Type' => 'application/json',
|
||||
"x-elastic-product-origin" => "logstash"
|
||||
}
|
||||
}
|
||||
username = @settings["var.kibana.username"]
|
||||
if username
|
||||
password = @settings["var.kibana.password"]
|
||||
|
|
|
@ -101,5 +101,33 @@ module LogStash module Modules
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "when making requests to Kibana" do
|
||||
let(:test_client) { double("client") }
|
||||
let(:mock_response) { double("response",
|
||||
code: 200,
|
||||
body: {"version" => {"number" => "1.2.3"}}.to_json,
|
||||
headers: {}
|
||||
)}
|
||||
let(:mock_http) { double("http") }
|
||||
let(:settings) { {"var.kibana.host" => "localhost:5601"} }
|
||||
|
||||
it "includes product origin header" do
|
||||
# The status API is checked on initialization, the `safely` method is used
|
||||
# for any REST calls, so just checkiing this :get covers the header addition.
|
||||
expect(test_client).to receive(:http)
|
||||
.with(:get, "https://localhost:5601/api/status",
|
||||
hash_including(
|
||||
headers: hash_including(
|
||||
"x-elastic-product-origin" => "logstash"
|
||||
)
|
||||
)
|
||||
)
|
||||
.and_return(mock_http)
|
||||
expect(mock_http).to receive(:call).and_return(mock_response)
|
||||
|
||||
described_class.new(settings, test_client)
|
||||
end
|
||||
end
|
||||
end
|
||||
end end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue