add limiterRefreshInterval option for limiter
This commit is contained in:
@@ -77,7 +77,7 @@ func (h *http2Handler) Init(md md.Metadata) error {
|
||||
}
|
||||
|
||||
if limiter := h.options.Limiter; limiter != nil {
|
||||
h.limiter = limiter_util.NewCachedTrafficLimiter(limiter, 30*time.Second, 60*time.Second)
|
||||
h.limiter = limiter_util.NewCachedTrafficLimiter(limiter, h.md.limiterRefreshInterval, 60*time.Second)
|
||||
}
|
||||
|
||||
for _, ro := range h.options.Recorders {
|
||||
@@ -487,11 +487,7 @@ func (h *http2Handler) observeStats(ctx context.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
d := h.md.observePeriod
|
||||
if d < time.Millisecond {
|
||||
d = 5 * time.Second
|
||||
}
|
||||
ticker := time.NewTicker(d)
|
||||
ticker := time.NewTicker(h.md.observePeriod)
|
||||
defer ticker.Stop()
|
||||
|
||||
for {
|
||||
|
||||
@@ -14,11 +14,12 @@ const (
|
||||
)
|
||||
|
||||
type metadata struct {
|
||||
probeResistance *probeResistance
|
||||
header http.Header
|
||||
hash string
|
||||
authBasicRealm string
|
||||
observePeriod time.Duration
|
||||
probeResistance *probeResistance
|
||||
header http.Header
|
||||
hash string
|
||||
authBasicRealm string
|
||||
observePeriod time.Duration
|
||||
limiterRefreshInterval time.Duration
|
||||
}
|
||||
|
||||
func (h *http2Handler) parseMetadata(md mdata.Metadata) error {
|
||||
@@ -42,7 +43,21 @@ func (h *http2Handler) parseMetadata(md mdata.Metadata) error {
|
||||
h.md.hash = mdutil.GetString(md, "hash")
|
||||
h.md.authBasicRealm = mdutil.GetString(md, "authBasicRealm")
|
||||
|
||||
h.md.observePeriod = mdutil.GetDuration(md, "observePeriod")
|
||||
h.md.observePeriod = mdutil.GetDuration(md, "observePeriod", "observer.observePeriod")
|
||||
if h.md.observePeriod == 0 {
|
||||
h.md.observePeriod = 5 * time.Second
|
||||
}
|
||||
if h.md.observePeriod < time.Second {
|
||||
h.md.observePeriod = time.Second
|
||||
}
|
||||
|
||||
h.md.limiterRefreshInterval = mdutil.GetDuration(md, "limiter.refreshInterval")
|
||||
if h.md.limiterRefreshInterval == 0 {
|
||||
h.md.limiterRefreshInterval = 30 * time.Second
|
||||
}
|
||||
if h.md.limiterRefreshInterval < time.Second {
|
||||
h.md.limiterRefreshInterval = time.Second
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user