request-log-analyzer 1.3.5 → 1.3.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (31) hide show
  1. data/lib/cli/database_console_init.rb +2 -1
  2. data/lib/request_log_analyzer.rb +1 -1
  3. data/lib/request_log_analyzer/aggregator.rb +1 -5
  4. data/lib/request_log_analyzer/aggregator/database_inserter.rb +4 -5
  5. data/lib/request_log_analyzer/controller.rb +10 -21
  6. data/lib/request_log_analyzer/database.rb +16 -91
  7. data/lib/request_log_analyzer/database/base.rb +4 -4
  8. data/lib/request_log_analyzer/database/request.rb +22 -0
  9. data/lib/request_log_analyzer/database/source.rb +13 -0
  10. data/lib/request_log_analyzer/database/warning.rb +14 -0
  11. data/lib/request_log_analyzer/file_format.rb +1 -13
  12. data/lib/request_log_analyzer/file_format/amazon_s3.rb +1 -2
  13. data/lib/request_log_analyzer/file_format/apache.rb +8 -10
  14. data/lib/request_log_analyzer/file_format/merb.rb +21 -5
  15. data/lib/request_log_analyzer/file_format/rails.rb +8 -14
  16. data/lib/request_log_analyzer/filter.rb +6 -10
  17. data/lib/request_log_analyzer/filter/anonymize.rb +2 -1
  18. data/lib/request_log_analyzer/log_processor.rb +6 -8
  19. data/lib/request_log_analyzer/request.rb +47 -35
  20. data/lib/request_log_analyzer/source.rb +4 -6
  21. data/lib/request_log_analyzer/source/database_loader.rb +3 -7
  22. data/lib/request_log_analyzer/source/log_parser.rb +3 -6
  23. data/lib/request_log_analyzer/tracker.rb +12 -19
  24. data/lib/request_log_analyzer/tracker/hourly_spread.rb +1 -2
  25. data/request-log-analyzer.gemspec +3 -3
  26. data/spec/database.yml +6 -0
  27. data/spec/unit/aggregator/database_inserter_spec.rb +3 -3
  28. data/spec/unit/database/base_class_spec.rb +9 -16
  29. data/spec/unit/database/database_spec.rb +9 -14
  30. data/spec/unit/tracker/tracker_api_spec.rb +111 -36
  31. metadata +7 -4
data/spec/database.yml CHANGED
@@ -1,3 +1,9 @@
1
+ # This file determines what databases are used to test the database
2
+ # functionality of request-log-analyzer. By default, only an SQLite3
3
+ # memory database is enabled.
4
+ #
5
+ # The syntax of this file is exactly the same as Rails's database.yml.
6
+
1
7
  sqlite3:
2
8
  adapter: "sqlite3"
3
9
  database: ":memory:"
@@ -66,7 +66,7 @@ describe RequestLogAnalyzer::Aggregator::DatabaseInserter do
66
66
  it "should insert a record in the request table" do
67
67
  lambda {
68
68
  @database_inserter.aggregate(@incomplete_request)
69
- }.should change(@database_inserter.database.request_class, :count).from(0).to(1)
69
+ }.should change(RequestLogAnalyzer::Database::Request, :count).from(0).to(1)
70
70
  end
71
71
 
72
72
  it "should insert a record in the first_lines table" do
@@ -77,7 +77,7 @@ describe RequestLogAnalyzer::Aggregator::DatabaseInserter do
77
77
 
78
78
  it "should insert records in all relevant line tables" do
79
79
  @database_inserter.aggregate(@completed_request)
80
- request = @database_inserter.database.request_class.first
80
+ request = RequestLogAnalyzer::Database::Request.first
81
81
  request.should have(2).test_lines
82
82
  request.should have(1).first_lines
83
83
  request.should have(1).eval_lines
@@ -85,7 +85,7 @@ describe RequestLogAnalyzer::Aggregator::DatabaseInserter do
85
85
  end
86
86
 
87
87
  it "should log a warning in the warnings table" do
88
- @database_inserter.database.warning_class.should_receive(:create!).with(hash_including(:warning_type => 'test_warning'))
88
+ RequestLogAnalyzer::Database::Warning.should_receive(:create!).with(hash_including(:warning_type => 'test_warning'))
89
89
  @database_inserter.warning(:test_warning, "Testing the warning system", 12)
90
90
  end
91
91
  end
@@ -15,16 +15,13 @@ describe RequestLogAnalyzer::Database::Base do
15
15
  @orm_class.stub!(:belongs_to)
16
16
  @orm_class.stub!(:serialize)
17
17
  @orm_class.stub!(:line_definition=)
18
+
18
19
  Class.stub!(:new).with(RequestLogAnalyzer::Database::Base).and_return(@orm_class)
19
20
 
20
- @request_class = mock('Request ActiveRecord::Base class')
21
- @request_class.stub!(:has_many)
22
- @source_class = mock('Source ActiveRecord::Base class')
23
- @source_class.stub!(:has_many)
21
+ RequestLogAnalyzer::Database::Request.stub!(:has_many)
22
+ RequestLogAnalyzer::Database::Source.stub!(:has_many)
24
23
 
25
24
  @database = mock_database
26
- @database.stub!(:request_class).and_return(@request_class)
27
- @database.stub!(:source_class).and_return(@source_class)
28
25
  RequestLogAnalyzer::Database::Base.stub!(:database).and_return(@database)
29
26
  end
30
27
 
@@ -49,12 +46,12 @@ describe RequestLogAnalyzer::Database::Base do
49
46
  end
50
47
 
51
48
  it "should set a :has_many relationship in the request class" do
52
- @request_class.should_receive(:has_many).with(:test_lines)
49
+ RequestLogAnalyzer::Database::Request.should_receive(:has_many).with(:test_lines)
53
50
  RequestLogAnalyzer::Database::Base.subclass_from_line_definition(@line_definition)
54
51
  end
55
52
 
56
53
  it "should set a :has_many relationship in the source class" do
57
- @source_class.should_receive(:has_many).with(:test_lines)
54
+ RequestLogAnalyzer::Database::Source.should_receive(:has_many).with(:test_lines)
58
55
  RequestLogAnalyzer::Database::Base.subclass_from_line_definition(@line_definition)
59
56
  end
60
57
 
@@ -73,14 +70,10 @@ describe RequestLogAnalyzer::Database::Base do
73
70
  describe '.subclass_from_table' do
74
71
  before(:each) do
75
72
 
76
- @request_class = mock('Request ActiveRecord::Base class')
77
- @request_class.stub!(:has_many)
78
- @source_class = mock('Source ActiveRecord::Base class')
79
- @source_class.stub!(:has_many)
73
+ RequestLogAnalyzer::Database::Request.stub!(:has_many)
74
+ RequestLogAnalyzer::Database::Source.stub!(:has_many)
80
75
 
81
76
  @database = mock_database
82
- @database.stub!(:request_class).and_return(@request_class)
83
- @database.stub!(:source_class).and_return(@source_class)
84
77
  @database.connection.stub!(:table_exists?).and_return(true)
85
78
  RequestLogAnalyzer::Database::Base.stub!(:database).and_return(@database)
86
79
 
@@ -107,7 +100,7 @@ describe RequestLogAnalyzer::Database::Base do
107
100
  end
108
101
 
109
102
  it "should create the :has_many relation in the request class" do
110
- @request_class.should_receive(:has_many).with(:completed_lines)
103
+ RequestLogAnalyzer::Database::Request.should_receive(:has_many).with(:completed_lines)
111
104
  RequestLogAnalyzer::Database::Base.subclass_from_table('completed_lines')
112
105
  end
113
106
 
@@ -117,7 +110,7 @@ describe RequestLogAnalyzer::Database::Base do
117
110
  end
118
111
 
119
112
  it "should create the :has_many relation in the request class" do
120
- @source_class.should_receive(:has_many).with(:completed_lines)
113
+ RequestLogAnalyzer::Database::Source.should_receive(:has_many).with(:completed_lines)
121
114
  RequestLogAnalyzer::Database::Base.subclass_from_table('completed_lines')
122
115
  end
123
116
 
@@ -15,11 +15,11 @@ describe RequestLogAnalyzer::Database do
15
15
  # FileFormat-agnostic classes
16
16
  default_orm_class_names.each do |const|
17
17
  it "should create the default #{const} constant" do
18
- Object.const_defined?(const).should be_true
18
+ RequestLogAnalyzer::Database.const_defined?(const).should be_true
19
19
  end
20
20
 
21
21
  it "should create the default #{const} class inheriting from ActiveRecord::Base and RequestLogAnalyzer::Database::Base" do
