config: add jitter interval for watcher to avoid dos

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
2021-08-04 00:37:56 +03:00
parent 1e8e57a708
commit f47fbb1030
6 changed files with 86 additions and 14 deletions

View File

@@ -5,9 +5,9 @@ import (
"reflect"
"strconv"
"strings"
"time"
"github.com/imdario/mergo"
"github.com/unistack-org/micro/v3/util/jitter"
rutil "github.com/unistack-org/micro/v3/util/reflect"
)
@@ -302,7 +302,7 @@ type defaultWatcher struct {
}
func (w *defaultWatcher) run() {
ticker := time.NewTicker(w.wopts.Interval)
ticker := jitter.NewTicker(w.wopts.MinInterval, w.wopts.MaxInterval)
defer ticker.Stop()
src := w.opts.Struct