Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
6f341eb5
Commit
6f341eb5
authored
May 04, 2015
by
Filip Grzadkowski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add metrics to measure cache hit ratio
parent
690c9914
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
34 additions
and
0 deletions
+34
-0
etcd_helper.go
pkg/tools/etcd_helper.go
+34
-0
No files found.
pkg/tools/etcd_helper.go
View file @
6f341eb5
...
...
@@ -31,10 +31,39 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/conversion"
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
"github.com/coreos/go-etcd/etcd"
"github.com/prometheus/client_golang/prometheus"
"github.com/golang/glog"
)
var
(
cacheHitCounter
=
prometheus
.
NewCounter
(
prometheus
.
CounterOpts
{
Name
:
"etcd_helper_cache_hit_count"
,
Help
:
"Counter of etcd helper cache hits."
,
},
)
cacheMissCounter
=
prometheus
.
NewCounter
(
prometheus
.
CounterOpts
{
Name
:
"etcd_helper_cache_miss_count"
,
Help
:
"Counter of etcd helper cache miss."
,
},
)
cacheEntryCounter
=
prometheus
.
NewCounter
(
prometheus
.
CounterOpts
{
Name
:
"etcd_helper_cache_entry_count"
,
Help
:
"Counter of etcd helper cache entries. This can be different from etcd_helper_cache_miss_count "
+
"because two concurrent threads can miss the cache and generate the same entry twice."
,
},
)
)
func
init
()
{
prometheus
.
MustRegister
(
cacheHitCounter
)
prometheus
.
MustRegister
(
cacheMissCounter
)
prometheus
.
MustRegister
(
cacheEntryCounter
)
}
// EtcdHelper offers common object marshalling/unmarshalling operations on an etcd client.
type
EtcdHelper
struct
{
Client
EtcdGetSet
...
...
@@ -179,8 +208,10 @@ func (h *EtcdHelper) getFromCache(index uint64) (runtime.Object, bool) {
glog
.
Errorf
(
"Error during DeepCopy of cached object: %q"
,
err
)
return
nil
,
false
}
cacheHitCounter
.
Inc
()
return
objCopy
.
(
runtime
.
Object
),
true
}
cacheMissCounter
.
Inc
()
return
nil
,
false
}
...
...
@@ -192,6 +223,9 @@ func (h *EtcdHelper) addToCache(index uint64, obj runtime.Object) {
}
h
.
mutex
.
Lock
()
defer
h
.
mutex
.
Unlock
()
if
_
,
found
:=
h
.
cache
[
index
];
!
found
{
cacheEntryCounter
.
Inc
()
}
h
.
cache
[
index
]
=
objCopy
.
(
runtime
.
Object
)
if
len
(
h
.
cache
)
>
maxEtcdCacheEntries
{
var
randomKey
uint64
...
...
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