mole 0.0.1 → 1.0.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/lib/mole/e_mole.rb +1 -1
- data/lib/mole/models/mole_feature.rb +5 -5
- data/lib/mole/models/mole_log.rb +1 -27
- data/lib/mole/moler.rb +17 -5
- data/lib/mole/version.rb +2 -2
- data/lib/mole.rb +2 -3
- data/spec/emole_spec.rb +2 -2
- data/spec/models/mole_feature_spec.rb +3 -3
- data/spec/models/mole_log_spec.rb +26 -39
- data/spec/moler_spec.rb +39 -27
- data/spec/spec_helper.rb +17 -0
- metadata +2 -2
data/lib/mole/e_mole.rb
CHANGED
@@ -28,7 +28,7 @@ module Mole
|
|
28
28
|
alias_method_chain :feature_alerts, :setup
|
29
29
|
|
30
30
|
# send out mole performance alert
|
31
|
-
def perf_alerts( context, user_id, options={} )
|
31
|
+
def perf_alerts( context, user_id, options={} )
|
32
32
|
Mole.logger.debug "Sending perf email from #{::Mole.emole_from} -- to #{::Mole.emole_recipients}"
|
33
33
|
subject "[PERF] #{@host} -- #{Mole.application} -- #{user_id}"
|
34
34
|
body :application => ::Mole.application,
|
@@ -10,16 +10,16 @@ class MoleFeature < ActiveRecord::Base
|
|
10
10
|
|
11
11
|
# find performance feature
|
12
12
|
def find_performance_feature( app_name )
|
13
|
-
|
13
|
+
find_or_create_feature( performance, app_name )
|
14
14
|
end
|
15
15
|
|
16
16
|
# find exception feature
|
17
17
|
def find_exception_feature( app_name )
|
18
|
-
|
18
|
+
find_or_create_feature( exception, app_name )
|
19
19
|
end
|
20
20
|
|
21
21
|
def find_all_feature( app_name )
|
22
|
-
|
22
|
+
find_or_create_feature( all, app_name )
|
23
23
|
end
|
24
24
|
|
25
25
|
# Finds all the features available for a given application
|
@@ -32,8 +32,8 @@ class MoleFeature < ActiveRecord::Base
|
|
32
32
|
:order => "name asc" )
|
33
33
|
end
|
34
34
|
|
35
|
-
# locates an existing feature or create a new one
|
36
|
-
def
|
35
|
+
# locates an existing feature or create a new one if it does not exist.
|
36
|
+
def find_or_create_feature( name, app_name, ctx_name=nil )
|
37
37
|
if name.nil? or name.empty?
|
38
38
|
::Mole.logger.error( "--- MOLE ERROR - Invalid feature. Empty or nil" )
|
39
39
|
return nil
|
data/lib/mole/models/mole_log.rb
CHANGED
@@ -4,28 +4,7 @@
|
|
4
4
|
class MoleLog < ActiveRecord::Base
|
5
5
|
belongs_to :mole_feature
|
6
6
|
|
7
|
-
class << self
|
8
|
-
# logs unchecked exception
|
9
|
-
def check_it( context, user_id, args )
|
10
|
-
if args[:boom]
|
11
|
-
args[:trace] = dump_stack( args[:boom] )
|
12
|
-
args[:boom] = args[:boom].to_s
|
13
|
-
end
|
14
|
-
log_it( context, MoleFeature::find_exception_feature( ::Mole.application ), user_id, args ) if ::Mole::moleable?
|
15
|
-
end
|
16
|
-
|
17
|
-
# logs perf occurence
|
18
|
-
def perf_it( context, user_id, args )
|
19
|
-
log_it( context, MoleFeature::find_performance_feature( ::Mole.application ), user_id, args ) if ::Mole::moleable?
|
20
|
-
end
|
21
|
-
|
22
|
-
# persists mole information to the database.
|
23
|
-
# This call will store information on the mole dedicated tables namely
|
24
|
-
# mole_features and mole_logs.
|
25
|
-
def mole_it(context, feature, user_id, args)
|
26
|
-
log_it( context, MoleFeature::find_feature( feature, ::Mole.application, context.class.name ), user_id, args ) if ::Mole::moleable?
|
27
|
-
end
|
28
|
-
|
7
|
+
class << self
|
29
8
|
# mole the bastard - create db entry into mole logs
|
30
9
|
def log_it( context, feature, user_id, args )
|
31
10
|
args ||= "no args"
|
@@ -39,11 +18,6 @@ class MoleLog < ActiveRecord::Base
|
|
39
18
|
:browser_type => browser_type )
|
40
19
|
end
|
41
20
|
|
42
|
-
# dumps partial stack
|
43
|
-
def dump_stack( boom )
|
44
|
-
buff = boom.backtrace[0...3].join( "-" )
|
45
|
-
end
|
46
|
-
|
47
21
|
# extract orginating ip address and browser type
|
48
22
|
def log_details( context ) #:nodoc:
|
49
23
|
ip_addr, browser_type = nil
|
data/lib/mole/moler.rb
CHANGED
@@ -12,7 +12,12 @@ module Mole
|
|
12
12
|
# configuration to see if this event should be persisted to the db or
|
13
13
|
# sent out to the logger.
|
14
14
|
def check_it( context, user_id, args )
|
15
|
-
return unless ::Mole.moleable?
|
15
|
+
return unless ::Mole.moleable?
|
16
|
+
# If exception is given record the first couple of frames
|
17
|
+
if args[:boom]
|
18
|
+
args[:trace] = dump_stack( args[:boom] )
|
19
|
+
args[:boom] = args[:boom].to_s
|
20
|
+
end
|
16
21
|
if ::Mole.persistent?
|
17
22
|
MoleLog.log_it( context, MoleFeature::find_exception_feature( ::Mole.application ), user_id, args )
|
18
23
|
else
|
@@ -38,14 +43,21 @@ module Mole
|
|
38
43
|
def mole_it(context, feature, user_id, args)
|
39
44
|
return unless ::Mole.moleable?
|
40
45
|
if ::Mole.persistent?
|
41
|
-
MoleLog.log_it( context, MoleFeature::
|
46
|
+
MoleLog.log_it( context, MoleFeature::find_or_create_feature( feature, ::Mole.application, context.class.name ), user_id, args )
|
42
47
|
else
|
43
48
|
::Mole.logger.log_it( context, feature, user_id, args )
|
44
49
|
end
|
45
50
|
# Send out email notification if requested
|
46
|
-
args[:
|
47
|
-
|
48
|
-
|
51
|
+
if args[:email] and args[:email] == true
|
52
|
+
args[:feature] = feature
|
53
|
+
Mole::EMole.deliver_feature_alerts( context, user_id, args )
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
# dumps partial stack
|
58
|
+
def dump_stack( boom )
|
59
|
+
buff = boom.backtrace[0...3].join( "-" )
|
60
|
+
end
|
49
61
|
end
|
50
62
|
end
|
51
63
|
end
|
data/lib/mole/version.rb
CHANGED
data/lib/mole.rb
CHANGED
@@ -26,9 +26,8 @@ unless defined? Mole
|
|
26
26
|
:perf_threshold => 5,
|
27
27
|
:mode => :transient,
|
28
28
|
:emole_from => "MOleBeatch",
|
29
|
-
:
|
30
|
-
:
|
31
|
-
|
29
|
+
:emole_recipients => [],
|
30
|
+
:mole_config => nil,
|
32
31
|
# logging options
|
33
32
|
:log_file => $stdout,
|
34
33
|
:log_level => :info,
|
data/spec/emole_spec.rb
CHANGED
@@ -9,8 +9,8 @@ describe Mole::EMole do
|
|
9
9
|
before( :each ) do
|
10
10
|
::Mole.reset_configuration!
|
11
11
|
::Mole.initialize( :moleable => true,
|
12
|
-
|
13
|
-
|
12
|
+
:emole_from => "MOleBeatch@liquidrail.com",
|
13
|
+
:emole_recipients => ['fernand@liquidrail.com'] )
|
14
14
|
end
|
15
15
|
|
16
16
|
it "should send out a correct perf alert" do
|
@@ -15,14 +15,14 @@ describe MoleFeature do
|
|
15
15
|
end
|
16
16
|
|
17
17
|
it "should create a new feature" do
|
18
|
-
feature = MoleFeature.
|
18
|
+
feature = MoleFeature.find_or_create_feature( "Fred", ::Mole.application, self.class.name )
|
19
19
|
feature.should_not be_nil
|
20
20
|
feature.name.should == "Fred"
|
21
21
|
feature.context.should == self.class.name
|
22
22
|
end
|
23
23
|
|
24
24
|
it "should not create a feature with no name" do
|
25
|
-
feature = MoleFeature.
|
25
|
+
feature = MoleFeature.find_or_create_feature( "", ::Mole.application, self.class.name )
|
26
26
|
feature.should be_nil
|
27
27
|
end
|
28
28
|
|
@@ -30,7 +30,7 @@ describe MoleFeature do
|
|
30
30
|
%w[ all performance exception].each do |f|
|
31
31
|
MoleFeature.send( "find_#{f}_feature".to_sym, ::Mole.application )
|
32
32
|
end
|
33
|
-
MoleFeature.
|
33
|
+
MoleFeature.find_or_create_feature( "Fred", ::Mole.application, self.class.name )
|
34
34
|
features = MoleFeature.find_features( ::Mole.application )
|
35
35
|
features.should have(4).mole_features
|
36
36
|
end
|
@@ -4,59 +4,46 @@ describe MoleLog do
|
|
4
4
|
before( :each ) do
|
5
5
|
::Mole.reset_configuration!
|
6
6
|
::Mole.initialize( :mode => :persistent, :log_level => :info, :moleable => true )
|
7
|
+
@args = { :blee => "Hello", :duh => "World" }
|
7
8
|
end
|
8
9
|
|
9
|
-
it "should log unchecked exceptions correctly" do
|
10
|
+
it "should log unchecked exceptions correctly" do
|
11
|
+
args = @args
|
12
|
+
feature = MoleFeature.find_exception_feature( ::Mole.application )
|
13
|
+
feature.should_not be_nil
|
10
14
|
begin
|
11
15
|
raise "Something crapped out"
|
12
|
-
rescue => boom
|
13
|
-
|
16
|
+
rescue => boom
|
17
|
+
args[:boom] = Mole::Moler.dump_stack( boom )
|
18
|
+
MoleLog.log_it( self, feature, 100, args )
|
14
19
|
end
|
15
|
-
|
16
|
-
except_feature.should_not be_nil
|
17
|
-
|
18
|
-
log = MoleLog.find( :all, :conditions => ['mole_feature_id = ?', except_feature.id] )
|
19
|
-
log.should_not be_nil
|
20
|
-
log.should have(1).mole_log
|
21
|
-
log.first.user_id.should == 100
|
20
|
+
check_it( feature, 100, @args )
|
22
21
|
end
|
23
22
|
|
24
|
-
it "should log perf exception correctly" do
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
log = MoleLog.find( :all, :conditions => ['mole_feature_id = ?', perf_feature.id] )
|
30
|
-
log.should_not be_nil
|
31
|
-
log.should have(1).mole_log
|
32
|
-
log.first.user_id.should == 100
|
23
|
+
it "should log perf exception correctly" do
|
24
|
+
feature = MoleFeature.find_performance_feature( ::Mole.application )
|
25
|
+
feature.should_not be_nil
|
26
|
+
MoleLog.log_it( self, feature, 200, @args )
|
27
|
+
check_it( feature, 200, @args )
|
33
28
|
end
|
34
29
|
|
35
30
|
it "should mole a feature correctly" do
|
36
|
-
|
37
|
-
feature
|
38
|
-
|
39
|
-
|
40
|
-
log = MoleLog.find( :all, :conditions => ['mole_feature_id = ?', feature.id] )
|
41
|
-
log.should_not be_nil
|
42
|
-
log.should have(1).mole_log
|
43
|
-
log.first.user_id.should == 100
|
31
|
+
feature = MoleFeature.find_or_create_feature( "fred", ::Mole.application, "Test".class.name )
|
32
|
+
feature.should_not be_nil
|
33
|
+
MoleLog.log_it( "Test", feature, 300, @args )
|
34
|
+
check_it( feature, 300, @args )
|
44
35
|
end
|
45
36
|
|
46
37
|
it "should log request info correctly" do
|
47
|
-
ctrl
|
48
|
-
|
49
|
-
feature
|
50
|
-
|
51
|
-
|
52
|
-
log
|
53
|
-
log.
|
54
|
-
log.should have(1).mole_log
|
55
|
-
log.first.user_id.should == 100
|
56
|
-
log.first.ip_address.should == "1.1.1.1"
|
57
|
-
log.first.browser_type.should == "GodZilla"
|
38
|
+
ctrl = Moled::Controller.new
|
39
|
+
feature = MoleFeature.find_or_create_feature( "fred", ::Mole.application, ctrl.class.name )
|
40
|
+
feature.should_not be_nil
|
41
|
+
MoleLog.log_it( ctrl, feature, 400, @args )
|
42
|
+
log = check_it( feature, 400, @args )
|
43
|
+
log.ip_address.should == "1.1.1.1"
|
44
|
+
log.browser_type.should == "GodZilla"
|
58
45
|
end
|
59
|
-
|
46
|
+
|
60
47
|
module Moled
|
61
48
|
class Controller
|
62
49
|
class Request
|
data/spec/moler_spec.rb
CHANGED
@@ -1,64 +1,76 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), "spec_helper" )
|
2
|
+
|
3
|
+
require 'action_mailer'
|
4
|
+
ActionMailer::Base.delivery_method = :sendmail
|
5
|
+
ActionMailer::Base.raise_delivery_errors = true
|
2
6
|
|
3
7
|
describe Mole::Moler do
|
4
8
|
TEST_LOG = "/tmp/test.log"
|
5
9
|
before( :each ) do
|
6
10
|
::Mole.reset_configuration!
|
7
11
|
@io = StringIO.new
|
8
|
-
::Mole.initialize( :mode
|
12
|
+
::Mole.initialize( :mode => :transient,
|
13
|
+
:logger_name => "Test",
|
14
|
+
:log_file => @io,
|
15
|
+
:moleable => true,
|
16
|
+
:emole_from => "MOleBeatch@liquidrail.com",
|
17
|
+
:emole_recipients => ['fernand@liquidrail.com'] )
|
18
|
+
@args = { :blee => "Hello", :duh => "World" }
|
9
19
|
end
|
10
20
|
|
11
21
|
it "should log unchecked to the db exceptions correctly" do
|
12
|
-
::Mole.switch_mode :persistent
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
22
|
+
::Mole.switch_mode :persistent
|
23
|
+
begin
|
24
|
+
raise "Something bad happened !"
|
25
|
+
rescue => boom
|
26
|
+
@args[:boom] = boom
|
27
|
+
::Mole::Moler.check_it( self, 100, @args )
|
28
|
+
end
|
29
|
+
feature = MoleFeature.find_exception_feature( ::Mole.application )
|
30
|
+
feature.should_not be_nil
|
31
|
+
check_it( feature, 100, @args )
|
21
32
|
end
|
22
33
|
|
23
34
|
it "should log perf exception to the db correctly" do
|
24
35
|
::Mole.switch_mode :persistent
|
25
|
-
::Mole::Moler.perf_it( self, 100,
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
log = MoleLog.find( :all, :conditions => ['mole_feature_id = ?', perf_feature.id] )
|
30
|
-
log.should_not be_nil
|
31
|
-
log.should have(1).mole_log
|
32
|
-
log.first.user_id.should == 100
|
36
|
+
::Mole::Moler.perf_it( self, 100, @args )
|
37
|
+
feature = MoleFeature.find_performance_feature( ::Mole.application )
|
38
|
+
feature.should_not be_nil
|
39
|
+
check_it( feature, 100, @args )
|
33
40
|
end
|
34
41
|
|
35
42
|
it "should mole a feature to the db correctly" do
|
36
43
|
::Mole.switch_mode :persistent
|
37
|
-
::Mole::Moler.mole_it( "Test", "fred", 100,
|
38
|
-
feature = MoleFeature.
|
44
|
+
::Mole::Moler.mole_it( "Test", "fred", 100, @args )
|
45
|
+
feature = MoleFeature.find_or_create_feature( "fred", ::Mole.application, "Test".class.name )
|
39
46
|
feature.should_not be_nil
|
47
|
+
check_it( feature, 100, @args )
|
48
|
+
end
|
40
49
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
50
|
+
it "should log a feature to the db and send an email correctly" do
|
51
|
+
::Mole.switch_mode :persistent
|
52
|
+
@args[:email] = true
|
53
|
+
::Mole::Moler.mole_it( "Test", "fred", 100, @args )
|
54
|
+
feature = MoleFeature.find_or_create_feature( "fred", ::Mole.application, "Test".class.name )
|
55
|
+
feature.should_not be_nil
|
56
|
+
check_it( feature, 100, { :email => true, :blee => "Hello", :duh => "World" } )
|
45
57
|
end
|
46
58
|
|
47
59
|
it "should log unchecked exceptions to the logger correctly" do
|
48
60
|
::Mole.switch_mode :transient
|
49
|
-
::Mole::Moler.check_it( self, 100,
|
61
|
+
::Mole::Moler.check_it( self, 100, @args )
|
50
62
|
@io.string[@io.string.index( "---" )..@io.string.size].should == "--- 100 -> blee=>Hello, duh=>World\n"
|
51
63
|
end
|
52
64
|
|
53
65
|
it "should log perf exception to the logger correctly" do
|
54
66
|
::Mole.switch_mode :transient
|
55
|
-
::Mole::Moler.perf_it( self, 100,
|
67
|
+
::Mole::Moler.perf_it( self, 100, @args )
|
56
68
|
@io.string[@io.string.index( "---" )..@io.string.size].should == "--- 100 -> blee=>Hello, duh=>World\n"
|
57
69
|
end
|
58
70
|
|
59
71
|
it "should mole a feature to the logger correctly" do
|
60
72
|
::Mole.switch_mode :transient
|
61
|
-
::Mole::Moler.mole_it( "Test", "Fred", 100,
|
73
|
+
::Mole::Moler.mole_it( "Test", "Fred", 100, @args )
|
62
74
|
@io.string[@io.string.index( "---" )..@io.string.size].should == "--- 100 -> blee=>Hello, duh=>World\n"
|
63
75
|
end
|
64
76
|
|
data/spec/spec_helper.rb
CHANGED
@@ -56,4 +56,21 @@ Spec::Runner.configure do |config|
|
|
56
56
|
rescue
|
57
57
|
end
|
58
58
|
end
|
59
|
+
end
|
60
|
+
|
61
|
+
# Convenience to check mole_logs
|
62
|
+
def check_it( feature, user_id, args={} )
|
63
|
+
log = MoleLog.find( :first, :conditions => ['mole_feature_id = ?', feature.id] )
|
64
|
+
log.should_not be_nil
|
65
|
+
log.user_id.should == user_id
|
66
|
+
log_args = YAML.load( log.params )
|
67
|
+
check_args( log_args, args )
|
68
|
+
log
|
59
69
|
end
|
70
|
+
def check_args( args, expected_args )
|
71
|
+
args.should have(expected_args.size).items
|
72
|
+
expected_args.keys.each do |k|
|
73
|
+
args[k].should_not be_nil
|
74
|
+
args[k].should == expected_args[k]
|
75
|
+
end
|
76
|
+
end
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.4
|
|
3
3
|
specification_version: 1
|
4
4
|
name: mole
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.0
|
7
|
-
date: 2008-03-
|
6
|
+
version: 1.0.0
|
7
|
+
date: 2008-03-02 00:00:00 -07:00
|
8
8
|
summary: A flexible way to track user's interactions within your ruby web applications
|
9
9
|
require_paths:
|
10
10
|
- lib
|