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>
This commit is contained in:
parent
c25a2e0fac
commit
b7480d5d12
1 changed files with 9 additions and 8 deletions
17
plugin/cache/handler.go
vendored
17
plugin/cache/handler.go
vendored
|
@ -27,8 +27,8 @@ func (c *Cache) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg)
|
||||||
|
|
||||||
server := metrics.WithServer(ctx)
|
server := metrics.WithServer(ctx)
|
||||||
|
|
||||||
i, ttl := c.get(now, state, server)
|
i, found := c.get(now, state, server)
|
||||||
if i != nil && ttl > 0 {
|
if i != nil && found {
|
||||||
resp := i.toMsg(r, now)
|
resp := i.toMsg(r, now)
|
||||||
|
|
||||||
state.SizeAndDo(resp)
|
state.SizeAndDo(resp)
|
||||||
|
@ -36,6 +36,7 @@ func (c *Cache) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg)
|
||||||
w.WriteMsg(resp)
|
w.WriteMsg(resp)
|
||||||
|
|
||||||
if c.prefetch > 0 {
|
if c.prefetch > 0 {
|
||||||
|
ttl := i.ttl(now)
|
||||||
i.Freq.Update(c.duration, now)
|
i.Freq.Update(c.duration, now)
|
||||||
|
|
||||||
threshold := int(math.Ceil(float64(c.percentage) / 100 * float64(i.origTTL)))
|
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.
|
// Name implements the Handler interface.
|
||||||
func (c *Cache) Name() string { return "cache" }
|
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())
|
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()
|
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()
|
cacheHits.WithLabelValues(server, Success).Inc()
|
||||||
return i.(*item), i.(*item).ttl(now)
|
return i.(*item), true
|
||||||
}
|
}
|
||||||
cacheMisses.WithLabelValues(server).Inc()
|
cacheMisses.WithLabelValues(server).Inc()
|
||||||
return nil, 0
|
return nil, false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Cache) exists(state request.Request) *item {
|
func (c *Cache) exists(state request.Request) *item {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue