Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
C
Coredns
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Railgun
Coredns
Commits
5b9b079d
Commit
5b9b079d
authored
Mar 21, 2021
by
Frank Riley
Committed by
GitHub
Mar 21, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add cache eviction metrics to the cache plugin (#4411)
Signed-off-by:
Frank Riley
<
fhriley@gmail.com
>
parent
ed3f287f
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
22 additions
and
5 deletions
+22
-5
plugin/cache/README.md
plugin/cache/README.md
+1
-0
plugin/cache/cache.go
plugin/cache/cache.go
+6
-2
plugin/cache/metrics.go
plugin/cache/metrics.go
+7
-0
plugin/pkg/cache/cache.go
plugin/pkg/cache/cache.go
+8
-3
No files found.
plugin/cache/README.md
View file @
5b9b079d
...
...
@@ -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.
...
...
plugin/cache/cache.go
View file @
5b9b079d
...
...
@@ -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
...
...
plugin/cache/metrics.go
View file @
5b9b079d
...
...
@@ -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"
})
)
plugin/pkg/cache/cache.go
View file @
5b9b079d
...
...
@@ -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.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment