cache: log a warning when Cache.Notify handles an error
Without these warnings, errors are silently ignored, which can make debugging problems more challenging.
This commit is contained in:
parent
a5a1fb2098
commit
e47131bfe6
|
@ -25,6 +25,7 @@ import (
|
||||||
|
|
||||||
"github.com/armon/go-metrics"
|
"github.com/armon/go-metrics"
|
||||||
"github.com/armon/go-metrics/prometheus"
|
"github.com/armon/go-metrics/prometheus"
|
||||||
|
"github.com/hashicorp/go-hclog"
|
||||||
"golang.org/x/time/rate"
|
"golang.org/x/time/rate"
|
||||||
|
|
||||||
"github.com/hashicorp/consul/acl"
|
"github.com/hashicorp/consul/acl"
|
||||||
|
@ -170,6 +171,8 @@ type ResultMeta struct {
|
||||||
|
|
||||||
// Options are options for the Cache.
|
// Options are options for the Cache.
|
||||||
type Options struct {
|
type Options struct {
|
||||||
|
Logger hclog.Logger
|
||||||
|
|
||||||
// EntryFetchMaxBurst max burst size of RateLimit for a single cache entry
|
// EntryFetchMaxBurst max burst size of RateLimit for a single cache entry
|
||||||
EntryFetchMaxBurst int
|
EntryFetchMaxBurst int
|
||||||
// EntryFetchRate represents the max calls/sec for a single cache entry
|
// EntryFetchRate represents the max calls/sec for a single cache entry
|
||||||
|
@ -189,6 +192,9 @@ func applyDefaultValuesOnOptions(options Options) Options {
|
||||||
if options.EntryFetchMaxBurst == 0 {
|
if options.EntryFetchMaxBurst == 0 {
|
||||||
options.EntryFetchMaxBurst = DefaultEntryFetchMaxBurst
|
options.EntryFetchMaxBurst = DefaultEntryFetchMaxBurst
|
||||||
}
|
}
|
||||||
|
if options.Logger == nil {
|
||||||
|
options.Logger = hclog.New(nil)
|
||||||
|
}
|
||||||
return options
|
return options
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -121,6 +121,12 @@ func (c *Cache) notifyBlockingQuery(ctx context.Context, r getOptions, correlati
|
||||||
} else {
|
} else {
|
||||||
failures++
|
failures++
|
||||||
wait = backOffWait(failures)
|
wait = backOffWait(failures)
|
||||||
|
|
||||||
|
c.options.Logger.
|
||||||
|
With("error", err).
|
||||||
|
With("cache-type", r.TypeEntry.Name).
|
||||||
|
With("index", index).
|
||||||
|
Warn("handling error in Cache.Notify")
|
||||||
}
|
}
|
||||||
|
|
||||||
if wait > 0 {
|
if wait > 0 {
|
||||||
|
@ -177,6 +183,11 @@ func (c *Cache) notifyPollingQuery(ctx context.Context, r getOptions, correlatio
|
||||||
failures = 0
|
failures = 0
|
||||||
} else {
|
} else {
|
||||||
failures++
|
failures++
|
||||||
|
c.options.Logger.
|
||||||
|
With("error", err).
|
||||||
|
With("cache-type", r.TypeEntry.Name).
|
||||||
|
With("index", index).
|
||||||
|
Warn("handling error in Cache.Notify")
|
||||||
}
|
}
|
||||||
|
|
||||||
var wait time.Duration
|
var wait time.Duration
|
||||||
|
|
|
@ -74,7 +74,8 @@
|
||||||
"CAPath": "",
|
"CAPath": "",
|
||||||
"Cache": {
|
"Cache": {
|
||||||
"EntryFetchMaxBurst": 42,
|
"EntryFetchMaxBurst": 42,
|
||||||
"EntryFetchRate": 0.334
|
"EntryFetchRate": 0.334,
|
||||||
|
"Logger": null
|
||||||
},
|
},
|
||||||
"CertFile": "",
|
"CertFile": "",
|
||||||
"CheckDeregisterIntervalMin": "0s",
|
"CheckDeregisterIntervalMin": "0s",
|
||||||
|
|
|
@ -97,6 +97,7 @@ func NewBaseDeps(configLoader ConfigLoader, logOut io.Writer) (BaseDeps, error)
|
||||||
d.RuntimeConfig = cfg
|
d.RuntimeConfig = cfg
|
||||||
d.Tokens = new(token.Store)
|
d.Tokens = new(token.Store)
|
||||||
|
|
||||||
|
cfg.Cache.Logger = d.Logger.Named("cache")
|
||||||
// cache-types are not registered yet, but they won't be used until the components are started.
|
// cache-types are not registered yet, but they won't be used until the components are started.
|
||||||
d.Cache = cache.New(cfg.Cache)
|
d.Cache = cache.New(cfg.Cache)
|
||||||
d.ConnPool = newConnPool(cfg, d.Logger, d.TLSConfigurator)
|
d.ConnPool = newConnPool(cfg, d.Logger, d.TLSConfigurator)
|
||||||
|
|
Loading…
Reference in New Issue