22
- Object.const_get(const).ancestors.should include(ActiveRecord::Base, RequestLogAnalyzer::Database::Base)
22
+ RequestLogAnalyzer::Database.const_get(const).ancestors.should include(ActiveRecord::Base, RequestLogAnalyzer::Database::Base)
23
23
  end
24
24
  end
25
25
 
@@ -38,8 +38,8 @@ describe RequestLogAnalyzer::Database do
38
38
  end
39
39
 
40
40
  it "should create a :has_many relation from the Request and Source class to the #{const} class" do
41
- @database.request_class.send(:reflections).should include(const.underscore.pluralize.to_sym)
42
- @database.source_class.send(:reflections).should include(const.underscore.pluralize.to_sym)
41
+ RequestLogAnalyzer::Database::Request.send(:reflections).should include(const.underscore.pluralize.to_sym)
42
+ RequestLogAnalyzer::Database::Source.send(:reflections).should include(const.underscore.pluralize.to_sym)
43
43
  end
44
44
  end
45
45
  end
@@ -60,6 +60,7 @@ describe RequestLogAnalyzer::Database do
60
60
  after(:each) { @database.remove_orm_classes! }
61
61
 
62
62
  default_orm_class_names.each do |klass|
63
+
63
64
  it "should create a table for the default #{klass} class" do
64
65
  @database.connection.should_receive(:create_table).with(klass.underscore.pluralize.to_sym)
65
66
  @database.send :create_database_schema!
@@ -67,7 +68,7 @@ describe RequestLogAnalyzer::Database do
67
68
 
68
69
  it "should create a #{klass} class inheriting from ActiveRecord and the base class of the ORM module" do
69
70
  @database.send :create_database_schema!
70
- @database.send("#{klass.underscore}_class".to_sym).ancestors.should include(ActiveRecord::Base, RequestLogAnalyzer::Database::Base)
71
+ RequestLogAnalyzer::Database.const_get(klass).ancestors.should include(ActiveRecord::Base, RequestLogAnalyzer::Database::Base)
71
72
  end
72
73
  end
73
74
 
@@ -92,15 +93,9 @@ describe RequestLogAnalyzer::Database do
92
93
  @connection = mock_connection
93
94
  @database.stub!(:connection).and_return(@connection)
94
95
 
95
- # Mock the request ORM class
96
- @request_class = mock('Request ActiveRecord::Base class')
97
- @request_class.stub!(:has_many)
98
-
99
- @source_class = mock('Source ActiveRecord::Base class')
100
- @source_class.stub!(:has_many)
101
-
102
- @database.stub!(:request_class).and_return(@request_class)
103
- @database.stub!(:source_class).and_return(@source_class)
96
+ # Mock the has_many method of the defaukt ORM classes
97
+ RequestLogAnalyzer::Database::Request.stub!(:has_many)
98
+ RequestLogAnalyzer::Database::Source.stub!(:has_many)
104
99
 
105
100
  @mock_class = Class.new(RequestLogAnalyzer::Database::Base)
106
101
 
@@ -1,49 +1,124 @@
1
1
  require File.dirname(__FILE__) + '/../../spec_helper'
2
2
 
3
- describe RequestLogAnalyzer::Tracker::Base, "API test" do
3
+ describe RequestLogAnalyzer::Tracker::Base do
4
4
 
5
- before(:each) do
6
- @tracker = Class.new(RequestLogAnalyzer::Tracker::Base).new
5
+ describe 'API' do
7
6
 
8
- @summarizer = RequestLogAnalyzer::Aggregator::Summarizer.new(mock_source)
9
- @summarizer.trackers << @tracker
10
- end
11
-
12
- it "should receive :prepare when the summarizer is preparing" do
13
- @tracker.should_receive(:prepare).once
14
- @summarizer.prepare
15
- end
16
-
17
- it "should receieve :finalize when the summarizer is finalizing" do
18
- @tracker.should_receive(:finalize).once
19
- @summarizer.finalize
7
+ before(:each) do
8
+ @tracker = Class.new(RequestLogAnalyzer::Tracker::Base).new
9
+
10
+ @summarizer = RequestLogAnalyzer::Aggregator::Summarizer.new(mock_source)
11
+ @summarizer.trackers << @tracker
12
+ end
13
+
14
+ it "should receive :prepare when the summarizer is preparing" do
15
+ @tracker.should_receive(:prepare).once
16
+ @summarizer.prepare
17
+ end
18
+
19
+ it "should receive :update for every request for which should_update? returns true" do
20
+ @tracker.should_receive(:should_update?).twice.and_return(true)
21
+ @tracker.should_receive(:update).twice
22
+
23
+ @summarizer.aggregate(testing_format.request(:field => 'value1'))
24
+ @summarizer.aggregate(testing_format.request(:field => 'value2'))
25
+ end
26
+
27
+ it "should not :update for every request for which should_update? returns false" do
28
+ @tracker.should_receive(:should_update?).twice.and_return(false)
29
+ @tracker.should_not_receive(:update)
30
+
31
+ @summarizer.aggregate(testing_format.request(:field => 'value1'))
32
+ @summarizer.aggregate(testing_format.request(:field => 'value2'))
33
+ end
34
+
35
+ it "should receive :report when the summary report is being built" do
36
+ @tracker.should_receive(:report).with(anything).once
37
+ @summarizer.report(mock_output)
38
+ end
39
+
40
+ it "should receieve :finalize when the summarizer is finalizing" do
41
+ @tracker.should_receive(:finalize).once
42
+ @summarizer.finalize
43
+ end
20
44
  end
21
45
 
22
- it "should receive :update for every request for which should_update? returns true" do
23
- @tracker.should_receive(:should_update?).twice.and_return(true)
24
- @tracker.should_receive(:update).twice
46
+ describe '#should_update?' do
47
+ before(:each) do
48
+ @tracker_class = Class.new(RequestLogAnalyzer::Tracker::Base)
49
+ end
25
50
 
26
- @summarizer.aggregate(testing_format.request(:field => 'value1'))
27
- @summarizer.aggregate(testing_format.request(:field => 'value2'))
28
- end
29
-
30
- it "should not :update for every request for which should_update? returns false" do
31
- @tracker.should_receive(:should_update?).twice.and_return(false)
32
- @tracker.should_not_receive(:update)
51
+ it "should return true by default, when no checks are installed" do
52
+ tracker = @tracker_class.new
53
+ tracker.should_update?(testing_format.request).should be_true
54
+ end
33
55
 
34
- @summarizer.aggregate(testing_format.request(:field => 'value1'))
35
- @summarizer.aggregate(testing_format.request(:field => 'value2'))
36
- end
56
+ it "should return false if the line type is not in the request" do
57
+ tracker = @tracker_class.new(:line_type => :not_there)
58
+ tracker.should_update?(request(:line_type => :different)).should be_false
59
+ end
60
+
61
+ it "should return true if the line type is in the request" do
62
+ tracker = @tracker_class.new(:line_type => :there)
63
+ tracker.should_update?(request(:line_type => :there)).should be_true
64
+ end
65
+
66
+ it "should return true if a field name is given to :if and it is in the request" do
67
+ tracker = @tracker_class.new(:if => :field)
68
+ tracker.should_update?(request(:field => 'anything')).should be_true
69
+ end
70
+
71
+ it "should return false if a field name is given to :if and it is not the request" do
72
+ tracker = @tracker_class.new(:if => :field)
73
+ tracker.should_update?(request(:other_field => 'anything')).should be_false
74
+ end
75
+
76
+ it "should return false if a field name is given to :unless and it is in the request" do
77
+ tracker = @tracker_class.new(:unless => :field)
78
+ tracker.should_update?(request(:field => 'anything')).should be_false
79
+ end
80
+
81
+ it "should return true if a field name is given to :unless and it is not the request" do
82
+ tracker = @tracker_class.new(:unless => :field)
83
+ tracker.should_update?(request(:other_field => 'anything')).should be_true
84
+ end
85
+
86
+ it "should return the value of the block if one is given to the :if option" do
87
+ tracker = @tracker_class.new(:if => lambda { false } )
88
+ tracker.should_update?(request(:field => 'anything')).should be_false
89
+ end
90
+
91
+ it "should return the inverse value of the block if one is given to the :if option" do
92
+ tracker = @tracker_class.new(:unless => lambda { false } )
93
+ tracker.should_update?(request(:field => 'anything')).should be_true
94
+ end
95
+
96
+ it "should return false if any of the checks fail" do
97
+ tracker = @tracker_class.new(:if => :field, :unless => lambda { false }, :line_type => :not_present )
98
+ tracker.should_update?(request(:line_type => :present, :field => 'anything')).should be_false
99
+ end
100
+
101
+ it "should return true if all of the checks succeed" do
102
+ tracker = @tracker_class.new(:if => :field, :unless => lambda { false }, :line_type => :present )
103
+ tracker.should_update?(request(:line_type => :present, :field => 'anything')).should be_true
104
+ end
105
+
37
106
 
38
- it "should receive :report when the summary report is being built" do
39
- @tracker.should_receive(:report).with(anything).once
40
- @summarizer.report(mock_output)
41
107
  end
42
108
 
43
- it "should receive :to_yaml object when finalizing" do
44
- @summarizer.options[:dump] = temp_output_file(:dump)
45
- @tracker.should_receive(:to_yaml_object).once
46
- @summarizer.to_yaml
109
+ describe '#to_yaml_object' do
110
+
111
+ before(:each) do
112
+ @tracker = Class.new(RequestLogAnalyzer::Tracker::Base).new
113
+
114
+ @summarizer = RequestLogAnalyzer::Aggregator::Summarizer.new(mock_source)
115
+ @summarizer.trackers << @tracker
116
+ end
117
+
118
+ it "should receive :to_yaml object when finalizing" do
119
+ @summarizer.options[:dump] = temp_output_file(:dump)
120
+ @tracker.should_receive(:to_yaml_object).once
121
+ @summarizer.to_yaml
122
+ end
47
123
  end
48
-
49
124
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: request-log-analyzer
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.5
4
+ version: 1.3.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Willem van Bergen
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2009-09-16 00:00:00 +02:00
13
+ date: 2009-09-20 00:00:00 +02:00
14
14
  default_executable: request-log-analyzer
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -45,10 +45,10 @@ extra_rdoc_files:
45
45
  - README.rdoc
46
46
  files:
47
47
  - spec/unit/filter/anonymize_filter_spec.rb
48
+ - spec/fixtures/rails_22_cached.log
48
49
  - lib/request_log_analyzer/line_definition.rb
49
50
  - lib/request_log_analyzer/output/html.rb
50
51
  - lib/request_log_analyzer/controller.rb
51
- - spec/fixtures/rails_22_cached.log
52
52
  - spec/lib/macros.rb
53
53
  - lib/request_log_analyzer/file_format/rails_development.rb
54
54
  - spec/fixtures/apache_combined.log
@@ -86,6 +86,7 @@ files:
86
86
  - lib/cli/progressbar.rb
87
87
  - lib/request_log_analyzer/mailer.rb
88
88
  - README.rdoc
89
+ - lib/request_log_analyzer/database/warning.rb
89
90
  - spec/fixtures/merb.log
90
91
  - lib/request_log_analyzer/tracker/hourly_spread.rb
91
92
  - .gitignore
@@ -104,6 +105,7 @@ files:
104
105
  - lib/request_log_analyzer/aggregator/database_inserter.rb
105
106
  - lib/request_log_analyzer/aggregator/summarizer.rb
106
107
  - lib/request_log_analyzer/file_format/rack.rb
108
+ - lib/request_log_analyzer/database/source.rb
107
109
  - lib/request_log_analyzer/file_format/rails.rb
108
110
  - spec/fixtures/decompression.tar.gz
109
111
  - spec/unit/tracker/traffic_tracker_spec.rb
@@ -127,10 +129,10 @@ files:
127
129
  - spec/unit/controller/controller_spec.rb
128
130
  - spec/lib/mocks.rb
129
131
  - spec/lib/helpers.rb
132
+ - spec/fixtures/rails_1x.log
130
133
  - lib/cli/database_console_init.rb
131
134
  - lib/request_log_analyzer/output.rb
132
135
  - lib/request_log_analyzer/file_format/apache.rb
133
- - spec/fixtures/rails_1x.log
134
136
  - spec/fixtures/decompression.log.zip
135
137
  - spec/unit/source/request_spec.rb
136
138
  - spec/unit/source/log_parser_spec.rb
@@ -143,6 +145,7 @@ files:
143
145
  - spec/unit/aggregator/summarizer_spec.rb
144
146
  - spec/fixtures/syslog_1x.log
145
147
  - spec/fixtures/rails_22.log
148
+ - lib/request_log_analyzer/database/request.rb
146
149
  - spec/fixtures/multiple_files_2.log
147
150
  - LICENSE
148
151
  - lib/request_log_analyzer/source/database_loader.rb