right_agent 2.3.1 → 2.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/right_agent/error_tracker.rb +38 -14
- data/right_agent.gemspec +2 -2
- data/spec/error_tracker_spec.rb +55 -15
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 417ec9216dbf120ff9b65b4cc81f89ba85bbd2b6
|
4
|
+
data.tar.gz: eb8a6033c5fb7265037a5976f824ad9116ebc8ec
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2de8f5d35bdb742e5805ff880085f847a7f416f29e1c251f202acb38d7dddcc6800f14430d6b25e52fd5efc1c195d74acb127c3e2e7b9282ce61703759bde348
|
7
|
+
data.tar.gz: 7b7234d5af8cb3fb0bb48289cfe4e9d2f35b2561936fc1e0f341aa56b1ab26869a2f39caf0f58b49e9a8cef7d27e3fb6284d3635390432b8e6b27169d1d4178d
|
@@ -19,6 +19,9 @@ module RightScale
|
|
19
19
|
|
20
20
|
include RightSupport::Ruby::EasySingleton
|
21
21
|
|
22
|
+
# Text used for filtered parameter value
|
23
|
+
FILTERED_PARAM_VALUE = "<hidden>"
|
24
|
+
|
22
25
|
# Container for exception statistics
|
23
26
|
attr_reader :exception_stats
|
24
27
|
|
@@ -32,6 +35,8 @@ module RightScale
|
|
32
35
|
# with exception class as key and :no_trace, :caller, or :trace as value; exceptions
|
33
36
|
# with :no_trace are not backtraced when logging nor are they recorded in stats
|
34
37
|
# or reported to Errbit
|
38
|
+
# @option options [Array<Symbol, String>] :filter_params names whose values are to be
|
39
|
+
# filtered when notifying
|
35
40
|
# @option options [String] :airbrake_endpoint URL for Airbrake for reporting exceptions
|
36
41
|
# to Errbit
|
37
42
|
# @option options [String] :airbrake_api_key for using the Airbrake API to access Errbit
|
@@ -40,7 +45,7 @@ module RightScale
|
|
40
45
|
def init(agent, agent_name, options = {})
|
41
46
|
@agent = agent
|
42
47
|
@trace_level = options[:trace_level] || {}
|
43
|
-
notify_init(agent_name, options
|
48
|
+
notify_init(agent_name, options)
|
44
49
|
reset_stats
|
45
50
|
true
|
46
51
|
end
|
@@ -113,14 +118,17 @@ module RightScale
|
|
113
118
|
data[:component] = component if component
|
114
119
|
if packet && packet.is_a?(Packet)
|
115
120
|
data[:action] = packet.type.split("/").last if packet.respond_to?(:type)
|
116
|
-
|
117
|
-
uuid = packet.token
|
121
|
+
params = packet.respond_to?(:payload) && packet.payload
|
122
|
+
uuid = packet.respond_to?(:token) && packet.token
|
118
123
|
elsif packet.is_a?(Hash)
|
119
124
|
action = packet[:path] || packet["path"]
|
120
125
|
data[:action] = action.split("/").last if action
|
121
|
-
|
126
|
+
params = packet[:data] || packet["data"]
|
122
127
|
uuid = packet[:uuid] || packet["uuid"]
|
128
|
+
else
|
129
|
+
params = uuid = nil
|
123
130
|
end
|
131
|
+
data[:parameters] = params.is_a?(Hash) ? filter(params) : {:param => params} if params
|
124
132
|
data[:session_data] = {:uuid => uuid} if uuid
|
125
133
|
HydraulicBrake.notify(data)
|
126
134
|
end
|
@@ -163,44 +171,60 @@ module RightScale
|
|
163
171
|
# Configure HydraulicBreak for exception notification
|
164
172
|
#
|
165
173
|
# @param [String] agent_name uniquely identifying agent process on given server
|
166
|
-
#
|
167
|
-
# @
|
168
|
-
# @
|
174
|
+
#
|
175
|
+
# @option options [Integer, NilClass] :shard_id identifying shard of database in use
|
176
|
+
# @option options [Array<Symbol, String>] :filter_params names whose values are to be
|
177
|
+
# filtered when notifying
|
178
|
+
# @option options [String] :airbrake_endpoint URL for Airbrake for reporting exceptions
|
179
|
+
# to Errbit
|
180
|
+
# @option options [String] :airbrake_api_key for using the Airbrake API to access Errbit
|
169
181
|
#
|
170
182
|
# @return [TrueClass] always true
|
171
183
|
#
|
172
184
|
# @raise [RuntimeError] hydraulic_brake gem missing
|
173
|
-
def notify_init(agent_name,
|
174
|
-
if
|
185
|
+
def notify_init(agent_name, options)
|
186
|
+
if options[:airbrake_endpoint] && options[:airbrake_api_key]
|
175
187
|
unless require_succeeds?("hydraulic_brake")
|
176
188
|
raise RuntimeError, "hydraulic_brake gem missing - required if airbrake options used in ErrorTracker"
|
177
189
|
end
|
178
190
|
|
179
191
|
@cgi_data = {
|
180
|
-
:shard_id => shard_id,
|
181
192
|
:process => $0,
|
182
193
|
:pid => Process.pid,
|
183
194
|
:agent_name => agent_name
|
184
195
|
}
|
185
|
-
@cgi_data[:shard_id] = shard_id if shard_id
|
196
|
+
@cgi_data[:shard_id] = options[:shard_id] if options[:shard_id]
|
186
197
|
@cgi_data[:sha] = CURRENT_SOURCE_SHA if defined?(CURRENT_SOURCE_SHA)
|
187
198
|
|
188
|
-
uri = URI.parse(
|
199
|
+
uri = URI.parse(options[:airbrake_endpoint])
|
189
200
|
HydraulicBrake.configure do |config|
|
190
201
|
config.secure = (uri.scheme == "https")
|
191
202
|
config.host = uri.host
|
192
203
|
config.port = uri.port
|
193
|
-
config.api_key =
|
204
|
+
config.api_key = options[:airbrake_api_key]
|
194
205
|
config.project_root = AgentConfig.root_dir
|
195
206
|
end
|
207
|
+
@filter_params = (options[:filter_params] || []).map { |p| p.to_s }
|
196
208
|
@notify_enabled = true
|
197
209
|
else
|
198
|
-
@cgi_data = {}
|
199
210
|
@notify_enabled = false
|
200
211
|
end
|
201
212
|
true
|
202
213
|
end
|
203
214
|
|
215
|
+
# Apply parameter filter
|
216
|
+
#
|
217
|
+
# @param [Hash] params to be filtered
|
218
|
+
#
|
219
|
+
# @return [Hash] filtered parameters
|
220
|
+
def filter(params)
|
221
|
+
if @filter_params
|
222
|
+
filtered_params = {}
|
223
|
+
params.each { |k, p| filtered_params[k] = @filter_params.include?(k.to_s) ? FILTERED_PARAM_VALUE : p }
|
224
|
+
filtered_params
|
225
|
+
end
|
226
|
+
end
|
227
|
+
|
204
228
|
end # ErrorTracker
|
205
229
|
|
206
230
|
end # RightScale
|
data/right_agent.gemspec
CHANGED
@@ -25,8 +25,8 @@ require 'rbconfig'
|
|
25
25
|
|
26
26
|
Gem::Specification.new do |spec|
|
27
27
|
spec.name = 'right_agent'
|
28
|
-
spec.version = '2.3.
|
29
|
-
spec.date = '2014-06-
|
28
|
+
spec.version = '2.3.2'
|
29
|
+
spec.date = '2014-06-18'
|
30
30
|
spec.authors = ['Lee Kirchhoff', 'Raphael Simon', 'Tony Spataro', 'Scott Messier']
|
31
31
|
spec.email = 'lee@rightscale.com'
|
32
32
|
spec.homepage = 'https://github.com/rightscale/right_agent'
|
data/spec/error_tracker_spec.rb
CHANGED
@@ -40,13 +40,18 @@ describe RightScale::ErrorTracker do
|
|
40
40
|
@tracker = RightScale::ErrorTracker.instance
|
41
41
|
@log = flexmock(RightScale::Log)
|
42
42
|
@brake = flexmock(HydraulicBrake)
|
43
|
+
@options = {
|
44
|
+
:shard_id => @shard_id,
|
45
|
+
:trace_level => @trace_level,
|
46
|
+
:airbrake_endpoint => @endpoint,
|
47
|
+
:airbrake_api_key => @api_key,
|
48
|
+
:filter_params => [:password] }
|
43
49
|
end
|
44
50
|
|
45
51
|
context :init do
|
46
52
|
it "initializes the tracker" do
|
47
|
-
flexmock(@tracker).should_receive(:notify_init).with(@agent_name, @
|
48
|
-
@tracker.init(@agent, @agent_name,
|
49
|
-
:airbrake_endpoint => @endpoint, :airbrake_api_key => @api_key).should be true
|
53
|
+
flexmock(@tracker).should_receive(:notify_init).with(@agent_name, @options).once
|
54
|
+
@tracker.init(@agent, @agent_name, @options).should be true
|
50
55
|
@tracker.instance_variable_get(:@agent).should == @agent
|
51
56
|
@tracker.instance_variable_get(:@trace_level).should == @trace_level
|
52
57
|
@tracker.exception_stats.should be_a RightSupport::Stats::Exceptions
|
@@ -154,8 +159,7 @@ describe RightScale::ErrorTracker do
|
|
154
159
|
context :notify do
|
155
160
|
before(:each) do
|
156
161
|
@exception = RuntimeError.new("error")
|
157
|
-
@tracker.init(@agent, @agent_name,
|
158
|
-
:airbrake_endpoint => @endpoint, :airbrake_api_key => @api_key)
|
162
|
+
@tracker.init(@agent, @agent_name, @options)
|
159
163
|
@cgi_data = @tracker.instance_variable_get(:@cgi_data)
|
160
164
|
end
|
161
165
|
|
@@ -204,6 +208,28 @@ describe RightScale::ErrorTracker do
|
|
204
208
|
@tracker.notify(@exception, packet = nil, agent = nil, "component").should be true
|
205
209
|
end
|
206
210
|
|
211
|
+
it "converts non-nil, non-hash payload in packet to a hash" do
|
212
|
+
request = RightScale::Request.new("/foo/bar", "payload", :token => "token")
|
213
|
+
@brake.should_receive(:notify).with(on { |a| a[:parameters] == {:param => "payload"} }).once
|
214
|
+
@tracker.notify(@exception, request).should be true
|
215
|
+
end
|
216
|
+
|
217
|
+
it "converts non-nil, non-hash data in event to a hash" do
|
218
|
+
@brake.should_receive(:notify).with(on { |a| a[:parameters] == {:param => "payload"} }).once
|
219
|
+
@tracker.notify(@exception, {"uuid" => "token", "path" => "/foo/bar", "data" => "payload"}).should be true
|
220
|
+
end
|
221
|
+
|
222
|
+
it "omits :parameters from notification if payload in packet is nil" do
|
223
|
+
request = RightScale::Request.new("/foo/bar", nil, :token => "token")
|
224
|
+
@brake.should_receive(:notify).with(on { |a| !a.has_key?(:parameters) }).once
|
225
|
+
@tracker.notify(@exception, request).should be true
|
226
|
+
end
|
227
|
+
|
228
|
+
it "omits :parameters from notification if data in packet is nil" do
|
229
|
+
@brake.should_receive(:notify).with(on { |a| !a.has_key?(:parameters) }).once
|
230
|
+
@tracker.notify(@exception, {"uuid" => "token", "path" => "/foo/bar", "data" => nil}).should be true
|
231
|
+
end
|
232
|
+
|
207
233
|
it "functions even if cgi_data has not been initialized by notify_init" do
|
208
234
|
@tracker.instance_variable_set(:@cgi_data, nil)
|
209
235
|
@brake.should_receive(:notify).with(on { |a| a[:error_message] == "error" &&
|
@@ -223,8 +249,7 @@ describe RightScale::ErrorTracker do
|
|
223
249
|
|
224
250
|
context :notify_callback do
|
225
251
|
it "returns proc that calls notify" do
|
226
|
-
@tracker.init(@agent, @agent_name,
|
227
|
-
:airbrake_endpoint => @endpoint, :airbrake_api_key => @api_key)
|
252
|
+
@tracker.init(@agent, @agent_name, @options)
|
228
253
|
flexmock(@tracker).should_receive(:notify).with("exception", "packet", "agent", "component").once
|
229
254
|
@tracker.notify_callback.call("exception", "packet", "agent", "component")
|
230
255
|
end
|
@@ -265,17 +290,16 @@ describe RightScale::ErrorTracker do
|
|
265
290
|
|
266
291
|
it "does not initialize if Airbrake endpoint or API key is undefined" do
|
267
292
|
@brake.should_receive(:configure).never
|
268
|
-
@tracker.send(:notify_init, @agent_name, @
|
293
|
+
@tracker.send(:notify_init, @agent_name, @options.merge(:airbrake_endpoint => nil))
|
269
294
|
@tracker.instance_variable_get(:@notify_enabled).should be false
|
270
|
-
@tracker.send(:notify_init, @agent_name, @
|
295
|
+
@tracker.send(:notify_init, @agent_name, @options.merge(:airbrake_api_key => nil))
|
271
296
|
@tracker.instance_variable_get(:@notify_enabled).should be false
|
272
|
-
@tracker.instance_variable_get(:@cgi_data).should be_empty
|
273
297
|
end
|
274
298
|
|
275
299
|
it "initializes cgi data and configures HydraulicBrake" do
|
276
300
|
config = ConfigMock.new
|
277
301
|
@brake.should_receive(:configure).and_yield(config).once
|
278
|
-
@tracker.send(:notify_init, @agent_name, @
|
302
|
+
@tracker.send(:notify_init, @agent_name, @options).should be true
|
279
303
|
cgi_data = @tracker.instance_variable_get(:@cgi_data)
|
280
304
|
cgi_data[:agent_name].should == @agent_name
|
281
305
|
cgi_data[:pid].should be_a Integer
|
@@ -287,20 +311,36 @@ describe RightScale::ErrorTracker do
|
|
287
311
|
config.api_key.should == @api_key
|
288
312
|
config.project_root.should be_a String
|
289
313
|
@tracker.instance_variable_get(:@notify_enabled).should be true
|
314
|
+
@tracker.instance_variable_get(:@filter_params).should == ["password"]
|
290
315
|
end
|
291
316
|
|
292
317
|
it "raises exception if hydraulic_gem is not available" do
|
293
318
|
flexmock(@tracker).should_receive(:require_succeeds?).with("hydraulic_brake").and_return(false)
|
294
319
|
lambda do
|
295
|
-
@tracker.send(:notify_init, @agent_name, @
|
320
|
+
@tracker.send(:notify_init, @agent_name, @options)
|
296
321
|
end.should raise_error(RuntimeError, /hydraulic_brake gem missing/)
|
297
322
|
end
|
298
323
|
end
|
299
324
|
|
300
|
-
context
|
325
|
+
context :filter do
|
326
|
+
|
301
327
|
before(:each) do
|
302
|
-
@
|
303
|
-
|
328
|
+
@params = {:user => "me", :password => "secret"}
|
329
|
+
end
|
330
|
+
|
331
|
+
it "applies filters" do
|
332
|
+
@tracker.init(@agent, @agent_name, @options)
|
333
|
+
@tracker.send(:filter, @params).should == {:user => "me", :password => "<hidden>"}
|
334
|
+
end
|
335
|
+
|
336
|
+
it "converts parameter names to string form before comparison" do
|
337
|
+
@tracker.init(@agent, @agent_name, @options)
|
338
|
+
@tracker.send(:filter, :user => "me", "password" => "secret").should == {:user => "me", "password" => "<hidden>"}
|
339
|
+
end
|
340
|
+
|
341
|
+
it "does not filter if no filters are specified" do
|
342
|
+
@tracker.init(@agent, @agent_name, @options.merge(:filter_params => nil))
|
343
|
+
@tracker.send(:filter, @params).should == @params
|
304
344
|
end
|
305
345
|
end
|
306
346
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: right_agent
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.3.
|
4
|
+
version: 2.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lee Kirchhoff
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2014-06-
|
14
|
+
date: 2014-06-18 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: right_support
|