request-log-analyzer 1.3.4 → 1.4.0
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.
- data/LICENSE +3 -3
- data/README.rdoc +1 -1
- data/bin/request-log-analyzer +17 -14
- data/lib/cli/command_line_arguments.rb +51 -51
- data/lib/cli/database_console.rb +3 -3
- data/lib/cli/database_console_init.rb +4 -3
- data/lib/cli/progressbar.rb +10 -10
- data/lib/cli/tools.rb +3 -3
- data/lib/request_log_analyzer/aggregator/database_inserter.rb +19 -17
- data/lib/request_log_analyzer/aggregator/echo.rb +14 -9
- data/lib/request_log_analyzer/aggregator/summarizer.rb +26 -26
- data/lib/request_log_analyzer/aggregator.rb +11 -15
- data/lib/request_log_analyzer/controller.rb +162 -89
- data/lib/request_log_analyzer/database/base.rb +22 -21
- data/lib/request_log_analyzer/database/connection.rb +3 -3
- data/lib/request_log_analyzer/database/request.rb +22 -0
- data/lib/request_log_analyzer/database/source.rb +13 -0
- data/lib/request_log_analyzer/database/warning.rb +14 -0
- data/lib/request_log_analyzer/database.rb +28 -103
- data/lib/request_log_analyzer/file_format/amazon_s3.rb +20 -20
- data/lib/request_log_analyzer/file_format/apache.rb +37 -30
- data/lib/request_log_analyzer/file_format/merb.rb +30 -13
- data/lib/request_log_analyzer/file_format/rack.rb +11 -0
- data/lib/request_log_analyzer/file_format/rails.rb +143 -73
- data/lib/request_log_analyzer/file_format/rails_development.rb +4 -49
- data/lib/request_log_analyzer/file_format.rb +16 -28
- data/lib/request_log_analyzer/filter/anonymize.rb +8 -7
- data/lib/request_log_analyzer/filter/field.rb +9 -9
- data/lib/request_log_analyzer/filter/timespan.rb +12 -10
- data/lib/request_log_analyzer/filter.rb +12 -16
- data/lib/request_log_analyzer/line_definition.rb +15 -14
- data/lib/request_log_analyzer/log_processor.rb +27 -29
- data/lib/request_log_analyzer/mailer.rb +15 -9
- data/lib/request_log_analyzer/output/fixed_width.rb +48 -48
- data/lib/request_log_analyzer/output/html.rb +20 -20
- data/lib/request_log_analyzer/output.rb +53 -12
- data/lib/request_log_analyzer/request.rb +88 -69
- data/lib/request_log_analyzer/source/database_loader.rb +10 -14
- data/lib/request_log_analyzer/source/log_parser.rb +57 -50
- data/lib/request_log_analyzer/source.rb +10 -12
- data/lib/request_log_analyzer/tracker/duration.rb +41 -134
- data/lib/request_log_analyzer/tracker/frequency.rb +31 -32
- data/lib/request_log_analyzer/tracker/hourly_spread.rb +21 -21
- data/lib/request_log_analyzer/tracker/timespan.rb +17 -17
- data/lib/request_log_analyzer/tracker/traffic.rb +106 -0
- data/lib/request_log_analyzer/tracker.rb +139 -32
- data/lib/request_log_analyzer.rb +5 -5
- data/request-log-analyzer.gemspec +19 -15
- data/spec/database.yml +6 -0
- data/spec/fixtures/rails_22.log +1 -1
- data/spec/integration/command_line_usage_spec.rb +7 -1
- data/spec/lib/helpers.rb +7 -7
- data/spec/lib/macros.rb +3 -3
- data/spec/lib/matchers.rb +41 -27
- data/spec/lib/mocks.rb +19 -15
- data/spec/lib/testing_format.rb +9 -9
- data/spec/spec_helper.rb +6 -6
- data/spec/unit/aggregator/database_inserter_spec.rb +16 -16
- data/spec/unit/aggregator/summarizer_spec.rb +4 -4
- data/spec/unit/controller/controller_spec.rb +2 -2
- data/spec/unit/controller/log_processor_spec.rb +1 -1
- data/spec/unit/database/base_class_spec.rb +26 -33
- data/spec/unit/database/connection_spec.rb +3 -3
- data/spec/unit/database/database_spec.rb +33 -38
- data/spec/unit/file_format/amazon_s3_format_spec.rb +5 -5
- data/spec/unit/file_format/apache_format_spec.rb +48 -11
- data/spec/unit/file_format/file_format_api_spec.rb +13 -13
- data/spec/unit/file_format/line_definition_spec.rb +24 -17
- data/spec/unit/file_format/merb_format_spec.rb +41 -45
- data/spec/unit/file_format/rails_format_spec.rb +157 -117
- data/spec/unit/filter/anonymize_filter_spec.rb +2 -2
- data/spec/unit/filter/field_filter_spec.rb +13 -13
- data/spec/unit/filter/filter_spec.rb +1 -1
- data/spec/unit/filter/timespan_filter_spec.rb +15 -15
- data/spec/unit/mailer_spec.rb +30 -0
- data/spec/unit/{source/request_spec.rb → request_spec.rb} +30 -30
- data/spec/unit/source/log_parser_spec.rb +27 -27
- data/spec/unit/tracker/duration_tracker_spec.rb +115 -78
- data/spec/unit/tracker/frequency_tracker_spec.rb +74 -63
- data/spec/unit/tracker/hourly_spread_spec.rb +28 -20
- data/spec/unit/tracker/timespan_tracker_spec.rb +25 -13
- data/spec/unit/tracker/tracker_api_spec.rb +117 -42
- data/spec/unit/tracker/traffic_tracker_spec.rb +107 -0
- data/tasks/github-gem.rake +125 -75
- data/tasks/request_log_analyzer.rake +2 -2
- metadata +19 -10
|
@@ -1,127 +1,167 @@
|
|
|
1
1
|
require File.dirname(__FILE__) + '/../../spec_helper'
|
|
2
2
|
|
|
3
3
|
describe RequestLogAnalyzer::FileFormat::Rails do
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
end
|
|
19
|
-
io.close
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
it "should find 4 completed requests" do
|
|
23
|
-
@log_parser.should_not_receive(:warn)
|
|
24
|
-
@log_parser.should_receive(:handle_request).exactly(4).times
|
|
25
|
-
@log_parser.parse_file(log_fixture(:rails_1x))
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
it "should parse a Rails 2.2 request properly" do
|
|
29
|
-
@log_parser.should_not_receive(:warn)
|
|
30
|
-
@log_parser.parse_file(log_fixture(:rails_22)) do |request|
|
|
31
|
-
request.should =~ :processing
|
|
32
|
-
request.should =~ :completed
|
|
33
|
-
|
|
34
|
-
request[:controller].should == 'PageController'
|
|
35
|
-
request[:action].should == 'demo'
|
|
36
|
-
request[:url].should == 'http://www.example.coml/demo'
|
|
37
|
-
request[:status].should == 200
|
|
38
|
-
request[:duration].should == 0.614
|
|
39
|
-
request[:db].should == 0.031
|
|
40
|
-
request[:view].should == 0.120
|
|
4
|
+
|
|
5
|
+
describe '.create' do
|
|
6
|
+
|
|
7
|
+
context 'without providing a lines argument' do
|
|
8
|
+
before(:each) { @rails = RequestLogAnalyzer::FileFormat.load(:rails) }
|
|
9
|
+
|
|
10
|
+
it "should create a valid file format" do
|
|
11
|
+
@rails.should be_valid
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
it "should parse the production lines" do
|
|
15
|
+
production_rails = RequestLogAnalyzer::FileFormat.load(:rails, 'production')
|
|
16
|
+
@rails.line_definitions.should == production_rails.line_definitions
|
|
17
|
+
end
|
|
41
18
|
end
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
19
|
+
|
|
20
|
+
context 'using a comma separated list of lines as argument' do
|
|
21
|
+
before(:each) { @rails = RequestLogAnalyzer::FileFormat.load(:rails, 'minimal,failure') }
|
|
22
|
+
|
|
23
|
+
it "should return a valid language" do
|
|
24
|
+
@rails.should be_valid
|
|
25
|
+
end
|
|
49
26
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
request[:status].should == 200
|
|
54
|
-
request[:duration].should == 0.21665
|
|
55
|
-
request[:db].should == 0.0
|
|
56
|
-
request[:view].should == 0.00926
|
|
27
|
+
it "should at least parse :processing and :completed lines" do
|
|
28
|
+
@rails.line_definitions.should include(:processing, :completed, :failure)
|
|
29
|
+
end
|
|
57
30
|
end
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
it "should parse cached requests" do
|
|
61
|
-
@log_parser.should_not_receive(:warn)
|
|
62
|
-
@log_parser.parse_file(log_fixture(:rails_22_cached)) do |request|
|
|
63
|
-
request.should be_completed
|
|
64
|
-
request =~ :cache_hit
|
|
65
|
-
end
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
it "should detect unordered requests in the logs" do
|
|
69
|
-
# No valid request should be found in cautious mode
|
|
70
|
-
@log_parser.should_not_receive(:handle_request)
|
|
71
|
-
# the first Processing-line will not give a warning, but the next one will
|
|
72
|
-
@log_parser.should_receive(:warn).with(:unclosed_request, anything).once
|
|
73
|
-
# Both Completed lines will give a warning
|
|
74
|
-
@log_parser.should_receive(:warn).with(:no_current_request, anything).twice
|
|
75
|
-
|
|
76
|
-
@log_parser.parse_file(log_fixture(:rails_unordered))
|
|
77
|
-
end
|
|
78
|
-
end
|
|
79
31
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
32
|
+
RequestLogAnalyzer::FileFormat::Rails::LINE_COLLECTIONS.keys.each do |constant|
|
|
33
|
+
|
|
34
|
+
context "using the '#{constant}' line collection constant" do
|
|
35
|
+
before(:each) { @rails = RequestLogAnalyzer::FileFormat.load(:rails, constant) }
|
|
36
|
+
|
|
37
|
+
it "should return a valid language" do
|
|
38
|
+
@rails.should be_valid
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
it "should at least parse :processing and :completed lines" do
|
|
42
|
+
@rails.line_definitions.should include(:processing, :completed)
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
94
46
|
end
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
47
|
+
|
|
48
|
+
describe '#parse_line' do
|
|
49
|
+
before(:each) { @rails = RequestLogAnalyzer::FileFormat.load(:rails, :all) }
|
|
50
|
+
|
|
51
|
+
{'with prefix' => 'LINE PREFIX: ', 'without prefix' => '' }.each do |context, prefix|
|
|
52
|
+
context context do
|
|
53
|
+
it "should parse a :processing line correctly" do
|
|
54
|
+
line = prefix + 'Processing PeopleController#index (for 1.1.1.1 at 2008-08-14 21:16:30) [GET]'
|
|
55
|
+
@rails.should parse_line(line).as(:processing).and_capture(:controller => 'PeopleController', :action => 'index', :timestamp => 20080814211630, :method => 'GET')
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
it "should parse a Rails 2.1 style :completed line correctly" do
|
|
59
|
+
line = prefix + 'Completed in 0.21665 (4 reqs/sec) | Rendering: 0.00926 (4%) | DB: 0.00000 (0%) | 200 OK [http://demo.nu/employees]'
|
|
60
|
+
@rails.should parse_line(line).as(:completed).and_capture(:duration => 0.21665, :db => 0.0, :view => 0.00926, :status => 200, :url => 'http://demo.nu/employees')
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
it "should parse a Rails 2.2 style :completed line correctly" do
|
|
64
|
+
line = prefix + 'Completed in 614ms (View: 120, DB: 31) | 200 OK [http://floorplanner.local/demo]'
|
|
65
|
+
@rails.should parse_line(line).as(:completed).and_capture(:duration => 0.614, :db => 0.031, :view => 0.120, :status => 200, :url => 'http://floorplanner.local/demo')
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
it "should parse a :failure line with exception correctly" do
|
|
69
|
+
line = prefix + "NoMethodError (undefined method `update_domain_account' for nil:NilClass):"
|
|
70
|
+
@rails.should parse_line(line).as(:failure).and_capture(:error => 'NoMethodError', :message => "undefined method `update_domain_account' for nil:NilClass")
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
it "should parse a :cache_hit line correctly" do
|
|
74
|
+
line = prefix + 'Filter chain halted as [#<ActionController::Caching::Actions::ActionCacheFilter:0x2a999ad620 @check=nil, @options={:store_options=>{}, :layout=>nil, :cache_path=>#<Proc:0x0000002a999b8890@/app/controllers/cached_controller.rb:8>}>] rendered_or_redirected.'
|
|
75
|
+
@rails.should parse_line(line).as(:cache_hit)
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
it "should parse a :parameters line correctly" do
|
|
79
|
+
line = prefix + ' Parameters: {"action"=>"cached", "controller"=>"cached"}'
|
|
80
|
+
@rails.should parse_line(line).as(:parameters).and_capture(:params => {:action => 'cached', :controller => 'cached'})
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
it "should parse a :rendered line correctly" do
|
|
84
|
+
line = prefix + 'Rendered layouts/_footer (2.9ms)'
|
|
85
|
+
@rails.should parse_line(line).as(:rendered).and_capture(:render_file => 'layouts/_footer', :render_duration => 0.0029)
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
it "should parse a :query_executed line with colors" do
|
|
89
|
+
line = prefix + ' [4;36;1mUser Load (0.4ms)[0m [0;1mSELECT * FROM `users` WHERE (`users`.`id` = 18205844) [0m'
|
|
90
|
+
@rails.should parse_line(line).as(:query_executed).and_capture(:query_class => 'User', :query_duration => 0.0004, :query_sql => 'SELECT * FROM users WHERE (users.id = :int)')
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
it "should parse a :query_executed line without colors" do
|
|
94
|
+
line = prefix + ' User Load (0.4ms) SELECT * FROM `users` WHERE (`users`.`id` = 18205844) '
|
|
95
|
+
@rails.should parse_line(line).as(:query_executed).and_capture(:query_class => 'User', :query_duration => 0.0004, :query_sql => 'SELECT * FROM users WHERE (users.id = :int)')
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
it "should parse a :query_cached line with colors" do
|
|
99
|
+
line = prefix + ' [4;35;1mCACHE (0.0ms)[0m [0mSELECT * FROM `users` WHERE (`users`.`id` = 0) [0m'
|
|
100
|
+
@rails.should parse_line(line).as(:query_cached).and_capture(:cached_duration => 0.0, :cached_sql => 'SELECT * FROM users WHERE (users.id = :int)')
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
it "should parse a :query_cached line without colors" do
|
|
104
|
+
line = prefix + ' CACHE (0.0ms) SELECT * FROM `users` WHERE (`users`.`id` = 0) '
|
|
105
|
+
@rails.should parse_line(line).as(:query_cached).and_capture(:cached_duration => 0.0, :cached_sql => 'SELECT * FROM users WHERE (users.id = :int)')
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
it "should not parse an unsupported line" do
|
|
109
|
+
line = prefix + 'nonsense line that should not be parsed as anything'
|
|
110
|
+
@rails.should_not parse_line(line)
|
|
111
|
+
end
|
|
112
|
+
end
|
|
113
|
+
end
|
|
100
114
|
end
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
115
|
+
|
|
116
|
+
describe '#parse_io' do
|
|
117
|
+
before(:each) do
|
|
118
|
+
@log_parser = RequestLogAnalyzer::Source::LogParser.new(
|
|
119
|
+
RequestLogAnalyzer::FileFormat.load(:rails), :parse_strategy => 'cautious')
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
it "should parse a Rails 2.1 style log and find valid Rails requests without warnings" do
|
|
123
|
+
@log_parser.should_not_receive(:warn)
|
|
124
|
+
@log_parser.parse_file(log_fixture(:rails_1x)) do |request|
|
|
125
|
+
request.should be_kind_of(RequestLogAnalyzer::FileFormat::Rails::Request)
|
|
126
|
+
request.should be_completed
|
|
127
|
+
end
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
it "should parse a Rails 2.2 style log and find valid Rails requests without warnings" do
|
|
131
|
+
@log_parser.should_not_receive(:warn)
|
|
132
|
+
@log_parser.parse_file(log_fixture(:rails_22)) do |request|
|
|
133
|
+
request.should be_kind_of(RequestLogAnalyzer::FileFormat::Rails::Request)
|
|
134
|
+
request.should be_completed
|
|
135
|
+
end
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
it "should parse a Rails SyslogLogger file with prefix and find valid requests without warnings" do
|
|
139
|
+
@log_parser.should_not_receive(:warn)
|
|
140
|
+
@log_parser.parse_file(log_fixture(:syslog_1x)) do |request|
|
|
141
|
+
request.should be_kind_of(RequestLogAnalyzer::FileFormat::Rails::Request)
|
|
142
|
+
request.should be_completed
|
|
143
|
+
end
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
it "should find 4 completed requests" do
|
|
147
|
+
@log_parser.should_not_receive(:warn)
|
|
148
|
+
@log_parser.should_receive(:handle_request).exactly(4).times
|
|
149
|
+
@log_parser.parse_file(log_fixture(:rails_1x))
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
it "should parse cached requests" do
|
|
153
|
+
@log_parser.should_not_receive(:warn)
|
|
154
|
+
@log_parser.parse_file(log_fixture(:rails_22_cached)) do |request|
|
|
155
|
+
request.should be_completed
|
|
156
|
+
request =~ :cache_hit
|
|
157
|
+
end
|
|
158
|
+
end
|
|
159
|
+
|
|
160
|
+
it "should detect unordered requests in the logs" do
|
|
161
|
+
@log_parser.should_not_receive(:handle_request)
|
|
162
|
+
@log_parser.should_receive(:warn).with(:unclosed_request, anything).once
|
|
163
|
+
@log_parser.should_receive(:warn).with(:no_current_request, anything).twice
|
|
164
|
+
@log_parser.parse_file(log_fixture(:rails_unordered))
|
|
165
|
+
end
|
|
120
166
|
end
|
|
121
|
-
|
|
122
|
-
it "should parse a cached query line without colors" do
|
|
123
|
-
info = @file_format.line_definitions[:query_cached].match_for(' CACHE (0.0ms) SELECT * FROM `users` WHERE (`users`.`id` = 0) ', @request)
|
|
124
|
-
info[:cached_duration].should == 0.0
|
|
125
|
-
info[:cached_sql].should == 'SELECT * FROM users WHERE (users.id = :int)'
|
|
126
|
-
end
|
|
127
|
-
end
|
|
167
|
+
end
|
|
@@ -5,7 +5,7 @@ describe RequestLogAnalyzer::Filter::Anonymize, 'anonymize request' do
|
|
|
5
5
|
before(:each) do
|
|
6
6
|
@filter = RequestLogAnalyzer::Filter::Anonymize.new(testing_format)
|
|
7
7
|
end
|
|
8
|
-
|
|
8
|
+
|
|
9
9
|
it "should anonimize ip" do
|
|
10
10
|
@filter.filter(request(:ip => '123.123.123.123'))[:ip].should_not eql('123.123.123.123')
|
|
11
11
|
end
|
|
@@ -17,5 +17,5 @@ describe RequestLogAnalyzer::Filter::Anonymize, 'anonymize request' do
|
|
|
17
17
|
it "should fuzz durations" do
|
|
18
18
|
@filter.filter(request(:duration => 100))[:duration].should_not eql(100)
|
|
19
19
|
end
|
|
20
|
-
|
|
20
|
+
|
|
21
21
|
end
|
|
@@ -5,22 +5,22 @@ describe RequestLogAnalyzer::Filter::Field, 'string in accept mode' do
|
|
|
5
5
|
before(:each) do
|
|
6
6
|
@filter = RequestLogAnalyzer::Filter::Field.new(testing_format, :field => :test, :value => 'test', :mode => :select)
|
|
7
7
|
end
|
|
8
|
-
|
|
8
|
+
|
|
9
9
|
it "should reject a request if the field value does not match" do
|
|
10
10
|
@filter.filter(request(:test => 'not test')).should be_nil
|
|
11
11
|
end
|
|
12
|
-
|
|
12
|
+
|
|
13
13
|
it "should reject a request if the field name does not match" do
|
|
14
14
|
@filter.filter(request(:testing => 'test')).should be_nil
|
|
15
15
|
end
|
|
16
16
|
|
|
17
17
|
it "should accept a request if the both name and value match" do
|
|
18
18
|
@filter.filter(request(:test => 'test')).should_not be_nil
|
|
19
|
-
end
|
|
20
|
-
|
|
19
|
+
end
|
|
20
|
+
|
|
21
21
|
it "should accept a request if the value is not the first value" do
|
|
22
22
|
@filter.filter(request([{:test => 'ignore'}, {:test => 'test'}])).should_not be_nil
|
|
23
|
-
end
|
|
23
|
+
end
|
|
24
24
|
end
|
|
25
25
|
|
|
26
26
|
describe RequestLogAnalyzer::Filter::Field, 'string in reject mode' do
|
|
@@ -28,22 +28,22 @@ describe RequestLogAnalyzer::Filter::Field, 'string in reject mode' do
|
|
|
28
28
|
before(:each) do
|
|
29
29
|
@filter = RequestLogAnalyzer::Filter::Field.new(testing_format, :field => :test, :value => 'test', :mode => :reject)
|
|
30
30
|
end
|
|
31
|
-
|
|
31
|
+
|
|
32
32
|
it "should accept a request if the field value does not match" do
|
|
33
33
|
@filter.filter(request(:test => 'not test')).should_not be_nil
|
|
34
34
|
end
|
|
35
|
-
|
|
35
|
+
|
|
36
36
|
it "should accept a request if the field name does not match" do
|
|
37
37
|
@filter.filter(request(:testing => 'test')).should_not be_nil
|
|
38
38
|
end
|
|
39
39
|
|
|
40
40
|
it "should reject a request if the both name and value match" do
|
|
41
41
|
@filter.filter(request(:test => 'test')).should be_nil
|
|
42
|
-
end
|
|
43
|
-
|
|
42
|
+
end
|
|
43
|
+
|
|
44
44
|
it "should reject a request if the value is not the first value" do
|
|
45
45
|
@filter.filter(request([{:test => 'ignore'}, {:test => 'test'}])).should be_nil
|
|
46
|
-
end
|
|
46
|
+
end
|
|
47
47
|
end
|
|
48
48
|
|
|
49
49
|
describe RequestLogAnalyzer::Filter::Field, 'regexp in accept mode' do
|
|
@@ -51,16 +51,16 @@ describe RequestLogAnalyzer::Filter::Field, 'regexp in accept mode' do
|
|
|
51
51
|
before(:each) do
|
|
52
52
|
@filter = RequestLogAnalyzer::Filter::Field.new(testing_format, :field => :test, :value => '/test/', :mode => :select)
|
|
53
53
|
end
|
|
54
|
-
|
|
54
|
+
|
|
55
55
|
it "should reject a request if the field value does not match" do
|
|
56
56
|
@filter.filter(request(:test => 'a working test')).should_not be_nil
|
|
57
57
|
end
|
|
58
|
-
|
|
58
|
+
|
|
59
59
|
it "should reject a request if the field name does not match" do
|
|
60
60
|
@filter.filter(request(:testing => 'test')).should be_nil
|
|
61
61
|
end
|
|
62
62
|
|
|
63
63
|
it "should accept a request if the value is not the first value" do
|
|
64
64
|
@filter.filter(request([{:test => 'ignore'}, {:test => 'testing 123'}])).should_not be_nil
|
|
65
|
-
end
|
|
65
|
+
end
|
|
66
66
|
end
|
|
@@ -5,7 +5,7 @@ describe RequestLogAnalyzer::Filter::Base, 'base filter' do
|
|
|
5
5
|
before(:each) do
|
|
6
6
|
@filter = RequestLogAnalyzer::Filter::Base.new(testing_format)
|
|
7
7
|
end
|
|
8
|
-
|
|
8
|
+
|
|
9
9
|
it "should return everything" do
|
|
10
10
|
@filter.filter(request(:ip => '123.123.123.123'))[:ip].should eql('123.123.123.123')
|
|
11
11
|
end
|
|
@@ -5,54 +5,54 @@ describe RequestLogAnalyzer::Filter::Timespan, 'both before and after' do
|
|
|
5
5
|
before(:each) do
|
|
6
6
|
@filter = RequestLogAnalyzer::Filter::Timespan.new(testing_format, :after => DateTime.parse('2009-01-01'), :before => DateTime.parse('2009-02-02'))
|
|
7
7
|
end
|
|
8
|
-
|
|
8
|
+
|
|
9
9
|
it "should reject a request before the after date" do
|
|
10
10
|
@filter.filter(request(:timestamp => 20081212000000)).should be_nil
|
|
11
11
|
end
|
|
12
|
-
|
|
12
|
+
|
|
13
13
|
it "should reject a request after the before date" do
|
|
14
14
|
@filter.filter(request(:timestamp => 20090303000000)).should be_nil
|
|
15
15
|
end
|
|
16
|
-
|
|
16
|
+
|
|
17
17
|
it "should accept a request between the after and before dates" do
|
|
18
18
|
@filter.filter(request(:timestamp => 20090102000000)).should_not be_nil
|
|
19
19
|
end
|
|
20
20
|
end
|
|
21
21
|
|
|
22
22
|
describe RequestLogAnalyzer::Filter::Timespan, 'only before' do
|
|
23
|
-
|
|
23
|
+
|
|
24
24
|
before(:each) do
|
|
25
|
-
@filter = RequestLogAnalyzer::Filter::Timespan.new(testing_format, :before => DateTime.parse('2009-02-02'))
|
|
25
|
+
@filter = RequestLogAnalyzer::Filter::Timespan.new(testing_format, :before => DateTime.parse('2009-02-02'))
|
|
26
26
|
end
|
|
27
|
-
|
|
27
|
+
|
|
28
28
|
it "should accept a request before the after date" do
|
|
29
29
|
@filter.filter(request(:timestamp => 20081212000000)).should_not be_nil
|
|
30
30
|
end
|
|
31
|
-
|
|
31
|
+
|
|
32
32
|
it "should reject a request after the before date" do
|
|
33
33
|
@filter.filter(request(:timestamp => 20090303000000)).should be_nil
|
|
34
34
|
end
|
|
35
|
-
|
|
35
|
+
|
|
36
36
|
it "should accept a request between the after and before dates" do
|
|
37
37
|
@filter.filter(request(:timestamp => 20090102000000)).should_not be_nil
|
|
38
|
-
end
|
|
38
|
+
end
|
|
39
39
|
end
|
|
40
40
|
|
|
41
|
-
describe RequestLogAnalyzer::Filter::Timespan, 'only after' do
|
|
42
|
-
|
|
41
|
+
describe RequestLogAnalyzer::Filter::Timespan, 'only after' do
|
|
42
|
+
|
|
43
43
|
before(:each) do
|
|
44
44
|
@filter = RequestLogAnalyzer::Filter::Timespan.new(testing_format, :after => DateTime.parse('2009-01-01'))
|
|
45
45
|
end
|
|
46
|
-
|
|
46
|
+
|
|
47
47
|
it "should reject a request before the after date" do
|
|
48
48
|
@filter.filter(request(:timestamp => 20081212000000)).should be_nil
|
|
49
49
|
end
|
|
50
|
-
|
|
50
|
+
|
|
51
51
|
it "should accept a request after the before date" do
|
|
52
52
|
@filter.filter(request(:timestamp => 20090303000000)).should_not be_nil
|
|
53
53
|
end
|
|
54
|
-
|
|
54
|
+
|
|
55
55
|
it "should accept a request between the after and before dates" do
|
|
56
56
|
@filter.filter(request(:timestamp => 20090102000000)).should_not be_nil
|
|
57
|
-
end
|
|
57
|
+
end
|
|
58
58
|
end
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
|
2
|
+
|
|
3
|
+
describe RequestLogAnalyzer::Mailer, 'mailer' do
|
|
4
|
+
|
|
5
|
+
it "should store printed data" do
|
|
6
|
+
@mailer = RequestLogAnalyzer::Mailer.new('alfa@beta.com', 'localhost', :debug => true)
|
|
7
|
+
|
|
8
|
+
@mailer << 'test1'
|
|
9
|
+
@mailer.puts 'test2'
|
|
10
|
+
|
|
11
|
+
@mailer.data.should eql(['test1', 'test2'])
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
it "should send mail" do
|
|
15
|
+
@mailer = RequestLogAnalyzer::Mailer.new('alfa@beta.com', 'localhost', :debug => true)
|
|
16
|
+
|
|
17
|
+
@mailer << 'test1'
|
|
18
|
+
@mailer.puts 'test2'
|
|
19
|
+
|
|
20
|
+
mail = @mailer.mail
|
|
21
|
+
|
|
22
|
+
mail[0].should include("contact@railsdoctors.com")
|
|
23
|
+
mail[0].should include("test1")
|
|
24
|
+
mail[0].should include("test2")
|
|
25
|
+
|
|
26
|
+
mail[1].should include("contact@railsdoctors.com")
|
|
27
|
+
mail[2].should include("alfa@beta.com")
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
end
|
|
@@ -1,49 +1,49 @@
|
|
|
1
|
-
require File.dirname(__FILE__) + '
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
|
2
2
|
|
|
3
3
|
describe RequestLogAnalyzer::Request do
|
|
4
|
-
|
|
4
|
+
|
|
5
5
|
before(:each) do
|
|
6
6
|
@request = testing_format.request
|
|
7
|
-
end
|
|
8
|
-
|
|
7
|
+
end
|
|
8
|
+
|
|
9
9
|
it "should be empty without any captured lines in it" do
|
|
10
10
|
@request.should be_empty
|
|
11
11
|
end
|
|
12
|
-
|
|
12
|
+
|
|
13
13
|
context :incomplete do
|
|
14
|
-
|
|
14
|
+
|
|
15
15
|
before(:each) do
|
|
16
16
|
@request << { :line_type => :test, :lineno => 1, :test_capture => 'awesome!' }
|
|
17
17
|
end
|
|
18
|
-
|
|
18
|
+
|
|
19
19
|
it "should be single if only one line has been added" do
|
|
20
20
|
@request.should_not be_empty
|
|
21
21
|
end
|
|
22
|
-
|
|
22
|
+
|
|
23
23
|
it "should not be a completed request" do
|
|
24
24
|
@request.should_not be_completed
|
|
25
|
-
end
|
|
26
|
-
|
|
25
|
+
end
|
|
26
|
+
|
|
27
27
|
it "should take the line type of the first line as global line_type" do
|
|
28
28
|
@request.lines[0][:line_type].should == :test
|
|
29
29
|
@request.should =~ :test
|
|
30
30
|
end
|
|
31
|
-
|
|
31
|
+
|
|
32
32
|
it "should return the first field value" do
|
|
33
33
|
@request[:test_capture].should == 'awesome!'
|
|
34
34
|
end
|
|
35
|
-
|
|
35
|
+
|
|
36
36
|
it "should return nil if no such field is present" do
|
|
37
37
|
@request[:nonexisting].should be_nil
|
|
38
38
|
end
|
|
39
39
|
end
|
|
40
|
-
|
|
40
|
+
|
|
41
41
|
context :completed do
|
|
42
|
-
|
|
42
|
+
|
|
43
43
|
before(:each) do
|
|
44
|
-
@request << { :line_type => :first, :lineno => 1, :name => 'first line!' }
|
|
45
|
-
@request << { :line_type => :test, :lineno => 4, :test_capture => 'testing' }
|
|
46
|
-
@request << { :line_type => :test, :lineno => 7, :test_capture => 'testing some more' }
|
|
44
|
+
@request << { :line_type => :first, :lineno => 1, :name => 'first line!' }
|
|
45
|
+
@request << { :line_type => :test, :lineno => 4, :test_capture => 'testing' }
|
|
46
|
+
@request << { :line_type => :test, :lineno => 7, :test_capture => 'testing some more' }
|
|
47
47
|
@request << { :line_type => :last, :lineno => 10, :time => 0.03 }
|
|
48
48
|
end
|
|
49
49
|
|
|
@@ -64,29 +64,29 @@ describe RequestLogAnalyzer::Request do
|
|
|
64
64
|
@request[:time].should == 0.03
|
|
65
65
|
end
|
|
66
66
|
|
|
67
|
-
it "should detect the first matching field value" do
|
|
67
|
+
it "should detect the first matching field value" do
|
|
68
68
|
@request.first(:test_capture).should == 'testing'
|
|
69
69
|
end
|
|
70
70
|
|
|
71
|
-
it "should detect the every matching field value" do
|
|
71
|
+
it "should detect the every matching field value" do
|
|
72
72
|
@request.every(:test_capture).should == ['testing', "testing some more"]
|
|
73
73
|
end
|
|
74
74
|
|
|
75
75
|
it "should set the first_lineno for a request to the lowest lineno encountered" do
|
|
76
76
|
@request.first_lineno.should eql(1)
|
|
77
77
|
end
|
|
78
|
-
|
|
78
|
+
|
|
79
79
|
it "should set the first_lineno for a request if a line with a lower lineno is added" do
|
|
80
|
-
@request << { :line_type => :test, :lineno => 0 }
|
|
80
|
+
@request << { :line_type => :test, :lineno => 0 }
|
|
81
81
|
@request.first_lineno.should eql(0)
|
|
82
|
-
end
|
|
82
|
+
end
|
|
83
83
|
|
|
84
84
|
it "should set the last_lineno for a request to the highest encountered lineno" do
|
|
85
85
|
@request.last_lineno.should eql(10)
|
|
86
86
|
end
|
|
87
|
-
|
|
87
|
+
|
|
88
88
|
it "should not set the last_lineno for a request if a line with a lower lineno is added" do
|
|
89
|
-
@request << { :line_type => :test, :lineno => 7 }
|
|
89
|
+
@request << { :line_type => :test, :lineno => 7 }
|
|
90
90
|
@request.last_lineno.should eql(10)
|
|
91
91
|
end
|
|
92
92
|
|
|
@@ -95,17 +95,17 @@ describe RequestLogAnalyzer::Request do
|
|
|
95
95
|
end
|
|
96
96
|
|
|
97
97
|
it "should set return a timestamp field if such a field is captured" do
|
|
98
|
-
@request << { :line_type => :first, :lineno => 1, :name => 'first line!', :timestamp => Time.now}
|
|
98
|
+
@request << { :line_type => :first, :lineno => 1, :name => 'first line!', :timestamp => Time.now}
|
|
99
99
|
@request.timestamp.should_not be_nil
|
|
100
|
-
end
|
|
100
|
+
end
|
|
101
101
|
end
|
|
102
|
-
|
|
102
|
+
|
|
103
103
|
context 'single line' do
|
|
104
104
|
# combined is both a header and a footer line
|
|
105
105
|
before(:each) { @request << { :line_type => :combined, :lineno => 1 } }
|
|
106
|
-
|
|
106
|
+
|
|
107
107
|
it "should be a completed request if the line is both header and footer" do
|
|
108
108
|
@request.should be_completed
|
|
109
|
-
end
|
|
109
|
+
end
|
|
110
110
|
end
|
|
111
|
-
end
|
|
111
|
+
end
|