Skip to content

Commit

Permalink
Moved to be populated and exposed also if monitoring xpack is disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
andsel committed Jan 24, 2020
1 parent 9646a6f commit 3388550
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 24 deletions.
50 changes: 31 additions & 19 deletions logstash-core/lib/logstash/api/commands/default_metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion logstash-core/lib/logstash/environment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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) }

Expand Down
16 changes: 13 additions & 3 deletions logstash-core/spec/logstash/api/commands/default_metadata_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
)
Expand Down
1 change: 0 additions & 1 deletion x-pack/lib/monitoring/monitoring.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit 3388550

Please sign in to comment.