request-log-analyzer 1.10.1 → 1.11.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/bin/request-log-analyzer +0 -1
- data/lib/request_log_analyzer.rb +15 -29
- data/lib/request_log_analyzer/aggregator.rb +5 -5
- data/lib/request_log_analyzer/aggregator/database_inserter.rb +2 -1
- data/lib/request_log_analyzer/controller.rb +0 -3
- data/lib/request_log_analyzer/database.rb +6 -7
- data/lib/request_log_analyzer/file_format.rb +42 -13
- data/lib/request_log_analyzer/file_format/apache.rb +1 -1
- data/lib/request_log_analyzer/file_format/delayed_job2.rb +2 -2
- data/lib/request_log_analyzer/file_format/delayed_job21.rb +2 -2
- data/lib/request_log_analyzer/file_format/haproxy.rb +107 -13
- data/lib/request_log_analyzer/file_format/mysql.rb +5 -5
- data/lib/request_log_analyzer/file_format/rails3.rb +7 -0
- data/lib/request_log_analyzer/filter.rb +4 -5
- data/lib/request_log_analyzer/line_definition.rb +6 -4
- data/lib/request_log_analyzer/output.rb +3 -5
- data/lib/request_log_analyzer/source.rb +3 -4
- data/lib/request_log_analyzer/source/log_parser.rb +56 -4
- data/lib/request_log_analyzer/tracker.rb +8 -8
- data/request-log-analyzer.gemspec +3 -3
- data/spec/fixtures/mysql_slow_query.log +0 -1
- data/spec/integration/command_line_usage_spec.rb +0 -5
- data/spec/lib/helpers.rb +2 -2
- data/spec/lib/matchers.rb +38 -7
- data/spec/lib/mocks.rb +1 -5
- data/spec/unit/database/base_class_spec.rb +1 -0
- data/spec/unit/file_format/amazon_s3_format_spec.rb +58 -55
- data/spec/unit/file_format/apache_format_spec.rb +74 -162
- data/spec/unit/file_format/common_regular_expressions_spec.rb +51 -26
- data/spec/unit/file_format/delayed_job21_format_spec.rb +22 -31
- data/spec/unit/file_format/delayed_job2_format_spec.rb +27 -32
- data/spec/unit/file_format/delayed_job_format_spec.rb +44 -63
- data/spec/unit/file_format/haproxy_format_spec.rb +69 -71
- data/spec/unit/file_format/line_definition_spec.rb +26 -33
- data/spec/unit/file_format/merb_format_spec.rb +22 -37
- data/spec/unit/file_format/mysql_format_spec.rb +80 -123
- data/spec/unit/file_format/oink_format_spec.rb +29 -61
- data/spec/unit/file_format/postgresql_format_spec.rb +2 -4
- data/spec/unit/file_format/rack_format_spec.rb +49 -44
- data/spec/unit/file_format/rails3_format_spec.rb +17 -20
- data/spec/unit/file_format/rails_format_spec.rb +52 -68
- data/spec/unit/file_format/w3c_format_spec.rb +40 -39
- data/spec/unit/source/log_parser_spec.rb +1 -1
- metadata +4 -7
- data/lib/mixins/gets_memory_protection.rb +0 -80
- data/lib/request_log_analyzer/output/fancy_html.rb +0 -44
- data/lib/request_log_analyzer/source/database_loader.rb +0 -87
@@ -2,51 +2,36 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe RequestLogAnalyzer::FileFormat::Merb do
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
subject { RequestLogAnalyzer::FileFormat.load(:merb) }
|
6
|
+
|
7
|
+
it { should be_well_formed }
|
8
|
+
it { should have_line_definition(:started).capturing(:timestamp) }
|
9
|
+
it { should have_line_definition(:params).capturing(:controller, :action, :namespace) }
|
10
|
+
it { should have_line_definition(:completed).capturing(:dispatch_time, :before_filters_time, :action_time, :after_filters_time) }
|
11
|
+
it { should have(4).report_trackers }
|
8
12
|
|
9
13
|
describe '#parse_line' do
|
10
|
-
|
11
|
-
|
12
|
-
|
14
|
+
let(:started_sample) { '~ Started request handling: Fri Aug 29 11:10:23 +0200 2008' }
|
15
|
+
let(:prefixed_started_sample) { '~ Aug 31 18:35:24 typekit-web001 merb: ~ Started request handling: Mon Aug 31 18:35:25 +0000 2009' }
|
16
|
+
let(:params_sample) { '~ Params: {"_method"=>"delete", "authenticity_token"=>"[FILTERED]", "action"=>"delete", "controller"=>"session"}' }
|
17
|
+
let(:completed_sample) { '~ {:dispatch_time=>0.006117, :after_filters_time=>6.1e-05, :before_filters_time=>0.000712, :action_time=>0.005833}' }
|
13
18
|
|
14
|
-
it
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
it "should parse a prefixed :started line correctly" do
|
20
|
-
line = '~ Aug 31 18:35:24 typekit-web001 merb: ~ Started request handling: Mon Aug 31 18:35:25 +0000 2009'
|
21
|
-
@file_format.should parse_line(line).as(:started).and_capture(:timestamp => 20090831183525)
|
22
|
-
end
|
19
|
+
it { should parse_line(started_sample, 'without prefix').as(:started).and_capture(:timestamp => 20080829111023) }
|
20
|
+
it { should parse_line(prefixed_started_sample, 'with prefix').as(:started).and_capture(:timestamp => 20090831183525) }
|
21
|
+
it { should parse_line(params_sample).as(:params).and_capture(:controller => 'session', :action => 'delete', :namespace => nil) }
|
22
|
+
it { should parse_line(completed_sample).as(:completed).and_capture(:dispatch_time => 0.006117,
|
23
|
+
:before_filters_time => 0.000712, :action_time => 0.005833, :after_filters_time => 6.1e-05) }
|
23
24
|
|
24
|
-
it
|
25
|
-
line = '~ Params: {"_method"=>"delete", "authenticity_token"=>"[FILTERED]", "action"=>"delete", "controller"=>"session"}'
|
26
|
-
@file_format.should parse_line(line).as(:params).and_capture(:controller => 'session', :action => 'delete', :namespace => nil)
|
27
|
-
end
|
28
|
-
|
29
|
-
it "should parse a :completed line correctly" do
|
30
|
-
line = '~ {:dispatch_time=>0.006117, :after_filters_time=>6.1e-05, :before_filters_time=>0.000712, :action_time=>0.005833}'
|
31
|
-
@file_format.should parse_line(line).as(:completed).and_capture(:dispatch_time => 0.006117,
|
32
|
-
:before_filters_time => 0.000712, :action_time => 0.005833, :after_filters_time => 6.1e-05)
|
33
|
-
end
|
25
|
+
it { should_not parse_line('~ nonsense', 'a nonsense line') }
|
34
26
|
end
|
35
27
|
|
36
28
|
describe '#parse_io' do
|
37
|
-
|
38
|
-
@log_parser = RequestLogAnalyzer::Source::LogParser.new(RequestLogAnalyzer::FileFormat.load(:merb))
|
39
|
-
end
|
29
|
+
let(:log_parser) { RequestLogAnalyzer::Source::LogParser.new(subject) }
|
40
30
|
|
41
|
-
it "should parse a
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
end
|
46
|
-
|
47
|
-
it "should find 11 completed requests" do
|
48
|
-
@log_parser.should_receive(:handle_request).exactly(11).times
|
49
|
-
@log_parser.parse_file(log_fixture(:merb))
|
31
|
+
it "should parse a log fragment correctly without warnings" do
|
32
|
+
log_parser.should_receive(:handle_request).exactly(11).times
|
33
|
+
log_parser.should_not_receive(:warn)
|
34
|
+
log_parser.parse_file(log_fixture(:merb))
|
50
35
|
end
|
51
36
|
end
|
52
37
|
end
|
@@ -2,153 +2,110 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe RequestLogAnalyzer::FileFormat::Mysql do
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
5
|
+
subject { RequestLogAnalyzer::FileFormat.load(:mysql) }
|
6
|
+
|
7
|
+
it { should be_well_formed }
|
8
|
+
it { should have_line_definition(:time).capturing(:timestamp) }
|
9
|
+
it { should have_line_definition(:user_host).capturing(:user, :host, :ip) }
|
10
|
+
it { should have_line_definition(:query_statistics).capturing(:query_time, :lock_time, :rows_sent, :rows_examined) }
|
11
|
+
it { should have_line_definition(:use_database).capturing(:database) }
|
12
|
+
it { should have_line_definition(:query_part).capturing(:query_fragment) }
|
13
|
+
it { should have_line_definition(:query).capturing(:query) }
|
14
|
+
it { should have(7).report_trackers }
|
15
|
+
|
9
16
|
describe '#parse_line' do
|
10
|
-
before(:each) do
|
11
|
-
@file_format = RequestLogAnalyzer::FileFormat.load(:mysql)
|
12
|
-
end
|
13
|
-
|
14
|
-
it "should parse a :time line correctly" do
|
15
|
-
line = '# Time: 091112 8:13:56'
|
16
|
-
@file_format.should parse_line(line).as(:time).and_capture(:timestamp => 20091112081356)
|
17
|
-
end
|
18
|
-
|
19
|
-
it "should parse a :user_host line correctly with IP present" do
|
20
|
-
line = '# User@Host: admin[admin] @ db1 [10.0.0.1]'
|
21
|
-
@file_format.should parse_line(line).as(:user_host).and_capture(:user => "admin", :host => 'db1', :ip => '10.0.0.1')
|
22
|
-
end
|
23
|
-
|
24
|
-
it "should parse a :user_host line correctly without a host" do
|
25
|
-
line = '# User@Host: admin[admin] @ [10.0.0.1]'
|
26
|
-
@file_format.should parse_line(line).as(:user_host).and_capture(:user => "admin", :host => '', :ip => '10.0.0.1')
|
27
|
-
end
|
28
|
-
|
29
|
-
it "should parse a :user_host line correctly with IP absent" do
|
30
|
-
line = '# User@Host: root[root] @ localhost []'
|
31
|
-
@file_format.should parse_line(line).as(:user_host).and_capture(:user => "root", :host => 'localhost', :ip => "")
|
32
|
-
end
|
33
|
-
|
34
|
-
it "should parse a :query_statistics line" do
|
35
|
-
line = '# Query_time: 10 Lock_time: 0 Rows_sent: 1191307 Rows_examined: 1191307'
|
36
|
-
@file_format.should parse_line(line).as(:query_statistics).and_capture(:query_time => 10.0,
|
37
|
-
:lock_time => 0.0, :rows_sent => 1191307, :rows_examined => 1191307)
|
38
|
-
end
|
39
|
-
|
40
|
-
it "should parse a :query_statistics line with floating point durations" do
|
41
|
-
line = '# Query_time: 10.00000 Lock_time: 0.00000 Rows_sent: 1191307 Rows_examined: 1191307'
|
42
|
-
@file_format.should parse_line(line).as(:query_statistics).and_capture(:query_time => 10.0,
|
43
|
-
:lock_time => 0.0, :rows_sent => 1191307, :rows_examined => 1191307)
|
44
|
-
end
|
45
|
-
|
46
|
-
it "should parse a :query_part line" do
|
47
|
-
line = ' AND clients.index > 0'
|
48
|
-
@file_format.should parse_line(line).as(:query_part).and_capture(:query_fragment => line)
|
49
|
-
end
|
50
17
|
|
51
|
-
|
52
|
-
|
53
|
-
@
|
54
|
-
'
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
it
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
it
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
18
|
+
let(:time_sample) { '# Time: 091112 8:13:56' }
|
19
|
+
let(:user_host_sample) { '# User@Host: admin[admin] @ db1 [10.0.0.1]' }
|
20
|
+
let(:user_host_wo_host_sample) { '# User@Host: admin[admin] @ [10.0.0.1]' }
|
21
|
+
let(:user_host_wo_ip_sample) { '# User@Host: root[root] @ localhost []' }
|
22
|
+
let(:float_query_statistics_sample) { '# Query_time: 10 Lock_time: 0 Rows_sent: 1191307 Rows_examined: 1191307' }
|
23
|
+
let(:int_query_statistics_sample) { '# Query_time: 10.00000 Lock_time: 0.00000 Rows_sent: 1191307 Rows_examined: 1191307' }
|
24
|
+
let(:partial_query_sample) { 'AND clients.index > 0' }
|
25
|
+
let(:full_query_sample) { 'SELECT /*!40001 SQL_NO_CACHE */ * FROM `events`; ' }
|
26
|
+
let(:use_db_sample) { 'use db;' }
|
27
|
+
let(:set_timestamp_sample) { 'SET timestamp=1250651725;' }
|
28
|
+
let(:set_insertid_sample) { 'SET insert_id=1250651725;' }
|
29
|
+
let(:set_timestamp_insertid_sample) { 'SET timestamp=1250651725, insert_id=45674;' }
|
30
|
+
|
31
|
+
it { should parse_line(time_sample).as(:time).and_capture(:timestamp => 20091112081356) }
|
32
|
+
it { should parse_line(user_host_sample).as(:user_host).and_capture(:user => "admin", :host => 'db1', :ip => '10.0.0.1') }
|
33
|
+
it { should parse_line(user_host_wo_host_sample, 'without host').as(:user_host).and_capture(:user => "admin", :host => '', :ip => '10.0.0.1') }
|
34
|
+
it { should parse_line(user_host_wo_ip_sample, 'without IP').as(:user_host).and_capture(:user => "root", :host => 'localhost', :ip => "") }
|
35
|
+
it { should parse_line(float_query_statistics_sample, 'using floats').as(:query_statistics).and_capture(:query_time => 10.0, :lock_time => 0.0, :rows_sent => 1191307, :rows_examined => 1191307) }
|
36
|
+
it { should parse_line(int_query_statistics_sample, 'using integers').as(:query_statistics).and_capture(:query_time => 10.0, :lock_time => 0.0, :rows_sent => 1191307, :rows_examined => 1191307) }
|
37
|
+
it { should parse_line(partial_query_sample).as(:query_part).and_capture(:query_fragment => 'AND clients.index > 0') }
|
38
|
+
it { should parse_line(full_query_sample).as(:query).and_capture(:query => 'SELECT /*!:int SQL_NO_CACHE */ * FROM events') }
|
39
|
+
it { should parse_line(use_db_sample).as(:use_database).and_capture(:database => 'db') }
|
40
|
+
|
41
|
+
it { should_not parse_line(set_timestamp_sample) }
|
42
|
+
it { should_not parse_line(set_insertid_sample) }
|
43
|
+
it { should_not parse_line(set_timestamp_insertid_sample) }
|
78
44
|
end
|
79
45
|
|
80
46
|
describe '#parse_io' do
|
81
|
-
|
82
|
-
@log_parser = RequestLogAnalyzer::Source::LogParser.new(RequestLogAnalyzer::FileFormat.load(:mysql))
|
83
|
-
end
|
47
|
+
let(:log_parser) { RequestLogAnalyzer::Source::LogParser.new(subject) }
|
84
48
|
|
85
49
|
it "should parse a single line query entry correctly" do
|
86
|
-
fixture =
|
87
|
-
# Time: 091112 18:13:56
|
88
|
-
# User@Host: admin[admin] @ db1 [10.0.0.1]
|
89
|
-
# Query_time: 10 Lock_time: 0 Rows_sent: 1191307 Rows_examined: 1191307
|
90
|
-
SELECT /*!40001 SQL_NO_CACHE */ * FROM `events`;
|
91
|
-
EOS
|
92
|
-
|
93
|
-
|
50
|
+
fixture = <<-EOS
|
51
|
+
# Time: 091112 18:13:56
|
52
|
+
# User@Host: admin[admin] @ db1 [10.0.0.1]
|
53
|
+
# Query_time: 10 Lock_time: 0 Rows_sent: 1191307 Rows_examined: 1191307
|
54
|
+
SELECT /*!40001 SQL_NO_CACHE */ * FROM `events`;
|
55
|
+
EOS
|
56
|
+
|
57
|
+
log_parser.parse_string(fixture) do |request|
|
94
58
|
request[:query].should == 'SELECT /*!:int SQL_NO_CACHE */ * FROM events'
|
95
59
|
end
|
96
60
|
end
|
97
61
|
|
98
62
|
it "should parse a multiline query entry correctly" do
|
99
|
-
fixture =
|
100
|
-
# Time: 091112 18:13:56
|
101
|
-
# User@Host: admin[admin] @ db1 [10.0.0.1]
|
102
|
-
# Query_time: 10 Lock_time: 0 Rows_sent: 1191307 Rows_examined: 1191307
|
103
|
-
SELECT * FROM `clients` WHERE (1=1
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
EOS
|
108
|
-
|
109
|
-
|
63
|
+
fixture = <<-EOS
|
64
|
+
# Time: 091112 18:13:56
|
65
|
+
# User@Host: admin[admin] @ db1 [10.0.0.1]
|
66
|
+
# Query_time: 10 Lock_time: 0 Rows_sent: 1191307 Rows_examined: 1191307
|
67
|
+
SELECT * FROM `clients` WHERE (1=1
|
68
|
+
AND clients.valid_from < '2009-12-05' AND (clients.valid_to IS NULL or clients.valid_to > '2009-11-20')
|
69
|
+
AND clients.index > 0
|
70
|
+
) AND (clients.deleted_at IS NULL);
|
71
|
+
EOS
|
72
|
+
|
73
|
+
log_parser.parse_string(fixture) do |request|
|
110
74
|
request[:query].should == "SELECT * FROM clients WHERE (:int=:int AND clients.valid_from < :date AND (clients.valid_to IS NULL or clients.valid_to > :date) AND clients.index > :int ) AND (clients.deleted_at IS NULL)"
|
111
75
|
end
|
112
76
|
end
|
113
77
|
|
114
|
-
it "should parse a request without timestamp correctly" do
|
115
|
-
fixture =
|
116
|
-
# User@Host: admin[admin] @ db1 [10.0.0.1]
|
117
|
-
# Query_time: 10 Lock_time: 0 Rows_sent: 1191307 Rows_examined: 1191307
|
118
|
-
SELECT /*!40001 SQL_NO_CACHE */ * FROM `events`;
|
119
|
-
EOS
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
request_counter.hit! if request.kind_of?(RequestLogAnalyzer::FileFormat::Mysql::Request) && request.completed?
|
125
|
-
end
|
78
|
+
it "should parse a request without timestamp correctly, without warnings" do
|
79
|
+
fixture = <<-EOS
|
80
|
+
# User@Host: admin[admin] @ db1 [10.0.0.1]
|
81
|
+
# Query_time: 10 Lock_time: 0 Rows_sent: 1191307 Rows_examined: 1191307
|
82
|
+
SELECT /*!40001 SQL_NO_CACHE */ * FROM `events`;
|
83
|
+
EOS
|
84
|
+
|
85
|
+
log_parser.should_receive(:handle_request).once
|
86
|
+
log_parser.should_not_receive(:warn)
|
87
|
+
log_parser.parse_string(fixture)
|
126
88
|
end
|
127
89
|
|
128
90
|
it "should parse a query with context information correctly" do
|
129
|
-
fixture =
|
130
|
-
# Time: 091112 18:13:56
|
131
|
-
# User@Host: admin[admin] @ db1 [10.0.0.1]
|
132
|
-
# Query_time: 10 Lock_time: 0 Rows_sent: 1191307 Rows_examined: 1191307
|
133
|
-
use database_name;
|
134
|
-
SET timestamp=4324342342423, insert_id = 224253443;
|
135
|
-
SELECT /*!40001 SQL_NO_CACHE */ * FROM `events`;
|
136
|
-
EOS
|
137
|
-
|
138
|
-
|
139
|
-
@log_parser.should_not_receive(:warn)
|
140
|
-
|
141
|
-
@log_parser.parse_io(StringIO.new(fixture)) do |request|
|
142
|
-
request_counter.hit! if request.kind_of?(RequestLogAnalyzer::FileFormat::Mysql::Request) && request.completed?
|
91
|
+
fixture = <<-EOS
|
92
|
+
# Time: 091112 18:13:56
|
93
|
+
# User@Host: admin[admin] @ db1 [10.0.0.1]
|
94
|
+
# Query_time: 10 Lock_time: 0 Rows_sent: 1191307 Rows_examined: 1191307
|
95
|
+
use database_name;
|
96
|
+
SET timestamp=4324342342423, insert_id = 224253443;
|
97
|
+
SELECT /*!40001 SQL_NO_CACHE */ * FROM `events`;
|
98
|
+
EOS
|
99
|
+
|
100
|
+
log_parser.parse_string(fixture) do |request|
|
143
101
|
request[:query].should == 'SELECT /*!:int SQL_NO_CACHE */ * FROM events'
|
144
102
|
end
|
145
|
-
|
146
103
|
end
|
147
104
|
|
148
|
-
|
149
105
|
it "should find 26 completed sloq query entries" do
|
150
|
-
|
151
|
-
|
106
|
+
log_parser.should_not_receive(:warn)
|
107
|
+
log_parser.should_receive(:handle_request).exactly(26).times
|
108
|
+
log_parser.parse_file(log_fixture(:mysql_slow_query))
|
152
109
|
end
|
153
110
|
end
|
154
111
|
end
|
@@ -1,103 +1,71 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe RequestLogAnalyzer::FileFormat::Oink do
|
4
|
-
describe '.create' do
|
5
4
|
|
6
|
-
|
7
|
-
before(:each) { @oink = RequestLogAnalyzer::FileFormat.load(:oink) }
|
8
|
-
|
9
|
-
it "should create a valid file format" do
|
10
|
-
@oink.should be_valid
|
11
|
-
end
|
12
|
-
|
13
|
-
it "should parse :memory_usage line" do
|
14
|
-
@oink.line_definitions.should include(:memory_usage)
|
15
|
-
end
|
16
|
-
|
17
|
-
end
|
18
|
-
|
19
|
-
end
|
5
|
+
subject { RequestLogAnalyzer::FileFormat.load(:oink) }
|
20
6
|
|
7
|
+
it { should have_line_definition(:memory_usage).capturing(:pid, :memory) }
|
8
|
+
it { should have_line_definition(:processing).capturing(:pid, :controller, :action, :ip) }
|
9
|
+
it { should have_line_definition(:instance_type_counter).capturing(:pid, :instance_counts) }
|
10
|
+
it { should have(12).report_trackers }
|
11
|
+
|
21
12
|
describe '#parse_line' do
|
22
|
-
|
23
|
-
|
13
|
+
let(:memory_usage_sample) { 'Jun 18 11:27:36 derek rails[67783]: Memory usage: 714052 | PID: 67783' }
|
14
|
+
let(:processing_sample) { 'Aug 14 21:16:30 derek rails[67783]: Processing PeopleController#index (for 1.1.1.1 at 2008-08-14 21:16:30) [GET]' }
|
15
|
+
let(:instance_type_counter_sample) { "Dec 13 12:00:44 storenvy rails[26364]: Instantiation Breakdown: Total: 732 | User: 376 | Post: 323 | Comment: 32 | Blog: 1" }
|
16
|
+
|
24
17
|
it "should parse a :memory_usage line correctly" do
|
25
|
-
|
26
|
-
@oink.should parse_line(line).as(:memory_usage).and_capture(:pid => 67783, :memory => 714052)
|
18
|
+
subject.should parse_line(memory_usage_sample).as(:memory_usage).and_capture(:pid => 67783, :memory => 714052)
|
27
19
|
end
|
28
20
|
|
29
21
|
it "should parse the PID from a :processing line correctly" do
|
30
|
-
|
31
|
-
@oink.should parse_line(line).as(:processing).and_capture(:pid => 67783, :controller => 'PeopleController', :action => 'index', :timestamp => 20080814211630, :method => 'GET', :ip => '1.1.1.1')
|
22
|
+
subject.should parse_line(processing_sample).as(:processing).and_capture(:pid => 67783, :controller => 'PeopleController', :action => 'index', :timestamp => 20080814211630, :method => 'GET', :ip => '1.1.1.1')
|
32
23
|
end
|
33
24
|
|
34
25
|
it "should parse a :instance_type_counter correctly" do
|
35
|
-
|
36
|
-
line = "Dec 13 12:00:44 storenvy rails[26364]: Instantiation Breakdown: Total: 732 | User: 376 | Post: 323 | Comment: 32 | Blog: 1"
|
37
|
-
|
38
|
-
@oink.should parse_line(line).as(:instance_type_counter).and_capture(:pid => 26364, :instance_counts => {'Total' => 732, 'User' => 376, 'Post' => 323, 'Comment' => 32, 'Blog' => 1})
|
26
|
+
subject.should parse_line(instance_type_counter_sample).as(:instance_type_counter).and_capture(:pid => 26364, :instance_counts => {'Total' => 732, 'User' => 376, 'Post' => 323, 'Comment' => 32, 'Blog' => 1})
|
39
27
|
end
|
40
28
|
end
|
41
29
|
|
42
30
|
describe '#parse_io' do
|
31
|
+
let(:log_parser) { RequestLogAnalyzer::Source::LogParser.new(subject) }
|
32
|
+
|
43
33
|
context "Rails 2.2 style log" do
|
44
|
-
before(:each) do
|
45
|
-
@log_parser = RequestLogAnalyzer::Source::LogParser.new(
|
46
|
-
RequestLogAnalyzer::FileFormat.load(:oink), :parse_strategy => 'cautious')
|
47
|
-
end
|
48
|
-
|
49
34
|
it "should parse requests" do
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
request_counter.hit! if request.kind_of?(RequestLogAnalyzer::FileFormat::Rails::Request) && request.completed?
|
54
|
-
end
|
35
|
+
log_parser.should_receive(:handle_request).exactly(4).times
|
36
|
+
log_parser.should_not_receive(:warn)
|
37
|
+
log_parser.parse_file(log_fixture(:oink_22))
|
55
38
|
end
|
56
39
|
|
57
40
|
it "should not record :memory_diff on first request" do
|
58
|
-
|
59
|
-
if
|
60
|
-
request[:memory_diff].should == nil
|
61
|
-
end
|
41
|
+
log_parser.parse_file(log_fixture(:oink_22)) do |request|
|
42
|
+
request[:memory_diff].should == nil if log_parser.parsed_requests == 1
|
62
43
|
end
|
63
44
|
end
|
64
45
|
|
65
46
|
it "should record :memory_diff of 2nd tracked PID" do
|
66
|
-
|
67
|
-
if
|
68
|
-
request[:memory_diff].should == 50000*1024
|
69
|
-
end
|
47
|
+
log_parser.parse_file(log_fixture(:oink_22)) do |request|
|
48
|
+
request[:memory_diff].should == 50000 * 1024 if log_parser.parsed_requests == 3
|
70
49
|
end
|
71
50
|
end
|
72
51
|
|
73
52
|
it "should record :memory_diff of 1st tracked PID" do
|
74
|
-
|
75
|
-
if
|
76
|
-
request[:memory_diff].should == 30000*1024
|
77
|
-
end
|
53
|
+
log_parser.parse_file(log_fixture(:oink_22)) do |request|
|
54
|
+
request[:memory_diff].should == 30000 * 1024 if log_parser.parsed_requests == 4
|
78
55
|
end
|
79
56
|
end
|
80
57
|
end
|
81
58
|
|
82
59
|
context 'Rails 2.2 style log w/failure' do
|
83
|
-
before(:each) do
|
84
|
-
@log_parser = RequestLogAnalyzer::Source::LogParser.new(
|
85
|
-
RequestLogAnalyzer::FileFormat.load(:oink), :parse_strategy => 'cautious')
|
86
|
-
end
|
87
|
-
|
88
60
|
it "should parse requests" do
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
request_counter.hit! if request.kind_of?(RequestLogAnalyzer::FileFormat::Rails::Request) && request.completed?
|
93
|
-
end
|
61
|
+
log_parser.should_receive(:handle_request).exactly(4).times
|
62
|
+
log_parser.should_not_receive(:warn)
|
63
|
+
log_parser.parse_file(log_fixture(:oink_22_failure))
|
94
64
|
end
|
95
65
|
|
96
66
|
it "should ignore memory changes when a failure occurs" do
|
97
|
-
|
98
|
-
if
|
99
|
-
request[:memory_diff].should == nil
|
100
|
-
end
|
67
|
+
log_parser.parse_file(log_fixture(:oink_22_failure)) do |request|
|
68
|
+
request[:memory_diff].should == nil if log_parser.parsed_requests == 4
|
101
69
|
end
|
102
70
|
end
|
103
71
|
end
|
@@ -5,7 +5,7 @@ describe RequestLogAnalyzer::FileFormat::Postgresql do
|
|
5
5
|
subject { RequestLogAnalyzer::FileFormat.load(:Postgresql) }
|
6
6
|
let(:log_parser) { RequestLogAnalyzer::Source::LogParser.new(subject) }
|
7
7
|
|
8
|
-
it { should
|
8
|
+
it { should be_well_formed }
|
9
9
|
|
10
10
|
describe '#parse_line' do
|
11
11
|
it "should parse a :query line correctly" do
|
@@ -32,10 +32,8 @@ describe RequestLogAnalyzer::FileFormat::Postgresql do
|
|
32
32
|
2010-10-10 15:00:02 GMT [38747]: [1670-1] LOCATION: exec_simple_query, postgres.c:1081
|
33
33
|
EOS
|
34
34
|
|
35
|
-
request_counter.should_receive(:hit!).exactly(1).times
|
36
35
|
log_parser.should_not_receive(:warn)
|
37
|
-
log_parser.
|
38
|
-
request_counter.hit! if request.kind_of?(RequestLogAnalyzer::FileFormat::Postgresql::Request) && request.completed?
|
36
|
+
log_parser.parse_string(fixture) do |request|
|
39
37
|
request[:query].should == 'INSERT INTO delayed_jobs (failed_at, locked_by, created_at, handler, updated_at, priority, run_at, attempts, locked_at, last_error) VALUES(NULL, NULL, :string, E:string, :string, :int, :string, :int, NULL, NULL) RETURNING id'
|
40
38
|
end
|
41
39
|
end
|