request-log-analyzer 1.9.9 → 1.10.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/spec/spec_helper.rb CHANGED
@@ -1,8 +1,9 @@
1
- $LOAD_PATH << File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
2
-
3
1
  require 'rubygems'
2
+ require 'bundler/setup'
3
+
4
4
  require 'rspec'
5
5
  require 'request_log_analyzer'
6
+ require 'stringio'
6
7
 
7
8
  module RequestLogAnalyzer::RSpec
8
9
  end
@@ -28,6 +28,23 @@ describe RequestLogAnalyzer::FileFormat::Apache do
28
28
  @line_definition.captures?(:duration).should be_true
29
29
  end
30
30
  end
31
+
32
+ describe '.access_line_definition' do
33
+ it "should parse values in microseconds when no argument is given to %D" do
34
+ format = RequestLogAnalyzer::FileFormat::Apache.create('%D')
35
+ format.should parse_line('12345').and_capture(:duration => 0.012345)
36
+ end
37
+
38
+ it "should parse values in microseconds when micro is given as argument to %D" do
39
+ format = RequestLogAnalyzer::FileFormat::Apache.create('%{micro}D')
40
+ format.should parse_line('12345').and_capture(:duration => 0.012345)
41
+ end
42
+
43
+ it "should parse values in microseconds when micro is given as argument to %D" do
44
+ format = RequestLogAnalyzer::FileFormat::Apache.create('%{milli}D')
45
+ format.should parse_line('12345').and_capture(:duration => 12.345)
46
+ end
47
+ end
31
48
 
32
49
  describe '.create' do
33
50
 
@@ -0,0 +1,84 @@
1
+ require 'spec_helper'
2
+
3
+ describe RequestLogAnalyzer::FileFormat::Haproxy do
4
+
5
+ before(:each) do
6
+ @file_format = RequestLogAnalyzer::FileFormat.load(:haproxy)
7
+ @log_parser = RequestLogAnalyzer::Source::LogParser.new(@file_format)
8
+ @sample1 = 'Feb 6 12:14:14 localhost haproxy[14389]: 10.0.1.2:33317 [06/Feb/2009:12:14:14.655] http-in static/srv1 10/0/30/69/109 200 2750 - - ---- 1/1/1/1/0 0/0 {1wt.eu} {} "GET /index.html HTTP/1.1"'
9
+ @sample2 = 'haproxy[18113]: 127.0.0.1:34549 [15/Oct/2003:15:19:06.103] px-http px-http/<NOSRV> -1/-1/-1/-1/+50001 408 +2750 - - cR-- 2/2/2/0/+2 0/0 ""'
10
+ end
11
+
12
+ it "should be a valid file format" do
13
+ @file_format.should be_valid
14
+ end
15
+
16
+ it "should parse access lines and capture all of its fields" do
17
+ @file_format.should have_line_definition(:haproxy).capturing(:client_ip, :accept_date, :frontend_name, :backend_name, :server_name, :tq, :tw, :tc, :tr, :tt, :status_code, :bytes_read, :captured_request_cookie, :captured_response_cookie, :termination_event_code, :terminated_session_state, :clientside_persistence_cookie, :serverside_persistence_cookie, :actconn, :feconn, :beconn, :srv_conn, :retries, :srv_queue, :backend_queue, :captured_request_headers, :captured_response_headers, :http_request)
18
+ end
19
+
20
+ it "should match the sample line" do
21
+ @file_format.parse_line(@sample1).should include(:line_definition, :captures)
22
+ end
23
+
24
+ it "should not match a nonsense line" do
25
+ @file_format.parse_line('dsadasdas dsaadsads dsaadsads').should be_nil
26
+ end
27
+
28
+ it "should parse and convert the sample fields correctly" do
29
+ @log_parser.parse_io(StringIO.new(@sample1)) do |request|
30
+ request[:client_ip].should == '10.0.1.2'
31
+ request[:accept_date].should == 20090206121414
32
+ request[:frontend_name].should == 'http-in'
33
+ request[:backend_name].should == 'static'
34
+ request[:server_name].should == 'srv1'
35
+ request[:tq].should == 0.010
36
+ request[:tw].should == 0.000
37
+ request[:tc].should == 0.030
38
+ request[:tr].should == 0.069
39
+ request[:tt].should == 0.109
40
+ request[:status_code].should == 200
41
+ request[:bytes_read].should == 2750
42
+ request[:captured_request_cookie].should == nil
43
+ request[:captured_response_cookie].should == nil
44
+ request[:termination_event_code].should == nil
45
+ request[:terminated_session_state].should == nil
46
+ request[:clientside_persistence_cookie].should == nil
47
+ request[:serverside_persistence_cookie].should == nil
48
+ request[:actconn].should == 1
49
+ request[:feconn].should == 1
50
+ request[:beconn].should == 1
51
+ request[:srv_conn].should == 1
52
+ request[:retries].should == 0
53
+ request[:srv_queue].should == 0
54
+ request[:backend_queue].should == 0
55
+ request[:captured_request_headers].should == '{1wt.eu}'
56
+ request[:captured_response_headers].should == nil
57
+ request[:http_request].should == 'GET /index.html HTTP/1.1'
58
+ end
59
+ end
60
+
61
+ it "should parse and convert edge case sample fields correctly" do
62
+ @log_parser.parse_io(StringIO.new(@sample2)) do |request|
63
+ request[:accept_date].should == 20031015151906
64
+ request[:server_name].should == '<NOSRV>'
65
+ request[:tq].should == nil
66
+ request[:tw].should == nil
67
+ request[:tc].should == nil
68
+ request[:tr].should == nil
69
+ request[:tt].should == 50.001
70
+ request[:bytes_read].should == 2750
71
+ request[:captured_request_cookie].should == nil
72
+ request[:captured_response_cookie].should == nil
73
+ request[:termination_event_code].should == 'c'
74
+ request[:terminated_session_state].should == 'R'
75
+ request[:clientside_persistence_cookie].should == nil
76
+ request[:serverside_persistence_cookie].should == nil
77
+ request[:retries].should == 2
78
+ request[:captured_request_headers].should == nil
79
+ request[:captured_response_headers].should == nil
80
+ request[:http_request].should == nil
81
+ end
82
+ end
83
+
84
+ end
@@ -2,64 +2,42 @@ require 'spec_helper'
2
2
 
