Skip to content

Commit

Permalink
fix agent stall when also using web argument
Browse files Browse the repository at this point in the history
  • Loading branch information
colinsurprenant committed Mar 28, 2014
1 parent 6350d68 commit 323f42f
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 4 deletions.
21 changes: 17 additions & 4 deletions lib/logstash/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ module Cabin::Mixins::Logger
class LogStash::Runner
include LogStash::Program

def initialize
@runners = []
end

def main(args)
require "logstash/util"
require "stud/trap"
Expand All @@ -74,7 +78,6 @@ def main(args)

args = [nil] if args.empty?

@runners = []
while args != nil && !args.empty?
args = run(args)
end
Expand Down Expand Up @@ -187,15 +190,16 @@ def wait
agent = LogStash::Agent.new($0)
begin
agent.parse(args)
@runners << Stud::Task.new { agent.execute }
rescue Clamp::HelpWanted => e
puts e.command.help
show_help(e.command)
return []
rescue Clamp::UsageError => e
# If 'too many arguments' then give the arguments to
# the next command. Otherwise it's a real error.
raise if e.message != "too many arguments"
remaining = agent.remaining_arguments
end
@runners << Stud::Task.new { agent.execute }

return remaining
end
Expand Down Expand Up @@ -229,8 +233,17 @@ def wait
return args
end # def run

def self.valid_caller?
caller.none?{|entry| entry =~ /rspec/}
end

private

def show_help(command)
puts command.help
end
end # class LogStash::Runner

if $0 == __FILE__
if $0 == __FILE__ && LogStash::Runner.valid_caller?
LogStash::Runner.new.main(ARGV)
end
42 changes: 42 additions & 0 deletions spec/runner_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
require "logstash/runner"
require "logstash/agent"
require "logstash/kibana"
require "stud/task"

class NullRunner
def run(args); end
end

describe LogStash::Runner do

context "argument parsing" do
it "should run agent" do
expect(Stud::Task).to receive(:new).once.and_return(nil)
args = ["agent", "-e", ""]
expect(subject.run(args)).to eq(nil)
end

it "should run agent help" do
expect(subject).to receive(:show_help).once.and_return(nil)
args = ["agent", "-h"]
expect(subject.run(args)).to eq([])
end

it "should run agent help and not run following commands" do
expect(subject).to receive(:show_help).once.and_return(nil)
args = ["agent", "-h", "web"]
expect(subject.run(args)).to eq([])
end

it "should run agent and web" do
expect(Stud::Task).to receive(:new).once
args = ["agent", "-e", "", "web"]
args = subject.run(args)
expect(args).to eq(["web"])

expect(LogStash::Kibana::Runner).to receive(:new).once.and_return(NullRunner.new)
args = subject.run(args)
expect(args).to eq(nil)
end
end
end

0 comments on commit 323f42f

Please sign in to comment.