request-log-analyzer 1.1.2 → 1.1.3
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/DESIGN +24 -10
- data/bin/request-log-analyzer +2 -27
- data/lib/cli/progressbar.rb +2 -19
- data/lib/cli/tools.rb +46 -0
- data/lib/request_log_analyzer/aggregator/database.rb +16 -5
- data/lib/request_log_analyzer/aggregator/echo.rb +1 -0
- data/lib/request_log_analyzer/aggregator/summarizer.rb +15 -13
- data/lib/request_log_analyzer/controller.rb +8 -4
- data/lib/request_log_analyzer/file_format/merb.rb +17 -4
- data/lib/request_log_analyzer/file_format/rails_development.rb +30 -92
- data/lib/request_log_analyzer/file_format.rb +8 -4
- data/lib/request_log_analyzer/filter/anonymize.rb +0 -3
- data/lib/request_log_analyzer/filter/field.rb +6 -1
- data/lib/request_log_analyzer/filter/timespan.rb +7 -1
- data/lib/request_log_analyzer/filter.rb +0 -4
- data/lib/request_log_analyzer/line_definition.rb +13 -2
- data/lib/request_log_analyzer/output/fixed_width.rb +7 -1
- data/lib/request_log_analyzer/output/html.rb +1 -0
- data/lib/request_log_analyzer/request.rb +4 -0
- data/lib/request_log_analyzer/source/log_parser.rb +19 -21
- data/lib/request_log_analyzer/source.rb +2 -1
- data/lib/request_log_analyzer/tracker/duration.rb +74 -14
- data/lib/request_log_analyzer/tracker/frequency.rb +22 -10
- data/lib/request_log_analyzer/tracker/hourly_spread.rb +18 -6
- data/lib/request_log_analyzer/tracker/timespan.rb +15 -8
- data/lib/request_log_analyzer.rb +4 -8
- data/spec/integration/command_line_usage_spec.rb +71 -0
- data/spec/lib/helper.rb +33 -0
- data/spec/lib/mocks.rb +47 -0
- data/spec/{file_formats/spec_format.rb → lib/testing_format.rb} +6 -1
- data/spec/spec_helper.rb +5 -41
- data/spec/{database_inserter_spec.rb → unit/aggregator/database_inserter_spec.rb} +40 -37
- data/spec/unit/aggregator/summarizer_spec.rb +28 -0
- data/spec/unit/controller/controller_spec.rb +43 -0
- data/spec/{log_processor_spec.rb → unit/controller/log_processor_spec.rb} +4 -3
- data/spec/{file_format_spec.rb → unit/file_format/file_format_api_spec.rb} +16 -4
- data/spec/{line_definition_spec.rb → unit/file_format/line_definition_spec.rb} +13 -6
- data/spec/{merb_format_spec.rb → unit/file_format/merb_format_spec.rb} +2 -2
- data/spec/{rails_format_spec.rb → unit/file_format/rails_format_spec.rb} +19 -11
- data/spec/unit/filter/anonymize_filter_spec.rb +22 -0
- data/spec/unit/filter/field_filter_spec.rb +69 -0
- data/spec/unit/filter/timespan_filter_spec.rb +61 -0
- data/spec/{log_parser_spec.rb → unit/source/log_parser_spec.rb} +7 -7
- data/spec/{request_spec.rb → unit/source/request_spec.rb} +5 -5
- data/spec/unit/tracker/duration_tracker_spec.rb +90 -0
- data/spec/unit/tracker/frequency_tracker_spec.rb +83 -0
- data/spec/unit/tracker/timespan_tracker_spec.rb +64 -0
- data/spec/unit/tracker/tracker_api_test.rb +45 -0
- metadata +50 -26
- data/spec/controller_spec.rb +0 -64
- data/spec/filter_spec.rb +0 -157
- data/spec/summarizer_spec.rb +0 -9
@@ -0,0 +1,90 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../spec_helper'
|
2
|
+
|
3
|
+
describe RequestLogAnalyzer::Tracker::Duration, 'static category' do
|
4
|
+
|
5
|
+
include RequestLogAnalyzer::Spec::Helper
|
6
|
+
|
7
|
+
before(:each) do
|
8
|
+
@tracker = RequestLogAnalyzer::Tracker::Duration.new(:duration => :duration, :category => :category)
|
9
|
+
@tracker.prepare
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should register a request in the right category" do
|
13
|
+
@tracker.update(request(:category => 'a', :duration => 0.2))
|
14
|
+
@tracker.categories.keys.should include('a')
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should register a hit in the right category" do
|
18
|
+
@tracker.update(request(:category => 'a', :duration => 0.2))
|
19
|
+
@tracker.update(request(:category => 'b', :duration => 0.3))
|
20
|
+
@tracker.update(request(:category => 'b', :duration => 0.4))
|
21
|
+
|
22
|
+
@tracker.hits('a').should == 1
|
23
|
+
@tracker.hits('b').should == 2
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should sum the durations of the same category as cumulative duration" do
|
27
|
+
@tracker.update(request(:category => 'a', :duration => 0.2))
|
28
|
+
@tracker.update(request(:category => 'b', :duration => 0.3))
|
29
|
+
@tracker.update(request(:category => 'b', :duration => 0.4))
|
30
|
+
|
31
|
+
@tracker.cumulative_duration('a').should == 0.2
|
32
|
+
@tracker.cumulative_duration('b').should == 0.7
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should calculate the average duration correctly" do
|
36
|
+
@tracker.update(request(:category => 'a', :duration => 0.2))
|
37
|
+
@tracker.update(request(:category => 'b', :duration => 0.3))
|
38
|
+
@tracker.update(request(:category => 'b', :duration => 0.4))
|
39
|
+
|
40
|
+
@tracker.average_duration('a').should == 0.2
|
41
|
+
@tracker.average_duration('b').should == 0.35
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
describe RequestLogAnalyzer::Tracker::Duration, 'dynamic category' do
|
47
|
+
|
48
|
+
include RequestLogAnalyzer::Spec::Helper
|
49
|
+
|
50
|
+
before(:each) do
|
51
|
+
@categorizer = Proc.new { |request| request[:duration] > 0.2 ? 'slow' : 'fast' }
|
52
|
+
@tracker = RequestLogAnalyzer::Tracker::Duration.new(:duration => :duration, :category => @categorizer)
|
53
|
+
@tracker.prepare
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should use the categorizer to determine the right category" do
|
57
|
+
@tracker.update(request(:category => 'a', :duration => 0.2))
|
58
|
+
@tracker.update(request(:category => 'b', :duration => 0.3))
|
59
|
+
@tracker.update(request(:category => 'b', :duration => 0.4))
|
60
|
+
|
61
|
+
@tracker.cumulative_duration('fast').should == 0.2
|
62
|
+
@tracker.cumulative_duration('slow').should == 0.7
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
describe RequestLogAnalyzer::Tracker::Duration, 'reporting' do
|
68
|
+
|
69
|
+
include RequestLogAnalyzer::Spec::Helper
|
70
|
+
|
71
|
+
before(:each) do
|
72
|
+
@tracker = RequestLogAnalyzer::Tracker::Duration.new(:category => :category, :duration => :duration)
|
73
|
+
@tracker.prepare
|
74
|
+
end
|
75
|
+
|
76
|
+
it "should generate a report without errors when one category is present" do
|
77
|
+
@tracker.update(request(:category => 'a', :duration => 0.2))
|
78
|
+
lambda { @tracker.report(mock_output) }.should_not raise_error
|
79
|
+
end
|
80
|
+
|
81
|
+
it "should generate a report without errors when no category is present" do
|
82
|
+
lambda { @tracker.report(mock_output) }.should_not raise_error
|
83
|
+
end
|
84
|
+
|
85
|
+
it "should generate a report without errors when multiple categories are present" do
|
86
|
+
@tracker.update(request(:category => 'a', :duration => 0.2))
|
87
|
+
@tracker.update(request(:category => 'b', :duration => 0.2))
|
88
|
+
lambda { @tracker.report(mock_output) }.should_not raise_error
|
89
|
+
end
|
90
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../spec_helper'
|
2
|
+
|
3
|
+
describe RequestLogAnalyzer::Tracker::Frequency, 'static category' do
|
4
|
+
|
5
|
+
include RequestLogAnalyzer::Spec::Helper
|
6
|
+
|
7
|
+
before(:each) do
|
8
|
+
@tracker = RequestLogAnalyzer::Tracker::Frequency.new(:category => :category)
|
9
|
+
@tracker.prepare
|
10
|
+
end
|
11
|
+
|
12
|
+
|
13
|
+
it "should register a request in the right category" do
|
14
|
+
@tracker.update(request(:category => 'a', :blah => 0.2))
|
15
|
+
@tracker.frequencies.keys.should include('a')
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should register a request in the right category" do
|
19
|
+
@tracker.update(request(:category => 'a', :blah => 0.2))
|
20
|
+
@tracker.update(request(:category => 'b', :blah => 0.2))
|
21
|
+
@tracker.update(request(:category => 'b', :blah => 0.2))
|
22
|
+
|
23
|
+
@tracker.frequency('a').should == 1
|
24
|
+
@tracker.frequency('b').should == 2
|
25
|
+
@tracker.overall_frequency.should == 3
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should sort correctly by frequency" do
|
29
|
+
@tracker.update(request(:category => 'a', :blah => 0.2))
|
30
|
+
@tracker.update(request(:category => 'b', :blah => 0.2))
|
31
|
+
@tracker.update(request(:category => 'b', :blah => 0.2))
|
32
|
+
|
33
|
+
@tracker.sorted_by_frequency.should == [['b', 2], ['a', 1]]
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
describe RequestLogAnalyzer::Tracker::Frequency, 'dynamic category' do
|
38
|
+
|
39
|
+
include RequestLogAnalyzer::Spec::Helper
|
40
|
+
|
41
|
+
before(:each) do
|
42
|
+
@categorizer = Proc.new { |request| request[:duration] > 0.2 ? 'slow' : 'fast' }
|
43
|
+
@tracker = RequestLogAnalyzer::Tracker::Frequency.new(:category => @categorizer)
|
44
|
+
@tracker.prepare
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should use the categorizer to determine the right category" do
|
48
|
+
@tracker.update(request(:category => 'a', :duration => 0.2))
|
49
|
+
@tracker.update(request(:category => 'b', :duration => 0.3))
|
50
|
+
@tracker.update(request(:category => 'b', :duration => 0.4))
|
51
|
+
|
52
|
+
@tracker.frequency('fast').should == 1
|
53
|
+
@tracker.frequency('slow').should == 2
|
54
|
+
@tracker.frequency('moderate').should == 0
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
|
60
|
+
describe RequestLogAnalyzer::Tracker::Frequency, 'reporting' do
|
61
|
+
|
62
|
+
include RequestLogAnalyzer::Spec::Helper
|
63
|
+
|
64
|
+
before(:each) do
|
65
|
+
@tracker = RequestLogAnalyzer::Tracker::Frequency.new(:category => :category)
|
66
|
+
@tracker.prepare
|
67
|
+
end
|
68
|
+
|
69
|
+
it "should generate a report without errors when one category is present" do
|
70
|
+
@tracker.update(request(:category => 'a', :blah => 0.2))
|
71
|
+
lambda { @tracker.report(mock_output) }.should_not raise_error
|
72
|
+
end
|
73
|
+
|
74
|
+
it "should generate a report without errors when no category is present" do
|
75
|
+
lambda { @tracker.report(mock_output) }.should_not raise_error
|
76
|
+
end
|
77
|
+
|
78
|
+
it "should generate a report without errors when multiple categories are present" do
|
79
|
+
@tracker.update(request(:category => 'a', :blah => 0.2))
|
80
|
+
@tracker.update(request(:category => 'b', :blah => 0.2))
|
81
|
+
lambda { @tracker.report(mock_output) }.should_not raise_error
|
82
|
+
end
|
83
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../spec_helper'
|
2
|
+
|
3
|
+
describe RequestLogAnalyzer::Tracker::Timespan do
|
4
|
+
|
5
|
+
include RequestLogAnalyzer::Spec::Helper
|
6
|
+
|
7
|
+
before(:each) do
|
8
|
+
@tracker = RequestLogAnalyzer::Tracker::Timespan.new
|
9
|
+
@tracker.prepare
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should set the first request timestamp correctly" do
|
13
|
+
@tracker.update(request(:timestamp => 20090102000000))
|
14
|
+
@tracker.update(request(:timestamp => 20090101000000))
|
15
|
+
@tracker.update(request(:timestamp => 20090103000000))
|
16
|
+
|
17
|
+
@tracker.first_timestamp.should == DateTime.parse('Januari 1, 2009 00:00:00')
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should set the last request timestamp correctly" do
|
21
|
+
@tracker.update(request(:timestamp => 20090102000000))
|
22
|
+
@tracker.update(request(:timestamp => 20090101000000))
|
23
|
+
@tracker.update(request(:timestamp => 20090103000000))
|
24
|
+
|
25
|
+
@tracker.last_timestamp.should == DateTime.parse('Januari 3, 2009 00:00:00')
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should return the correct timespan in days when multiple requests are given" do
|
29
|
+
@tracker.update(request(:timestamp => 20090102000000))
|
30
|
+
@tracker.update(request(:timestamp => 20090101000000))
|
31
|
+
@tracker.update(request(:timestamp => 20090103000000))
|
32
|
+
|
33
|
+
@tracker.timespan.should == 2
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should return a timespan of 0 days when only one timestamp is set" do
|
37
|
+
@tracker.update(request(:timestamp => 20090103000000))
|
38
|
+
@tracker.timespan.should == 0
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should raise an error when no timestamp is set" do
|
42
|
+
lambda { @tracker.timespan }.should raise_error
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe RequestLogAnalyzer::Tracker::Timespan, 'reporting' do
|
47
|
+
|
48
|
+
include RequestLogAnalyzer::Spec::Helper
|
49
|
+
|
50
|
+
before(:each) do
|
51
|
+
@tracker = RequestLogAnalyzer::Tracker::Timespan.new
|
52
|
+
@tracker.prepare
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should generate a report without errors when no request was tracked" do
|
56
|
+
lambda { @tracker.report(mock_output) }.should_not raise_error
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should generate a report without errors when multiple requests were tracked" do
|
60
|
+
@tracker.update(request(:category => 'a', :timestamp => 20090102000000))
|
61
|
+
@tracker.update(request(:category => 'a', :timestamp => 20090101000000))
|
62
|
+
lambda { @tracker.report(mock_output) }.should_not raise_error
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../spec_helper'
|
2
|
+
|
3
|
+
describe RequestLogAnalyzer::Tracker::Base, "API test" do
|
4
|
+
|
5
|
+
include RequestLogAnalyzer::Spec::Helper
|
6
|
+
|
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 receieve :finalize when the summarizer is finalizing" do
|
20
|
+
@tracker.should_receive(:finalize).once
|
21
|
+
@summarizer.finalize
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should receive :update for every request for which should_update? returns true" do
|
25
|
+
@tracker.should_receive(:should_update?).twice.and_return(true)
|
26
|
+
@tracker.should_receive(:update).twice
|
27
|
+
|
28
|
+
@summarizer.aggregate(testing_format.request(:field => 'value1'))
|
29
|
+
@summarizer.aggregate(testing_format.request(:field => 'value2'))
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should not :update for every request for which should_update? returns false" do
|
33
|
+
@tracker.should_receive(:should_update?).twice.and_return(false)
|
34
|
+
@tracker.should_not_receive(:update)
|
35
|
+
|
36
|
+
@summarizer.aggregate(testing_format.request(:field => 'value1'))
|
37
|
+
@summarizer.aggregate(testing_format.request(:field => 'value2'))
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should receive :report when the summary report is being built" do
|
41
|
+
@tracker.should_receive(:report).with(anything).once
|
42
|
+
@summarizer.report(mock_output)
|
43
|
+
end
|
44
|
+
|
45
|
+
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.1.
|
4
|
+
version: 1.1.3
|
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-01-
|
13
|
+
date: 2009-01-29 00:00:00 +01:00
|
14
14
|
default_executable: request-log-analyzer
|
15
15
|
dependencies: []
|
16
16
|
|
@@ -34,6 +34,7 @@ files:
|
|
34
34
|
- lib/cli
|
35
35
|
- lib/cli/command_line_arguments.rb
|
36
36
|
- lib/cli/progressbar.rb
|
37
|
+
- lib/cli/tools.rb
|
37
38
|
- lib/request_log_analyzer
|
38
39
|
- lib/request_log_analyzer.rb
|
39
40
|
- lib/request_log_analyzer/aggregator
|
@@ -69,12 +70,6 @@ files:
|
|
69
70
|
- lib/request_log_analyzer/tracker/hourly_spread.rb
|
70
71
|
- lib/request_log_analyzer/tracker/timespan.rb
|
71
72
|
- spec
|
72
|
-
- spec/controller_spec.rb
|
73
|
-
- spec/database_inserter_spec.rb
|
74
|
-
- spec/file_format_spec.rb
|
75
|
-
- spec/file_formats
|
76
|
-
- spec/file_formats/spec_format.rb
|
77
|
-
- spec/filter_spec.rb
|
78
73
|
- spec/fixtures
|
79
74
|
- spec/fixtures/merb.log
|
80
75
|
- spec/fixtures/multiple_files_1.log
|
@@ -87,14 +82,37 @@ files:
|
|
87
82
|
- spec/fixtures/test_file_format.log
|
88
83
|
- spec/fixtures/test_language_combined.log
|
89
84
|
- spec/fixtures/test_order.log
|
90
|
-
- spec/
|
91
|
-
- spec/
|
92
|
-
- spec/
|
93
|
-
- spec/
|
94
|
-
- spec/
|
95
|
-
- spec/
|
85
|
+
- spec/integration
|
86
|
+
- spec/integration/command_line_usage_spec.rb
|
87
|
+
- spec/lib
|
88
|
+
- spec/lib/helper.rb
|
89
|
+
- spec/lib/mocks.rb
|
90
|
+
- spec/lib/testing_format.rb
|
96
91
|
- spec/spec_helper.rb
|
97
|
-
- spec/
|
92
|
+
- spec/unit
|
93
|
+
- spec/unit/aggregator
|
94
|
+
- spec/unit/aggregator/database_inserter_spec.rb
|
95
|
+
- spec/unit/aggregator/summarizer_spec.rb
|
96
|
+
- spec/unit/controller
|
97
|
+
- spec/unit/controller/controller_spec.rb
|
98
|
+
- spec/unit/controller/log_processor_spec.rb
|
99
|
+
- spec/unit/file_format
|
100
|
+
- spec/unit/file_format/file_format_api_spec.rb
|
101
|
+
- spec/unit/file_format/line_definition_spec.rb
|
102
|
+
- spec/unit/file_format/merb_format_spec.rb
|
103
|
+
- spec/unit/file_format/rails_format_spec.rb
|
104
|
+
- spec/unit/filter
|
105
|
+
- spec/unit/filter/anonymize_filter_spec.rb
|
106
|
+
- spec/unit/filter/field_filter_spec.rb
|
107
|
+
- spec/unit/filter/timespan_filter_spec.rb
|
108
|
+
- spec/unit/source
|
109
|
+
- spec/unit/source/log_parser_spec.rb
|
110
|
+
- spec/unit/source/request_spec.rb
|
111
|
+
- spec/unit/tracker
|
112
|
+
- spec/unit/tracker/duration_tracker_spec.rb
|
113
|
+
- spec/unit/tracker/frequency_tracker_spec.rb
|
114
|
+
- spec/unit/tracker/timespan_tracker_spec.rb
|
115
|
+
- spec/unit/tracker/tracker_api_test.rb
|
98
116
|
- tasks
|
99
117
|
- tasks/github-gem.rake
|
100
118
|
- tasks/request_log_analyzer.rake
|
@@ -130,14 +148,20 @@ signing_key:
|
|
130
148
|
specification_version: 2
|
131
149
|
summary: A command line tool to analyze Rails logs
|
132
150
|
test_files:
|
133
|
-
- spec/
|
134
|
-
- spec/database_inserter_spec.rb
|
135
|
-
- spec/
|
136
|
-
- spec/
|
137
|
-
- spec/
|
138
|
-
- spec/
|
139
|
-
- spec/
|
140
|
-
- spec/merb_format_spec.rb
|
141
|
-
- spec/rails_format_spec.rb
|
142
|
-
- spec/
|
143
|
-
- spec/
|
151
|
+
- spec/integration/command_line_usage_spec.rb
|
152
|
+
- spec/unit/aggregator/database_inserter_spec.rb
|
153
|
+
- spec/unit/aggregator/summarizer_spec.rb
|
154
|
+
- spec/unit/controller/controller_spec.rb
|
155
|
+
- spec/unit/controller/log_processor_spec.rb
|
156
|
+
- spec/unit/file_format/file_format_api_spec.rb
|
157
|
+
- spec/unit/file_format/line_definition_spec.rb
|
158
|
+
- spec/unit/file_format/merb_format_spec.rb
|
159
|
+
- spec/unit/file_format/rails_format_spec.rb
|
160
|
+
- spec/unit/filter/anonymize_filter_spec.rb
|
161
|
+
- spec/unit/filter/field_filter_spec.rb
|
162
|
+
- spec/unit/filter/timespan_filter_spec.rb
|
163
|
+
- spec/unit/source/log_parser_spec.rb
|
164
|
+
- spec/unit/source/request_spec.rb
|
165
|
+
- spec/unit/tracker/duration_tracker_spec.rb
|
166
|
+
- spec/unit/tracker/frequency_tracker_spec.rb
|
167
|
+
- spec/unit/tracker/timespan_tracker_spec.rb
|
data/spec/controller_spec.rb
DELETED
@@ -1,64 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
-
|
3
|
-
describe RequestLogAnalyzer::Controller do
|
4
|
-
|
5
|
-
include RequestLogAnalyzerSpecHelper
|
6
|
-
|
7
|
-
it "should use a custom output generator correctly" do
|
8
|
-
|
9
|
-
mock_output = mock('RequestLogAnalyzer::Output::Base')
|
10
|
-
mock_output.stub!(:io).and_return(mock_io)
|
11
|
-
mock_output.should_receive(:header)
|
12
|
-
mock_output.should_receive(:footer)
|
13
|
-
|
14
|
-
file_format = RequestLogAnalyzer::FileFormat.load(:rails)
|
15
|
-
source = RequestLogAnalyzer::Source::LogParser.new(file_format, :source_files => log_fixture(:rails_1x))
|
16
|
-
controller = RequestLogAnalyzer::Controller.new(source, :output => mock_output)
|
17
|
-
|
18
|
-
controller.run!
|
19
|
-
end
|
20
|
-
|
21
|
-
it "should call aggregators correctly when run" do
|
22
|
-
|
23
|
-
file_format = RequestLogAnalyzer::FileFormat.load(:rails)
|
24
|
-
source = RequestLogAnalyzer::Source::LogParser.new(file_format, :source_files => log_fixture(:rails_1x))
|
25
|
-
controller = RequestLogAnalyzer::Controller.new(source, :output => mock_output)
|
26
|
-
|
27
|
-
mock_aggregator = mock('RequestLogAnalyzer::Aggregator::Base')
|
28
|
-
mock_aggregator.should_receive(:prepare).once.ordered
|
29
|
-
mock_aggregator.should_receive(:aggregate).with(an_instance_of(file_format.class::Request)).at_least(:twice).ordered
|
30
|
-
mock_aggregator.should_receive(:finalize).once.ordered
|
31
|
-
mock_aggregator.should_receive(:report).once.ordered
|
32
|
-
|
33
|
-
controller.aggregators << mock_aggregator
|
34
|
-
controller.run!
|
35
|
-
end
|
36
|
-
|
37
|
-
it "should call filters when run" do
|
38
|
-
file_format = RequestLogAnalyzer::FileFormat.load(:rails)
|
39
|
-
source = RequestLogAnalyzer::Source::LogParser.new(file_format, :source_files => log_fixture(:rails_1x))
|
40
|
-
controller = RequestLogAnalyzer::Controller.new(source, :output => mock_output)
|
41
|
-
|
42
|
-
mock_filter = mock('RequestLogAnalyzer::Filter::Base')
|
43
|
-
mock_filter.should_receive(:prepare).once.ordered
|
44
|
-
mock_filter.should_receive(:filter).at_least(:twice)
|
45
|
-
|
46
|
-
controller.should_not_receive(:aggregate_request)
|
47
|
-
|
48
|
-
controller.filters << mock_filter
|
49
|
-
controller.run!
|
50
|
-
end
|
51
|
-
|
52
|
-
it "should run well from the command line with the most important features" do
|
53
|
-
|
54
|
-
temp_file = "#{File.dirname(__FILE__)}/fixtures/report.txt"
|
55
|
-
temp_db = "#{File.dirname(__FILE__)}/fixtures/output.db"
|
56
|
-
binary = "#{File.dirname(__FILE__)}/../bin/request-log-analyzer"
|
57
|
-
|
58
|
-
system("#{binary} #{log_fixture(:rails_1x)} --database #{temp_db} --select Controller PeopleController --file #{temp_file} > /dev/null").should be_true
|
59
|
-
|
60
|
-
File.unlink(temp_file)
|
61
|
-
File.unlink(temp_db)
|
62
|
-
end
|
63
|
-
|
64
|
-
end
|
data/spec/filter_spec.rb
DELETED
@@ -1,157 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
-
|
3
|
-
describe RequestLogAnalyzer::Filter::Timespan, 'both before and after' do
|
4
|
-
include RequestLogAnalyzerSpecHelper
|
5
|
-
|
6
|
-
before(:each) do
|
7
|
-
@filter = RequestLogAnalyzer::Filter::Timespan.new(spec_format, :after => DateTime.parse('2009-01-01'), :before => DateTime.parse('2009-02-02'))
|
8
|
-
@filter.prepare
|
9
|
-
end
|
10
|
-
|
11
|
-
it "should reject a request before the after date" do
|
12
|
-
@filter.filter(request(:timestamp => 20081212000000)).should be_nil
|
13
|
-
end
|
14
|
-
|
15
|
-
it "should reject a request after the before date" do
|
16
|
-
@filter.filter(request(:timestamp => 20090303000000)).should be_nil
|
17
|
-
end
|
18
|
-
|
19
|
-
it "should accept a request between the after and before dates" do
|
20
|
-
@filter.filter(request(:timestamp => 20090102000000)).should_not be_nil
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
describe RequestLogAnalyzer::Filter::Timespan, 'only before' do
|
25
|
-
include RequestLogAnalyzerSpecHelper
|
26
|
-
|
27
|
-
before(:each) do
|
28
|
-
@filter = RequestLogAnalyzer::Filter::Timespan.new(spec_format, :before => DateTime.parse('2009-02-02'))
|
29
|
-
@filter.prepare
|
30
|
-
end
|
31
|
-
|
32
|
-
it "should accept a request before the after date" do
|
33
|
-
@filter.filter(request(:timestamp => 20081212000000)).should_not be_nil
|
34
|
-
end
|
35
|
-
|
36
|
-
it "should reject a request after the before date" do
|
37
|
-
@filter.filter(request(:timestamp => 20090303000000)).should be_nil
|
38
|
-
end
|
39
|
-
|
40
|
-
it "should accept a request between the after and before dates" do
|
41
|
-
@filter.filter(request(:timestamp => 20090102000000)).should_not be_nil
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
describe RequestLogAnalyzer::Filter::Timespan, 'only after' do
|
46
|
-
include RequestLogAnalyzerSpecHelper
|
47
|
-
|
48
|
-
before(:each) do
|
49
|
-
@filter = RequestLogAnalyzer::Filter::Timespan.new(spec_format, :after => DateTime.parse('2009-01-01'))
|
50
|
-
@filter.prepare
|
51
|
-
end
|
52
|
-
|
53
|
-
it "should reject a request before the after date" do
|
54
|
-
@filter.filter(request(:timestamp => 20081212000000)).should be_nil
|
55
|
-
end
|
56
|
-
|
57
|
-
it "should accept a request after the before date" do
|
58
|
-
@filter.filter(request(:timestamp => 20090303000000)).should_not be_nil
|
59
|
-
end
|
60
|
-
|
61
|
-
it "should accept a request between the after and before dates" do
|
62
|
-
@filter.filter(request(:timestamp => 20090102000000)).should_not be_nil
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
describe RequestLogAnalyzer::Filter::Field, 'string in accept mode' do
|
67
|
-
include RequestLogAnalyzerSpecHelper
|
68
|
-
|
69
|
-
before(:each) do
|
70
|
-
@filter = RequestLogAnalyzer::Filter::Field.new(spec_format, :field => :test, :value => 'test', :mode => :select)
|
71
|
-
@filter.prepare
|
72
|
-
end
|
73
|
-
|
74
|
-
it "should reject a request if the field value does not match" do
|
75
|
-
@filter.filter(request(:test => 'not test')).should be_nil
|
76
|
-
end
|
77
|
-
|
78
|
-
it "should reject a request if the field name does not match" do
|
79
|
-
@filter.filter(request(:testing => 'test')).should be_nil
|
80
|
-
end
|
81
|
-
|
82
|
-
it "should accept a request if the both name and value match" do
|
83
|
-
@filter.filter(request(:test => 'test')).should_not be_nil
|
84
|
-
end
|
85
|
-
|
86
|
-
it "should accept a request if the value is not the first value" do
|
87
|
-
@filter.filter(request([{:test => 'ignore'}, {:test => 'test'}])).should_not be_nil
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
describe RequestLogAnalyzer::Filter::Field, 'string in reject mode' do
|
92
|
-
include RequestLogAnalyzerSpecHelper
|
93
|
-
|
94
|
-
before(:each) do
|
95
|
-
@filter = RequestLogAnalyzer::Filter::Field.new(spec_format, :field => :test, :value => 'test', :mode => :reject)
|
96
|
-
@filter.prepare
|
97
|
-
end
|
98
|
-
|
99
|
-
it "should accept a request if the field value does not match" do
|
100
|
-
@filter.filter(request(:test => 'not test')).should_not be_nil
|
101
|
-
end
|
102
|
-
|
103
|
-
it "should accept a request if the field name does not match" do
|
104
|
-
@filter.filter(request(:testing => 'test')).should_not be_nil
|
105
|
-
end
|
106
|
-
|
107
|
-
it "should reject a request if the both name and value match" do
|
108
|
-
@filter.filter(request(:test => 'test')).should be_nil
|
109
|
-
end
|
110
|
-
|
111
|
-
it "should reject a request if the value is not the first value" do
|
112
|
-
@filter.filter(request([{:test => 'ignore'}, {:test => 'test'}])).should be_nil
|
113
|
-
end
|
114
|
-
end
|
115
|
-
|
116
|
-
describe RequestLogAnalyzer::Filter::Field, 'regexp in accept mode' do
|
117
|
-
include RequestLogAnalyzerSpecHelper
|
118
|
-
|
119
|
-
before(:each) do
|
120
|
-
@filter = RequestLogAnalyzer::Filter::Field.new(spec_format, :field => :test, :value => '/test/', :mode => :select)
|
121
|
-
@filter.prepare
|
122
|
-
end
|
123
|
-
|
124
|
-
it "should reject a request if the field value does not match" do
|
125
|
-
@filter.filter(request(:test => 'a working test')).should_not be_nil
|
126
|
-
end
|
127
|
-
|
128
|
-
it "should reject a request if the field name does not match" do
|
129
|
-
@filter.filter(request(:testing => 'test')).should be_nil
|
130
|
-
end
|
131
|
-
|
132
|
-
it "should accept a request if the value is not the first value" do
|
133
|
-
@filter.filter(request([{:test => 'ignore'}, {:test => 'testing 123'}])).should_not be_nil
|
134
|
-
end
|
135
|
-
end
|
136
|
-
|
137
|
-
describe RequestLogAnalyzer::Filter::Anonymize, 'anonymize request' do
|
138
|
-
include RequestLogAnalyzerSpecHelper
|
139
|
-
|
140
|
-
before(:each) do
|
141
|
-
@filter = RequestLogAnalyzer::Filter::Anonymize.new(spec_format)
|
142
|
-
@filter.prepare
|
143
|
-
end
|
144
|
-
|
145
|
-
it "should anonimize ip" do
|
146
|
-
@filter.filter(request(:ip => '123.123.123.123'))[:ip].should_not eql('123.123.123.123')
|
147
|
-
end
|
148
|
-
|
149
|
-
it "should anonimize url" do
|
150
|
-
@filter.filter(request(:url => 'https://test.mysite.com/employees'))[:url].should eql('http://example.com/employees')
|
151
|
-
end
|
152
|
-
|
153
|
-
it "should fuzz durations" do
|
154
|
-
@filter.filter(request(:duration => 100))[:duration].should_not eql(100)
|
155
|
-
end
|
156
|
-
|
157
|
-
end
|