diff options
author | 2018-06-26 15:11:17 +0800 | |
---|---|---|
committer | 2018-06-26 09:11:17 +0200 | |
commit | b7480d5d1216aa87d80d240a31de750079eba904 (patch) | |
tree | 01fde93e1f92925a19c04ed76fdaa2326934a5fb /plugin/cache/handler.go | |
parent | c25a2e0fac398c4454578abef8ea0870099fac97 (diff) | |
download | coredns-b7480d5d1216aa87d80d240a31de750079eba904.tar.gz coredns-b7480d5d1216aa87d80d240a31de750079eba904.tar.zst coredns-b7480d5d1216aa87d80d240a31de750079eba904.zip |
plugin/cache: Fix: metric `cache miss total` shall include ttl case (#1897)
In the case of ttl <= 0, `cacheMisses` should increase its counter.
Signed-off-by: Jun Li <lijun.git@gmail.com>
Diffstat (limited to 'plugin/cache/handler.go')
-rw-r--r-- | plugin/cache/handler.go | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/plugin/cache/handler.go b/plugin/cache/handler.go index bb5898934..11e1323f6 100644 --- a/plugin/cache/handler.go +++ b/plugin/cache/handler.go @@ -27,8 +27,8 @@ func (c *Cache) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) server := metrics.WithServer(ctx) - i, ttl := c.get(now, state, server) - if i != nil && ttl > 0 { + i, found := c.get(now, state, server) + if i != nil && found { resp := i.toMsg(r, now) state.SizeAndDo(resp) @@ -36,6 +36,7 @@ func (c *Cache) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) w.WriteMsg(resp) if c.prefetch > 0 { + ttl := i.ttl(now) i.Freq.Update(c.duration, now) threshold := int(math.Ceil(float64(c.percentage) / 100 * float64(i.origTTL))) @@ -64,20 +65,20 @@ func (c *Cache) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) // Name implements the Handler interface. func (c *Cache) Name() string { return "cache" } -func (c *Cache) get(now time.Time, state request.Request, server string) (*item, int) { +func (c *Cache) get(now time.Time, state request.Request, server string) (*item, bool) { k := hash(state.Name(), state.QType(), state.Do()) - if i, ok := c.ncache.Get(k); ok { + if i, ok := c.ncache.Get(k); ok && i.(*item).ttl(now) > 0 { cacheHits.WithLabelValues(server, Denial).Inc() - return i.(*item), i.(*item).ttl(now) + return i.(*item), true } - if i, ok := c.pcache.Get(k); ok { + if i, ok := c.pcache.Get(k); ok && i.(*item).ttl(now) > 0 { cacheHits.WithLabelValues(server, Success).Inc() - return i.(*item), i.(*item).ttl(now) + return i.(*item), true } cacheMisses.WithLabelValues(server).Inc() - return nil, 0 + return nil, false } func (c *Cache) exists(state request.Request) *item { |