Permalink
Browse files

Deprecated :dump and added scout and munin integration specs

  • Loading branch information...
1 parent c199d96 commit 4a2332e898cde149097ab469f91d21a6f3c644de @barttenbrinke barttenbrinke committed Sep 30, 2009
View
2 lib/request_log_analyzer/aggregator/summarizer.rb
@@ -90,7 +90,7 @@ def aggregate(request)
# Call finalize on all trackers. Saves a YAML dump if this is set in the options.
def finalize
@trackers.each { |tracker| tracker.finalize }
- save_results_dump(options[:dump]) if options[:dump]
+ save_results_dump(options[:yaml]) if options[:yaml]
end
# Saves the results of all the trackers in YAML format to a file.
View
21 lib/request_log_analyzer/controller.rb
@@ -30,7 +30,7 @@ def self.build_from_arguments(arguments)
options[:database] = arguments[:database]
options[:reset_database] = arguments[:reset_database]
options[:debug] = arguments[:debug]
- options[:dump] = arguments[:dump]
+ options[:yaml] = arguments[:dump]
options[:parse_strategy] = arguments[:parse_strategy]
options[:no_progress] = arguments[:no_progress]
options[:format] = arguments[:format]
@@ -80,9 +80,9 @@ def self.build_from_arguments(arguments)
# * <tt>:database</tt> Database file
# * <tt>:reset_database</tt>
# * <tt>:debug</tt> Enables echo aggregator.
- # * <tt>:dump</tt>
+ # * <tt>:yaml</tt> Output to YAML
# * <tt>:parse_strategy</tt>
- # * <tt>:no_progress</tt>
+ # * <tt>:no_progress</tt> Do not display the progress bar
# * <tt>:output</tt> :fixed_width, :html or Output class. Defaults to fixed width.
# * <tt>:file</tt> Filestring or File or StringIO
# * <tt>:format</tt> :rails, {:apache => 'FORMATSTRING'}, :merb, etcetera or Format Class. Defaults to :rails.
@@ -100,14 +100,20 @@ def self.build_from_arguments(arguments)
# Refactor :database => options[:database], :dump => options[:dump] away from contoller intialization.
def self.build(options)
# Defaults
- options[:output] ||= :fixed_width
+ options[:output] ||= 'fixed_width'
options[:format] ||= :rails
options[:aggregator] ||= [:summarizer]
options[:report_width] ||= 80
options[:report_amount] ||= 20
options[:report_sort] ||= 'sum,mean'
options[:boring] ||= false
+ # Backwards compatibility
+ if options[:dump] && options[:yaml].blank?
+ warn "[DEPRECATION] `:dump` is deprecated. Please use `:yaml` instead."
+ options[:yaml] = options[:dump]
+ end
+
# Set the output class
output_args = {}
output_object = nil
@@ -145,8 +151,9 @@ def self.build(options)
controller = Controller.new( RequestLogAnalyzer::Source::LogParser.new(file_format, :source_files => options[:source_files]),
{ :output => output_instance,
:database => options[:database], # FUGLY!
- :dump => options[:dump],
- :reset_database => options[:reset_database]})
+ :yaml => options[:yaml],
+ :reset_database => options[:reset_database],
+ :no_progress => options[:no_progress]})
# register filters
if options[:after] || options[:before]
@@ -188,7 +195,7 @@ def self.build(options)
# <tt>format</tt> Logfile format. Defaults to :rails
# Options are passd on to the LogParser.
# * <tt>:database</tt> Database the controller should use.
- # * <tt>:dump</tt> Yaml Dump the contrller should use.
+ # * <tt>:yaml</tt> Yaml Dump the contrller should use.
# * <tt>:output</tt> All report outputs get << through this output.
# * <tt>:no_progress</tt> No progress bar
def initialize(source, options = {})
View
6 spec/integration/command_line_usage_spec.rb
@@ -72,9 +72,9 @@
end
it "should dump the results to a YAML file" do
- run("#{log_fixture(:rails_1x)} --dump #{temp_output_file(:dump)}")
- File.exist?(temp_output_file(:dump)).should be_true
- YAML::load(File.read(temp_output_file(:dump))).should have_at_least(1).item
+ run("#{log_fixture(:rails_1x)} --dump #{temp_output_file(:yaml)}")
+ File.exist?(temp_output_file(:yaml)).should be_true
+ YAML::load(File.read(temp_output_file(:yaml))).should have_at_least(1).item
end
it "should parse 4 requests from the standard input" do
View
58 spec/integration/munin_plugins_rails_spec.rb
@@ -0,0 +1,58 @@
+require File.dirname(__FILE__) + '/../spec_helper.rb'
+
+describe RequestLogAnalyzer, 'when harvesting like munin-plugins-rails the YAML output' do
+
+ before(:each) do
+ cleanup_temp_files!
+ run("#{log_fixture(:rails_1x)} --dump #{temp_output_file(:yaml)}")
+ @rla = YAML::load(File.read(temp_output_file(:yaml)))
+ end
+
+ after(:each) do
+ cleanup_temp_files!
+ end
+
+ it "should contain database times" do
+ @rla["Database time"].each do |item|
+ item[1][:min].should_not be_nil
+ item[1][:max].should_not be_nil
+ item[1][:hits].should_not be_nil
+ item[1][:sum].should_not be_nil
+ end
+ end
+
+ it "should contain request times" do
+ @rla["Request duration"].each do |item|
+ item[1][:min].should_not be_nil
+ item[1][:max].should_not be_nil
+ item[1][:hits].should_not be_nil
+ item[1][:sum].should_not be_nil
+ end
+ end
+
+ it "should contain failed requests" do
+ @rla.keys.should include("Failed requests")
+ end
+
+ it "should contain Process blockers" do
+ @rla.keys.should include("Process blockers (> 1 sec duration)")
+ end
+
+ it "should contain HTTP Methods" do
+ @rla["HTTP methods"]["GET"].should_not be_nil
+ end
+
+ it "should contain HTTP Methods" do
+ @rla["HTTP methods"]["GET"].should_not be_nil
+ end
+
+ it "should contain view rendering times" do
+ @rla["View rendering time"].each do |item|
+ item[1][:min].should_not be_nil
+ item[1][:max].should_not be_nil
+ item[1][:hits].should_not be_nil
+ item[1][:sum].should_not be_nil
+ end
+ end
+
+end
View
19 spec/integration/scout_spec.rb
@@ -0,0 +1,19 @@
+require File.dirname(__FILE__) + '/../spec_helper.rb'
+
+describe RequestLogAnalyzer, 'when using the rla API like the scout plugin' do
+
+ before(:each) do
+ @summary = StringIO.new
+ RequestLogAnalyzer::Controller.build(
+ :output => :HTML,
+ :file => @summary,
+ :source_files => "#{log_fixture(:rails_1x)}",
+ :no_progress => true
+ ).run!
+ end
+
+ it "should generate a summary" do
+ @summary.string.should_not be_nil
+ end
+
+end
View
2 spec/unit/tracker/tracker_api_spec.rb
@@ -116,7 +116,7 @@
end
it "should receive :to_yaml object when finalizing" do
- @summarizer.options[:dump] = temp_output_file(:dump)
+ @summarizer.options[:yaml] = temp_output_file(:yaml)
@tracker.should_receive(:to_yaml_object).once
@summarizer.to_yaml
end

0 comments on commit 4a2332e

Please sign in to comment.