wvanbergen-request-log-analyzer 1.2.5 → 1.2.6

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ .svn/
2
+ .DS_Store
3
+ request-log-analyzer-*.gem
4
+ requests.db
5
+ /pkg
6
+ /doc
7
+ /tmp
8
+ /classes
9
+ /files
10
+ /coverage
data/Rakefile CHANGED
@@ -1,3 +1,5 @@
1
1
  Dir[File.dirname(__FILE__) + "/tasks/*.rake"].each { |file| load(file) }
2
+
3
+ GithubGem::RakeTasks.new(:gem)
2
4
 
3
- task :default => "spec:fancy"
5
+ task :default => "spec:specdoc"
@@ -46,6 +46,7 @@ module RequestLogAnalyzer::Aggregator
46
46
  def finalize
47
47
  @request_count = orm_module::Request.count
48
48
  remove_database_connection!
49
+ deinitialize_orm_module!
49
50
  end
50
51
 
51
52
  # Records w warining in the warnings table.
@@ -84,14 +85,20 @@ module RequestLogAnalyzer::Aggregator
84
85
  orm_base_class.abstract_class = true
85
86
  orm_module.const_set('Base', orm_base_class)
86
87
  end
87
- end
88
-
88
+ end
89
+
90
+ # Deinitializes the ORM module and the ActiveRecord::Base subclass.
91
+ def deinitialize_orm_module!
92
+ file_format.class.send(:remove_const, 'Database') if file_format.class.const_defined?('Database')
93
+ @orm_module = nil
94
+ end
95
+
89
96
  # Established a connection with the database for this session
90
97
  def establish_database_connection!
91
98
  orm_module::Base.establish_connection(:adapter => 'sqlite3', :database => options[:database])
92
99
  #ActiveRecord::Migration.class_eval("def self.connection; #{@orm_module.to_s}::Base.connection; end ")
93
- end
94
-
100
+ end
101
+
95
102
  def remove_database_connection!
96
103
  #ActiveRecord::Migration.class_eval("def self.connection; ActiveRecord::Base.connection; end ")
97
104
  orm_module::Base.remove_connection
@@ -130,8 +137,8 @@ module RequestLogAnalyzer::Aggregator
130
137
  klass = Class.new(orm_module::Base)
131
138
  klass.send(:belongs_to, :request)
132
139
 
133
- definition.captures.each do |capture|
134
- klass.send(:serialize, capture[:name], Hash) if capture[:provides]
140
+ definition.captures.select { |c| c.has_key?(:provides) }.each do |capture|
141
+ klass.send(:serialize, capture[:name], Hash)
135
142
  end
136
143
 
137
144
  orm_module.const_set(class_name, klass) unless orm_module.const_defined?(class_name)
@@ -11,7 +11,7 @@ module RequestLogAnalyzer
11
11
 
12
12
  # The current version of request-log-analyzer.
13
13
  # This will be diplayed in output reports etc.
14
- VERSION = '1.2.5'
14
+ VERSION = "1.2.6"
15
15
 
16
16
  # Loads constants in the RequestLogAnalyzer namespace using self.load_default_class_file(base, const)
17
17
  # <tt>const</tt>:: The constant that is not yet loaded in the RequestLogAnalyzer namespace. This should be passed as a string or symbol.
