Ensure that Cache options are reloaded when `consul reload` is performed.
This will apply cache throttling parameters are properly applied: * cache.EntryFetchMaxBurst * cache.EntryFetchRate When values are updated, a log is displayed in info.
This commit is contained in:
parent
8d66456880
commit
dd385f05e6
|
@ -3748,6 +3748,12 @@ func (a *Agent) reloadConfigInternal(newCfg *config.RuntimeConfig) error {
|
|||
return err
|
||||
}
|
||||
|
||||
if a.cache.ReloadOptions(newCfg.Cache) {
|
||||
a.logger.Info("Cache options have been updated")
|
||||
} else {
|
||||
a.logger.Debug("Cache options have not been modified")
|
||||
}
|
||||
|
||||
// Update filtered metrics
|
||||
metrics.UpdateFilter(newCfg.Telemetry.AllowedPrefixes,
|
||||
newCfg.Telemetry.BlockedPrefixes)
|
||||
|
|
|
@ -144,16 +144,21 @@ type Options struct {
|
|||
EntryFetchRate rate.Limit
|
||||
}
|
||||
|
||||
// New creates a new cache with the given RPC client and reasonable defaults.
|
||||
// Further settings can be tweaked on the returned value.
|
||||
func New(options Options) *Cache {
|
||||
// applyDefaultValuesOnOptions set default values on options and returned updated value
|
||||
func applyDefaultValuesOnOptions(options Options) Options {
|
||||
if options.EntryFetchRate == 0.0 {
|
||||
options.EntryFetchRate = DefaultEntryFetchRate
|
||||
}
|
||||
if options.EntryFetchMaxBurst == 0 {
|
||||
options.EntryFetchMaxBurst = DefaultEntryFetchMaxBurst
|
||||
}
|
||||
return options
|
||||
}
|
||||
|
||||
// New creates a new cache with the given RPC client and reasonable defaults.
|
||||
// Further settings can be tweaked on the returned value.
|
||||
func New(options Options) *Cache {
|
||||
options = applyDefaultValuesOnOptions(options)
|
||||
// Initialize the heap. The buffer of 1 is really important because
|
||||
// its possible for the expiry loop to trigger the heap to update
|
||||
// itself and it'd block forever otherwise.
|
||||
|
@ -234,6 +239,28 @@ func (c *Cache) RegisterType(n string, typ Type) {
|
|||
c.types[n] = typeEntry{Name: n, Type: typ, Opts: &opts}
|
||||
}
|
||||
|
||||
// ReloadOptions updates the cache with the new options
|
||||
// return true if Cache is updated, false if already up to date
|
||||
func (c *Cache) ReloadOptions(options Options) bool {
|
||||
options = applyDefaultValuesOnOptions(options)
|
||||
if c.options.EntryFetchRate != options.EntryFetchRate || c.options.EntryFetchMaxBurst != options.EntryFetchMaxBurst {
|
||||
c.entriesLock.RLock()
|
||||
defer c.entriesLock.RUnlock()
|
||||
for _, entry := range c.entries {
|
||||
if c.options.EntryFetchRate != options.EntryFetchRate {
|
||||
entry.FetchRateLimiter.SetLimit(options.EntryFetchRate)
|
||||
}
|
||||
if c.options.EntryFetchMaxBurst != options.EntryFetchMaxBurst {
|
||||
entry.FetchRateLimiter.SetBurst(options.EntryFetchMaxBurst)
|
||||
}
|
||||
}
|
||||
c.options.EntryFetchRate = options.EntryFetchRate
|
||||
c.options.EntryFetchMaxBurst = options.EntryFetchMaxBurst
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// Get loads the data for the given type and request. If data satisfying the
|
||||
// minimum index is present in the cache, it is returned immediately. Otherwise,
|
||||
// this will block until the data is available or the request timeout is
|
||||
|
|
Loading…
Reference in New Issue