Skip to content

Commit

Permalink
Prevent infinite keys on long idle samples
Browse files Browse the repository at this point in the history
  • Loading branch information
lmarburger committed Jul 3, 2012
1 parent 0597f7f commit a3ecaf0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/metriks/exponentially_decaying_sample.rb
Expand Up @@ -39,6 +39,7 @@ def snapshot
def update(value, timestamp = Time.now)
@mutex.synchronize do
priority = weight(timestamp - @start_time) / rand
priority = Float::MAX if priority.infinite?
new_count = @count.update { |v| v + 1 }

if priority.nan?
Expand Down
11 changes: 11 additions & 0 deletions test/histogram_test.rb
Expand Up @@ -185,4 +185,15 @@ def test_exponential_sample_snapshot_threaded

assert_equal 49.5, snapshot.median
end

def test_long_idle_sample
Time.stubs(:now).returns(Time.new(2000))
sample = Metriks::ExponentiallyDecayingSample.new(Metriks::Histogram::DEFAULT_SAMPLE_SIZE, Metriks::Histogram::DEFAULT_ALPHA)
Time.unstub(:now)
@histogram = Metriks::Histogram.new(sample)

@histogram.update(5)

assert_equal 5, @histogram.min
end
end

0 comments on commit a3ecaf0

Please sign in to comment.