request-log-analyzer 1.13.1 → 1.13.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.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/bin/console +17 -0
- data/lib/cli/command_line_arguments.rb +29 -36
- data/lib/cli/database_console.rb +1 -3
- data/lib/cli/database_console_init.rb +11 -11
- data/lib/cli/progressbar.rb +30 -32
- data/lib/cli/tools.rb +20 -23
- data/lib/request_log_analyzer.rb +8 -8
- data/lib/request_log_analyzer/aggregator.rb +4 -7
- data/lib/request_log_analyzer/aggregator/database_inserter.rb +10 -13
- data/lib/request_log_analyzer/aggregator/echo.rb +5 -7
- data/lib/request_log_analyzer/aggregator/summarizer.rb +15 -18
- data/lib/request_log_analyzer/class_level_inheritable_attributes.rb +23 -0
- data/lib/request_log_analyzer/controller.rb +36 -42
- data/lib/request_log_analyzer/database.rb +4 -6
- data/lib/request_log_analyzer/database/base.rb +39 -41
- data/lib/request_log_analyzer/database/connection.rb +8 -10
- data/lib/request_log_analyzer/database/request.rb +1 -3
- data/lib/request_log_analyzer/database/source.rb +0 -2
- data/lib/request_log_analyzer/database/warning.rb +4 -6
- data/lib/request_log_analyzer/file_format.rb +46 -49
- data/lib/request_log_analyzer/file_format/amazon_s3.rb +15 -19
- data/lib/request_log_analyzer/file_format/apache.rb +42 -45
- data/lib/request_log_analyzer/file_format/delayed_job.rb +13 -15
- data/lib/request_log_analyzer/file_format/delayed_job2.rb +9 -11
- data/lib/request_log_analyzer/file_format/delayed_job21.rb +9 -11
- data/lib/request_log_analyzer/file_format/delayed_job3.rb +5 -8
- data/lib/request_log_analyzer/file_format/delayed_job4.rb +5 -8
- data/lib/request_log_analyzer/file_format/haproxy.rb +44 -48
- data/lib/request_log_analyzer/file_format/merb.rb +13 -17
- data/lib/request_log_analyzer/file_format/mysql.rb +21 -25
- data/lib/request_log_analyzer/file_format/nginx.rb +0 -2
- data/lib/request_log_analyzer/file_format/oink.rb +30 -31
- data/lib/request_log_analyzer/file_format/postgresql.rb +11 -15
- data/lib/request_log_analyzer/file_format/rack.rb +0 -2
- data/lib/request_log_analyzer/file_format/rails.rb +100 -104
- data/lib/request_log_analyzer/file_format/rails3.rb +19 -23
- data/lib/request_log_analyzer/file_format/rails_development.rb +0 -1
- data/lib/request_log_analyzer/file_format/w3c.rb +16 -18
- data/lib/request_log_analyzer/filter.rb +0 -2
- data/lib/request_log_analyzer/filter/anonymize.rb +4 -7
- data/lib/request_log_analyzer/filter/field.rb +3 -6
- data/lib/request_log_analyzer/filter/timespan.rb +2 -6
- data/lib/request_log_analyzer/line_definition.rb +16 -19
- data/lib/request_log_analyzer/log_processor.rb +10 -14
- data/lib/request_log_analyzer/mailer.rb +9 -12
- data/lib/request_log_analyzer/output.rb +12 -14
- data/lib/request_log_analyzer/output/fixed_width.rb +21 -28
- data/lib/request_log_analyzer/output/html.rb +11 -14
- data/lib/request_log_analyzer/request.rb +53 -33
- data/lib/request_log_analyzer/source.rb +2 -5
- data/lib/request_log_analyzer/source/log_parser.rb +9 -16
- data/lib/request_log_analyzer/tracker.rb +10 -12
- data/lib/request_log_analyzer/tracker/duration.rb +4 -6
- data/lib/request_log_analyzer/tracker/frequency.rb +9 -11
- data/lib/request_log_analyzer/tracker/hourly_spread.rb +8 -11
- data/lib/request_log_analyzer/tracker/numeric_value.rb +40 -44
- data/lib/request_log_analyzer/tracker/timespan.rb +5 -8
- data/lib/request_log_analyzer/tracker/traffic.rb +8 -10
- data/lib/request_log_analyzer/version.rb +1 -1
- data/request-log-analyzer.gemspec +6 -6
- data/spec/integration/command_line_usage_spec.rb +33 -33
- data/spec/integration/mailer_spec.rb +181 -185
- data/spec/integration/munin_plugins_rails_spec.rb +20 -20
- data/spec/integration/scout_spec.rb +40 -41
- data/spec/lib/helpers.rb +8 -9
- data/spec/lib/macros.rb +2 -4
- data/spec/lib/matchers.rb +20 -25
- data/spec/lib/mocks.rb +10 -11
- data/spec/lib/testing_format.rb +8 -10
- data/spec/spec_helper.rb +5 -1
- data/spec/unit/aggregator/database_inserter_spec.rb +23 -23
- data/spec/unit/aggregator/summarizer_spec.rb +7 -7
- data/spec/unit/controller/controller_spec.rb +14 -14
- data/spec/unit/controller/log_processor_spec.rb +3 -3
- data/spec/unit/database/base_class_spec.rb +36 -37
- data/spec/unit/database/connection_spec.rb +10 -10
- data/spec/unit/database/database_spec.rb +11 -11
- data/spec/unit/file_format/amazon_s3_format_spec.rb +66 -62
- data/spec/unit/file_format/apache_format_spec.rb +57 -52
- data/spec/unit/file_format/common_regular_expressions_spec.rb +18 -21
- data/spec/unit/file_format/delayed_job21_format_spec.rb +22 -16
- data/spec/unit/file_format/delayed_job2_format_spec.rb +22 -16
- data/spec/unit/file_format/delayed_job3_format_spec.rb +14 -10
- data/spec/unit/file_format/delayed_job4_format_spec.rb +14 -10
- data/spec/unit/file_format/delayed_job_format_spec.rb +12 -12
- data/spec/unit/file_format/file_format_api_spec.rb +19 -19
- data/spec/unit/file_format/format_autodetection_spec.rb +7 -7
- data/spec/unit/file_format/haproxy_format_spec.rb +53 -49
- data/spec/unit/file_format/inheritance_spec.rb +13 -0
- data/spec/unit/file_format/line_definition_spec.rb +35 -33
- data/spec/unit/file_format/merb_format_spec.rb +13 -11
- data/spec/unit/file_format/mysql_format_spec.rb +24 -24
- data/spec/unit/file_format/oink_format_spec.rb +29 -29
- data/spec/unit/file_format/postgresql_format_spec.rb +9 -9
- data/spec/unit/file_format/rack_format_spec.rb +36 -31
- data/spec/unit/file_format/rails3_format_spec.rb +46 -46
- data/spec/unit/file_format/rails_format_spec.rb +52 -53
- data/spec/unit/file_format/w3c_format_spec.rb +27 -24
- data/spec/unit/filter/anonymize_filter_spec.rb +7 -7
- data/spec/unit/filter/field_filter_spec.rb +26 -26
- data/spec/unit/filter/filter_spec.rb +4 -4
- data/spec/unit/filter/timespan_filter_spec.rb +22 -22
- data/spec/unit/mailer_spec.rb +21 -21
- data/spec/unit/request_spec.rb +29 -29
- data/spec/unit/source/log_parser_spec.rb +5 -5
- data/spec/unit/tracker/duration_tracker_spec.rb +23 -23
- data/spec/unit/tracker/frequency_tracker_spec.rb +29 -30
- data/spec/unit/tracker/hourly_spread_spec.rb +35 -35
- data/spec/unit/tracker/numeric_value_tracker_spec.rb +71 -72
- data/spec/unit/tracker/timespan_tracker_spec.rb +31 -31
- data/spec/unit/tracker/tracker_api_spec.rb +43 -44
- data/spec/unit/tracker/traffic_tracker_spec.rb +7 -7
- metadata +38 -35
|
@@ -4,46 +4,45 @@ describe RequestLogAnalyzer::Tracker::Frequency do
|
|
|
4
4
|
|
|
5
5
|
context 'static category' do
|
|
6
6
|
before(:each) do
|
|
7
|
-
@tracker = RequestLogAnalyzer::Tracker::Frequency.new(:
|
|
7
|
+
@tracker = RequestLogAnalyzer::Tracker::Frequency.new(category: :category)
|
|
8
8
|
@tracker.prepare
|
|
9
9
|
end
|
|
10
10
|
|
|
11
|
-
it
|
|
12
|
-
@tracker.update(request(:
|
|
11
|
+
it 'should register a request in the right category' do
|
|
12
|
+
@tracker.update(request(category: 'a', blah: 0.2))
|
|
13
13
|
@tracker.categories.should include('a')
|
|
14
14
|
end
|
|
15
15
|
|
|
16
|
-
it
|
|
17
|
-
@tracker.update(request(:
|
|
18
|
-
@tracker.update(request(:
|
|
19
|
-
@tracker.update(request(:
|
|
16
|
+
it 'should register a request in the right category' do
|
|
17
|
+
@tracker.update(request(category: 'a', blah: 0.2))
|
|
18
|
+
@tracker.update(request(category: 'b', blah: 0.2))
|
|
19
|
+
@tracker.update(request(category: 'b', blah: 0.2))
|
|
20
20
|
|
|
21
21
|
@tracker.frequency('a').should == 1
|
|
22
22
|
@tracker.frequency('b').should == 2
|
|
23
23
|
@tracker.overall_frequency.should == 3
|
|
24
24
|
end
|
|
25
25
|
|
|
26
|
-
it
|
|
27
|
-
@tracker.update(request(:
|
|
28
|
-
@tracker.update(request(:
|
|
29
|
-
@tracker.update(request(:
|
|
26
|
+
it 'should sort correctly by frequency' do
|
|
27
|
+
@tracker.update(request(category: 'a', blah: 0.2))
|
|
28
|
+
@tracker.update(request(category: 'b', blah: 0.2))
|
|
29
|
+
@tracker.update(request(category: 'b', blah: 0.2))
|
|
30
30
|
|
|
31
31
|
@tracker.sorted_by_frequency.should == [['b', 2], ['a', 1]]
|
|
32
32
|
end
|
|
33
33
|
end
|
|
34
|
-
|
|
35
34
|
|
|
36
35
|
context 'dynamic category' do
|
|
37
36
|
before(:each) do
|
|
38
|
-
@categorizer =
|
|
39
|
-
@tracker = RequestLogAnalyzer::Tracker::Frequency.new(:
|
|
37
|
+
@categorizer = proc { |request| request[:duration] > 0.2 ? 'slow' : 'fast' }
|
|
38
|
+
@tracker = RequestLogAnalyzer::Tracker::Frequency.new(category: @categorizer)
|
|
40
39
|
@tracker.prepare
|
|
41
40
|
end
|
|
42
41
|
|
|
43
|
-
it
|
|
44
|
-
@tracker.update(request(:
|
|
45
|
-
@tracker.update(request(:
|
|
46
|
-
@tracker.update(request(:
|
|
42
|
+
it 'should use the categorizer to determine the right category' do
|
|
43
|
+
@tracker.update(request(category: 'a', duration: 0.2))
|
|
44
|
+
@tracker.update(request(category: 'b', duration: 0.3))
|
|
45
|
+
@tracker.update(request(category: 'b', duration: 0.4))
|
|
47
46
|
|
|
48
47
|
@tracker.frequency('fast').should == 1
|
|
49
48
|
@tracker.frequency('slow').should == 2
|
|
@@ -53,36 +52,36 @@ describe RequestLogAnalyzer::Tracker::Frequency do
|
|
|
53
52
|
|
|
54
53
|
describe '#report' do
|
|
55
54
|
before(:each) do
|
|
56
|
-
@tracker = RequestLogAnalyzer::Tracker::Frequency.new(:
|
|
55
|
+
@tracker = RequestLogAnalyzer::Tracker::Frequency.new(category: :category)
|
|
57
56
|
@tracker.prepare
|
|
58
57
|
end
|
|
59
58
|
|
|
60
|
-
it
|
|
61
|
-
@tracker.update(request(:
|
|
59
|
+
it 'should generate a report without errors when one category is present' do
|
|
60
|
+
@tracker.update(request(category: 'a', blah: 0.2))
|
|
62
61
|
lambda { @tracker.report(mock_output) }.should_not raise_error
|
|
63
62
|
end
|
|
64
63
|
|
|
65
|
-
it
|
|
64
|
+
it 'should generate a report without errors when no category is present' do
|
|
66
65
|
lambda { @tracker.report(mock_output) }.should_not raise_error
|
|
67
66
|
end
|
|
68
67
|
|
|
69
|
-
it
|
|
70
|
-
@tracker.update(request(:
|
|
71
|
-
@tracker.update(request(:
|
|
68
|
+
it 'should generate a report without errors when multiple categories are present' do
|
|
69
|
+
@tracker.update(request(category: 'a', blah: 0.2))
|
|
70
|
+
@tracker.update(request(category: 'b', blah: 0.2))
|
|
72
71
|
lambda { @tracker.report(mock_output) }.should_not raise_error
|
|
73
72
|
end
|
|
74
73
|
end
|
|
75
74
|
|
|
76
75
|
describe '#to_yaml_object' do
|
|
77
76
|
before(:each) do
|
|
78
|
-
@tracker = RequestLogAnalyzer::Tracker::Frequency.new(:
|
|
77
|
+
@tracker = RequestLogAnalyzer::Tracker::Frequency.new(category: :category)
|
|
79
78
|
@tracker.prepare
|
|
80
79
|
end
|
|
81
80
|
|
|
82
|
-
it
|
|
83
|
-
@tracker.update(request(:
|
|
84
|
-
@tracker.update(request(:
|
|
85
|
-
@tracker.to_yaml_object.should == {
|
|
81
|
+
it 'should generate a YAML output' do
|
|
82
|
+
@tracker.update(request(category: 'a', blah: 0.2))
|
|
83
|
+
@tracker.update(request(category: 'b', blah: 0.2))
|
|
84
|
+
@tracker.to_yaml_object.should == { 'a' => 1, 'b' => 1 }
|
|
86
85
|
end
|
|
87
86
|
end
|
|
88
87
|
end
|
|
@@ -7,43 +7,43 @@ describe RequestLogAnalyzer::Tracker::HourlySpread do
|
|
|
7
7
|
@tracker.prepare
|
|
8
8
|
end
|
|
9
9
|
|
|
10
|
-
it
|
|
11
|
-
@tracker.update(request(:
|
|
12
|
-
@tracker.update(request(:
|
|
13
|
-
@tracker.update(request(:
|
|
10
|
+
it 'should store timestamps correctly' do
|
|
11
|
+
@tracker.update(request(timestamp: 20_090_102_000_000))
|
|
12
|
+
@tracker.update(request(timestamp: 20_090_101_000_000))
|
|
13
|
+
@tracker.update(request(timestamp: 20_090_103_000_000))
|
|
14
14
|
|
|
15
15
|
@tracker.hour_frequencies[0].should eql(3)
|
|
16
16
|
end
|
|
17
17
|
|
|
18
|
-
it
|
|
19
|
-
@tracker.update(request(:
|
|
20
|
-
@tracker.update(request(:
|
|
21
|
-
@tracker.update(request(:
|
|
22
|
-
@tracker.update(request(:
|
|
18
|
+
it 'should count the number of timestamps correctly' do
|
|
19
|
+
@tracker.update(request(timestamp: 20_090_102_000_000))
|
|
20
|
+
@tracker.update(request(timestamp: 20_090_101_000_000))
|
|
21
|
+
@tracker.update(request(timestamp: 20_090_103_000_000))
|
|
22
|
+
@tracker.update(request(timestamp: 20_090_103_010_000))
|
|
23
23
|
|
|
24
24
|
@tracker.total_requests.should eql(4)
|
|
25
25
|
end
|
|
26
26
|
|
|
27
|
-
it
|
|
28
|
-
@tracker.update(request(:
|
|
29
|
-
@tracker.update(request(:
|
|
30
|
-
@tracker.update(request(:
|
|
27
|
+
it 'should set the first request timestamp correctly' do
|
|
28
|
+
@tracker.update(request(timestamp: 20_090_102_000_000))
|
|
29
|
+
@tracker.update(request(timestamp: 20_090_101_000_000))
|
|
30
|
+
@tracker.update(request(timestamp: 20_090_103_000_000))
|
|
31
31
|
|
|
32
32
|
@tracker.first_timestamp.should == DateTime.parse('Januari 1, 2009 00:00:00')
|
|
33
33
|
end
|
|
34
34
|
|
|
35
|
-
it
|
|
36
|
-
@tracker.update(request(:
|
|
37
|
-
@tracker.update(request(:
|
|
38
|
-
@tracker.update(request(:
|
|
35
|
+
it 'should set the last request timestamp correctly' do
|
|
36
|
+
@tracker.update(request(timestamp: 20_090_102_000_000))
|
|
37
|
+
@tracker.update(request(timestamp: 20_090_101_000_000))
|
|
38
|
+
@tracker.update(request(timestamp: 20_090_103_000_000))
|
|
39
39
|
|
|
40
40
|
@tracker.last_timestamp.should == DateTime.parse('Januari 3, 2009 00:00:00')
|
|
41
41
|
end
|
|
42
42
|
|
|
43
|
-
it
|
|
44
|
-
@tracker.update(request(:
|
|
45
|
-
@tracker.update(request(:
|
|
46
|
-
@tracker.update(request(:
|
|
43
|
+
it 'should return the correct timespan in days when multiple requests are given' do
|
|
44
|
+
@tracker.update(request(timestamp: 20_090_102_000_000))
|
|
45
|
+
@tracker.update(request(timestamp: 20_090_101_000_000))
|
|
46
|
+
@tracker.update(request(timestamp: 20_090_103_000_000))
|
|
47
47
|
|
|
48
48
|
@tracker.timespan.should == 2
|
|
49
49
|
end
|
|
@@ -57,23 +57,23 @@ describe RequestLogAnalyzer::Tracker::HourlySpread, 'reporting' do
|
|
|
57
57
|
@tracker.prepare
|
|
58
58
|
end
|
|
59
59
|
|
|
60
|
-
it
|
|
60
|
+
it 'should generate a report without errors when no request was tracked' do
|
|
61
61
|
lambda { @tracker.report(mock_output) }.should_not raise_error
|
|
62
62
|
end
|
|
63
63
|
|
|
64
|
-
it
|
|
65
|
-
@tracker.update(request(:
|
|
66
|
-
@tracker.update(request(:
|
|
67
|
-
@tracker.update(request(:
|
|
68
|
-
@tracker.update(request(:
|
|
64
|
+
it 'should generate a report without errors when multiple requests were tracked' do
|
|
65
|
+
@tracker.update(request(timestamp: 20_090_102_000_000))
|
|
66
|
+
@tracker.update(request(timestamp: 20_090_101_000_000))
|
|
67
|
+
@tracker.update(request(timestamp: 20_090_103_000_000))
|
|
68
|
+
@tracker.update(request(timestamp: 20_090_103_010_000))
|
|
69
69
|
lambda { @tracker.report(mock_output) }.should_not raise_error
|
|
70
70
|
end
|
|
71
|
-
|
|
72
|
-
it
|
|
73
|
-
@tracker.update(request(:
|
|
74
|
-
@tracker.update(request(:
|
|
75
|
-
@tracker.update(request(:
|
|
76
|
-
@tracker.update(request(:
|
|
77
|
-
@tracker.to_yaml_object.should == {
|
|
71
|
+
|
|
72
|
+
it 'should generate a YAML output' do
|
|
73
|
+
@tracker.update(request(timestamp: 20_090_102_000_000))
|
|
74
|
+
@tracker.update(request(timestamp: 20_090_101_000_000))
|
|
75
|
+
@tracker.update(request(timestamp: 20_090_103_000_000))
|
|
76
|
+
@tracker.update(request(timestamp: 20_090_103_010_000))
|
|
77
|
+
@tracker.to_yaml_object.should == { '22:00 - 23:00' => 0, '9:00 - 10:00' => 0, '7:00 - 8:00' => 0, '2:00 - 3:00' => 0, '12:00 - 13:00' => 0, '11:00 - 12:00' => 0, '16:00 - 17:00' => 0, '15:00 - 16:00' => 0, '19:00 - 20:00' => 0, '3:00 - 4:00' => 0, '21:00 - 22:00' => 0, '20:00 - 21:00' => 0, '14:00 - 15:00' => 0, '13:00 - 14:00' => 0, '4:00 - 5:00' => 0, '10:00 - 11:00' => 0, '18:00 - 19:00' => 0, '17:00 - 18:00' => 0, '8:00 - 9:00' => 0, '6:00 - 7:00' => 0, '5:00 - 6:00' => 0, '1:00 - 2:00' => 1, '0:00 - 1:00' => 3, '23:00 - 24:00' => 0 }
|
|
78
78
|
end
|
|
79
|
-
end
|
|
79
|
+
end
|
|
@@ -4,37 +4,36 @@ describe RequestLogAnalyzer::Tracker::NumericValue do
|
|
|
4
4
|
|
|
5
5
|
context 'static category' do
|
|
6
6
|
before(:each) do
|
|
7
|
-
@tracker = RequestLogAnalyzer::Tracker::NumericValue.new(:
|
|
7
|
+
@tracker = RequestLogAnalyzer::Tracker::NumericValue.new(category: :category, value: :blah)
|
|
8
8
|
@tracker.prepare
|
|
9
9
|
end
|
|
10
10
|
|
|
11
|
-
it
|
|
12
|
-
@tracker.update(request(:
|
|
11
|
+
it 'should register a request in the right category' do
|
|
12
|
+
@tracker.update(request(category: 'a', blah: 2))
|
|
13
13
|
@tracker.categories.should include('a')
|
|
14
14
|
end
|
|
15
15
|
|
|
16
|
-
it
|
|
17
|
-
@tracker.update(request(:
|
|
18
|
-
@tracker.update(request(:
|
|
19
|
-
@tracker.update(request(:
|
|
16
|
+
it 'should register requests in the right category' do
|
|
17
|
+
@tracker.update(request(category: 'a', blah: 2))
|
|
18
|
+
@tracker.update(request(category: 'b', blah: 2))
|
|
19
|
+
@tracker.update(request(category: 'b', blah: 2))
|
|
20
20
|
|
|
21
21
|
@tracker.categories['a'][:sum].should == 2
|
|
22
22
|
@tracker.categories['b'][:sum].should == 4
|
|
23
23
|
end
|
|
24
24
|
end
|
|
25
25
|
|
|
26
|
-
|
|
27
26
|
context 'dynamic category' do
|
|
28
27
|
before(:each) do
|
|
29
|
-
@categorizer =
|
|
30
|
-
@tracker = RequestLogAnalyzer::Tracker::NumericValue.new(:
|
|
28
|
+
@categorizer = proc { |request| request[:duration] > 0.2 ? 'slow' : 'fast' }
|
|
29
|
+
@tracker = RequestLogAnalyzer::Tracker::NumericValue.new(category: @categorizer, value: :blah)
|
|
31
30
|
@tracker.prepare
|
|
32
31
|
end
|
|
33
32
|
|
|
34
|
-
it
|
|
35
|
-
@tracker.update(request(:
|
|
36
|
-
@tracker.update(request(:
|
|
37
|
-
@tracker.update(request(:
|
|
33
|
+
it 'should use the categorizer to determine the right category' do
|
|
34
|
+
@tracker.update(request(category: 'a', duration: 0.2, blah: 2))
|
|
35
|
+
@tracker.update(request(category: 'b', duration: 0.3, blah: 2))
|
|
36
|
+
@tracker.update(request(category: 'b', duration: 0.4, blah: 2))
|
|
38
37
|
|
|
39
38
|
@tracker.categories['fast'][:sum].should == 2
|
|
40
39
|
@tracker.categories['slow'][:sum].should == 4
|
|
@@ -43,57 +42,57 @@ describe RequestLogAnalyzer::Tracker::NumericValue do
|
|
|
43
42
|
|
|
44
43
|
describe '#update' do
|
|
45
44
|
before(:each) do
|
|
46
|
-
@tracker = RequestLogAnalyzer::Tracker::NumericValue.new(:
|
|
47
|
-
:
|
|
45
|
+
@tracker = RequestLogAnalyzer::Tracker::NumericValue.new(value: :duration, category: :category,
|
|
46
|
+
min_bucket_value: 0.0001, max_bucket_value: 1000)
|
|
48
47
|
|
|
49
48
|
@tracker.prepare
|
|
50
49
|
|
|
51
|
-
@tracker.update(request(:
|
|
52
|
-
@tracker.update(request(:
|
|
53
|
-
@tracker.update(request(:
|
|
50
|
+
@tracker.update(request(category: 'a', duration: 0.4))
|
|
51
|
+
@tracker.update(request(category: 'a', duration: 0.2))
|
|
52
|
+
@tracker.update(request(category: 'a', duration: 0.3))
|
|
54
53
|
end
|
|
55
54
|
|
|
56
|
-
it
|
|
55
|
+
it 'should sum of the durations for a category correctly' do
|
|
57
56
|
@tracker.sum('a').should be_within(0.000001).of(0.9)
|
|
58
57
|
end
|
|
59
58
|
|
|
60
|
-
it
|
|
59
|
+
it 'should overall sum of the durations correctly' do
|
|
61
60
|
@tracker.sum_overall.should be_within(0.000001).of(0.9)
|
|
62
61
|
end
|
|
63
62
|
|
|
64
|
-
it
|
|
63
|
+
it 'should keep track of the minimum and maximum duration' do
|
|
65
64
|
@tracker.min('a').should == 0.2
|
|
66
65
|
@tracker.max('a').should == 0.4
|
|
67
66
|
end
|
|
68
67
|
|
|
69
|
-
it
|
|
68
|
+
it 'should calculate the mean duration correctly' do
|
|
70
69
|
@tracker.mean('a').should be_within(0.000001).of(0.3)
|
|
71
70
|
end
|
|
72
71
|
|
|
73
|
-
it
|
|
72
|
+
it 'should calculate the overall mean duration correctly' do
|
|
74
73
|
@tracker.mean_overall.should be_within(0.000001).of(0.3)
|
|
75
74
|
end
|
|
76
75
|
|
|
77
|
-
it
|
|
76
|
+
it 'should calculate the duration variance correctly' do
|
|
78
77
|
@tracker.variance('a').should be_within(0.000001).of(0.01)
|
|
79
78
|
end
|
|
80
79
|
|
|
81
|
-
it
|
|
80
|
+
it 'should calculate the duration standard deviation correctly' do
|
|
82
81
|
@tracker.stddev('a').should be_within(0.000001).of(0.1)
|
|
83
82
|
end
|
|
84
83
|
|
|
85
|
-
it
|
|
86
|
-
@tracker.update(request(:
|
|
87
|
-
@tracker.update(request(:
|
|
88
|
-
@tracker.update(request(:
|
|
89
|
-
@tracker.update(request(:
|
|
90
|
-
@tracker.update(request(:
|
|
91
|
-
@tracker.update(request(:
|
|
92
|
-
@tracker.update(request(:
|
|
84
|
+
it 'should calculate the bucket spread correctly' do
|
|
85
|
+
@tracker.update(request(category: 'a', duration: 0.3))
|
|
86
|
+
@tracker.update(request(category: 'a', duration: 0.3))
|
|
87
|
+
@tracker.update(request(category: 'a', duration: 0.3))
|
|
88
|
+
@tracker.update(request(category: 'a', duration: 0.3))
|
|
89
|
+
@tracker.update(request(category: 'a', duration: 0.3))
|
|
90
|
+
@tracker.update(request(category: 'a', duration: 0.3))
|
|
91
|
+
@tracker.update(request(category: 'a', duration: 0.3))
|
|
93
92
|
# 0.2, 0.3 and 0.4 are already there, so, 10 values in total
|
|
94
|
-
|
|
93
|
+
|
|
95
94
|
@tracker.median('a').should be_within(0.01).of(0.3)
|
|
96
|
-
|
|
95
|
+
|
|
97
96
|
@tracker.percentile_interval('a', 80).begin.should be_within(0.01).of(0.3)
|
|
98
97
|
@tracker.percentile_interval('a', 80).end.should be_within(0.01).of(0.3)
|
|
99
98
|
@tracker.percentile_interval('a', 90).begin.should be_within(0.01).of(0.2)
|
|
@@ -103,85 +102,85 @@ describe RequestLogAnalyzer::Tracker::NumericValue do
|
|
|
103
102
|
|
|
104
103
|
describe '#report' do
|
|
105
104
|
before(:each) do
|
|
106
|
-
@tracker = RequestLogAnalyzer::Tracker::NumericValue.new(:
|
|
105
|
+
@tracker = RequestLogAnalyzer::Tracker::NumericValue.new(category: :category, value: :blah)
|
|
107
106
|
@tracker.prepare
|
|
108
107
|
end
|
|
109
108
|
|
|
110
|
-
it
|
|
111
|
-
@tracker.update(request(:
|
|
109
|
+
it 'should generate a report without errors when one category is present' do
|
|
110
|
+
@tracker.update(request(category: 'a', blah: 2))
|
|
112
111
|
lambda { @tracker.report(mock_output) }.should_not raise_error
|
|
113
112
|
end
|
|
114
113
|
|
|
115
|
-
it
|
|
114
|
+
it 'should generate a report without errors when no category is present' do
|
|
116
115
|
lambda { @tracker.report(mock_output) }.should_not raise_error
|
|
117
116
|
end
|
|
118
117
|
|
|
119
|
-
it
|
|
120
|
-
@tracker.update(request(:
|
|
121
|
-
@tracker.update(request(:
|
|
118
|
+
it 'should generate a report without errors when multiple categories are present' do
|
|
119
|
+
@tracker.update(request(category: 'a', blah: 2))
|
|
120
|
+
@tracker.update(request(category: 'b', blah: 2))
|
|
122
121
|
lambda { @tracker.report(mock_output) }.should_not raise_error
|
|
123
122
|
end
|
|
124
123
|
end
|
|
125
124
|
|
|
126
125
|
describe '#to_yaml_object' do
|
|
127
126
|
before(:each) do
|
|
128
|
-
@tracker = RequestLogAnalyzer::Tracker::NumericValue.new(:
|
|
127
|
+
@tracker = RequestLogAnalyzer::Tracker::NumericValue.new(category: :category, value: :blah)
|
|
129
128
|
@tracker.prepare
|
|
130
129
|
end
|
|
131
130
|
|
|
132
|
-
it
|
|
133
|
-
@tracker.update(request(:
|
|
134
|
-
@tracker.update(request(:
|
|
135
|
-
@tracker.to_yaml_object.keys.should =~
|
|
136
|
-
|
|
137
|
-
@tracker.to_yaml_object['a'].should include(:
|
|
131
|
+
it 'should generate a YAML output' do
|
|
132
|
+
@tracker.update(request(category: 'a', blah: 2))
|
|
133
|
+
@tracker.update(request(category: 'b', blah: 3))
|
|
134
|
+
@tracker.to_yaml_object.keys.should =~ %w(a b)
|
|
135
|
+
|
|
136
|
+
@tracker.to_yaml_object['a'].should include(min: 2, hits: 1, max: 2, mean: 2.0, sum: 2, sum_of_squares: 0.0)
|
|
138
137
|
@tracker.to_yaml_object['a'][:interval_95_percent].should be_member(2)
|
|
139
|
-
|
|
140
|
-
@tracker.to_yaml_object['b'].should include(:
|
|
138
|
+
|
|
139
|
+
@tracker.to_yaml_object['b'].should include(min: 3, hits: 1, max: 3, mean: 3.0, sum: 3, sum_of_squares: 0.0)
|
|
141
140
|
@tracker.to_yaml_object['b'][:interval_95_percent].should be_member(3)
|
|
142
141
|
end
|
|
143
142
|
end
|
|
144
143
|
|
|
145
144
|
describe '#display_value' do
|
|
146
145
|
before(:each) do
|
|
147
|
-
@tracker = RequestLogAnalyzer::Tracker::NumericValue.new(:
|
|
146
|
+
@tracker = RequestLogAnalyzer::Tracker::NumericValue.new(category: :category, value: :blah)
|
|
148
147
|
@tracker.prepare
|
|
149
148
|
end
|
|
150
149
|
|
|
151
|
-
it
|
|
150
|
+
it 'should not crash on nil' do
|
|
152
151
|
lambda { @tracker.display_value(nil) }.should_not raise_error
|
|
153
152
|
@tracker.display_value(nil).should_not be_nil
|
|
154
|
-
@tracker.display_value(nil).should_not eql(
|
|
153
|
+
@tracker.display_value(nil).should_not eql('')
|
|
155
154
|
end
|
|
156
155
|
|
|
157
|
-
it
|
|
156
|
+
it 'should not touch thousands' do
|
|
158
157
|
@tracker.display_value(1000).should eql('1000 ')
|
|
159
158
|
@tracker.display_value(5000).should eql('5000 ')
|
|
160
159
|
@tracker.display_value(9001).should eql('9001 ')
|
|
161
160
|
end
|
|
162
161
|
|
|
163
|
-
it
|
|
164
|
-
@tracker.display_value(
|
|
165
|
-
@tracker.display_value(
|
|
166
|
-
@tracker.display_value(
|
|
162
|
+
it 'should reduce milions to thousands (k)' do
|
|
163
|
+
@tracker.display_value(1_000_000).should eql('1000k')
|
|
164
|
+
@tracker.display_value(5_000_000).should eql('5000k')
|
|
165
|
+
@tracker.display_value(9_000_001).should eql('9000k')
|
|
167
166
|
end
|
|
168
167
|
|
|
169
|
-
it
|
|
170
|
-
@tracker.display_value(
|
|
171
|
-
@tracker.display_value(
|
|
172
|
-
@tracker.display_value(
|
|
168
|
+
it 'should reduce giga to millons (M)' do
|
|
169
|
+
@tracker.display_value(1_000_000_000).should eql('1000M')
|
|
170
|
+
@tracker.display_value(5_000_000_000).should eql('5000M')
|
|
171
|
+
@tracker.display_value(9_000_000_001).should eql('9000M')
|
|
173
172
|
end
|
|
174
173
|
|
|
175
|
-
it
|
|
176
|
-
@tracker.display_value(
|
|
177
|
-
@tracker.display_value(
|
|
178
|
-
@tracker.display_value(
|
|
174
|
+
it 'should reduce teras to gigas (G)' do
|
|
175
|
+
@tracker.display_value(1_000_000_000_000).should eql('1000G')
|
|
176
|
+
@tracker.display_value(5_000_000_000_000).should eql('5000G')
|
|
177
|
+
@tracker.display_value(9_000_000_001_001).should eql('9000G')
|
|
179
178
|
end
|
|
180
179
|
|
|
181
|
-
it
|
|
182
|
-
@tracker.display_value(
|
|
183
|
-
@tracker.display_value(
|
|
184
|
-
@tracker.display_value(
|
|
180
|
+
it 'should reduce petas to teras (T)' do
|
|
181
|
+
@tracker.display_value(1_000_000_000_000_000).should eql('1000T')
|
|
182
|
+
@tracker.display_value(5_000_000_000_000_000).should eql('5000T')
|
|
183
|
+
@tracker.display_value(9_000_000_001_001_000).should eql('9000T')
|
|
185
184
|
end
|
|
186
185
|
end
|
|
187
186
|
end
|