add zones label to cache metrics (#5124)

* add zones to cache metrics

Signed-off-by: Elijah Andrews <elijahcandrews@gmail.com>
This commit is contained in:
Elijah Andrews
2022-02-14 12:10:30 -05:00
committed by GitHub
parent d97dbbef61
commit 80195c399f
5 changed files with 35 additions and 31 deletions

12
plugin/cache/cache.go vendored
View File

@@ -21,6 +21,8 @@ type Cache struct {
Next plugin.Handler
Zones []string
zonesMetricLabel string
ncache *cache.Cache
ncap int
nttl time.Duration
@@ -162,11 +164,11 @@ func (w *ResponseWriter) WriteMsg(res *dns.Msg) error {
if hasKey && duration > 0 {
if w.state.Match(res) {
w.set(res, key, mt, duration)
cacheSize.WithLabelValues(w.server, Success).Set(float64(w.pcache.Len()))
cacheSize.WithLabelValues(w.server, Denial).Set(float64(w.ncache.Len()))
cacheSize.WithLabelValues(w.server, Success, w.zonesMetricLabel).Set(float64(w.pcache.Len()))
cacheSize.WithLabelValues(w.server, Denial, w.zonesMetricLabel).Set(float64(w.ncache.Len()))
} else {
// Don't log it, but increment counter
cacheDrops.WithLabelValues(w.server).Inc()
cacheDrops.WithLabelValues(w.server, w.zonesMetricLabel).Inc()
}
}
@@ -195,7 +197,7 @@ func (w *ResponseWriter) set(m *dns.Msg, key uint64, mt response.Type, duration
case response.NoError, response.Delegation:
i := newItem(m, w.now(), duration)
if w.pcache.Add(key, i) {
evictions.WithLabelValues(w.server, Success).Inc()
evictions.WithLabelValues(w.server, Success, w.zonesMetricLabel).Inc()
}
// when pre-fetching, remove the negative cache entry if it exists
if w.prefetch {
@@ -205,7 +207,7 @@ func (w *ResponseWriter) set(m *dns.Msg, key uint64, mt response.Type, duration
case response.NameError, response.NoData, response.ServerError:
i := newItem(m, w.now(), duration)
if w.ncache.Add(key, i) {
evictions.WithLabelValues(w.server, Denial).Inc()
evictions.WithLabelValues(w.server, Denial, w.zonesMetricLabel).Inc()
}
case response.OtherError: