Fix: cloud_id not propagating from monitoring config

Fixes #11800
This commit is contained in:
Karol Bucek 2020-04-16 18:01:06 +02:00
parent 21b1ef531e
commit ee2d819d44
2 changed files with 37 additions and 11 deletions

View file

@ -4,8 +4,6 @@
require 'logstash/logging/logger'
require 'logstash/outputs/elasticsearch'
require 'logstash/json'
require 'json'
module LogStash
module LicenseChecker
@ -17,8 +15,7 @@ module LogStash
def initialize(settings, feature, options)
@namespace = "xpack.#{feature}"
@settings = settings
@es_options = options
@es_options.merge!("resurrect_delay" => 30)
@es_options = options.merge('resurrect_delay' => 30)
end
##
@ -62,8 +59,10 @@ module LogStash
# # log originate from the `ElasticsearchSource`
def build_client
es = LogStash::Outputs::ElasticSearch.new(@es_options)
new_logger = logger
es.instance_eval { @logger = new_logger }
es.instance_variable_set :@logger, logger
es.fill_hosts_from_cloud_id
es.fill_user_password_from_cloud_auth
es.setup_hosts
es.build_client
end

View file

@ -3,15 +3,13 @@
# you may not use this file except in compliance with the Elastic License.
require "spec_helper"
require "logstash/json"
require 'support/helpers'
require "license_checker/license_reader"
require "helpers/elasticsearch_options"
require "monitoring/monitoring"
require "stud/temporary"
describe LogStash::LicenseChecker::LicenseReader do
let(:elasticsearch_url) { ["https://localhost:9898"] }
let(:elasticsearch_url) { "https://localhost:9898" }
let(:elasticsearch_username) { "elastictest" }
let(:elasticsearch_password) { "testchangeme" }
let(:extension) { LogStash::MonitoringExtension.new }
@ -25,7 +23,7 @@ describe LogStash::LicenseChecker::LicenseReader do
let(:settings) do
{
"xpack.monitoring.enabled" => true,
"xpack.monitoring.elasticsearch.hosts" => elasticsearch_url,
"xpack.monitoring.elasticsearch.hosts" => [ elasticsearch_url ],
"xpack.monitoring.elasticsearch.username" => elasticsearch_username,
"xpack.monitoring.elasticsearch.password" => elasticsearch_password,
}
@ -101,4 +99,33 @@ describe LogStash::LicenseChecker::LicenseReader do
end
end
end
it "builds ES client" do
expect( subject.client.options[:hosts].size ).to eql 1
expect( subject.client.options[:hosts][0].to_s ).to eql elasticsearch_url # URI#to_s
expect( subject.client.options ).to include(:user => elasticsearch_username, :password => elasticsearch_password)
end
context 'with cloud_id' do
let(:cloud_id) do
'westeurope-1:d2VzdGV1cm9wZS5henVyZS5lbGFzdGljLWNsb3VkLmNvbTo5MjQzJGUxZTYzMTIwMWZiNjRkNTVhNzVmNDMxZWI2MzQ5NTg5JDljYzYwMGUwMGQwYjRhMThiNmY2NmU2ZTcyMTQwODA3'
end
let(:cloud_auth) do
'elastic:LnWMLeK3EQPTf3G3F1IBdFvO'
end
let(:settings) do
{
"xpack.monitoring.enabled" => true,
"xpack.monitoring.elasticsearch.cloud_id" => cloud_id,
"xpack.monitoring.elasticsearch.cloud_auth" => cloud_auth
}
end
it "builds ES client" do
expect( subject.client.options[:hosts].size ).to eql 1
expect( subject.client.options[:hosts][0].to_s ).to eql 'https://e1e631201fb64d55a75f431eb6349589.westeurope.azure.elastic-cloud.com:9243'
expect( subject.client.options ).to include(:user => 'elastic', :password => 'LnWMLeK3EQPTf3G3F1IBdFvO')
end
end
end