class RequestLogAnalyzer::Aggregator::Summarizer
Attributes
Public Class Methods
Initialize summarizer. Generate trackers from speciefied source.file_format.report_trackers and set them up
RequestLogAnalyzer::Aggregator::Base::new
# File lib/request_log_analyzer/aggregator/summarizer.rb 42 def initialize(source, options = {}) 43 super(source, options) 44 @warnings_encountered = {} 45 @trackers = source.file_format.report_trackers 46 setup 47 end
Public Instance Methods
Pass all requests to trackers and let them update if necessary. request
The request to pass.
# File lib/request_log_analyzer/aggregator/summarizer.rb 60 def aggregate(request) 61 @trackers.each do |tracker| 62 tracker.update(request) if tracker.should_update?(request) 63 end 64 end
Call finalize on all trackers. Saves a YAML dump if this is set in the options.
# File lib/request_log_analyzer/aggregator/summarizer.rb 67 def finalize 68 @trackers.each { |tracker| tracker.finalize } 69 save_results_dump(options[:yaml]) if options[:yaml] 70 end
Returns true if there were any log ordering warnings
# File lib/request_log_analyzer/aggregator/summarizer.rb 141 def has_log_ordering_warnings? 142 @warnings_encountered[:no_current_request] && @warnings_encountered[:no_current_request] > 0 143 end
Returns true if there were any warnings generated by the trackers
# File lib/request_log_analyzer/aggregator/summarizer.rb 136 def has_warnings? 137 @warnings_encountered.reduce(0) { |result, (_, value)| result += value } > 0 138 end
Call prepare on all trackers.
# File lib/request_log_analyzer/aggregator/summarizer.rb 53 def prepare 54 fail 'No trackers set up in Summarizer!' if @trackers.nil? || @trackers.empty? 55 @trackers.each { |tracker| tracker.prepare } 56 end
Call report on all trackers. output
RequestLogAnalyzer::Output
object to output to
# File lib/request_log_analyzer/aggregator/summarizer.rb 90 def report(output) 91 report_header(output) 92 if source.parsed_requests > 0 93 @trackers.each { |tracker| output.report_tracker(tracker) } 94 else 95 output.puts 96 output.puts('There were no requests analyzed.') 97 end 98 report_footer(output) 99 end
Generate report header. output
RequestLogAnalyzer::Output
object to output to
# File lib/request_log_analyzer/aggregator/summarizer.rb 103 def report_header(output) 104 output.title('Request summary') 105 106 output.with_style(cell_separator: false) do 107 output.table({ width: 20 }, { font: :bold }) do |rows| 108 source.processed_files.each do |f| 109 rows << ['Processed File:', f] 110 end 111 rows << ['Parsed lines:', source.parsed_lines] 112 rows << ['Skipped lines:', source.skipped_lines] 113 rows << ['Parsed requests:', source.parsed_requests] 114 rows << ['Skipped requests:', source.skipped_requests] 115 rows << ['Warnings:', @warnings_encountered.map { |(key, value)| "#{key}: #{value}" }.join(', ')] if has_warnings? 116 end 117 end 118 output << "\n" 119 end
Saves the results of all the trackers in YAML format to a file. filename
The file to store the YAML dump in.
# File lib/request_log_analyzer/aggregator/summarizer.rb 74 def save_results_dump(filename) 75 File.open(filename, 'w') { |file| file.write(to_yaml) } 76 end
# File lib/request_log_analyzer/aggregator/summarizer.rb 49 def setup 50 end
Exports all the tracker results to YAML. It will call the to_yaml_object method for every tracker and combines these into a single YAML export.
# File lib/request_log_analyzer/aggregator/summarizer.rb 80 def to_yaml 81 require 'yaml' 82 trackers_export = @trackers.reduce({}) do |export, tracker| 83 export[tracker.title] = tracker.to_yaml_object; export 84 end 85 YAML.dump(trackers_export) 86 end
Store an encountered warning type
Type of warning message
Warning message lineno
The line on which the error was encountered
# File lib/request_log_analyzer/aggregator/summarizer.rb 149 def warning(type, _message, _lineno) 150 @warnings_encountered[type] ||= 0 151 @warnings_encountered[type] += 1 152 end