right_support 2.8.17 → 2.8.20

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/VERSION CHANGED
@@ -1 +1 @@
1
- 2.8.17
1
+ 2.8.20
@@ -85,7 +85,7 @@ module RightSupport::Log
85
85
  # Instance methods that become available to classes that include Mixin.
86
86
  module InstanceMethods
87
87
  def logger
88
- @logger || self.class.logger
88
+ @logger || (self.class.respond_to?(:logger) && self.class.logger) || RightSupport::Log::Mixin.default_logger
89
89
  end
90
90
 
91
91
  def logger=(logger)
@@ -47,12 +47,20 @@ module RightSupport::Rack
47
47
  end
48
48
 
49
49
  # Add a logger to the Rack environment and call the next middleware.
50
- # Set "rack.logging.enabled" in Rack environment to indicate whether logging
51
- # is enabled for this request for use by other middleware in the call chain.
52
50
  #
53
51
  # @param [Hash] env Rack environment
52
+ # @option env [TrueClass|FalseClass] 'rack.logging.enabled' in Rack
53
+ # environment to indicate whether logging is enabled for this request for
54
+ # use by other middleware in the call chain.
55
+ # @option env [TrueClass|FalseClass] 'sinatra.error' is set by Sinatra to
56
+ # pass error info (exception object) to handlers.
57
+ # @option env [TrueClass|FalseClass] 'sinatra.error.handled' is true to
58
+ # prevent any additional error handlers in the call chain from processing
59
+ # an error that has already handled been handled (i.e. log and response)
60
+ # (default = false).
54
61
  #
55
- # @return [Object] always returns whatever value is returned by the next layer of middleware
62
+ # @return [Object] always returns whatever value is returned by the next
63
+ # layer of middleware
56
64
  def call(env)
57
65
  logger = env["rack.logger"]
58
66
  env["rack.logging.enabled"] = enabled = logging_enabled?(logger, env)
@@ -61,7 +69,9 @@ module RightSupport::Rack
61
69
 
62
70
  log_request_begin(logger, env) if enabled
63
71
  status, header, body = @app.call(env)
64
- log_exception(logger, env['sinatra.error']) if env['sinatra.error']
72
+ if env['sinatra.error'] && !env['sinatra.error.handled']
73
+ log_exception(logger, env['sinatra.error'])
74
+ end
65
75
  log_request_end(logger, status, header, began_at) if enabled
66
76
 
67
77
  return [status, header, body]
@@ -31,7 +31,7 @@ module RightSupport::Stats
31
31
  # at value V for average A to reach 90% of the original difference between A and V
32
32
  # For example, for A = 0, V = 1, RECENT_SIZE = 3 the progression for A is
33
33
  # 0, 0.3, 0.5, 0.7, 0.8, 0.86, 0.91, 0.94, 0.96, 0.97, 0.98, 0.99, ...
34
- RECENT_SIZE = 3
34
+ RECENT_SIZE = 3.0
35
35
 
36
36
  # Maximum string length for activity type
37
37
  MAX_TYPE_SIZE = 60
@@ -130,8 +130,10 @@ module RightSupport::Stats
130
130
  #
131
131
  # @return [Float, NilClass] Recent average rate, or nil if total is 0
132
132
  def avg_rate
133
- if @total > 0
134
- if @interval == 0.0 then 0.0 else 1.0 / @interval end
133
+ if @total > 1
134
+ @interval == 0.0 ? 0.0 : 1.0 / @interval
135
+ elsif @total == 1
136
+ 0.0
135
137
  end
136
138
  end
137
139
 
@@ -204,7 +206,7 @@ module RightSupport::Stats
204
206
  #
205
207
  # @return [Float] New average
206
208
  def average(current, value)
207
- ((current * (RECENT_SIZE - 1)) + value) / RECENT_SIZE.to_f
209
+ ((current * (RECENT_SIZE - 1)) + value) / RECENT_SIZE
208
210
  end
209
211
 
210
212
  public
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "right_support"
8
- s.version = "2.8.17"
8
+ s.version = "2.8.20"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Tony Spataro", "Sergey Sergyenko", "Ryan Williamson", "Lee Kirchhoff", "Alexey Karpik", "Scott Messier"]
12
- s.date = "2014-03-01"
12
+ s.date = "2014-03-21"
13
13
  s.description = "A toolkit of useful, reusable foundation code created by RightScale."
14
14
  s.email = "support@rightscale.com"
