right_agent 2.1.1 → 2.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -145,7 +145,8 @@ module RightScale
145
145
  # provided during object initialization
146
146
  # @option options [Hash] :headers to be added to request
147
147
  # @option options [Numeric] :poll_timeout maximum wait for individual poll; defaults to :request_timeout
148
- # @option options [Symbol] :log_level to use when logging information about the request other than errors
148
+ # @option options [Symbol] :log_level to use when logging information about the request other than errors;
149
+ # defaults to :info
149
150
  #
150
151
  # @return [Object] result returned by receiver of request
151
152
  #
@@ -154,11 +155,11 @@ module RightScale
154
155
  def request(verb, path, params = {}, options = {})
155
156
  started_at = Time.now
156
157
  filter = @filter_params + (options[:filter_params] || []).map { |p| p.to_s }
157
- log_level = options[:log_level] || Log.level
158
+ log_level = options[:log_level] || :info
158
159
  request_uuid = options[:request_uuid] || RightSupport::Data::UUID.generate
159
160
  connect_options, request_options = @http_client.options(verb, path, params, request_headers(request_uuid, options), options)
160
161
 
161
- Log.send(log_level, "Requesting #{verb.to_s.upcase} <#{request_uuid}> " + log_text(path, params, filter, log_level))
162
+ Log.send(log_level, "Requesting #{verb.to_s.upcase} <#{request_uuid}> " + log_text(path, params, filter))
162
163
 
163
164
  used = {}
164
165
  result, code, body, headers = if verb != :poll
@@ -171,14 +172,14 @@ module RightScale
171
172
  result
172
173
  rescue RightSupport::Net::NoResult => e
173
174
  handle_no_result(e, used[:host]) do |e2|
174
- log_failure(used[:host], path, params, filter, request_uuid, started_at, log_level, e2)
175
+ log_failure(used[:host], path, params, filter, request_uuid, started_at, e2)
175
176
  end
176
177
  rescue RestClient::Exception => e
177
178
  e2 = HttpExceptions.convert(e)
178
- log_failure(used[:host], path, params, filter, request_uuid, started_at, log_level, e2)
179
+ log_failure(used[:host], path, params, filter, request_uuid, started_at, e2)
179
180
  raise e2
180
181
  rescue Exception => e
181
- log_failure(used[:host], path, params, filter, request_uuid, started_at, log_level, e)
182
+ log_failure(used[:host], path, params, filter, request_uuid, started_at, e)
182
183
  raise
183
184
  end
184
185
 
@@ -304,7 +305,7 @@ module RightScale
304
305
  length = (headers && headers[:content_length]) || (body && body.size) || "-"
305
306
  duration = "%.0fms" % ((Time.now - started_at) * 1000)
306
307
  completed = "Completed <#{request_uuid}> in #{duration} | #{code || "nil"} [#{host}#{path}] | #{length} bytes"
307
- completed << " | #{result.inspect}" if log_level == :debug
308
+ completed << " | #{result.inspect}" if Log.level == :debug
308
309
  Log.send(log_level, completed)
309
310
  true
310
311
  end
@@ -318,14 +319,13 @@ module RightScale
318
319
  # @param [Array] filter list of parameters whose value is to be hidden
319
320
  # @param [String] request_uuid uniquely identifying request
320
321
  # @param [Time] started_at time for request
321
- # @param [Symbol] log_level to use when logging information about the request
322
322
  # @param [Exception, String] exception or message that should be logged
323
323
  #
324
324
  # @return [TrueClass] Always return true
325
- def log_failure(host, path, params, filter, request_uuid, started_at, log_level, exception)
325
+ def log_failure(host, path, params, filter, request_uuid, started_at, exception)
326
326
  code = exception.respond_to?(:http_code) ? exception.http_code : "nil"
327
327
  duration = "%.0fms" % ((Time.now - started_at) * 1000)
328
- Log.error("Failed <#{request_uuid}> in #{duration} | #{code} " + log_text(path, params, filter, log_level, host, exception))
328
+ Log.error("Failed <#{request_uuid}> in #{duration} | #{code} " + log_text(path, params, filter, host, exception))
329
329
  true
