evidence 0.0.5 → 0.0.6

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f2314c07b4b1873ae89834bd97ac81be2f0c1783
4
- data.tar.gz: b297e819e4f1792b05dc3a49dde97066378aed13
3
+ metadata.gz: c4452c553dbfd933c77777214e88a3c6651b6d6b
4
+ data.tar.gz: 20caf0f7e7237d665f7198020b6ed992191e7c0e
5
5
  SHA512:
6
- metadata.gz: 28d755cd6038e0c97bbee4ea1da7ed25940aaa8162887685a0da565b708c30cedcae3720ef0568d1d38fae1ee9560ce2a310fa01dafa3cc02c085b2f7745802d
7
- data.tar.gz: 763e35c45812f677a1dc0448b80eab549396913cad12033dca7d5543ea822e63f0945ec746857460483c1dfbf4ebfe179f77bb3d561a7ebb97a7e34352665ff1
6
+ metadata.gz: 2df08138de4eb510a9ae6c055c780e8e2131df176dbb7552f53f72344f1a9707ad058970519f4e8786a492a0ef96915df4af7517429bb23d8d684fed1d8b64a1
7
+ data.tar.gz: 3b8c55e4d356e7074011ed7e074d3ff1dcea185f012b80d451763dc6807c53188cee143445dedbba58a8796903b79e85d17ecfce9c465d76eeac35692b964b32
@@ -0,0 +1,55 @@
1
+ module Evidence
2
+ class ActionParser
3
+
4
+ def initialize(pid, message, action_patterns)
5
+ @pid, @message = pid, message
6
+ @processes = Hash.new
7
+ @start_action_pattern, @end_action_pattern = action_patterns[:start], action_patterns[:end]
8
+ end
9
+
10
+ def to_proc
11
+ lambda do |log|
12
+ pid = @pid[log]
13
+ if @processes.has_key?(pid)
14
+ @processes[pid] << log
15
+ if end_action?(@message[log])
16
+ parse_action_logs(@processes.delete(pid))
17
+ end
18
+ else
19
+ if start_action?(@message[log])
20
+ @processes[pid] = [log]
21
+ end
22
+ nil
23
+ end
24
+ end
25
+ end
26
+
27
+ def parse_action_logs(logs)
28
+ {
29
+ request: request(@message[logs[0]]),
30
+ response: response(@message[logs[-1]]),
31
+ logs: logs
32
+ }
33
+ end
34
+
35
+ def end_action?(msg)
36
+ msg =~ @end_action_pattern
37
+ end
38
+
39
+ def start_action?(msg)
40
+ msg =~ @start_action_pattern
41
+ end
42
+
43
+ def request(msg)
44
+ to_hash(@start_action_pattern.match(msg))
45
+ end
46
+
47
+ def response(msg)
48
+ to_hash(@end_action_pattern.match(msg))
49
+ end
50
+
51
+ def to_hash(m)
52
+ Hash[m.names.map(&:to_sym).zip(m.captures)]
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,27 @@
1
+ module Evidence
2
+ def rails2_action_patterns
3
+ {
4
+ start: /^
5
+ (\#012\#012)? # ignore encoded newlines
6
+ Processing\s+
7
+ (?<controller>\w+)\#(?<action>\w+)\s+
8
+ \(for\s+
9
+ (?<remote_addr>[^\s]+)\s+
10
+ at\s+
11
+ (?<timestamp>[^\)]+)\)\s+
12
+ \[(?<method>[\w]+)\]
13
+ $/x,
14
+ end: /^
15
+ Completed\sin\s
16
+ (?<completed_time>\d+)ms\s+
17
+ \((View\:\s(?<view_time>\d+))?
18
+ \s*,?\s*
19
+ (\s*DB\:\s(?<db_time>\d+))?
20
+ \)\s+\|\s+
21
+ (?<code>\d+)\s+
22
+ (?<status>\w+)\s+
23
+ \[(?<url>.+)\]
24
+ $/x
25
+ }
26
+ end
27
+ end
@@ -1,9 +1,10 @@
1
1
  module Evidence
