right_support 2.8.21 → 2.8.22

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.8.21
1
+ 2.8.22
@@ -66,7 +66,6 @@ module RightSupport::Stats
66
66
 
67
67
  # Mark the start of an activity and update counts and average rate
68
68
  # with weighting toward past activity
69
- # Ignore the update if its type contains "stats"
70
69
  #
71
70
  # @param type [String, Symbol] Type of activity, with anything that is not a symbol, true, or false
72
71
  # automatically converted to a String and truncated to MAX_TYPE_SIZE characters; defaults to nil
@@ -75,20 +74,18 @@ module RightSupport::Stats
75
74
  # @return [Time] Update time
76
75
  def update(type = nil, id = nil)
77
76
  now = Time.now
78
- if type.nil? || type !~ /stats/
79
- @interval = average(@interval, now - @last_start_time) if @measure_rate
80
- @last_start_time = now
81
- @total += 1
82
- unless type.nil?
83
- unless [Symbol, TrueClass, FalseClass].include?(type.class)
84
- type = type.inspect unless type.is_a?(String)
85
- type = type[0, MAX_TYPE_SIZE - 3] + "..." if type.size > (MAX_TYPE_SIZE - 3)
86
- end
87
- @count_per_type[type] = (@count_per_type[type] || 0) + 1
77
+ @interval = average(@interval, now - @last_start_time) if @measure_rate
78
+ @last_start_time = now
79
+ @total += 1
80
+ unless type.nil?
81
+ unless [Symbol, TrueClass, FalseClass].include?(type.class)
82
+ type = type.inspect unless type.is_a?(String)
83
+ type = type[0, MAX_TYPE_SIZE - 3] + "..." if type.size > (MAX_TYPE_SIZE - 3)
88
84
  end
89
- @last_type = type
90
- @last_id = id
85
+ @count_per_type[type] = (@count_per_type[type] || 0) + 1
91
86
  end
87
+ @last_type = type
88
+ @last_id = id
92
89
  now
93
90
  end
94
91
 
@@ -127,17 +124,13 @@ module RightSupport::Stats
127
124
  end
128
125
 
129
126
  # Convert average interval to average rate
127
+ # Adjust interval before computing average to take into account when last activity occurred
130
128
  #
131
129
  # @return [Float, NilClass] Recent average rate, or nil if total is 0
132
130
  def avg_rate
133
- if @total > 1
134
- @interval == 0.0 ? 0.0 : 1.0 / @interval
135
- elsif @total == 1
136
- 0.0
137
- end
131
+ 1.0 / average(@interval, Time.now - @last_start_time) if @measure_rate && @total > 0
138
132
  end
139
133
 
140
-
141
134
  # Get average duration of activity
142
135
  #
143
136
  # @return [Float, NilClass] Average duration in seconds of activity weighted
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{right_support}
8
- s.version = "2.8.21"
8
+ s.version = "2.8.22"
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 = %q{2014-04-04}
12
+ s.date = %q{2014-04-07}
13
13
  s.description = %q{A toolkit of useful, reusable foundation code created by RightScale.}
14
14
  s.email = %q{support@rightscale.com}