330
330
  end
331
331
 
@@ -334,13 +334,12 @@ module RightScale
334
334
  # @param [String] path in URI for desired resource
335
335
  # @param [Hash] params for HTTP request
336
336
  # @param [Array, NilClass] filter augmentation to base filter list
337
- # @param [Symbol] log_level to use when logging information about the request
338
337
  # @param [String] host server URL where request was attempted if known
339
338
  # @param [Exception, String, NilClass] exception or failure message that should be logged
340
339
  #
341
340
  # @return [String] Log text
342
- def log_text(path, params, filter, log_level, host = nil, exception = nil)
343
- filtered_params = (exception || log_level == :debug) ? filter(params, filter).inspect : nil
341
+ def log_text(path, params, filter, host = nil, exception = nil)
342
+ filtered_params = (exception || Log.level == :debug) ? filter(params, filter).inspect : nil
344
343
  text = filtered_params ? "#{path} #{filtered_params}" : path
345
344
  text = "[#{host}#{text}]" if host
346
345
  text << " | #{self.class.exception_text(exception)}" if exception
@@ -530,7 +530,6 @@ module RightScale
530
530
 
531
531
  # Make long-polling request to receive one or more events
532
532
  # Do not return until an event is received or the polling times out or fails
533
- # Limit logging unless in debug mode
534
533
  #
535
534
  # @param [Array, NilClass] routing_keys as strings to assist router in delivering
536
535
  # event to interested parties
@@ -552,7 +551,6 @@ module RightScale
552
551
  params[:ack] = ack if ack && ack.any?
553
552
 
554
553
  options = {
555
- :log_level => :debug,
556
554
  :request_timeout => @connect_interval,
557
555
  :poll_timeout => @options[:listen_timeout] }
558
556
 
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.1.1'
29
- spec.date = '2014-04-01'
28
+ spec.version = '2.1.2'
29
+ spec.date = '2014-04-07'
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'
@@ -140,26 +140,27 @@ describe RightScale::BalancedHttpClient do
140
140
  @client.request(:post, @path) rescue nil
141
141
  end
142
142
 
143
- it "logs using specified log level" do
143
+ it "logs using specified :log_level" do
144
144
  @params = {:some => "data"}
145
- @log.should_receive(:debug).with("Requesting POST <random uuid> /foo/bar {:some=>\"data\"}").once
146
- @log.should_receive(:debug).with("Completed <random uuid> in 10ms | 200 [http://my.com/foo/bar] | 11 bytes | {\"out\"=>123}").once
145
+ @log.should_receive(:debug).with("Requesting POST <random uuid> /foo/bar").once
146
+ @log.should_receive(:debug).with("Completed <random uuid> in 10ms | 200 [http://my.com/foo/bar] | 11 bytes").once
147
147
  @client.request(:post, @path, @params, :log_level => :debug)
148
148
  end
149
149
 
150
- it "logs using configured log level if none specified" do
150
+ it "logs using :info level by default" do
151
151
  @params = {:some => "data"}
152
152
  @log.should_receive(:level).and_return(:debug)
153
- @log.should_receive(:debug).with("Requesting POST <random uuid> /foo/bar {:some=>\"data\"}").once
154
- @log.should_receive(:debug).with("Completed <random uuid> in 10ms | 200 [http://my.com/foo/bar] | 11 bytes | {\"out\"=>123}").once
153
+ @log.should_receive(:info).with("Requesting POST <random uuid> /foo/bar {:some=>\"data\"}").once
154
+ @log.should_receive(:info).with("Completed <random uuid> in 10ms | 200 [http://my.com/foo/bar] | 11 bytes | {\"out\"=>123}").once
155
155
  @client.request(:post, @path, @params)
156
156
  end
157
157
 
158
- it "appends specified filter parameters to list" do
158
+ it "appends specified filter parameters to list when Log.level is :debug" do
159
159
  @params = {:some => "data", :secret => "data", :other => "data"}
