errplane 0.5.10 → 0.5.11
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/errplane/max_queue.rb +3 -10
- data/lib/errplane/rails/instrumentation.rb +8 -13
- data/lib/errplane/rails.rb +2 -0
- data/lib/errplane/railtie.rb +4 -2
- data/lib/errplane/transmitter.rb +1 -1
- data/lib/errplane/version.rb +1 -1
- data/lib/errplane/worker.rb +12 -10
- data/lib/errplane.rb +1 -1
- data/spec/unit/max_queue_spec.rb +7 -7
- metadata +24 -24
data/lib/errplane/max_queue.rb
CHANGED
@@ -1,14 +1,7 @@
|
|
1
1
|
module Errplane
|
2
|
-
class MaxQueue <
|
3
|
-
|
4
|
-
|
5
|
-
def initialize(max_depth = 10_000)
|
6
|
-
@max_depth = max_depth
|
7
|
-
super()
|
8
|
-
end
|
9
|
-
|
10
|
-
def push_or_discard(data)
|
11
|
-
push(data) if size < @max_depth
|
2
|
+
class MaxQueue < SizedQueue
|
3
|
+
def push(obj)
|
4
|
+
super if @que.length < @max
|
12
5
|
end
|
13
6
|
end
|
14
7
|
end
|
@@ -1,6 +1,13 @@
|
|
1
1
|
module Errplane
|
2
2
|
module Rails
|
3
3
|
module Instrumentation
|
4
|
+
def benchmark_for_instrumentation
|
5
|
+
start = Time.now
|
6
|
+
yield
|
7
|
+
elapsed = ((Time.now - start) * 1000).ceil
|
8
|
+
Errplane.report("instrumentation/#{controller_name}##{action_name}", :value => elapsed)
|
9
|
+
end
|
10
|
+
|
4
11
|
def self.included(base)
|
5
12
|
base.extend(ClassMethods)
|
6
13
|
end
|
@@ -8,19 +15,7 @@ module Errplane
|
|
8
15
|
module ClassMethods
|
9
16
|
def instrument(methods = [])
|
10
17
|
methods = [methods] unless methods.is_a?(Array)
|
11
|
-
|
12
|
-
::Rails.logger.debug "OVERRIDING METHOD: #{method}"
|
13
|
-
|
14
|
-
class_eval <<-EVAL_METHOD
|
15
|
-
def #{method}_with_instrumentation
|
16
|
-
Errplane.report(\"instrumentation/#{self.class}##{method}\")
|
17
|
-
#{method}_without_instrumentation
|
18
|
-
end
|
19
|
-
EVAL_METHOD
|
20
|
-
|
21
|
-
alias_method "#{method}_without_instrumentation", method
|
22
|
-
alias_method method, "#{method}_with_instrumentation"
|
23
|
-
end
|
18
|
+
around_filter :benchmark_for_instrumentation, :only => methods
|
24
19
|
end
|
25
20
|
end
|
26
21
|
end
|
data/lib/errplane/rails.rb
CHANGED
@@ -3,6 +3,7 @@ require 'errplane'
|
|
3
3
|
require 'errplane/rails/middleware/hijack_rescue_action_everywhere'
|
4
4
|
require 'errplane/rails/air_traffic_controller'
|
5
5
|
require 'errplane/rails/benchmarking'
|
6
|
+
require 'errplane/rails/instrumentation'
|
6
7
|
|
7
8
|
module Errplane
|
8
9
|
module Rails
|
@@ -10,6 +11,7 @@ module Errplane
|
|
10
11
|
ActionController::Base.send(:include, Errplane::Rails::AirTrafficController)
|
11
12
|
ActionController::Base.send(:include, Errplane::Rails::Middleware::HijackRescueActionEverywhere)
|
12
13
|
ActionController::Base.send(:include, Errplane::Rails::Benchmarking)
|
14
|
+
ActionController::Base.send(:include, Errplane::Rails::Instrumentation)
|
13
15
|
|
14
16
|
::Rails.configuration.middleware.insert_after 'ActionController::Failsafe', Errplane::Rack
|
15
17
|
|
data/lib/errplane/railtie.rb
CHANGED
@@ -90,6 +90,8 @@ module Errplane
|
|
90
90
|
ActiveSupport.on_load(:action_controller) do
|
91
91
|
require 'errplane/rails/air_traffic_controller'
|
92
92
|
include Errplane::Rails::AirTrafficController
|
93
|
+
require 'errplane/rails/instrumentation'
|
94
|
+
include Errplane::Rails::Instrumentation
|
93
95
|
end
|
94
96
|
|
95
97
|
if defined?(::ActionDispatch::DebugExceptions)
|
@@ -101,7 +103,7 @@ module Errplane
|
|
101
103
|
end
|
102
104
|
|
103
105
|
if defined?(ActiveSupport::Notifications)
|
104
|
-
ActiveSupport::Notifications.subscribe do |name, start, finish, id, payload|
|
106
|
+
ActiveSupport::Notifications.subscribe "process_action.action_controller" do |name, start, finish, id, payload|
|
105
107
|
if Errplane.configuration.instrumentation_enabled?
|
106
108
|
h = { :name => name,
|
107
109
|
:start => start,
|
@@ -109,7 +111,7 @@ module Errplane
|
|
109
111
|
:nid => id,
|
110
112
|
:payload => payload,
|
111
113
|
:source => "active_support"}
|
112
|
-
Errplane.queue.
|
114
|
+
Errplane.queue.push(h)
|
113
115
|
end
|
114
116
|
end
|
115
117
|
end
|
data/lib/errplane/transmitter.rb
CHANGED
data/lib/errplane/version.rb
CHANGED
data/lib/errplane/worker.rb
CHANGED
@@ -5,6 +5,9 @@ require "base64"
|
|
5
5
|
|
6
6
|
module Errplane
|
7
7
|
class Worker
|
8
|
+
MAX_POST_LINES = 200
|
9
|
+
POST_RETRIES = 5
|
10
|
+
|
8
11
|
class << self
|
9
12
|
include Errplane::Logger
|
10
13
|
|
@@ -20,7 +23,7 @@ module Errplane
|
|
20
23
|
url = "/api/v2/time_series/applications/#{Errplane.configuration.application_id}/environments/#{Errplane.configuration.rails_environment}?api_key=#{Errplane.configuration.api_key}"
|
21
24
|
log :debug, "Posting to: #{url}"
|
22
25
|
|
23
|
-
retry_count =
|
26
|
+
retry_count = POST_RETRIES
|
24
27
|
begin
|
25
28
|
http = Net::HTTP.new("api.errplane.com", "80")
|
26
29
|
response = http.post(url, data)
|
@@ -38,28 +41,27 @@ module Errplane
|
|
38
41
|
end
|
39
42
|
|
40
43
|
def spawn_threads()
|
41
|
-
Errplane.configuration.queue_worker_threads.times do
|
42
|
-
log :debug, "Spawning background worker thread."
|
44
|
+
Errplane.configuration.queue_worker_threads.times do |thread_num|
|
45
|
+
log :debug, "Spawning background worker thread #{thread_num}."
|
43
46
|
|
44
47
|
Thread.new do
|
45
48
|
while true
|
46
49
|
sleep Errplane.configuration.queue_worker_polling_interval
|
47
|
-
check_background_queue
|
50
|
+
check_background_queue(thread_num)
|
48
51
|
end
|
49
52
|
end
|
50
53
|
|
51
54
|
end
|
52
55
|
end
|
53
56
|
|
54
|
-
def check_background_queue
|
55
|
-
log :debug, "Checking background queue."
|
57
|
+
def check_background_queue(thread_num = 0)
|
58
|
+
log :debug, "Checking background queue on thread #{thread_num} (#{Thread.list.count - 1} active)"
|
56
59
|
|
57
60
|
data = []
|
58
61
|
|
59
|
-
while !Errplane.queue.empty?
|
60
|
-
|
61
|
-
|
62
|
-
log :debug, n.inspect
|
62
|
+
while data.size < MAX_POST_LINES && !Errplane.queue.empty?
|
63
|
+
n = Errplane.queue.pop(true) rescue next;
|
64
|
+
log :debug, "Found data in the queue! (#{n[:name]})"
|
63
65
|
|
64
66
|
begin
|
65
67
|
case n[:source]
|
data/lib/errplane.rb
CHANGED
data/spec/unit/max_queue_spec.rb
CHANGED
@@ -1,31 +1,31 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Errplane::MaxQueue do
|
4
|
-
it "should inherit from
|
5
|
-
Errplane::MaxQueue.new.should be_a(
|
4
|
+
it "should inherit from SizedQueue" do
|
5
|
+
Errplane::MaxQueue.new(1).should be_a(SizedQueue)
|
6
6
|
end
|
7
7
|
|
8
8
|
context "#new" do
|
9
9
|
it "should allow max_depth to be set" do
|
10
10
|
queue = Errplane::MaxQueue.new(500)
|
11
|
-
queue.
|
11
|
+
queue.max.should == 500
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
|
-
context "#
|
15
|
+
context "#push" do
|
16
16
|
it "should allow an item to be added if the queue is not full" do
|
17
17
|
queue = Errplane::MaxQueue.new(5)
|
18
18
|
queue.size.should be_zero
|
19
|
-
queue.
|
19
|
+
queue.push(1)
|
20
20
|
queue.size.should == 1
|
21
21
|
end
|
22
22
|
|
23
23
|
it "should not allow items to be added if the queue is full" do
|
24
24
|
queue = Errplane::MaxQueue.new(5)
|
25
25
|
queue.size.should be_zero
|
26
|
-
5.times { |n| queue.
|
26
|
+
5.times { |n| queue.push(n) }
|
27
27
|
queue.size.should == 5
|
28
|
-
queue.
|
28
|
+
queue.push(6)
|
29
29
|
queue.size.should == 5
|
30
30
|
end
|
31
31
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: errplane
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.11
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-11-
|
12
|
+
date: 2012-11-25 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: json
|
16
|
-
requirement: &
|
16
|
+
requirement: &70188314227440 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70188314227440
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: activesupport
|
27
|
-
requirement: &
|
27
|
+
requirement: &70188314226840 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: 2.3.14
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70188314226840
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: actionpack
|
38
|
-
requirement: &
|
38
|
+
requirement: &70188314226240 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: 2.3.14
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70188314226240
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: bundler
|
49
|
-
requirement: &
|
49
|
+
requirement: &70188314225640 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: 1.0.0
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70188314225640
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: fakeweb
|
60
|
-
requirement: &
|
60
|
+
requirement: &70188314224760 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: '0'
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *70188314224760
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: guard
|
71
|
-
requirement: &
|
71
|
+
requirement: &70188314223540 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ! '>='
|
@@ -76,10 +76,10 @@ dependencies:
|
|
76
76
|
version: '0'
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *70188314223540
|
80
80
|
- !ruby/object:Gem::Dependency
|
81
81
|
name: guard-rspec
|
82
|
-
requirement: &
|
82
|
+
requirement: &70188314222400 !ruby/object:Gem::Requirement
|
83
83
|
none: false
|
84
84
|
requirements:
|
85
85
|
- - ! '>='
|
@@ -87,10 +87,10 @@ dependencies:
|
|
87
87
|
version: '0'
|
88
88
|
type: :development
|
89
89
|
prerelease: false
|
90
|
-
version_requirements: *
|
90
|
+
version_requirements: *70188314222400
|
91
91
|
- !ruby/object:Gem::Dependency
|
92
92
|
name: rake
|
93
|
-
requirement: &
|
93
|
+
requirement: &70188314221600 !ruby/object:Gem::Requirement
|
94
94
|
none: false
|
95
95
|
requirements:
|
96
96
|
- - ! '>='
|
@@ -98,10 +98,10 @@ dependencies:
|
|
98
98
|
version: '0'
|
99
99
|
type: :development
|
100
100
|
prerelease: false
|
101
|
-
version_requirements: *
|
101
|
+
version_requirements: *70188314221600
|
102
102
|
- !ruby/object:Gem::Dependency
|
103
103
|
name: rdoc
|
104
|
-
requirement: &
|
104
|
+
requirement: &70188314220340 !ruby/object:Gem::Requirement
|
105
105
|
none: false
|
106
106
|
requirements:
|
107
107
|
- - ! '>='
|
@@ -109,10 +109,10 @@ dependencies:
|
|
109
109
|
version: '0'
|
110
110
|
type: :development
|
111
111
|
prerelease: false
|
112
|
-
version_requirements: *
|
112
|
+
version_requirements: *70188314220340
|
113
113
|
- !ruby/object:Gem::Dependency
|
114
114
|
name: rspec
|
115
|
-
requirement: &
|
115
|
+
requirement: &70188314219300 !ruby/object:Gem::Requirement
|
116
116
|
none: false
|
117
117
|
requirements:
|
118
118
|
- - ! '>='
|
@@ -120,10 +120,10 @@ dependencies:
|
|
120
120
|
version: '0'
|
121
121
|
type: :development
|
122
122
|
prerelease: false
|
123
|
-
version_requirements: *
|
123
|
+
version_requirements: *70188314219300
|
124
124
|
- !ruby/object:Gem::Dependency
|
125
125
|
name: tzinfo
|
126
|
-
requirement: &
|
126
|
+
requirement: &70188314218040 !ruby/object:Gem::Requirement
|
127
127
|
none: false
|
128
128
|
requirements:
|
129
129
|
- - ! '>='
|
@@ -131,7 +131,7 @@ dependencies:
|
|
131
131
|
version: '0'
|
132
132
|
type: :development
|
133
133
|
prerelease: false
|
134
|
-
version_requirements: *
|
134
|
+
version_requirements: *70188314218040
|
135
135
|
description: This gem provides exception reporting with Errplane for Rails 3.x applications.
|
136
136
|
email:
|
137
137
|
- todd@errplane.com
|