15
15
  s.extra_rdoc_files = [
@@ -74,16 +74,6 @@ describe RightSupport::Stats::Activity do
74
74
  @stats.instance_variable_get(:@count_per_type).should == {"test" => 1}
75
75
  end
76
76
 
77
- it "doesn't update counts when type contains 'stats'" do
78
- flexmock(Time).should_receive(:now).and_return(1000010)
79
- @stats.update("my stats")
80
- @stats.instance_variable_get(:@interval).should == 0.0
81
- @stats.instance_variable_get(:@last_start_time).should == @now
82
- @stats.instance_variable_get(:@avg_duration).should be_nil
83
- @stats.instance_variable_get(:@total).should == 0
84
- @stats.instance_variable_get(:@count_per_type).should == {}
85
- end
86
-
87
77
  it "limits length of type string when submitting update" do
88
78
  flexmock(Time).should_receive(:now).and_return(1000010)
89
79
  @stats.update("test 12345678901234567890123456789012345678901234567890123456789")
@@ -184,17 +174,28 @@ describe RightSupport::Stats::Activity do
184
174
  flexmock(Time).should_receive(:now).and_return(1000020, 1000042)
185
175
  @stats.avg_rate.should be_nil
186
176
  @stats.update
187
- @stats.update
188
- @stats.instance_variable_get(:@interval).should == 4.0
177
+ @stats.instance_variable_get(:@interval).should == 2.0
189
178
  @stats.avg_rate.should == 0.25
190
179
  end
191
180
 
192
- it "does not convert interval to rate if there is only one event" do
193
- flexmock(Time).should_receive(:now).and_return(1000020)
181
+ it "adjusts rate based on interval since last event" do
182
+ flexmock(Time).should_receive(:now).and_return(1000020, 1000042, 1000086)
194
183
  @stats.avg_rate.should be_nil
195
184
  @stats.update
196
- @stats.instance_variable_get(:@interval).should == 2.0
197
- @stats.avg_rate.should == 0.0
185
+ @stats.update
186
+ @stats.instance_variable_get(:@interval).should == 4.0
187
+ @stats.avg_rate.should == 0.125
188
+ end
189
+
190
+ it "does not compute average unless measuring rate is enabled" do
191
+ @stats = RightSupport::Stats::Activity.new(false)
192
+ flexmock(Time).should_receive(:now).and_return(1000010)
193
+ @stats.update
194
+ @stats.avg_rate.should be_nil
195
+ end
196
+
197
+ it "does not compute average if there have been no events" do
198
+ @stats.avg_rate.should be_nil
198
199
  end
199
200
  end
200
201
 
@@ -243,9 +244,9 @@ describe RightSupport::Stats::Activity do
243
244
 
244
245
  context :all do
245
246
  it "returns all activity aspects that were measured except duration" do
246
- flexmock(Time).should_receive(:now).and_return(1000010)
247
+ flexmock(Time).should_receive(:now).and_return(1000020, 1000042)
247
248
  @stats.update
248
- @stats.all.should == {"last" => {"elapsed" => 0}, "total" => 1, "rate" => 0.0}
249
+ @stats.all.should == {"last" => {"elapsed" => 22}, "total" => 1, "rate" => 0.25}
249
250
  end
250
251
 
251
252
  it "excludes rate if it is not being measured" do
@@ -336,7 +336,7 @@ describe RightSupport::Stats do
336
336
  " (1) Mon Jan 12 #{@hr}:46:40 Exception: Test error\n" +
337
337
  " heartbeat : 60 sec\n" +
338
338
  " returns : no queue consumers: 67%, no queue: 33%, total: 3, \n" +
339
- " last: no queue consumers (10 sec ago), rate: 0/sec\n"
339
+ " last: no queue consumers (10 sec ago), rate: 1.0/sec\n"
340
340
  end
341
341
  end
342
342
 
@@ -350,7 +350,7 @@ describe RightSupport::Stats do
350
350
  activity.update("more testing")
351
351
  flexmock(Time).should_receive(:now).and_return(1000010)
352
352
  @helpers.activity_str(activity.all).should == "more testing: 75%, testing: 25%, total: 4, last: more testing (10 sec ago), " +
353
- "rate: 0/sec"
353
+ "rate: 1.0/sec"
354
354
  end
355
355
 
356
356
  it 'converts last activity stats to string' do
@@ -496,7 +496,7 @@ describe RightSupport::Stats do
496
496
  result = @helpers.sub_stats_str("my sub-stats", stats, :name_width => 13, :sub_stat_value_width => 60)
497
497
  result.should == "my sub-stats : activity1 % : none\n" +
498
498
  " activity1 last : none\n" +
499
- " activity2 % : more testing: 75%, testing: 25%, total: 4\n" +
499
+ " activity2 % : more testing: 60%, testing: 20%, stats: 20%, total: 5\n" +
500
500
  " activity2 last : more testing: 46 min 40 sec ago\n" +
501
501
  " activity3 last : testing forever: 46 min 40 sec ago and still active\n" +
502
502
  " empty_hash : none\n" +
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: 5
4
+ hash: 3
5
5
  prerelease: false
6
6
  segments:
7
7
  - 2
8
8
  - 8
9
- - 21
10
- version: 2.8.21
9
+ - 22
10
+ version: 2.8.22
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-04-04 00:00:00 -07:00
23
+ date: 2014-04-07 00:00:00 -07:00
24
24
  default_executable:
25
25
  dependencies:
26
26
  - !ruby/object:Gem::Dependency