Skip to content

Commit

Permalink
Add cluster_uuid setting to default config file, displaying it in Nod…
Browse files Browse the repository at this point in the history
…e stats HTTP API

Fixes #11106
  • Loading branch information
cachedout authored and andsel committed Jan 27, 2020
1 parent 6eb2517 commit 020e87e
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 15 deletions.
45 changes: 31 additions & 14 deletions logstash-core/lib/logstash/api/commands/default_metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +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"),
}
}
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 @@ -36,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
38 changes: 38 additions & 0 deletions logstash-core/spec/logstash/api/commands/default_metadata_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
describe LogStash::Api::Commands::DefaultMetadata do
include_context "api setup"

def registerIfNot(setting)
LogStash::SETTINGS.register(setting) unless LogStash::SETTINGS.registered?(setting.name)
end

let(:report_method) { :all }
subject(:report) do
factory = ::LogStash::Api::CommandFactory.new(LogStash::Api::Service.new(@agent))
Expand All @@ -12,9 +16,43 @@

let(:report_class) { described_class }

before :all do
registerIfNot(LogStash::Setting::Boolean.new("xpack.monitoring.enabled", false))
registerIfNot(LogStash::Setting::ArrayCoercible.new("xpack.monitoring.elasticsearch.hosts", String, [ "http://localhost:9200" ] ))
registerIfNot(LogStash::Setting::NullableString.new("xpack.monitoring.elasticsearch.username", "logstash_TEST system"))
registerIfNot(LogStash::Setting::NullableString.new("xpack.monitoring.elasticsearch.username", "logstash_TEST system"))
end

after :each do
LogStash::SETTINGS.set_value("xpack.monitoring.enabled", false)
end

describe "#plugins_stats_report" do
let(:report_method) { :all }

# Enforce just the structure
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 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
)
end

it "check keys" do
expect(report.keys).to include(
:host,
Expand Down

0 comments on commit 020e87e

Please sign in to comment.