@@ -0,0 +1,36 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'request-log-analyzer'
3
+ s.version = "1.2.6"
4
+ s.date = "2009-09-02"
5
+
6
+ s.rubyforge_project = 'r-l-a'
7
+
8
+ s.bindir = 'bin'
9
+ s.executables = ['request-log-analyzer']
10
+ s.default_executable = 'request-log-analyzer'
11
+
12
+ s.summary = "A command line tool to analyze request logs for Rails, Merb and other application servers"
13
+ s.description = <<-eos
14
+ Request log analyzer's purpose is to find ot how your web application is being used and to focus your optimization efforts.
15
+ This tool will parse all requests in the application's log file and aggregate the information. Once it is finished parsing
16
+ the log file(s), it will show the requests that take op most server time using various metrics. It can also insert all
17
+ parsed request information into a database so you can roll your own analysis. It supports Rails- and Merb-based applications
18
+ out of the box, but file formats of other applications can easily be supported by supplying an easy to write log file format
19
+ definition.
20
+ eos
21
+
22
+ s.rdoc_options << '--title' << s.name << '--main' << 'README.rdoc' << '--line-numbers' << '--inline-source'
23
+ s.extra_rdoc_files = ['README.rdoc']
24
+
25
+ s.requirements << "To use the database inserter, ActiveRecord and an appropriate database adapter are required."
26
+
27
+ s.add_development_dependency('rspec', '>= 1.2.4')
28
+ s.add_development_dependency('git', '>= 1.1.0')
29
+
30
+ s.authors = ['Willem van Bergen', 'Bart ten Brinke']
31
+ s.email = ['willem@railsdoctors.com', 'bart@railsdoctors.com']
32
+ s.homepage = 'http://railsdoctors.com'
33
+
34
+ s.files = %w(spec/unit/filter/anonymize_filter_spec.rb lib/request_log_analyzer/line_definition.rb lib/request_log_analyzer/output/html.rb lib/request_log_analyzer/controller.rb spec/fixtures/rails_22_cached.log lib/request_log_analyzer/file_format/rails_development.rb spec/lib/macros.rb spec/fixtures/merb_prefixed.log tasks/request_log_analyzer.rake spec/unit/file_format/file_format_api_spec.rb spec/integration/command_line_usage_spec.rb spec/fixtures/decompression.log.bz2 lib/request_log_analyzer/log_processor.rb lib/request_log_analyzer/tracker.rb lib/request_log_analyzer/filter.rb spec/fixtures/rails_unordered.log bin/request-log-analyzer request-log-analyzer.gemspec DESIGN.rdoc spec/unit/filter/timespan_filter_spec.rb lib/request_log_analyzer/filter/field.rb lib/request_log_analyzer/tracker/frequency.rb spec/fixtures/decompression.log.gz spec/fixtures/decompression.log spec/lib/matchers.rb spec/fixtures/test_order.log lib/request_log_analyzer/output/fixed_width.rb lib/request_log_analyzer/filter/anonymize.rb spec/lib/testing_format.rb lib/request_log_analyzer/tracker/timespan.rb lib/request_log_analyzer/aggregator.rb lib/cli/progressbar.rb README.rdoc spec/fixtures/merb.log lib/request_log_analyzer/tracker/hourly_spread.rb .gitignore spec/unit/tracker/tracker_api_spec.rb spec/unit/tracker/duration_tracker_spec.rb lib/request_log_analyzer/aggregator/echo.rb spec/unit/controller/log_processor_spec.rb lib/request_log_analyzer.rb Rakefile spec/spec_helper.rb spec/unit/filter/filter_spec.rb lib/request_log_analyzer/aggregator/summarizer.rb lib/request_log_analyzer/file_format/rails.rb spec/fixtures/test_language_combined.log spec/fixtures/decompression.tar.gz spec/unit/filter/field_filter_spec.rb spec/spec.opts lib/request_log_analyzer/aggregator/database.rb lib/request_log_analyzer/filter/timespan.rb lib/request_log_analyzer/source/log_parser.rb spec/fixtures/decompression.tgz spec/unit/tracker/timespan_tracker_spec.rb spec/unit/tracker/hourly_spread_spec.rb spec/fixtures/header_and_footer.log lib/cli/tools.rb lib/request_log_analyzer/file_format/merb.rb spec/fixtures/multiple_files_1.log spec/unit/file_format/merb_format_spec.rb spec/unit/file_format/line_definition_spec.rb lib/request_log_analyzer/source.rb lib/request_log_analyzer/request.rb spec/unit/controller/controller_spec.rb lib/request_log_analyzer/output.rb spec/lib/helpers.rb spec/fixtures/rails_1x.log spec/lib/mocks.rb spec/fixtures/decompression.log.zip spec/unit/source/request_spec.rb spec/unit/source/log_parser_spec.rb spec/fixtures/test_file_format.log lib/request_log_analyzer/source/database.rb spec/unit/aggregator/database_spec.rb tasks/github-gem.rake lib/request_log_analyzer/tracker/duration.rb lib/request_log_analyzer/file_format.rb spec/unit/aggregator/summarizer_spec.rb spec/fixtures/rails_22.log spec/fixtures/multiple_files_2.log spec/fixtures/syslog_1x.log LICENSE spec/unit/tracker/frequency_tracker_spec.rb spec/unit/file_format/rails_format_spec.rb lib/cli/command_line_arguments.rb)
35
+ s.test_files = %w(spec/unit/filter/anonymize_filter_spec.rb spec/unit/file_format/file_format_api_spec.rb spec/integration/command_line_usage_spec.rb spec/unit/filter/timespan_filter_spec.rb spec/unit/tracker/tracker_api_spec.rb spec/unit/tracker/duration_tracker_spec.rb spec/unit/controller/log_processor_spec.rb spec/unit/filter/filter_spec.rb spec/unit/filter/field_filter_spec.rb spec/unit/tracker/timespan_tracker_spec.rb spec/unit/tracker/hourly_spread_spec.rb spec/unit/file_format/merb_format_spec.rb spec/unit/file_format/line_definition_spec.rb spec/unit/controller/controller_spec.rb spec/unit/source/request_spec.rb spec/unit/source/log_parser_spec.rb spec/unit/aggregator/database_spec.rb spec/unit/aggregator/summarizer_spec.rb spec/unit/tracker/frequency_tracker_spec.rb spec/unit/file_format/rails_format_spec.rb)
36
+ end
@@ -2,7 +2,7 @@ require File.dirname(__FILE__) + '/../../spec_helper'
2
2
 
3
3
  describe RequestLogAnalyzer::Aggregator::Database do
4
4
 
5
- before(:each) do
5
+ before(:all) do
6
6
  log_parser = RequestLogAnalyzer::Source::LogParser.new(testing_format)
7
7
  @database_inserter = RequestLogAnalyzer::Aggregator::Database.new(log_parser, :database => ':memory:')
8
8
 
@@ -16,12 +16,18 @@ describe RequestLogAnalyzer::Aggregator::Database do
16
16
  describe '#prepare' do
17
17
 
18
18
  before(:each) do
19
- @database_inserter.stub!(:establish_database_connection!)
19
+ @database_inserter.stub!(:initialize_orm_module!)
20
+ @database_inserter.stub!(:establish_database_connection!)
20
21
  @database_inserter.stub!(:create_database_schema!)
21
22
  end
22
23
 
24
+ it 'should create the ORM mdoule in which the classes can be created' do
25
+ @database_inserter.should_receive(:initialize_orm_module!)
26
+ @database_inserter.prepare
27
+ end
28
+
23
29
  it 'should establish the database connection' do
24
- @database_inserter.should_receive(:establish_database_connection!)
30
+ @database_inserter.should_receive(:establish_database_connection!)
25
31
  @database_inserter.prepare
26
32
  end
27
33
 
@@ -31,6 +37,30 @@ describe RequestLogAnalyzer::Aggregator::Database do
31
37
  end
32
38
  end
33
39
 
40
+ # The database inserter creates is own "Database" module within the file format
41
+ # class to create all the classes that are needed.
42
+ describe '#initialize_orm_module!' do
43
+
44
+ before(:all) { @database_inserter.send(:deinitialize_orm_module!) }
45
+ after(:all) { @database_inserter.send(:initialize_orm_module!) }
46
+
47
+ before(:each) { @database_inserter.send(:initialize_orm_module!) }
48
+ after(:each) { @database_inserter.send(:deinitialize_orm_module!) }
49
+
50
+ it "should create a Database module under the file format's class" do
51
+ testing_format.class.should be_const_defined('Database')
52
+ end
53
+
54
+ it "should define a Base class in the Database module" do
55
+ testing_format.class::Database.should be_const_defined('Base')
56
+ end
57
+
58
+ it "should create a ActiveRecord::Base class in the Database module" do
59
+ testing_format.class::Database::Base.ancestors.should include(ActiveRecord::Base)
60
+ end
61
+
62
+ end
63
+
34
64
  # The create_database_table method should create a database table according to the line definition,