3
3
  describe RequestLogAnalyzer::FileFormat::Postgresql do
4
4
 
5
- it "should be a valid file format" do
6
- RequestLogAnalyzer::FileFormat.load(:Postgresql).should be_valid
7
- end
5
+ subject { RequestLogAnalyzer::FileFormat.load(:Postgresql) }
6
+ let(:log_parser) { RequestLogAnalyzer::Source::LogParser.new(subject) }
7
+
8
+ it { should be_valid }
8
9
 
9
10
  describe '#parse_line' do
10
- before(:each) do
11
- @file_format = RequestLogAnalyzer::FileFormat.load(:Postgresql)
12
- end
13
-
14
11
  it "should parse a :query line correctly" do
15
- line = '2004-05-07 11:58:36 LOG: query: SELECT plugin_id, plugin_name FROM plugins'
16
- @file_format.should parse_line(line).as(:query).and_capture(:timestamp => 20040507115836, :query_fragment => 'SELECT plugin_id, plugin_name FROM plugins')
12
+ line = '2010-10-10 13:52:07 GMT [38747]: [33-1] LOG: 00000: duration: 0.710 ms statement: SELECT * FROM "delayed_jobs"'
13
+ subject.should parse_line(line).as(:query).and_capture(:timestamp => 20101010135207, :query_fragment => 'SELECT * FROM "delayed_jobs"')
17
14
  end
18
15
 
19
16
  it "should parse a :query_fragment line correctly" do
20
- line = ' groups.type_id,users.user_name,users.realname,'
21
- @file_format.should parse_line(line).as(:query_fragment).and_capture(:query_fragment => "groups.type_id,users.user_name,users.realname,")
17
+ line = ' ("failed_at", "locked_by", "created_at", "handler", "updated_at", "priority", "run_at", "attempts", "locked_at",'
18
+ subject.should parse_line(line).as(:query_fragment).and_capture(:query_fragment => '("failed_at", "locked_by", "created_at", "handler", "updated_at", "priority", "run_at", "attempts", "locked_at",')
22
19
  end
