Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

show headers by default. Add table_output #29

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ Before you can run your test is necessary to bootstrap your logstash installatio
If you are in 1.5.x:
- Run `rake bootstrap` to setup the system.
- Run `lsperfm-deps` to install the test dependencies

For 1.4:
- Run `bin/logstash deps` to setup everything.

Expand Down
26 changes: 21 additions & 5 deletions lib/lsperfm.rb
Original file line number Diff line number Diff line change
@@ -1,21 +1,37 @@
require 'yaml'
require 'lsperfm/core'
require 'terminal-table'

module LogStash
module PerformanceMeter

extend self

def invoke
debug = !!ENV['DEBUG']
headers = !!ENV['HEADERS']
debug = 'false' != ENV.fetch('DEBUG', 'false')
display_headers = 'false' != ENV.fetch('HEADERS', 'true')
table_output = 'false' != ENV.fetch('TABLE_OUTPUT', 'false')
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was surprised to learn the ENV hash didn't have a better structure to deal with true or false values, instead of by presence & stringifying everything - making !!'false' => true . This fixes that case.


install_path = ARGV.size > 1 ? ARGV[1] : Dir.pwd
definition = ARGV.size > 0 ? ARGV[0] : ""
install_path = ARGV.size > 1 ? ARGV[1] : Dir.pwd
definition = ARGV.size > 0 ? ARGV[0] : ""

runner = LogStash::PerformanceMeter::Core.new(definition, install_path)
runner.config = '.lsperfm' if File.exist?('.lsperfm.yml')
puts runner.run(debug, headers).join("\n")

results = runner.run(debug)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes the runner/core return all it's info - headers & results; letting this method deal with how to display it.

headings = results.slice!(0)

puts ''
if table_output
table = Terminal::Table.new
table.headings = headings.split(',') if display_headers
table.rows = results.map { |result| result.split(',') }

puts table
else
puts headings if display_headers
puts results.join('\n')
end
end

end
Expand Down
4 changes: 2 additions & 2 deletions lib/lsperfm/core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ def initialize(definition, install_path, config='', runner = LogStash::Performan
@config = load_config(config)
end

def run(debug=false, headers=false)
def run(debug=false)
tests = load_tests(definition)
lines = (headers ? ["name, #{runner.headers.join(',')}"] : [])
lines = ["name,#{runner.headers.join(',')}"]
reporter = LogStash::PerformanceMeter::Reporter.new.start
tests.each do |test|
events = test[:events].to_i
Expand Down
4 changes: 2 additions & 2 deletions lib/lsperfm/core/run.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def self.read_input_file(file_path)

def feed_input_events(io, events_count, lines, last_message)
loop_count = (events_count / lines.size).ceil # how many time we send the input file over
(1..loop_count).each{lines.each {|line| io.puts(line)}}
loop_count.times{lines.each {|line| io.puts(line)}}

io.puts(last_message)
io.flush
Expand All @@ -85,7 +85,7 @@ def feed_input_interval(io, seconds, lines, last_message)
count = 0

while true
(1..loop_count).each{lines.each {|line| io.puts(line)}}
loop_count.times{lines.each {|line| io.puts(line)}}
count += lines_per_iteration
break if (Time.now - start_time) >= seconds
end
Expand Down
1 change: 1 addition & 0 deletions logstash-perftool.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Gem::Specification.new do |gem|

gem.executables = ["lsperfm", "lsperfm-deps"]

gem.add_dependency "terminal-table"
gem.add_development_dependency "bundler", "~> 1.7"
gem.add_development_dependency "rake", "~> 10.0"
gem.add_development_dependency "rspec", '~> 3.3', '>= 3.3.0' #(MIT license)
Expand Down
2 changes: 1 addition & 1 deletion spec/lib/runner_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
let(:command) { [File.join(Dir.pwd, LogStash::PerformanceMeter::Runner::LOGSTASH_BIN), "-f", "spec/fixtures/simple.conf"]}

it "invokes the logstash command" do
Open3.should_receive(:popen3).with(*command).and_return(true)
expect(Open3).to receive(:popen3).with(*command).and_return(true)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

deprecation notice for using 'should(a)' syntax

runner.run(events, 0, lines)
end

Expand Down