config: add jitter interval for watcher to avoid dos
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
15
util/jitter/random.go
Normal file
15
util/jitter/random.go
Normal file
@@ -0,0 +1,15 @@
|
||||
// Package jitter provides a random jitter
|
||||
package jitter
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/unistack-org/micro/v3/util/rand"
|
||||
)
|
||||
|
||||
// Random returns a random time to jitter with max cap specified
|
||||
func Random(d time.Duration) time.Duration {
|
||||
var rng rand.Rand
|
||||
v := rng.Float64() * float64(d.Nanoseconds())
|
||||
return time.Duration(v)
|
||||
}
|
Reference in New Issue
Block a user