diff --git a/logstash-core/lib/logstash/api/commands/default_metadata.rb b/logstash-core/lib/logstash/api/commands/default_metadata.rb index b487fb24a66..3835d9b5ba2 100644 --- a/logstash-core/lib/logstash/api/commands/default_metadata.rb +++ b/logstash-core/lib/logstash/api/commands/default_metadata.rb @@ -7,25 +7,31 @@ module Api module Commands class DefaultMetadata < Commands::Base def all - {:host => host, - :version => version, - :http_address => http_address, - :id => service.agent.id, - :name => service.agent.name, - :ephemeral_id => service.agent.ephemeral_id, - :status => "green", # This is hard-coded to mirror x-pack behavior - :snapshot => ::BUILD_INFO["build_snapshot"], - :pipeline => { - :workers => LogStash::SETTINGS.get("pipeline.workers"), - :batch_size => LogStash::SETTINGS.get("pipeline.batch.size"), - :batch_delay => LogStash::SETTINGS.get("pipeline.batch.delay"), - }, - }.merge(LogStash::SETTINGS.registered?("xpack.monitoring.enabled") && LogStash::SETTINGS.get("xpack.monitoring.enabled") ? - {:monitoring => { - :hosts => LogStash::SETTINGS.get("xpack.monitoring.elasticsearch.hosts"), - :username => LogStash::SETTINGS.get("xpack.monitoring.elasticsearch.username") - }.merge(LogStash::SETTINGS.set?("xpack.monitoring.cluster_uuid") ? - {:cluster_uuid => LogStash::SETTINGS.get("xpack.monitoring.cluster_uuid")} : {})} : {}) + res = {:host => host, + :version => version, + :http_address => http_address, + :id => service.agent.id, + :name => service.agent.name, + :ephemeral_id => service.agent.ephemeral_id, + :status => "green", # This is hard-coded to mirror x-pack behavior + :snapshot => ::BUILD_INFO["build_snapshot"], + :pipeline => { + :workers => LogStash::SETTINGS.get("pipeline.workers"), + :batch_size => LogStash::SETTINGS.get("pipeline.batch.size"), + :batch_delay => LogStash::SETTINGS.get("pipeline.batch.delay"), + }, + } + monitoring = {} + if enabled_xpack_monitoring? + monitoring = monitoring.merge({ + :hosts => LogStash::SETTINGS.get("xpack.monitoring.elasticsearch.hosts"), + :username => LogStash::SETTINGS.get("xpack.monitoring.elasticsearch.username") + }) + end + if LogStash::SETTINGS.set?("monitoring.cluster_uuid") + monitoring = monitoring.merge({:cluster_uuid => LogStash::SETTINGS.get("monitoring.cluster_uuid")}) + end + res.merge(monitoring.empty? ? {} : {:monitoring => monitoring}) end def host @@ -41,6 +47,12 @@ def http_address rescue ::LogStash::Instrument::MetricStore::MetricNotFound, NoMethodError => e nil end + + private + def enabled_xpack_monitoring? + LogStash::SETTINGS.registered?("xpack.monitoring.enabled") && + LogStash::SETTINGS.get("xpack.monitoring.enabled") + end end end end diff --git a/logstash-core/lib/logstash/environment.rb b/logstash-core/lib/logstash/environment.rb index 24f00ab200e..7d37d302f23 100644 --- a/logstash-core/lib/logstash/environment.rb +++ b/logstash-core/lib/logstash/environment.rb @@ -71,7 +71,8 @@ module Environment Setting::TimeValue.new("slowlog.threshold.debug", "-1"), Setting::TimeValue.new("slowlog.threshold.trace", "-1"), Setting::String.new("keystore.classname", "org.logstash.secret.store.backend.JavaKeyStore"), - Setting::String.new("keystore.file", ::File.join(::File.join(LogStash::Environment::LOGSTASH_HOME, "config"), "logstash.keystore"), false) # will be populated on + Setting::String.new("keystore.file", ::File.join(::File.join(LogStash::Environment::LOGSTASH_HOME, "config"), "logstash.keystore"), false), # will be populated on + Setting::NullableString.new("monitoring.cluster_uuid") # post_process ].each {|setting| SETTINGS.register(setting) } diff --git a/logstash-core/spec/logstash/api/commands/default_metadata_spec.rb b/logstash-core/spec/logstash/api/commands/default_metadata_spec.rb index d9b830d47f6..0f5aaf3e27d 100644 --- a/logstash-core/spec/logstash/api/commands/default_metadata_spec.rb +++ b/logstash-core/spec/logstash/api/commands/default_metadata_spec.rb @@ -16,7 +16,7 @@ LogStash::SETTINGS.register(LogStash::Setting::Boolean.new("xpack.monitoring.enabled", false)) unless LogStash::SETTINGS.registered?("xpack.monitoring.enabled") LogStash::SETTINGS.register(LogStash::Setting::ArrayCoercible.new("xpack.monitoring.elasticsearch.hosts", String, [ "http://localhost:9200" ] )) unless LogStash::SETTINGS.registered?("xpack.monitoring.elasticsearch.hosts") LogStash::SETTINGS.register(LogStash::Setting::NullableString.new("xpack.monitoring.elasticsearch.username", "logstash_TEST system")) unless LogStash::SETTINGS.registered?("xpack.monitoring.elasticsearch.username") - LogStash::SETTINGS.register(LogStash::Setting::NullableString.new("xpack.monitoring.cluster_uuid")) unless LogStash::SETTINGS.registered?("xpack.monitoring.cluster_uuid") + LogStash::SETTINGS.register(LogStash::Setting::NullableString.new("monitoring.cluster_uuid")) unless LogStash::SETTINGS.registered?("monitoring.cluster_uuid") end after :each do @@ -25,15 +25,25 @@ describe "#plugins_stats_report" do let(:report_method) { :all } + # Enforce just the structure - it "check monitoring" do + it "check monitoring exist when cluster_uuid has been defined" do + LogStash::SETTINGS.set_value("monitoring.cluster_uuid", "cracking_cluster") + expect(report.keys).to include( + :monitoring + ) + end + + it "check monitoring exist when monitoring is enabled" do LogStash::SETTINGS.set_value("xpack.monitoring.enabled", true) expect(report.keys).to include( :monitoring ) end - it "check monitoring does not appear when not enabled" do + + it "check monitoring does not appear when not enabled and nor cluster_uuid is defined" do LogStash::SETTINGS.set_value("xpack.monitoring.enabled", false) + LogStash::SETTINGS.get_setting("monitoring.cluster_uuid").reset expect(report.keys).not_to include( :monitoring ) diff --git a/x-pack/lib/monitoring/monitoring.rb b/x-pack/lib/monitoring/monitoring.rb index 1e7b7ab66a0..01e98d61aae 100644 --- a/x-pack/lib/monitoring/monitoring.rb +++ b/x-pack/lib/monitoring/monitoring.rb @@ -192,7 +192,6 @@ def additionals_settings(settings) settings.register(LogStash::Setting::NullableString.new("xpack.monitoring.elasticsearch.ssl.truststore.password")) settings.register(LogStash::Setting::NullableString.new("xpack.monitoring.elasticsearch.ssl.keystore.path")) settings.register(LogStash::Setting::NullableString.new("xpack.monitoring.elasticsearch.ssl.keystore.password")) - settings.register(LogStash::Setting::NullableString.new("xpack.monitoring.cluster_uuid")) settings.register(LogStash::Setting::String.new("xpack.monitoring.elasticsearch.ssl.verification_mode", "certificate", true, ["none", "certificate"])) settings.register(LogStash::Setting::Boolean.new("xpack.monitoring.elasticsearch.sniffing", false)) settings.register(LogStash::Setting::Boolean.new("xpack.monitoring.collection.pipeline.details.enabled", true))