35
65
  # so that parsed lines can be stored in it later on.
36
66
  describe '#create_database_table' do
@@ -1,272 +1,256 @@
1
1
  require 'rubygems'
2
- require 'rubyforge'
3
2
  require 'rake'
4
3
  require 'rake/tasklib'
5
4
  require 'date'
5
+ require 'git'
6
6
 
7
- module Rake
7
+ module GithubGem
8
8
 
9
- class GithubGem < TaskLib
10
-
11
- attr_accessor :name
12
- attr_accessor :specification
13
-
14
- def self.define_tasks!
15
- gem_task_builder = Rake::GithubGem.new
16
- gem_task_builder.register_all_tasks!
9
+ def self.detect_gemspec_file
10
+ FileList['*.gemspec'].first
11
+ end
12
+
13
+ def self.detect_main_include
14
+ if detect_gemspec_file =~ /^(\.*)\.gemspec$/ && File.exist?("lib/#{$1}.rb")
15
+ "lib/#{$1}.rb"
16
+ elsif FileList['lib/*.rb'].length == 1
17
+ FileList['lib/*.rb'].first
18
+ else
19
+ raise "Could not detect main include file!"
17
20
  end
21
+ end
22
+
23
+ class RakeTasks
24
+
25
+ attr_reader :gemspec, :modified_files, :git
26
+ attr_accessor :gemspec_file, :task_namespace, :main_include, :root_dir, :spec_pattern, :test_pattern, :remote, :remote_branch, :local_branch
18
27
 
28
+ def initialize(task_namespace = :gem)
29
+ @gemspec_file = GithubGem.detect_gemspec_file
30
+ @task_namespace = task_namespace
31
+ @main_include = GithubGem.detect_main_include
32
+ @modified_files = []
33
+ @root_dir = Dir.pwd
34
+ @test_pattern = 'test/**/*_test.rb'
35
+ @spec_pattern = 'spec/**/*_spec.rb'
36
+ @local_branch = 'master'
37
+ @remote = 'origin'
38
+ @remote_branch = 'master'
39
+
40
+
41
+ yield(self) if block_given?
19
42
 
20
- def initialize
21
- reload_gemspec!
43
+ @git = Git.open(@root_dir)
44
+ load_gemspec!
45
+ define_tasks!
22
46
  end
47
+
48
+ protected
49
+
50
+ def define_test_tasks!
51
+ require 'rake/testtask'
23
52
 
24
- def register_all_tasks!
25
- namespace(:gem) do
26
- desc "Updates the file lists for this gem"
27
- task(:manifest) { manifest_task }
28
-
29
- desc "Releases a new version of #{@name}"
30
- task(:build => [:manifest]) { build_task }
31
-
32
-
33
- release_dependencies = [:check_clean_master_branch, :version, :build, :create_tag]
34
- release_dependencies.push 'doc:publish' if has_rdoc?
35
- release_dependencies.unshift 'test' if has_tests?
36
- release_dependencies.unshift 'spec' if has_specs?
37
-
38
- desc "Releases a new version of #{@name}"
39
- task(:release => release_dependencies) { release_task }
40
-
41
- namespace(:release) do
42
- release_checks = [:check_clean_master_branch, :check_version, :build]
43
- release_checks.push 'doc:compile' if has_rdoc?
44
- release_checks.unshift 'test' if has_tests?
45
- release_checks.unshift 'spec' if has_specs?
46
-
47
- desc "Test release conditions"
48
- task(:check => release_checks) { release_check_task }
53
+ namespace(:test) do
54
+ Rake::TestTask.new(:basic) do |t|
55
+ t.pattern = test_pattern
56
+ t.verbose = true
57
+ t.libs << 'test'
49
58
  end
50
-
51
- # helper task for releasing
52
- task(:check_clean_master_branch) { verify_fast_forward('master', 'origin', 'master'); verify_clean_status('master') }
53
- task(:check_version) { verify_version(ENV['VERSION'] || @specification.version) }
54
- task(:version => [:check_version]) { set_gem_version! }
55
- task(:create_tag) { create_version_tag! }
56
59
  end
57
60
 
58
- # Register RDoc tasks
59
- if has_rdoc?
60
- require 'rake/rdoctask'
61
-
62
- namespace(:doc) do
63
- desc 'Generate documentation for request-log-analyzer'
64
- Rake::RDocTask.new(:compile) do |rdoc|
65
- rdoc.rdoc_dir = 'doc'
66
- rdoc.title = @name
67
- rdoc.options += @specification.rdoc_options
68
- rdoc.rdoc_files.include(@specification.extra_rdoc_files)
69
- rdoc.rdoc_files.include('lib/**/*.rb')
70
- end
71
-
72
- desc "Publish RDoc files for #{@name} to Github"
73
- task(:publish => :compile) do
74
- sh 'git checkout gh-pages'
75
- sh 'git pull origin gh-pages'
76
- sh 'cp -rf doc/* .'
77
- sh "git commit -am \"Publishing newest RDoc documentation for #{@name}\""
78
- sh "git push origin gh-pages"
79
- sh "git checkout master"
80
- end
81
- end
82
- end
61
+ desc "Run all unit tests for #{gemspec.name}"
62
+ task(:test => ['test:basic'])
63
+ end
83
64
 
84
- # Setup :spec task if RSpec files exist
85
- if has_specs?
86
- require 'spec/rake/spectask'
65
+ def define_rspec_tasks!
66
+ require 'spec/rake/spectask'
87
67
 
88
- desc "Run all specs for #{@name}"
89
- Spec::Rake::SpecTask.new(:spec) do |t|
90
- t.spec_files = FileList['spec/**/*_spec.rb']
68
+ namespace(:spec) do
69
+ desc "Verify all RSpec examples for #{gemspec.name}"
70
+ Spec::Rake::SpecTask.new(:basic) do |t|
71
+ t.spec_files = FileList[spec_pattern]
91
72
  end
