aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--plugin/cache/README.md1
-rw-r--r--plugin/cache/cache.go8
-rw-r--r--plugin/cache/metrics.go7
-rw-r--r--plugin/pkg/cache/cache.go11
4 files changed, 22 insertions, 5 deletions
diff --git a/plugin/cache/README.md b/plugin/cache/README.md
index 28a427371..e311e3214 100644
--- a/plugin/cache/README.md
+++ b/plugin/cache/README.md
@@ -79,6 +79,7 @@ If monitoring is enabled (via the *prometheus* plugin) then the following metric
* `coredns_cache_prefetch_total{server}` - Counter of times the cache has prefetched a cached item.
* `coredns_cache_drops_total{server}` - Counter of responses excluded from the cache due to request/response question name mismatch.
* `coredns_cache_served_stale_total{server}` - Counter of requests served from stale cache entries.
+* `coredns_cache_evictions_total{server, type}` - Counter of cache evictions.
Cache types are either "denial" or "success". `Server` is the server handling the request, see the
prometheus plugin for documentation.
diff --git a/plugin/cache/cache.go b/plugin/cache/cache.go
index 2a56500a3..5673cc948 100644
--- a/plugin/cache/cache.go
+++ b/plugin/cache/cache.go
@@ -190,7 +190,9 @@ func (w *ResponseWriter) set(m *dns.Msg, key uint64, mt response.Type, duration
switch mt {
case response.NoError, response.Delegation:
i := newItem(m, w.now(), duration)
- w.pcache.Add(key, i)
+ if w.pcache.Add(key, i) {
+ evictions.WithLabelValues(w.server, Success).Inc()
+ }
// when pre-fetching, remove the negative cache entry if it exists
if w.prefetch {
w.ncache.Remove(key)
@@ -198,7 +200,9 @@ 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)
- w.ncache.Add(key, i)
+ if w.ncache.Add(key, i) {
+ evictions.WithLabelValues(w.server, Denial).Inc()
+ }
case response.OtherError:
// don't cache these
diff --git a/plugin/cache/metrics.go b/plugin/cache/metrics.go
index b4b11ae26..f502c238d 100644
--- a/plugin/cache/metrics.go
+++ b/plugin/cache/metrics.go
@@ -50,4 +50,11 @@ var (
Name: "served_stale_total",
Help: "The number of requests served from stale cache entries.",
}, []string{"server"})
+ // evictions is the counter of cache evictions.
+ evictions = promauto.NewCounterVec(prometheus.CounterOpts{
+ Namespace: plugin.Namespace,
+ Subsystem: "cache",
+ Name: "evictions_total",
+ Help: "The count of cache evictions.",
+ }, []string{"server", "type"})
)
diff --git a/plugin/pkg/cache/cache.go b/plugin/pkg/cache/cache.go
index 3a2c8ff7f..19a4e7a80 100644
--- a/plugin/pkg/cache/cache.go
+++ b/plugin/pkg/cache/cache.go
@@ -45,9 +45,10 @@ func New(size int) *Cache {
}
// Add adds a new element to the cache. If the element already exists it is overwritten.
-func (c *Cache) Add(key uint64, el interface{}) {
+// Returns true if an existing element was evicted to make room for this element.
+func (c *Cache) Add(key uint64, el interface{}) bool {
shard := key & (shardSize - 1)
- c.shards[shard].Add(key, el)
+ return c.shards[shard].Add(key, el)
}
// Get looks up element index under key.
@@ -75,18 +76,22 @@ func (c *Cache) Len() int {
func newShard(size int) *shard { return &shard{items: make(map[uint64]interface{}), size: size} }
// Add adds element indexed by key into the cache. Any existing element is overwritten
-func (s *shard) Add(key uint64, el interface{}) {
+// Returns true if an existing element was evicted to make room for this element.
+func (s *shard) Add(key uint64, el interface{}) bool {
+ eviction := false
s.Lock()
if len(s.items) >= s.size {
if _, ok := s.items[key]; !ok {
for k := range s.items {
delete(s.items, k)
+ eviction = true
break
}
}
}
s.items[key] = el
s.Unlock()
+ return eviction
}
// Remove removes the element indexed by key from the cache.
e=''/>
path: root/src/bun.js/scripts/generate-classes.ts (unfollow)
AgeCommit message (Expand)AuthorFilesLines
2023-04-06fix(node:events): fix abort behaviorGravatar Derrick Farris 3-170/+177
2023-04-06test(node:events): remove `console.log`Gravatar Derrick Farris 1-1/+0
2023-04-06feat(node:events): finish `EE.AsyncIterator` and `node:events.on()`, add some...Gravatar Derrick Farris 5-369/+276
2023-04-06wip(node:events): get async iter working, work through test flakinessGravatar Derrick Farris 5-236/+328
2023-04-06wip(node:events): fix `node:events.on` async iter to specGravatar Derrick Farris 16-136/+1116
2023-04-06docs: add a section on uninstalling bun (#2560)Gravatar dave caruso 1-0/+8
2023-04-06docs(cli/bunx): add notice (#2574)Gravatar Jozef Steinhübl 1-0/+4
2023-04-06Fix `toEqual` when the second array has extra array holes (#2580)Gravatar Dylan Conway 3-18/+76
2023-04-06Add last modify field "mtime" for FileBlob (#1431) (#2491)Gravatar Zhongwei Yao 6-33/+128
2023-04-06bun-types: infer strict `Subprocess` from `Bun.spawn()` options, part 2 (#2573)Gravatar dave caruso 9-67/+165
2023-04-06cache needs to update, move to another process (#2578)Gravatar Dylan Conway 2-156/+171
2023-04-06fix(ws): export Server (#2575)Gravatar hiroki osame 1-13/+30
2023-04-06docs(CONTRIBUTING): referece development guide (#2576)Gravatar hiroki osame 1-1/+5
2023-04-05rebase (#1501)Gravatar dave caruso 2-144/+305
2023-04-05Update `typecheck` (#2572)Gravatar Colin McDonnell 3-4/+8
2023-04-05prependGravatar Jarred Sumner 1-7/+3
2023-04-05Add tests for `bun test` with preload scripts (#2566)Gravatar Jake Boone 2-1/+107
2023-04-05Disable buffering when we clear terminalGravatar Jarred Sumner 1-0/+2
2023-04-05PrettierGravatar Jarred Sumner 3-4/+4
2023-04-05fix(fetch.proxy) fix proxy authentication (#2554)Gravatar Ciro Spaciari 3-31/+186
2023-04-05fix: build warnings (#2562)Gravatar hiroki osame 4-4/+1
2023-04-05In Documentation, move --watch before the script name (#2569)Gravatar Lawlzer 1-4/+5
2023-04-05fix `deepEquals` with array holes and accessors (#2557)Gravatar Dylan Conway 2-10/+249
2023-04-05fix: modules to have null prototype (#2561)Gravatar hiroki osame 2-2/+9
2023-04-04:clock1: :clock2: :clock3:Gravatar Jarred Sumner 1-1/+1
2023-04-04Implement `import.meta.main` (#2556)Gravatar Jarred Sumner 10-8/+89
2023-04-04Dylan/fix some failing tests (#2544)Gravatar Jarred Sumner 10-29/+72
2023-04-04Add npm benchmark (#2555)Gravatar Colin McDonnell 13-1/+271
2023-04-03Use absolute paths morebun-v0.5.9Gravatar Jarred Sumner 2-6/+11
2023-04-03Fix test failureGravatar Jarred Sumner 1-15/+18