Skip to content
Browse files

some exdec sanity check guards

  • Loading branch information...
1 parent c839a91 commit 986523fda1c6a0e22eecd8e26e8df2c513d22050 @joewilliams joewilliams committed Apr 24, 2012
Showing with 9 additions and 6 deletions.
  1. +4 −1 src/folsom_sample_exdec.erl
  2. +5 −5 test/folsom_erlang_checks.erl
View
5 src/folsom_sample_exdec.erl
@@ -92,7 +92,10 @@ update_on_priority(#exdec{reservoir = Reservoir} = Sample, First, Priority, NewS
update_on_priority(Sample, _, _, _, _) ->
Sample.
-weight(Alpha, T) ->
+% gaurd against a possible bug, T should always be =< ?HOURSECS
+% also to prevent overflow issues make sure alpha is always =<
+% math:log(1.79769313486231570815e+308) / 3599 = 0.19721664709457737
+weight(Alpha, T) when T =< ?HOURSECS, Alpha =< 0.19721664709457737 ->
math:exp(Alpha * T).
priority(Alpha, Time, Start, Rand) ->
View
10 test/folsom_erlang_checks.erl
@@ -46,13 +46,13 @@ create_metrics() ->
ok = folsom_metrics:new_counter(counter),
ok = folsom_metrics:new_gauge(<<"gauge">>),
- ok = folsom_metrics:new_histogram(<<"uniform">>, uniform, 5000, 1),
- ok = folsom_metrics:new_histogram(exdec, exdec, 5000, 1),
- ok = folsom_metrics:new_histogram(none, none, 5000, 1),
+ ok = folsom_metrics:new_histogram(<<"uniform">>, uniform, 5000),
+ ok = folsom_metrics:new_histogram(exdec, exdec),
+ ok = folsom_metrics:new_histogram(none, none, 5000),
- ok = folsom_metrics:new_histogram(nonea, none, 5000, 1),
+ ok = folsom_metrics:new_histogram(nonea, none, 5000),
- ok = folsom_metrics:new_histogram(timed, none, 5000, 1),
+ ok = folsom_metrics:new_histogram(timed, none, 5000),
ok = folsom_metrics:new_history(<<"history">>),
ok = folsom_metrics:new_meter(meter),

0 comments on commit 986523f

Please sign in to comment.
Something went wrong with that request. Please try again.