73
+
74
+ desc "Verify all RSpec examples for #{gemspec.name} and output specdoc"
75
+ Spec::Rake::SpecTask.new(:specdoc) do |t|
76
+ t.spec_files = FileList[spec_pattern]
77
+ t.spec_opts << '--format' << 'specdoc' << '--color'
78
+ end
79
+
80
+ desc "Run RCov on specs for #{gemspec.name}"
81
+ Spec::Rake::SpecTask.new(:rcov) do |t|
82
+ t.spec_files = FileList[spec_pattern]
83
+ t.rcov = true
84
+ t.rcov_opts = ['--exclude', '"spec/*,gems/*"', '--rails']
85
+ end
92
86
  end
93
87
 
94
- # Setup :test task if unit test files exist
95
- if has_tests?
96
- require 'rake/testtask'
97
-
98
- desc "Run all unit tests for #{@name}"
99
- Rake::TestTask.new(:test) do |t|
100
- t.pattern = 'test/**/*_test.rb'
101
- t.verbose = true
102
- t.libs << 'test'
103
- end
104
- end
88
+ desc "Verify all RSpec examples for #{gemspec.name} and output specdoc"
89
+ task(:spec => ['spec:specdoc'])
105
90
  end
106
91
 
107
- protected
92
+ # Defines the rake tasks
93
+ def define_tasks!
94
+
95
+ define_test_tasks! if has_tests?
96
+ define_rspec_tasks! if has_specs?
97
+
98
+ namespace(@task_namespace) do
99
+ desc "Updates the filelist in the gemspec file"
100
+ task(:manifest) { manifest_task }
101
+
102
+ desc "Builds the .gem package"
103
+ task(:build => :manifest) { build_task }
108
104
 
109
- def has_rdoc?
110
- @specification.has_rdoc
111
- end
105
+ desc "Sets the version of the gem in the gemspec"
106
+ task(:set_version => [:check_version, :check_current_branch]) { version_task }
107
+ task(:check_version => :fetch_origin) { check_version_task }
108
+
109
+ task(:fetch_origin) { fetch_origin_task }
110
+ task(:check_current_branch) { check_current_branch_task }
111
+ task(:check_clean_status) { check_clean_status_task }
112
+ task(:check_not_diverged => :fetch_origin) { check_not_diverged_task }
113
+
114
+ checks = [:check_current_branch, :check_clean_status, :check_not_diverged, :check_version]
115
+ checks.unshift('spec:basic') if has_specs?
116
+ checks.unshift('test:basic') if has_tests?
117
+
118
+ desc "Perform all checks that would occur before a release"
119
+ task(:release_checks => checks)
112
120
 
113
- def has_specs?
114
- Dir['spec/**/*_spec.rb'].any?
121
+ desc "Release a new verison of the gem"
122
+ task(:release => [:release_checks, :set_version, :build, :push_changes]) { release_task }
123
+
124
+ task(:push_changes => [:commit_modified_files, :tag_version]) { push_changes_task }
125
+ task(:tag_version) { tag_version_task }
126
+ task(:commit_modified_files) { commit_modified_files_task }
127
+ end
115
128
  end
116
129
 
117
- def has_tests?
118
- Dir['test/**/*_test.rb'].any?
119
- end
120
-
121
- def reload_gemspec!
122
- raise "No gemspec file found!" if gemspec_file.nil?
123
- spec = File.read(gemspec_file)
124
- @specification = eval(spec)
125
- @name = specification.name
126
- end
127
-
128
- def run_command(command)
129
- lines = []
130
- IO.popen(command) { |f| lines = f.readlines }
131
- return lines
130
+ def manifest_task
131
+ # Load all the gem's files using "git ls-files"
132
+ repository_files = git.ls_files.keys
133
+ test_files = Dir[test_pattern] + Dir[spec_pattern]
134
+
135
+ update_gemspec(:files, repository_files)
136
+ update_gemspec(:test_files, repository_files & test_files)
132
137
  end
133
138
 
134
- def git_modified?(file)
135
- return !run_command('git status').detect { |line| Regexp.new(Regexp.quote(file)) =~ line }.nil?
139
+ def build_task
140
+ sh "gem build -q #{gemspec_file}"
141
+ Dir.mkdir('pkg') unless File.exist?('pkg')
142
+ sh "mv #{gemspec.name}-#{gemspec.version}.gem pkg/#{gemspec.name}-#{gemspec.version}.gem"
136
143
  end
137
144
 
138
- def git_commit_file(file, message, branch = nil)
139
- verify_current_branch(branch) unless branch.nil?
140
- if git_modified?(file)
141
- sh "git add #{file}"
142
- sh "git commit -m \"#{message}\""
143
- else
144
- raise "#{file} is not modified and cannot be committed!"
145
- end
145
+ def version_task
146
+ update_gemspec(:version, ENV['VERSION']) if ENV['VERSION']
147
+ update_gemspec(:date, Date.today)
148
+
149
+ update_version_file(gemspec.version)
150
+ update_version_constant(gemspec.version)
146
151
  end
147
152
 
148
- def git_create_tag(tag_name, message)
149
- sh "git tag -a \"#{tag_name}\" -m \"#{message}\""
153
+ def check_version_task
154
+ raise "#{ENV['VERSION']} is not a valid version number!" if ENV['VERSION'] && !Gem::Version.correct?(ENV['VERSION'])
155
+ proposed_version = Gem::Version.new(ENV['VERSION'] || gemspec.version)
156
+ # Loads the latest version number using the created tags
157
+ newest_version = git.tags.map { |tag| tag.name.split('-').last }.compact.map { |v| Gem::Version.new(v) }.max
158
+ raise "This version (#{proposed_version}) is not higher than the highest tagged version (#{newest_version})" if newest_version && newest_version >= proposed_version
150
159
  end
151
160
 
152
- def git_push(remote = 'origin', branch = 'master', options = [])
153
- verify_clean_status(branch)
154
- options_str = options.map { |o| "--#{o}"}.join(' ')
155
- sh "git push #{options_str} #{remote} #{branch}"
161
+ def check_not_diverged_task
162
+ raise "The current branch is diverged from the remote branch!" if git.log.between('HEAD', git.branches["#{remote}/#{remote_branch}"].gcommit).any?
156
163
  end
157
164
 
