Skip to content

Commit

Permalink
add back --pluginpath option
Browse files Browse the repository at this point in the history
support adding plugin paths

support --pluginpath option

missing doc

refactor using @purbon suggestions

Agent#configure_plugin_paths spec

solves elastic#3580
  • Loading branch information
colinsurprenant committed Jul 15, 2015
1 parent 00cf4d9 commit 52aec3b
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 2 deletions.
16 changes: 15 additions & 1 deletion lib/logstash/agent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ class LogStash::Agent < Clamp::Command
option ["-V", "--version"], :flag,
I18n.t("logstash.agent.flag.version")

option ["-p", "--pluginpath"] , "PATH",
I18n.t("logstash.agent.flag.pluginpath"),
:multivalued => true,
:attribute_name => :plugin_paths

option ["-t", "--configtest"], :flag,
I18n.t("logstash.agent.flag.configtest"),
:attribute_name => :config_test
Expand Down Expand Up @@ -204,6 +209,7 @@ def show_gems
# Log file stuff, plugin path checking, etc.
def configure
configure_logging(log_file)
configure_plugin_paths(plugin_paths)
end # def configure

# Point logging at a specific path.
Expand All @@ -229,7 +235,6 @@ def configure_logging(path)
else
@logger.level = :warn
end

end

if log_file
Expand All @@ -254,6 +259,15 @@ def configure_logging(path)
# http://jira.codehaus.org/browse/JRUBY-7003
end # def configure_logging

# add the given paths for ungemified/bare plugins lookups
# @param paths [String, Array<String>] plugins path string or list of path strings to add
def configure_plugin_paths(paths)
Array(paths).each do |path|
fail(I18n.t("logstash.agent.configuration.plugin_path_missing", :path => path)) unless File.directory?(path)
LogStash::Environment.add_plugin_path(path)
end
end

def load_config(path)
begin
uri = URI.parse(path)
Expand Down
8 changes: 8 additions & 0 deletions lib/logstash/environment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,14 @@ def load_locale!
I18n.reload!
fail "No locale? This is a bug." if I18n.available_locales.empty?
end

# add path for bare/ungemified plugins lookups. the path must be the base path that will include
# the dir structure 'logstash/TYPE/NAME.rb' where TYPE is 'inputs' 'filters', 'outputs' or 'codecs'
# and NAME is the name of the plugin
# @param path [String] plugins path to add
def add_plugin_path(path)
$LOAD_PATH << path
end
end
end

Expand Down
11 changes: 11 additions & 0 deletions spec/core/environment_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,18 @@
allow(Dir).to receive(:glob).and_return([])
expect { subject.load_runtime_jars! }.to raise_error
end
end
end

context "add_plugin_path" do
let(:path) { "/some/path" }

before(:each) { expect($LOAD_PATH).to_not include(path) }
after(:each) { $LOAD_PATH.delete(path) }

it "should add the path to $LOAD_PATH" do
expect{subject.add_plugin_path(path)}.to change{$LOAD_PATH.size}.by(1)
expect($LOAD_PATH).to include(path)
end
end
end
26 changes: 25 additions & 1 deletion spec/logstash/agent_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
end
end
end

context "when remote" do
context 'supported scheme' do
let(:path) { "http://test.local/superconfig.conf" }
Expand All @@ -34,4 +34,28 @@
end
end
end

context "--pluginpath" do
let(:single_path) { "/some/path" }
let(:multiple_paths) { ["/some/path1", "/some/path2"] }

it "should add single valid dir path to the environment" do
expect(File).to receive(:directory?).and_return(true)
expect(LogStash::Environment).to receive(:add_plugin_path).with(single_path)
subject.configure_plugin_paths(single_path)
end

it "should fail with single invalid dir path" do
expect(File).to receive(:directory?).and_return(false)
expect(LogStash::Environment).not_to receive(:add_plugin_path)
expect{subject.configure_plugin_paths(single_path)}.to raise_error(LogStash::ConfigurationError)
end

it "should add multiple valid dir path to the environment" do
expect(File).to receive(:directory?).exactly(multiple_paths.size).times.and_return(true)
multiple_paths.each{|path| expect(LogStash::Environment).to receive(:add_plugin_path).with(path)}
subject.configure_plugin_paths(multiple_paths)
end
end
end

0 comments on commit 52aec3b

Please sign in to comment.