160
- @log.should_receive(:debug).with("Requesting POST <random uuid> /foo/bar {:some=>\"data\", :secret=>\"<hidden>\", :other=>\"<hidden>\"}").once
161
- @log.should_receive(:debug).with("Completed <random uuid> in 10ms | 200 [http://my.com/foo/bar] | 11 bytes | {\"out\"=>123}").once
162
- @client.request(:post, @path, @params, :log_level => :debug, :filter_params => [:other])
160
+ @log.should_receive(:level).and_return(:debug)
161
+ @log.should_receive(:info).with("Requesting POST <random uuid> /foo/bar {:some=>\"data\", :secret=>\"<hidden>\", :other=>\"<hidden>\"}").once
162
+ @log.should_receive(:info).with("Completed <random uuid> in 10ms | 200 [http://my.com/foo/bar] | 11 bytes | {\"out\"=>123}").once
163
+ @client.request(:post, @path, @params, :filter_params => [:other])
163
164
  end
164
165
 
165
166
  it "removes user and password from host when logging" do
@@ -433,7 +434,7 @@ describe RightScale::BalancedHttpClient do
433
434
  @client.send(:log_success, @result, 200, @body, @headers, "http://my.com", @path, "uuid", @now, :info).should be true
434
435
  end
435
436
 
436
- it "logs response length using response body size of :content_lenght not available" do
437
+ it "logs response length using response body size of :content_length not available" do
437
438
  @log.should_receive(:info).with("Completed <uuid> in 10ms | 200 [http://my.com/foo/bar] | 11 bytes").once
438
439
  @client.send(:log_success, @result, 200, @body, @headers, "http://my.com", @path, "uuid", @now, :info).should be true
439
440
  end
@@ -443,9 +444,15 @@ describe RightScale::BalancedHttpClient do
443
444
  @client.send(:log_success, @result, 200, @body, @headers, "http://my.com", @path, "uuid", @now - 0.01, :info).should be true
444
445
  end
445
446
 
446
- it "log result if log level option set to :debug" do
447
- @log.should_receive(:debug).with("Completed <uuid> in 10ms | 200 [http://my.com/foo/bar] | 11 bytes | {\"out\"=>123}").once
448
- @client.send(:log_success, @result, 200, @body, @headers, "http://my.com", @path, "uuid", @now, :debug).should be true
447
+ it "log result if Log.level is set to :debug" do
448
+ @log.should_receive(:level).and_return(:debug)
449
+ @log.should_receive(:info).with("Completed <uuid> in 10ms | 200 [http://my.com/foo/bar] | 11 bytes | {\"out\"=>123}").once
450
+ @client.send(:log_success, @result, 200, @body, @headers, "http://my.com", @path, "uuid", @now, :info).should be true
451
+ end
452
+
453
+ it "logs using the specified log_level" do
454
+ @log.should_receive(:debug).once
455
+ @client.send(:log_success, @result, 200, @body, @headers, "http://my.com", @path, "uuid", @now, :debug)
449
456
  end
450
457
  end
451
458
 
@@ -457,17 +464,17 @@ describe RightScale::BalancedHttpClient do
457
464
  it "logs exception" do
458
465
  exception = RightScale::HttpExceptions.create(400, "bad data")
459
466
  @log.should_receive(:error).with("Failed <uuid> in 10ms | 400 [http://my.com/foo/bar \"params\"] | 400 Bad Request: bad data").once
460
- @client.send(:log_failure, @url, @path, "params", [], "uuid", @now, :info, exception).should be true
467
+ @client.send(:log_failure, @url, @path, "params", [], "uuid", @now, exception).should be true
461
468
  end
462
469
 
463
470
  it "logs error string" do
464
471
  @log.should_receive(:error).with("Failed <uuid> in 10ms | nil [http://my.com/foo/bar \"params\"] | bad data").once
465
- @client.send(:log_failure, @url, @path, "params", [], "uuid", @now, :info, "bad data").should be true
472
+ @client.send(:log_failure, @url, @path, "params", [], "uuid", @now, "bad data").should be true
466
473
  end
467
474
 
468
475
  it "filters parameters" do
469
476
  @log.should_receive(:error).with("Failed <uuid> in 10ms | nil [http://my.com/foo/bar {:secret=>\"<hidden>\"}] | bad data").once