2
- class RailsActionParser
2
+ class ActionParser
3
3
 
4
- def initialize(pid, message)
4
+ def initialize(pid, message, action_patterns)
5
5
  @pid, @message = pid, message
6
6
  @processes = Hash.new
7
+ @start_action_pattern, @end_action_pattern = action_patterns[:start], action_patterns[:end]
7
8
  end
8
9
 
9
10
  def to_proc
@@ -32,46 +33,19 @@ module Evidence
32
33
  end
33
34
 
34
35
  def end_action?(msg)
35
- msg =~ end_action_pattern
36
+ msg =~ @end_action_pattern
36
37
  end
37
38
 
38
39
  def start_action?(msg)
39
- msg =~ start_action_pattern
40
+ msg =~ @start_action_pattern
40
41
  end
41
42
 
42
43
  def request(msg)
43
- to_hash(start_action_pattern.match(msg))
44
+ to_hash(@start_action_pattern.match(msg))
44
45
  end
45
46
 
46
47
  def response(msg)
47
- to_hash(end_action_pattern.match(msg))
48
- end
49
-
50
- def start_action_pattern
51
- /^
52
- (\#012\#012)? # ignore encoded newlines
53
- Processing\s+
54
- (?<controller>\w+)\#(?<action>\w+)\s+
55
- \(for\s+
56
- (?<remote_addr>[^\s]+)\s+
57
- at\s+
58
- (?<timestamp>[^\)]+)\)\s+
59
- \[(?<method>[\w]+)\]
60
- $/x
61
- end
62
-
63
- # Completed in 755ms (View: 330, DB: 215) | 200 OK [url]
64
- def end_action_pattern
65
- /^
66
- Completed\sin\s
67
- (?<completed_time>\d+)ms\s+
68
- \(View\:\s(?<view_time>\d+)
69
- (,\s*DB\:\s(?<db_time>\d+))?
70
- \)\s+\|\s+
71
- (?<code>\d+)\s+
72
- (?<status>\w+)\s+
73
- \[(?<url>.+)\]
74
- $/x
48
+ to_hash(@end_action_pattern.match(msg))
75
49
  end
76
50
 
77
51
  def to_hash(m)
data/lib/evidence.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'evidence/lazy'
2
- require 'evidence/rails_action_parser'
2
+ require 'evidence/rails'
3
+ require 'evidence/action_parser'
3
4
 
4
5
  Enumerator::Lazy.send(:include, Evidence::Lazy)
5
6
 
@@ -17,12 +18,16 @@ module Evidence
17
18
  end
18
19
  end
19
20
 
21
+ # default to rails 2
22
+ def rails_action_parser(pid, message, version=2)
23
+ rails2_action_parser(pid, message)
24
+ end
20
25
  # Parse out rails actions by given:
21
26
  # pid: a lambda returns process id used to group logs
22
27
  # message: a lambda returns rails log string message
23
28
  # example: logs.map(&rails_action_parser(pid, message)).compact
24
- def rails_action_parser(pid, message)
25
- RailsActionParser.new(pid, message)
29
+ def rails2_action_parser(pid, message)
30
+ ActionParser.new(pid, message, rails2_action_patterns)
26
31
  end
27
32
 
28
33
  # Rails action request timestamp parser
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: evidence
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Xiao Li
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-08-16 00:00:00.000000000 Z
12
+ date: 2013-08-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -34,7 +34,9 @@ extensions: []
34
34
  extra_rdoc_files: []
35
35
  files:
36
36
  - README.md
37
+ - lib/evidence/action_parser.rb
37
38
  - lib/evidence/lazy.rb
39
+ - lib/evidence/rails.rb
38
40
  - lib/evidence/rails_action_parser.rb
39
41
  - lib/evidence.rb
40
42
  - examples/mingle_logs_analysis.rb