15
15
  s.extra_rdoc_files = [
@@ -137,7 +137,7 @@ Gem::Specification.new do |s|
137
137
  s.homepage = "https://github.com/rightscale/right_support"
138
138
  s.licenses = ["MIT"]
139
139
  s.require_paths = ["lib"]
140
- s.rubygems_version = "1.8.15"
140
+ s.rubygems_version = "1.8.26"
141
141
  s.summary = "Reusable foundation code."
142
142
 
143
143
  if s.respond_to? :specification_version then
@@ -7,7 +7,33 @@ end
7
7
  class Bystander < InnocentVictim
8
8
  end
9
9
 
10
+ module Parasite
11
+ include RightSupport::Log::Mixin
12
+ end
13
+
14
+ class Host
15
+ include Parasite
16
+ end
17
+
10
18
  describe RightSupport::Log::Mixin do
19
+ context 'when mixed into a module' do
20
+ before(:each) do
21
+ @victim = Host.new
22
+ end
23
+
24
+ it 'provides instance-level accesssor to hosts' do
25
+ @victim.should respond_to(:logger)
26
+ @victim.should respond_to(:logger=)
27
+ @victim.logger.info 'haha'
28
+ end
29
+
30
+ it 'provides a module-method-level accessor' do
31
+ Parasite.should respond_to(:logger)
32
+ Parasite.should respond_to(:logger=)
33
+ Parasite.logger.info 'haha'
34
+ end
35
+ end
36
+
11
37
  context 'when mixed into a base class' do
12
38
  before(:each) do
13
39
  @victim = InnocentVictim.new
@@ -16,10 +42,13 @@ describe RightSupport::Log::Mixin do
16
42
  it 'provides a class-level accessor' do
17
43
  @victim.class.should respond_to(:logger)
18
44
  @victim.class.should respond_to(:logger=)
45
+ @victim.class.logger.info 'haha'
19
46
  end
20
47
 
21
48
  it 'provides an instance-level accessor' do
22
49
  @victim.should respond_to(:logger)
50
+ @victim.should respond_to(:logger=)
51
+ @victim.logger.info 'haha'
23
52
  end
24
53
 
25
54
  context :logger do
@@ -88,4 +117,4 @@ describe RightSupport::Log::Mixin do
88
117
  Bystander.logger.error('foo')
89
118
  end
90
119
  end
91
- end
120
+ end
@@ -45,6 +45,13 @@ describe RightSupport::Rack::RequestLogger do
45
45
  @logger.should_receive(:error)
46
46
  @middleware.call(@env)
47
47
  end
48
+
49
+ it 'skips logging the exception when already handled' do
50
+ @logger.should_receive(:info)
51
+ @logger.should_receive(:error).never
52
+ @env['sinatra.error.handled'] = true
53
+ @middleware.call(@env)
54
+ end
48
55
  end
49
56
 
50
57
  context 'when limit logging extent' do
@@ -181,11 +181,20 @@ describe RightSupport::Stats::Activity do
181
181
 
182
182
  context :avg_rate do
183
183
  it "converts interval to rate" do
184
+ flexmock(Time).should_receive(:now).and_return(1000020, 1000042)
185
+ @stats.avg_rate.should be_nil
186
+ @stats.update
187
+ @stats.update
188
+ @stats.instance_variable_get(:@interval).should == 4.0
189
+ @stats.avg_rate.should == 0.25
190
+ end
191
+
192
+ it "does not convert interval to rate if there is only one event" do
184
193
  flexmock(Time).should_receive(:now).and_return(1000020)
185
194
  @stats.avg_rate.should be_nil
186
195
  @stats.update
187
196
  @stats.instance_variable_get(:@interval).should == 2.0
188
- @stats.avg_rate.should == 0.5
197
+ @stats.avg_rate.should == 0.0
189
198
  end
190
199
  end
191
200
 
@@ -236,7 +245,7 @@ describe RightSupport::Stats::Activity do
236
245
  it "returns all activity aspects that were measured except duration" do
237
246
  flexmock(Time).should_receive(:now).and_return(1000010)
238
247
  @stats.update
239
- @stats.all.should == {"last" => {"elapsed" => 0}, "total" => 1, "rate" => 1.0}
248
+ @stats.all.should == {"last" => {"elapsed" => 0}, "total" => 1, "rate" => 0.0}
240
249
  end
241
250
 
242
251
  it "excludes rate if it is not being measured" do
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: right_support
3
3
  version: !ruby/object:Gem::Version
4
- hash: 13
4
+ hash: 7
5
5
  prerelease:
6
6
  segments:
7
7
  - 2
8
8
  - 8
9
- - 17
10
- version: 2.8.17
9
+ - 20
10
+ version: 2.8.20
11
11
  platform: ruby
12
12
  authors:
13
13
  - Tony Spataro
@@ -20,7 +20,7 @@ autorequire:
20
20
  bindir: bin
21
21
  cert_chain: []
22
22
 
23
- date: 2014-03-01 00:00:00 Z
23
+ date: 2014-03-21 00:00:00 Z
24
24
  dependencies:
25
25
  - !ruby/object:Gem::Dependency
26
26
  type: :development