470
- @client.send(:log_failure, @url, @path, {:secret => "data"}, ["secret"], "uuid", @now, :info, "bad data").should be true
477
+ @client.send(:log_failure, @url, @path, {:secret => "data"}, ["secret"], "uuid", @now, "bad data").should be true
471
478
  end
472
479
  end
473
480
 
@@ -478,37 +485,38 @@ describe RightScale::BalancedHttpClient do
478
485
 
479
486
  context "when no exception" do
480
487
 
481
- context "in info mode with no host" do
488
+ context "and Log.level is :info with no host" do
482
489
  it "generates text containing path" do
483
- text = @client.send(:log_text, @path, {:value => 123}, [], :info)
490
+ text = @client.send(:log_text, @path, {:value => 123}, [])
484
491
  text.should == "/foo/bar"
485
492
  end
486
493
  end
487
494
 
488
- context "in info mode with host" do
495
+ context "and Log.level is :info with host" do
489
496
  it "generates text containing host and path" do
490
- text = @client.send(:log_text, @path, {:value => 123}, [], :info, @url)
497
+ text = @client.send(:log_text, @path, {:value => 123}, [], @url)
491
498
  text.should == "[http://my.com/foo/bar]"
492
499
  end
493
500
  end
494
501
 
495
- context "and in debug mode" do
502
+ context "and Log.level is :debug" do
496
503
  it "generates text containing containing host, path, and filtered parameters" do
497
- text = @client.send(:log_text, @path, {:some => "data", :secret => "data"}, ["secret"], :debug, @url)
504
+ @log.should_receive(:level).and_return(:debug)
505
+ text = @client.send(:log_text, @path, {:some => "data", :secret => "data"}, ["secret"], @url)
498
506
  text.should == "[http://my.com/foo/bar {:some=>\"data\", :secret=>\"<hidden>\"}]"
499
507
  end
500
508
  end
501
509
  end
502
510
 
503
511
  context "when exception" do
504
- it "includes params regardless of mode" do
505
- text = @client.send(:log_text, @path, {:some => "data", :secret => "data"}, ["secret"], :info, @url, "failed")
512
+ it "includes params regardless of Log.level" do
513
+ text = @client.send(:log_text, @path, {:some => "data", :secret => "data"}, ["secret"], @url, "failed")
506
514
  text.should == "[http://my.com/foo/bar {:some=>\"data\", :secret=>\"<hidden>\"}] | failed"
507
515
  end
508
516
 
509
517
  it "includes exception text" do
510
518
  exception = RightScale::HttpExceptions.create(400, "bad data")
511
- text = @client.send(:log_text, @path, {:some => "data", :secret => "data"}, ["secret"], :info, @url, exception)
519
+ text = @client.send(:log_text, @path, {:some => "data", :secret => "data"}, ["secret"], @url, exception)
512
520
  text.should == "[http://my.com/foo/bar {:some=>\"data\", :secret=>\"<hidden>\"}] | 400 Bad Request: bad data"
513
521
  end
514
522
  end
@@ -683,7 +683,7 @@ describe RightScale::RouterClient do
683
683
  it "uses listen timeout for request poll timeout and connect interval for request timeout" do
684
684
  @client.instance_variable_set(:@connect_interval, 300)
685
685
  flexmock(@client).should_receive(:make_request).with(:poll, "/listen", Hash, "listen", nil,
686
- {:poll_timeout => 60, :request_timeout => 300, :log_level => :debug}).and_return([@event]).once
686
+ {:poll_timeout => 60, :request_timeout => 300}).and_return([@event]).once
687
687
  @client.send(:long_poll, @routing_keys, @ack, &@handler)
688
688
  end
689
689
 
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.1.1
4
+ version: 2.1.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2014-04-01 00:00:00.000000000 Z
15
+ date: 2014-04-07 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: right_support
@@ -412,7 +412,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
412
412
  version: '0'
413
413
  segments:
414
414
  - 0
415
- hash: 4244231635060832919
415
+ hash: 701936506677112594
416
416
  requirements: []
417
417
  rubyforge_project:
418
418
  rubygems_version: 1.8.26