158
- def gemspec_version=(new_version)
159
- spec = File.read(gemspec_file)
160
- spec.gsub!(/^(\s*s\.version\s*=\s*)('|")(.+)('|")(\s*)$/) { "#{$1}'#{new_version}'#{$5}" }
161
- spec.gsub!(/^(\s*s\.date\s*=\s*)('|")(.+)('|")(\s*)$/) { "#{$1}'#{Date.today.strftime('%Y-%m-%d')}'#{$5}" }
162
- File.open(gemspec_file, 'w') { |f| f << spec }
163
- reload_gemspec!
165
+ def check_clean_status_task
166
+ raise "The current working copy contains modifications" if git.status.changed.any?
164
167
  end
165
168
 
166
- def gemspec_date=(new_date)
167
- spec = File.read(gemspec_file)
168
- spec.gsub!(/^(\s*s\.date\s*=\s*)('|")(.+)('|")(\s*)$/) { "#{$1}'#{new_date.strftime('%Y-%m-%d')}'#{$5}" }
169
- File.open(gemspec_file, 'w') { |f| f << spec }
170
- reload_gemspec!
169
+ def check_current_branch_task
170
+ raise "Currently not on #{local_branch} branch!" unless git.branch.name == local_branch.to_s
171
171
  end
172
172
 
173
- def gemspec_file
174
- @gemspec_file ||= Dir['*.gemspec'].first
173
+ def fetch_origin_task
174
+ git.fetch('origin')
175
175
  end
176
176
 
177
- def verify_current_branch(branch)
178
- run_command('git branch').detect { |line| /^\* (.+)/ =~ line }
179
- raise "You are currently not working in the #{branch} branch!" unless branch == $1
177
+ def commit_modified_files_task
178
+ if modified_files.any?
179
+ modified_files.each { |file| git.add(file) }
180
+ git.commit("Released #{gemspec.name} gem version #{gemspec.version}")
181
+ end
180
182
  end
181
183
 
182
- def verify_fast_forward(local_branch = 'master', remote = 'origin', remote_branch = 'master')
183
- sh "git fetch #{remote}"
184
- lines = run_command("git rev-list #{local_branch}..remotes/#{remote}/#{remote_branch}")
185
- raise "Remote branch #{remote}/#{remote_branch} has commits that are not yet incorporated in local #{local_branch} branch" unless lines.length == 0
184
+ def tag_version_task
185
+ git.add_tag("#{gemspec.name}-#{gemspec.version}")
186
186
  end
187
187
 
188
- def verify_clean_status(on_branch = nil)
189
- lines = run_command('git status')
190
- raise "You are currently not working in the #{on_branch} branch!" unless on_branch.nil? || (/^\# On branch (.+)/ =~ lines.first && $1 == on_branch)
191
- raise "Your master branch contains modifications!" unless /^nothing to commit \(working directory clean\)/ =~ lines.last
188
+ def push_changes_task
189
+ git.push(remote, remote_branch, true)
192
190
  end
193
191
 
194
- def verify_version(new_version)
195
- newest_version = run_command('git tag').map { |tag| tag.split(name + '-').last }.compact.map { |v| Gem::Version.new(v) }.max
196
- raise "This version number (#{new_version}) is not higher than the highest tagged version (#{newest_version})" if !newest_version.nil? && newest_version >= Gem::Version.new(new_version.to_s)
192
+ def release_task
193
+ puts
194
+ puts '------------------------------------------------------------'
195
+ puts "Released #{gemspec.name} version #{gemspec.version}"
197
196
  end
198
197
 
199
- def set_gem_version!
200
- # update gemspec file
201
- self.gemspec_version = ENV['VERSION'] if Gem::Version.correct?(ENV['VERSION'])
202
- self.gemspec_date = Date.today
203
- end
204
-
205
- def manifest_task
206
- verify_current_branch('master')
207
-
208
- list = Dir['**/*'].sort
209
- list -= [gemspec_file]
210
-
211
- if File.exist?('.gitignore')
212
- File.read('.gitignore').each_line do |glob|
213
- glob = glob.chomp.sub(/^\//, '')
214
- list -= Dir[glob]
215
- list -= Dir["#{glob}/**/*"] if File.directory?(glob) and !File.symlink?(glob)
216
- end
217
- end
218
-
219
- # update the spec file
220
- spec = File.read(gemspec_file)
221
- spec.gsub! /^(\s* s.(test_)?files \s* = \s* )( \[ [^\]]* \] | %w\( [^)]* \) )/mx do
222
- assignment = $1
223
- bunch = $2 ? list.grep(/^(test.*_test\.rb|spec.*_spec.rb)$/) : list
224
- '%s%%w(%s)' % [assignment, bunch.join(' ')]
225
- end
226
-
227
- File.open(gemspec_file, 'w') { |f| f << spec }
228
- reload_gemspec!
229
- end
198
+ private
230
199
 
231
- def build_task
232
- sh "gem build #{gemspec_file}"
233
- Dir.mkdir('pkg') unless File.exist?('pkg')
234
- sh "mv #{name}-#{specification.version}.gem pkg/#{name}-#{specification.version}.gem"
200
+ def has_specs?
201
+ FileList[spec_pattern].any?
235
202
  end
236
203
 
237
- def install_task
238
- raise "#{name} .gem file not found" unless File.exist?("pkg/#{name}-#{specification.version}.gem")
239
- sh "gem install pkg/#{name}-#{specification.version}.gem"
204
+ def has_tests?
205
+ FileList[test_pattern].any?
240
206
  end
241
207
 
242
- def uninstall_task
243
- raise "#{name} .gem file not found" unless File.exist?("pkg/#{name}-#{specification.version}.gem")
244
- sh "gem uninstall #{name}"
245
- end
246
208
 
247
- def create_version_tag!
248
- # commit the gemspec file
249
- git_commit_file(gemspec_file, "Updated #{gemspec_file} for release of version #{@specification.version}") if git_modified?(gemspec_file)
250
-
251
- # create tag and push changes
252
- git_create_tag("#{@name}-#{@specification.version}", "Tagged version #{@specification.version}")
253
- git_push('origin', 'master', [:tags])
209
+ # Loads the gemspec file
210
+ def load_gemspec!
211
+ @gemspec = eval(File.read(@gemspec_file))
254
212
  end
255
213
 
256
- def release_task
257
- puts
258
- puts '------------------------------------------------------------'
259
- puts "Released #{@name} - version #{@specification.version}"
214
+ # Updates the VERSION file with the new version
215
+ def update_version_file(version)
216
+ if File.exists?('VERSION')
217
+ File.open('VERSION', 'w') { |f| f << version.to_s }
218
+ modified_files << 'VERSION'
219
+ end
260
220
  end
261
221
 
262
- def release_check_task
263
- puts
264
- puts '------------------------------------------------------------'
265
- puts "Checked all conditions for a release of version #{ENV['VERSION'] || @specification.version}!"
266
- puts 'You should be safe to do a release now.'
267
- puts '------------------------------------------------------------'
222
+ # Updates the VERSION constant in the main include file if it exists
223
+ def update_version_constant(version)
224
+ file_contents = File.read(main_include)
225
+ if file_contents.sub!(/^(\s+VERSION\s*=\s*)[^\s].*$/) { $1 + version.to_s.inspect }
226
+ File.open(main_include, 'w') { |f| f << file_contents }
227
+ modified_files << main_include
228
+ end
229
+ end
230
+
231
+ # Updates an attribute of the gemspec file.
232
+ # This function will open the file, and search/replace the attribute using a regular expression.
233
+ def update_gemspec(attribute, new_value, literal = false)
234
+
235
+ unless literal
236
+ new_value = case new_value
237
+ when Array then "%w(#{new_value.join(' ')})"
238
+ when Hash, String then new_value.inspect
239
+ when Date then new_value.strftime('%Y-%m-%d').inspect
240
+ else raise "Cannot write value #{new_value.inspect} to gemspec file!"
241
+ end
242
+ end
243
+
244
+ spec = File.read(gemspec_file)
245
+ regexp = Regexp.new('^(\s+\w+\.' + Regexp.quote(attribute.to_s) + '\s*=\s*)[^\s].*$')
246
+ if spec.sub!(regexp) { $1 + new_value }
247
+ File.open(gemspec_file, 'w') { |f| f << spec }
248
+ modified_files << gemspec_file
249
+
250
+ # Reload the gemspec so the changes are incorporated
251
+ load_gemspec!
252
+ end
268
253
  end
254
+
269
255
  end
270
256
  end
271
-
272
- Rake::GithubGem.define_tasks!
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wvanbergen-request-log-analyzer
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.5
4
+ version: 1.2.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Willem van Bergen
@@ -10,12 +10,33 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2009-09-01 00:00:00 -07:00
13
+ date: 2009-09-02 00:00:00 -07:00
14
14
  default_executable: request-log-analyzer
15
- dependencies: []
16
-
17
- description: Rails log analyzer's purpose is to find what actions are best candidates for optimization. This tool will parse all requests in the Rails logfile and aggregate the information. Once it is finished parsing the log file, it will show the requests that take op most server time using various metrics.
18
- email: willem@vanbergen.org
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: rspec
18
+ type: :development
19
+ version_requirement:
20
+ version_requirements: !ruby/object:Gem::Requirement
21
+ requirements:
22
+ - - ">="
23
+ - !ruby/object:Gem::Version
24
+ version: 1.2.4
25
+ version:
26
+ - !ruby/object:Gem::Dependency
27
+ name: git
28
+ type: :development
29
+ version_requirement:
30
+ version_requirements: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: 1.1.0
35
+ version:
36
+ description: Request log analyzer's purpose is to find ot how your web application is being used and to focus your optimization efforts. This tool will parse all requests in the application's log file and aggregate the information. Once it is finished parsing the log file(s), it will show the requests that take op most server time using various metrics. It can also insert all parsed request information into a database so you can roll your own analysis. It supports Rails- and Merb-based applications out of the box, but file formats of other applications can easily be supported by supplying an easy to write log file format definition.
37
+ email:
38
+ - willem@railsdoctors.com
39
+ - bart@railsdoctors.com
19
40
  executables:
20
41
  - request-log-analyzer
21
42
  extensions: []
@@ -23,116 +44,94 @@ extensions: []
23
44
  extra_rdoc_files:
24
45
  - README.rdoc
25
46
  files:
26
- - DESIGN.rdoc
27
- - LICENSE
28
- - README.rdoc
29
- - RELEASE_NOTES.rdoc
30
- - Rakefile
31
- - bin
32
- - bin/request-log-analyzer
33
- - lib
34
- - lib/cli
35
- - lib/cli/command_line_arguments.rb
36
- - lib/cli/progressbar.rb
37
- - lib/cli/tools.rb
38
- - lib/request_log_analyzer
39
- - lib/request_log_analyzer.rb
40
- - lib/request_log_analyzer/aggregator
41
- - lib/request_log_analyzer/aggregator.rb
42
- - lib/request_log_analyzer/aggregator/database.rb
43
- - lib/request_log_analyzer/aggregator/echo.rb
44
- - lib/request_log_analyzer/aggregator/summarizer.rb
47
+ - spec/unit/filter/anonymize_filter_spec.rb
48
+ - lib/request_log_analyzer/line_definition.rb
49
+ - lib/request_log_analyzer/output/html.rb
45
50
  - lib/request_log_analyzer/controller.rb
46
- - lib/request_log_analyzer/file_format
47
- - lib/request_log_analyzer/file_format.rb
48
- - lib/request_log_analyzer/file_format/merb.rb
49
- - lib/request_log_analyzer/file_format/rails.rb
51
+ - spec/fixtures/rails_22_cached.log
50
52
  - lib/request_log_analyzer/file_format/rails_development.rb
51
- - lib/request_log_analyzer/filter
52
- - lib/request_log_analyzer/filter.rb
53
- - lib/request_log_analyzer/filter/anonymize.rb
54
- - lib/request_log_analyzer/filter/field.rb
55
- - lib/request_log_analyzer/filter/timespan.rb
56
- - lib/request_log_analyzer/line_definition.rb
53
+ - spec/lib/macros.rb
54
+ - spec/fixtures/merb_prefixed.log
55
+ - tasks/request_log_analyzer.rake
56
+ - spec/unit/file_format/file_format_api_spec.rb
57
+ - spec/integration/command_line_usage_spec.rb
58
+ - spec/fixtures/decompression.log.bz2
57
59
  - lib/request_log_analyzer/log_processor.rb
58
- - lib/request_log_analyzer/output
59
- - lib/request_log_analyzer/output.rb
60
- - lib/request_log_analyzer/output/fixed_width.rb
61
- - lib/request_log_analyzer/output/html.rb
62
- - lib/request_log_analyzer/request.rb
63
- - lib/request_log_analyzer/source
64
- - lib/request_log_analyzer/source.rb
65
- - lib/request_log_analyzer/source/database.rb
66
- - lib/request_log_analyzer/source/log_parser.rb
67
- - lib/request_log_analyzer/tracker
68
60
  - lib/request_log_analyzer/tracker.rb
69
- - lib/request_log_analyzer/tracker/duration.rb
61
+ - lib/request_log_analyzer/filter.rb
62
+ - spec/fixtures/rails_unordered.log
63
+ - bin/request-log-analyzer
64
+ - request-log-analyzer.gemspec
65
+ - DESIGN.rdoc
66
+ - spec/unit/filter/timespan_filter_spec.rb
67
+ - lib/request_log_analyzer/filter/field.rb
70
68
  - lib/request_log_analyzer/tracker/frequency.rb
71
- - lib/request_log_analyzer/tracker/hourly_spread.rb
72
- - lib/request_log_analyzer/tracker/timespan.rb
73
- - spec
74
- - spec/fixtures
75
- - spec/fixtures/decompression.log
76
- - spec/fixtures/decompression.log.bz2
77
69
  - spec/fixtures/decompression.log.gz
78
- - spec/fixtures/decompression.log.zip
70
+ - spec/fixtures/decompression.log
71
+ - spec/lib/matchers.rb
72
+ - spec/fixtures/test_order.log
73
+ - lib/request_log_analyzer/output/fixed_width.rb
74
+ - lib/request_log_analyzer/filter/anonymize.rb
75
+ - spec/lib/testing_format.rb
76
+ - lib/request_log_analyzer/tracker/timespan.rb
77
+ - lib/request_log_analyzer/aggregator.rb
78
+ - lib/cli/progressbar.rb
79
+ - README.rdoc
80
+ - spec/fixtures/merb.log
81
+ - lib/request_log_analyzer/tracker/hourly_spread.rb
82
+ - .gitignore
83
+ - spec/unit/tracker/tracker_api_spec.rb
84
+ - spec/unit/tracker/duration_tracker_spec.rb
85
+ - lib/request_log_analyzer/aggregator/echo.rb
86
+ - spec/unit/controller/log_processor_spec.rb
87
+ - lib/request_log_analyzer.rb
88
+ - Rakefile
89
+ - spec/spec_helper.rb
90
+ - spec/unit/filter/filter_spec.rb
91
+ - lib/request_log_analyzer/aggregator/summarizer.rb
92
+ - lib/request_log_analyzer/file_format/rails.rb
93
+ - spec/fixtures/test_language_combined.log
79
94
  - spec/fixtures/decompression.tar.gz
95
+ - spec/unit/filter/field_filter_spec.rb
96
+ - spec/spec.opts
97
+ - lib/request_log_analyzer/aggregator/database.rb
98
+ - lib/request_log_analyzer/filter/timespan.rb
99
+ - lib/request_log_analyzer/source/log_parser.rb
80
100
  - spec/fixtures/decompression.tgz
101
+ - spec/unit/tracker/timespan_tracker_spec.rb
102
+ - spec/unit/tracker/hourly_spread_spec.rb
81
103
  - spec/fixtures/header_and_footer.log
82
- - spec/fixtures/merb.log
83
- - spec/fixtures/merb_prefixed.log
104
+ - lib/cli/tools.rb
105
+ - lib/request_log_analyzer/file_format/merb.rb
84
106
  - spec/fixtures/multiple_files_1.log
85
- - spec/fixtures/multiple_files_2.log
86
- - spec/fixtures/rails_1x.log
87
- - spec/fixtures/rails_22.log
88
- - spec/fixtures/rails_22_cached.log
89
- - spec/fixtures/rails_unordered.log
90
- - spec/fixtures/syslog_1x.log
91
- - spec/fixtures/test_file_format.log
92
- - spec/fixtures/test_language_combined.log
93
- - spec/fixtures/test_order.log
94
- - spec/integration
95
- - spec/integration/command_line_usage_spec.rb
96
- - spec/lib
107
+ - spec/unit/file_format/merb_format_spec.rb
108
+ - spec/unit/file_format/line_definition_spec.rb
109
+ - lib/request_log_analyzer/source.rb
110
+ - lib/request_log_analyzer/request.rb
111
+ - spec/unit/controller/controller_spec.rb
112
+ - lib/request_log_analyzer/output.rb
97
113
  - spec/lib/helpers.rb
98
- - spec/lib/macros.rb
99
- - spec/lib/matchers.rb
114
+ - spec/fixtures/rails_1x.log
100
115
  - spec/lib/mocks.rb
101
- - spec/lib/testing_format.rb
102
- - spec/spec.opts
103
- - spec/spec_helper.rb
104
- - spec/unit
105
- - spec/unit/aggregator
116
+ - spec/fixtures/decompression.log.zip
117
+ - spec/unit/source/request_spec.rb
118
+ - spec/unit/source/log_parser_spec.rb
119
+ - spec/fixtures/test_file_format.log
120
+ - lib/request_log_analyzer/source/database.rb
106
121
  - spec/unit/aggregator/database_spec.rb
122
+ - tasks/github-gem.rake
123
+ - lib/request_log_analyzer/tracker/duration.rb
124
+ - lib/request_log_analyzer/file_format.rb
107
125
  - spec/unit/aggregator/summarizer_spec.rb
108
- - spec/unit/controller
109
- - spec/unit/controller/controller_spec.rb
110
- - spec/unit/controller/log_processor_spec.rb
111
- - spec/unit/file_format
112
- - spec/unit/file_format/file_format_api_spec.rb
113
- - spec/unit/file_format/line_definition_spec.rb
114
- - spec/unit/file_format/merb_format_spec.rb
115
- - spec/unit/file_format/rails_format_spec.rb
116
- - spec/unit/filter
117
- - spec/unit/filter/anonymize_filter_spec.rb
118
- - spec/unit/filter/field_filter_spec.rb
119
- - spec/unit/filter/filter_spec.rb
120
- - spec/unit/filter/timespan_filter_spec.rb
121
- - spec/unit/source
122
- - spec/unit/source/log_parser_spec.rb
123
- - spec/unit/source/request_spec.rb
124
- - spec/unit/tracker
125
- - spec/unit/tracker/duration_tracker_spec.rb
126
+ - spec/fixtures/rails_22.log
127
+ - spec/fixtures/multiple_files_2.log
128
+ - spec/fixtures/syslog_1x.log
129
+ - LICENSE
126
130
  - spec/unit/tracker/frequency_tracker_spec.rb
127
- - spec/unit/tracker/hourly_spread_spec.rb
128
- - spec/unit/tracker/timespan_tracker_spec.rb
129
- - spec/unit/tracker/tracker_api_spec.rb
130
- - tasks
131
- - tasks/github-gem.rake
132
- - tasks/request_log_analyzer.rake
133
- - tasks/rspec.rake
134
- has_rdoc: true
135
- homepage: http://github.com/wvanbergen/request-log-analyzer/wikis
131
+ - spec/unit/file_format/rails_format_spec.rb
132
+ - lib/cli/command_line_arguments.rb
133
+ has_rdoc: false
134
+ homepage: http://railsdoctors.com
136
135
  post_install_message:
137
136
  rdoc_options:
138
137
  - --title
@@ -155,31 +154,31 @@ required_rubygems_version: !ruby/object:Gem::Requirement
155
154
  - !ruby/object:Gem::Version
156
155
  version: "0"
157
156
  version:
158
- requirements: []
159
-
157
+ requirements:
158
+ - To use the database inserter, ActiveRecord and an appropriate database adapter are required.
160
159
  rubyforge_project: r-l-a
161
160
  rubygems_version: 1.2.0
162
161
  signing_key:
163
162
  specification_version: 2
164
- summary: A command line tool to analyze Rails logs
163
+ summary: A command line tool to analyze request logs for Rails, Merb and other application servers
165
164
  test_files:
165
+ - spec/unit/filter/anonymize_filter_spec.rb
166
+ - spec/unit/file_format/file_format_api_spec.rb
166
167
  - spec/integration/command_line_usage_spec.rb
167
- - spec/unit/aggregator/database_spec.rb
168
- - spec/unit/aggregator/summarizer_spec.rb
169
- - spec/unit/controller/controller_spec.rb
168
+ - spec/unit/filter/timespan_filter_spec.rb
169
+ - spec/unit/tracker/tracker_api_spec.rb
170
+ - spec/unit/tracker/duration_tracker_spec.rb
170
171
  - spec/unit/controller/log_processor_spec.rb
171
- - spec/unit/file_format/file_format_api_spec.rb
172
- - spec/unit/file_format/line_definition_spec.rb
173
- - spec/unit/file_format/merb_format_spec.rb
174
- - spec/unit/file_format/rails_format_spec.rb
175
- - spec/unit/filter/anonymize_filter_spec.rb
176
- - spec/unit/filter/field_filter_spec.rb
177
172
  - spec/unit/filter/filter_spec.rb
178
- - spec/unit/filter/timespan_filter_spec.rb
179
- - spec/unit/source/log_parser_spec.rb
173
+ - spec/unit/filter/field_filter_spec.rb
174
+ - spec/unit/tracker/timespan_tracker_spec.rb
175
+ - spec/unit/tracker/hourly_spread_spec.rb
176
+ - spec/unit/file_format/merb_format_spec.rb
177
+ - spec/unit/file_format/line_definition_spec.rb
178
+ - spec/unit/controller/controller_spec.rb
180
179
  - spec/unit/source/request_spec.rb
181
- - spec/unit/tracker/duration_tracker_spec.rb
180
+ - spec/unit/source/log_parser_spec.rb
181
+ - spec/unit/aggregator/database_spec.rb
182
+ - spec/unit/aggregator/summarizer_spec.rb
182
183
  - spec/unit/tracker/frequency_tracker_spec.rb
183
- - spec/unit/tracker/hourly_spread_spec.rb
184
- - spec/unit/tracker/timespan_tracker_spec.rb
185
- - spec/unit/tracker/tracker_api_spec.rb
184
+ - spec/unit/file_format/rails_format_spec.rb
data/RELEASE_NOTES.rdoc DELETED
@@ -1,19 +0,0 @@
1
- === 1.2.3
2
- * Refactored database functions
3
- * Cleaned up specs and tried some heckle
4
- * Interrupts are handled more gracefully
5
- * Moved munin tracker to seperate Github project (http://github.com/barttenbrinke/munin-plugins-rails/)
6
-
7
- === 1.2.2
8
- * Not released
9
-
10
- === 1.2.1
11
- * Compressed logfile support
12
- * Parsable YAML results as output (use --dump <filename> )
13
- * Full Rdoc
14
- * Release notes
15
- * Updated rails take tasks
16
-
17
- === 1.2.0
18
- * Ruby 1.9 support
19
- * Rcov coverage
data/tasks/rspec.rake DELETED
@@ -1,19 +0,0 @@
1
- require 'rake'
2
- require 'spec/rake/spectask'
3
-
4
- namespace :spec do
5
- desc "Run all rspec with RCov"
6
- Spec::Rake::SpecTask.new(:rcov) do |t|
7
-
8
- t.spec_files = FileList['spec/**/*_spec.rb']
9
- t.rcov = true
10
- t.rcov_opts = ['--exclude', '"spec/*,gems/*"', '--rails']
11
- end
12
-
13
- desc "Run all specs in spec directory (excluding plugin specs)"
14
- Spec::Rake::SpecTask.new(:fancy) do |t|
15
- t.spec_opts = ['--options', "\"spec/spec.opts\""]
16
- t.spec_files = FileList['spec/**/*_spec.rb']
17
- end
18
- end
19
-