23
20
 
24
- it "should parse a :duration line correctly" do
25
- line = '2004-05-07 11:58:36 LOG: duration: 0.002612 sec'
26
- @file_format.should parse_line(line).as(:duration).and_capture(:query_time => 0.002612)
27
- end
21
+ it "should parse a :query line correctly" do
22
+ line = '2010-10-10 13:52:07 GMT [38747]: [33-1] LOG: 00000: duration: 0.710 ms statement: SELECT * FROM "delayed_jobs"'
23
+ subject.should parse_line(line).as(:query).and_capture(:query_time => 0.710)
24
+ end
28
25
  end
29
26
 
30
27
  describe '#parse_io' do
31
- before(:each) do
32
- @log_parser = RequestLogAnalyzer::Source::LogParser.new(RequestLogAnalyzer::FileFormat.load(:postgresql))
33
- end
34
-
35
28
  it "should parse a multiline query entry correctly" do
36
- fixture = <<EOS
37
- 2004-05-07 11:58:22 LOG: query: SELECT groups.group_name,groups.unix_group_name,
38
- groups.type_id,users.user_name,users.realname,
39
- news_bytes.forum_id,news_bytes.summary,news_bytes.post_date,news_bytes.details
40
- FROM users,news_bytes,groups
41
- WHERE news_bytes.group_id='98' AND news_bytes.is_approved <> '4'
42
- AND users.user_id=news_bytes.submitted_by
43
- AND news_bytes.group_id=groups.group_id
44
- ORDER BY post_date DESC LIMIT 10 OFFSET 0
45
- 2004-05-07 11:58:22 LOG: duration: 0.002680 sec
46
- EOS
47
- @log_parser.parse_io(StringIO.new(fixture)) do |request|
48
- request.should be_kind_of(RequestLogAnalyzer::FileFormat::Postgresql::Request)
49
- request[:query].should == "SELECT groups.group_name,groups.unix_group_name, groups.type_id,users.user_name,users.realname, news_bytes.forum_id,news_bytes.summary,news_bytes.post_date,news_bytes.details FROM users,news_bytes,groups WHERE news_bytes.group_id=:string AND news_bytes.is_approved <> :string AND users.user_id=news_bytes.submitted_by AND news_bytes.group_id=groups.group_id ORDER BY post_date DESC LIMIT :int OFFSET :int"
50
- end
51
- end
52
-
53
- it "should parse a dualline query entry correctly" do
54
- fixture = <<EOS
55
- 2004-05-07 11:58:36 LOG: query: SELECT type, count FROM project_sums_agg WHERE group_id=59
56
- 2004-05-07 11:58:36 LOG: duration: 0.001197 sec
57
- EOS
58
- @log_parser.parse_io(StringIO.new(fixture)) do |request|
59
- request.should be_kind_of(RequestLogAnalyzer::FileFormat::Postgresql::Request)
60
- request[:query].should == "SELECT type, count FROM project_sums_agg WHERE group_id=:int"
29
+ fixture = <<-EOS
30
+ 2010-10-10 15:00:02 GMT [38747]: [1669-1] LOG: 00000: duration: 0.195 ms statement: INSERT INTO "delayed_jobs" ("failed_at", "locked_by", "created_at", "handler", "updated_at", "priority", "run_at", "attempts", "locked_at", "last_error") VALUES(NULL, NULL, '2010-10-10 15:00:02.159884', E'--- !ruby/object:RuntheChooChootrain {}
31
+ ', '2010-10-10 15:00:02.159884', 0, '2010-10-10 16:00:00.000000', 0, NULL, NULL) RETURNING "id"
32
+ 2010-10-10 15:00:02 GMT [38747]: [1670-1] LOCATION: exec_simple_query, postgres.c:1081
33
+ EOS
34
+
35
+ request_counter.should_receive(:hit!).exactly(1).times
36
+ log_parser.should_not_receive(:warn)
37
+ log_parser.parse_io(StringIO.new(fixture)) do |request|
38
+ request_counter.hit! if request.kind_of?(RequestLogAnalyzer::FileFormat::Postgresql::Request) && request.completed?
39
+ 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'
61
40
  end
62
41
  end
63
42
  end
64
43
  end
65
-
@@ -44,9 +44,9 @@ describe RequestLogAnalyzer::FileFormat::Rails do
44
44
  end
45
45
 
46
46
  it "should parse :completed lines correctly" do
47
- line = 'Completed 200 OK in 170ms (Views: 78.4ms | ActiveRecord: 48.2ms)'
47
+ line = 'Completed 200 OK in 170ms (Views: 78.0ms | ActiveRecord: 48.2ms)'
48
48
  @file_format.should parse_line(line).as(:completed).and_capture(
49
- :duration => 0.170, :status => 200)
49
+ :duration => 0.170, :view => 0.078, :db => 0.0482, :status => 200)
50
50
  end
