rcrowley / go-metrics

Go port of Coda Hale's Metrics library
Other
3.43k stars 493 forks source link

ExpDecaySample.Update - problem with rand.Float64() divider #281

Open LopatkinEvgeniy opened 3 years ago

LopatkinEvgeniy commented 3 years ago

There is a code:

func (s *ExpDecaySample) update(t time.Time, v int64) {
// ...

    s.values.Push(expDecaySample{
        k: math.Exp(t.Sub(s.t0).Seconds()*s.alpha) / rand.Float64(),
        v: v,
    })

// ...
{

If rand.Float64() will return zero then the "k" value will be Inf. So this value will never be dropped (until rescale). This will increase the error of the results. Maybe division by random number is not a good idea?