Make BucketedTimeSeries::rate() more accurate
Summary:
Make rate() and countRate() more accurate when queried for a specific
time range.
Previously these functions divided the estimated sum/count by the entire
time range specified. This underestimated the rate if we don't actually
have data for the entire time period. (Since the sum computed only
takes into account the time range for which we have data.)
For example, if the timeseries duration was 60 seconds, but only 30
seconds of data had been entered so far, rate(now - 60, now) would
underestimate the rate by half, since there was only 30 seconds worth of
data available. The no-argument version of rate() did work correctly in
that case.
Test Plan:
Added a new unit test for this behavior.
Also fixed the existing rate test code, which had the same bug and
expected the underestimated rate.
Reviewed By: delong.j@fb.com
FB internal diff:
D778114