51
51
 
52
52
  it "should parse :completed lines correctly when ActiveRecord is not mentioned" do
@@ -54,6 +54,12 @@ describe RequestLogAnalyzer::FileFormat::Rails do
54
54
  @file_format.should parse_line(line).as(:completed).and_capture(:duration => 0.364, :status => 200)
55
55
  end
56
56
 
57
+ it "should parse :completed lines correctly when other durations are specified" do
58
+ line = 'Completed 200 OK in 384ms (Views: 222.0ms | ActiveRecord: 121.0ms | Sphinx: 0.0ms)'
59
+ @file_format.should parse_line(line).as(:completed).and_capture(:duration => 0.384, :view => 0.222,
60
+ :db => 0.121, :status => 200)
61
+ end
62
+
57
63
 
58
64
  it "should pase :failure lines correctly" do
59
65
  line = "ActionView::Template::Error (undefined local variable or method `field' for #<Class>) on line #3 of /Users/willem/Code/warehouse/app/views/queries/execute.csv.erb:"
@@ -0,0 +1,46 @@
1
+ require 'spec_helper'
2
+
3
+ describe RequestLogAnalyzer::FileFormat::W3c do
4
+
5
+ before(:each) do
6
+ @file_format = RequestLogAnalyzer::FileFormat.load(:w3c)
7
+ @log_parser = RequestLogAnalyzer::Source::LogParser.new(@file_format)
8
+ # date time c-ip cs-username s-ip s-port cs-method cs-uri-stem cs-uri-query sc-status sc-bytes cs-bytes time-taken cs(User-Agent) cs(Referrer)
9
+ @sample = '2002-05-24 20:18:01 172.224.24.114 - 206.73.118.24 80 GET /Default.htm - 200 7930 248 31 Mozilla/4.0+(compatible;+MSIE+5.01;+Windows+2000+Server) http://64.224.24.114/'
10
+ end
11
+
12
+ it "should be a valid file format" do
13
+ @file_format.should be_valid
14
+ end
15
+
16
+ it "should parse access lines and capture all of its fields" do
17
+ @file_format.should have_line_definition(:access).capturing(:timestamp, :remote_ip, :username, :local_ip, :port, :method, :path, :http_status, :bytes_sent, :bytes_received, :duration, :user_agent, :referer)
18
+ end
19
+
20
+ it "should match the sample line" do
21
+ @file_format.parse_line(@sample).should include(:line_definition, :captures)
22
+ end
23
+
24
+ it "should not match a nonsense line" do
25
+ @file_format.parse_line('#Software: Microsoft Internet Information Services 6.0').should be_nil
26
+ end
27
+
28
+ it "should parse and convert the sample fields correctly" do
29
+ @log_parser.parse_io(StringIO.new(@sample)) do |request|
30
+ request[:timestamp].should == 20020524201801
31
+ request[:remote_ip].should == "172.224.24.114"
32
+ request[:username].should == nil
33
+ request[:local_ip].should == "206.73.118.24"
34
+ request[:port].should == 80
35
+ request[:method].should == 'GET'
36
+ request[:path].should == '/Default.htm'
37
+ request[:http_status].should == 200
38
+ request[:bytes_sent].should == 7930
39
+ request[:bytes_received].should == 248
40
+ request[:duration].should == 0.031
41
+ request[:user_agent].should == 'Mozilla/4.0+(compatible;+MSIE+5.01;+Windows+2000+Server)'
42
+ request[:referer].should == 'http://64.224.24.114/'
43
+ end
44
+ end
45
+
46
+ end
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 1
7
- - 9
8
- - 9
9
- version: 1.9.9
7
+ - 10
8
+ - 0
9
+ version: 1.10.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Willem van Bergen
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-12-17 00:00:00 -05:00
18
+ date: 2011-02-26 00:00:00 -05:00
19
19
  default_executable: request-log-analyzer
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -84,6 +84,7 @@ extra_rdoc_files:
84
84
  files:
