Initialize the path.settings inside the runner class

The `path.settings` requires the LOGSTASH_HOME constant to be defined,
the problem is that constant is only defined when you are actually
inside the logstash application, This was causing a bug when you were
testing plugin individually because that constant wasn't defined.

Fixes: #5361

Fixes #5363
This commit is contained in:
Pier-Hugues Pellerin 2016-05-26 11:20:28 -04:00
parent 03ece707c7
commit 12debcf529
2 changed files with 8 additions and 1 deletions

View file

@ -13,7 +13,6 @@ module LogStash
Setting::Boolean.new("config.reload.automatic", false), Setting::Boolean.new("config.reload.automatic", false),
Setting::Numeric.new("config.reload.interval", 3), Setting::Numeric.new("config.reload.interval", 3),
Setting::Boolean.new("metric.collect", true) {|v| v == true }, # metric collection cannot be disabled Setting::Boolean.new("metric.collect", true) {|v| v == true }, # metric collection cannot be disabled
Setting::String.new("path.settings", ::File.join(Environment::LOGSTASH_HOME, "config")),
Setting::String.new("pipeline.id", "main"), Setting::String.new("pipeline.id", "main"),
Setting::Numeric.new("pipeline.workers", LogStash::Config::CpuCoreStrategy.maximum), Setting::Numeric.new("pipeline.workers", LogStash::Config::CpuCoreStrategy.maximum),
Setting::Numeric.new("pipeline.output.workers", 1), Setting::Numeric.new("pipeline.output.workers", 1),

View file

@ -15,8 +15,14 @@ require "logstash/agent"
require "logstash/config/defaults" require "logstash/config/defaults"
require "logstash/shutdown_watcher" require "logstash/shutdown_watcher"
require "logstash/patches/clamp" require "logstash/patches/clamp"
require "logstash/settings"
class LogStash::Runner < Clamp::StrictCommand class LogStash::Runner < Clamp::StrictCommand
# The `path.settings` need to be defined in the runner instead of the `logstash-core/lib/logstash/environment.r`
# because the `Environment::LOGSTASH_HOME` doesn't exist in the context of the `logstash-core` gem.
#
# See issues https://github.com/elastic/logstash/issues/5361
LogStash::SETTINGS.register(LogStash::Setting::String.new("path.settings", ::File.join(LogStash::Environment::LOGSTASH_HOME, "config")))
# Node Settings # Node Settings
option ["-n", "--node.name"], "NAME", option ["-n", "--node.name"], "NAME",
@ -129,7 +135,9 @@ class LogStash::Runner < Clamp::StrictCommand
def run(args) def run(args)
settings_path = fetch_settings_path(args) settings_path = fetch_settings_path(args)
@settings.set("path.settings", settings_path) if settings_path @settings.set("path.settings", settings_path) if settings_path
LogStash::SETTINGS.from_yaml(LogStash::SETTINGS.get("path.settings")) LogStash::SETTINGS.from_yaml(LogStash::SETTINGS.get("path.settings"))
super(*[args]) super(*[args])
end end