85
85
  - .gitignore
86
86
  - DESIGN.rdoc
87
+ - Gemfile
87
88
  - LICENSE
88
89
  - README.rdoc
89
90
  - Rakefile
@@ -112,6 +113,7 @@ files:
112
113
  - lib/request_log_analyzer/file_format/delayed_job.rb
113
114
  - lib/request_log_analyzer/file_format/delayed_job2.rb
114
115
  - lib/request_log_analyzer/file_format/delayed_job21.rb
116
+ - lib/request_log_analyzer/file_format/haproxy.rb
115
117
  - lib/request_log_analyzer/file_format/merb.rb
116
118
  - lib/request_log_analyzer/file_format/mysql.rb
117
119
  - lib/request_log_analyzer/file_format/oink.rb
@@ -120,6 +122,7 @@ files:
120
122
  - lib/request_log_analyzer/file_format/rails.rb
121
123
  - lib/request_log_analyzer/file_format/rails3.rb
122
124
  - lib/request_log_analyzer/file_format/rails_development.rb
125
+ - lib/request_log_analyzer/file_format/w3c.rb
123
126
  - lib/request_log_analyzer/filter.rb
124
127
  - lib/request_log_analyzer/filter/anonymize.rb
125
128
  - lib/request_log_analyzer/filter/field.rb
@@ -196,6 +199,7 @@ files:
196
199
  - spec/unit/file_format/delayed_job_format_spec.rb
197
200
  - spec/unit/file_format/file_format_api_spec.rb
198
201
  - spec/unit/file_format/format_autodetection_spec.rb
202
+ - spec/unit/file_format/haproxy_format_spec.rb
199
203
  - spec/unit/file_format/line_definition_spec.rb
200
204
  - spec/unit/file_format/merb_format_spec.rb
201
205
  - spec/unit/file_format/mysql_format_spec.rb
@@ -204,6 +208,7 @@ files:
204
208
  - spec/unit/file_format/rack_format_spec.rb
205
209
  - spec/unit/file_format/rails3_format_spec.rb
206
210
  - spec/unit/file_format/rails_format_spec.rb
211
+ - spec/unit/file_format/w3c_format_spec.rb
207
212
  - spec/unit/filter/anonymize_filter_spec.rb
208
213
  - spec/unit/filter/field_filter_spec.rb
209
214
  - spec/unit/filter/filter_spec.rb
@@ -277,6 +282,7 @@ test_files:
277
282
  - spec/unit/file_format/delayed_job_format_spec.rb
278
283
  - spec/unit/file_format/file_format_api_spec.rb
279
284
  - spec/unit/file_format/format_autodetection_spec.rb
285
+ - spec/unit/file_format/haproxy_format_spec.rb
280
286
  - spec/unit/file_format/line_definition_spec.rb
281
287
  - spec/unit/file_format/merb_format_spec.rb
282
288
  - spec/unit/file_format/mysql_format_spec.rb
@@ -285,6 +291,7 @@ test_files:
285
291
  - spec/unit/file_format/rack_format_spec.rb
286
292
  - spec/unit/file_format/rails3_format_spec.rb
287
293
  - spec/unit/file_format/rails_format_spec.rb
294
+ - spec/unit/file_format/w3c_format_spec.rb
288
295
  - spec/unit/filter/anonymize_filter_spec.rb
289
296
  - spec/unit/filter/field_filter_spec.rb
290
297
  - spec/unit/filter/filter_spec.rb