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
a514fa04
Unverified
Commit
a514fa04
authored
Feb 27, 2019
by
Kubernetes Prow Robot
Committed by
GitHub
Feb 27, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #74636 from logicalhan/reflector-metrics
Remove reflector metrics since they are causing a memory leak
parents
02bd660a
ca096f80
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
1 addition
and
28 deletions
+1
-28
prometheus.go
pkg/util/reflector/prometheus/prometheus.go
+0
-2
reflector.go
staging/src/k8s.io/client-go/tools/cache/reflector.go
+1
-26
No files found.
pkg/util/reflector/prometheus/prometheus.go
View file @
a514fa04
...
@@ -85,8 +85,6 @@ func init() {
...
@@ -85,8 +85,6 @@ func init() {
prometheus
.
MustRegister
(
watchDuration
)
prometheus
.
MustRegister
(
watchDuration
)
prometheus
.
MustRegister
(
itemsPerWatch
)
prometheus
.
MustRegister
(
itemsPerWatch
)
prometheus
.
MustRegister
(
lastResourceVersion
)
prometheus
.
MustRegister
(
lastResourceVersion
)
cache
.
SetReflectorMetricsProvider
(
prometheusMetricsProvider
{})
}
}
type
prometheusMetricsProvider
struct
{}
type
prometheusMetricsProvider
struct
{}
...
...
staging/src/k8s.io/client-go/tools/cache/reflector.go
View file @
a514fa04
...
@@ -24,10 +24,8 @@ import (
...
@@ -24,10 +24,8 @@ import (
"net"
"net"
"net/url"
"net/url"
"reflect"
"reflect"
"strconv"
"strings"
"strings"
"sync"
"sync"
"sync/atomic"
"syscall"
"syscall"
"time"
"time"
...
@@ -96,17 +94,10 @@ func NewReflector(lw ListerWatcher, expectedType interface{}, store Store, resyn
...
@@ -96,17 +94,10 @@ func NewReflector(lw ListerWatcher, expectedType interface{}, store Store, resyn
return
NewNamedReflector
(
naming
.
GetNameFromCallsite
(
internalPackages
...
),
lw
,
expectedType
,
store
,
resyncPeriod
)
return
NewNamedReflector
(
naming
.
GetNameFromCallsite
(
internalPackages
...
),
lw
,
expectedType
,
store
,
resyncPeriod
)
}
}
// reflectorDisambiguator is used to disambiguate started reflectors.
// initialized to an unstable value to ensure meaning isn't attributed to the suffix.
var
reflectorDisambiguator
=
int64
(
time
.
Now
()
.
UnixNano
()
%
12345
)
// NewNamedReflector same as NewReflector, but with a specified name for logging
// NewNamedReflector same as NewReflector, but with a specified name for logging
func
NewNamedReflector
(
name
string
,
lw
ListerWatcher
,
expectedType
interface
{},
store
Store
,
resyncPeriod
time
.
Duration
)
*
Reflector
{
func
NewNamedReflector
(
name
string
,
lw
ListerWatcher
,
expectedType
interface
{},
store
Store
,
resyncPeriod
time
.
Duration
)
*
Reflector
{
reflectorSuffix
:=
atomic
.
AddInt64
(
&
reflectorDisambiguator
,
1
)
r
:=
&
Reflector
{
r
:=
&
Reflector
{
name
:
name
,
name
:
name
,
// we need this to be unique per process (some names are still the same) but obvious who it belongs to
metrics
:
newReflectorMetrics
(
makeValidPrometheusMetricLabel
(
fmt
.
Sprintf
(
"reflector_"
+
name
+
"_%d"
,
reflectorSuffix
))),
listerWatcher
:
lw
,
listerWatcher
:
lw
,
store
:
store
,
store
:
store
,
expectedType
:
reflect
.
TypeOf
(
expectedType
),
expectedType
:
reflect
.
TypeOf
(
expectedType
),
...
@@ -174,8 +165,6 @@ func (r *Reflector) ListAndWatch(stopCh <-chan struct{}) error {
...
@@ -174,8 +165,6 @@ func (r *Reflector) ListAndWatch(stopCh <-chan struct{}) error {
// to be served from cache and potentially be delayed relative to
// to be served from cache and potentially be delayed relative to
// etcd contents. Reflector framework will catch up via Watch() eventually.
// etcd contents. Reflector framework will catch up via Watch() eventually.
options
:=
metav1
.
ListOptions
{
ResourceVersion
:
"0"
}
options
:=
metav1
.
ListOptions
{
ResourceVersion
:
"0"
}
r
.
metrics
.
numberOfLists
.
Inc
()
start
:=
r
.
clock
.
Now
()
if
err
:=
func
()
error
{
if
err
:=
func
()
error
{
initTrace
:=
trace
.
New
(
"Reflector "
+
r
.
name
+
" ListAndWatch"
)
initTrace
:=
trace
.
New
(
"Reflector "
+
r
.
name
+
" ListAndWatch"
)
...
@@ -204,7 +193,6 @@ func (r *Reflector) ListAndWatch(stopCh <-chan struct{}) error {
...
@@ -204,7 +193,6 @@ func (r *Reflector) ListAndWatch(stopCh <-chan struct{}) error {
return
fmt
.
Errorf
(
"%s: Failed to list %v: %v"
,
r
.
name
,
r
.
expectedType
,
err
)
return
fmt
.
Errorf
(
"%s: Failed to list %v: %v"
,
r
.
name
,
r
.
expectedType
,
err
)
}
}
initTrace
.
Step
(
"Objects listed"
)
initTrace
.
Step
(
"Objects listed"
)
r
.
metrics
.
listDuration
.
Observe
(
time
.
Since
(
start
)
.
Seconds
())
listMetaInterface
,
err
:=
meta
.
ListAccessor
(
list
)
listMetaInterface
,
err
:=
meta
.
ListAccessor
(
list
)
if
err
!=
nil
{
if
err
!=
nil
{
return
fmt
.
Errorf
(
"%s: Unable to understand list result %#v: %v"
,
r
.
name
,
list
,
err
)
return
fmt
.
Errorf
(
"%s: Unable to understand list result %#v: %v"
,
r
.
name
,
list
,
err
)
...
@@ -216,7 +204,6 @@ func (r *Reflector) ListAndWatch(stopCh <-chan struct{}) error {
...
@@ -216,7 +204,6 @@ func (r *Reflector) ListAndWatch(stopCh <-chan struct{}) error {
return
fmt
.
Errorf
(
"%s: Unable to understand list result %#v (%v)"
,
r
.
name
,
list
,
err
)
return
fmt
.
Errorf
(
"%s: Unable to understand list result %#v (%v)"
,
r
.
name
,
list
,
err
)
}
}
initTrace
.
Step
(
"Objects extracted"
)
initTrace
.
Step
(
"Objects extracted"
)
r
.
metrics
.
numberOfItemsInList
.
Observe
(
float64
(
len
(
items
)))
if
err
:=
r
.
syncWith
(
items
,
resourceVersion
);
err
!=
nil
{
if
err
:=
r
.
syncWith
(
items
,
resourceVersion
);
err
!=
nil
{
return
fmt
.
Errorf
(
"%s: Unable to sync list result: %v"
,
r
.
name
,
err
)
return
fmt
.
Errorf
(
"%s: Unable to sync list result: %v"
,
r
.
name
,
err
)
}
}
...
@@ -272,7 +259,6 @@ func (r *Reflector) ListAndWatch(stopCh <-chan struct{}) error {
...
@@ -272,7 +259,6 @@ func (r *Reflector) ListAndWatch(stopCh <-chan struct{}) error {
TimeoutSeconds
:
&
timeoutSeconds
,
TimeoutSeconds
:
&
timeoutSeconds
,
}
}
r
.
metrics
.
numberOfWatches
.
Inc
()
w
,
err
:=
r
.
listerWatcher
.
Watch
(
options
)
w
,
err
:=
r
.
listerWatcher
.
Watch
(
options
)
if
err
!=
nil
{
if
err
!=
nil
{
switch
err
{
switch
err
{
...
@@ -324,11 +310,6 @@ func (r *Reflector) watchHandler(w watch.Interface, resourceVersion *string, err
...
@@ -324,11 +310,6 @@ func (r *Reflector) watchHandler(w watch.Interface, resourceVersion *string, err
// Stopping the watcher should be idempotent and if we return from this function there's no way
// Stopping the watcher should be idempotent and if we return from this function there's no way
// we're coming back in with the same watch interface.
// we're coming back in with the same watch interface.
defer
w
.
Stop
()
defer
w
.
Stop
()
// update metrics
defer
func
()
{
r
.
metrics
.
numberOfItemsInWatch
.
Observe
(
float64
(
eventCount
))
r
.
metrics
.
watchDuration
.
Observe
(
time
.
Since
(
start
)
.
Seconds
())
}()
loop
:
loop
:
for
{
for
{
...
@@ -384,7 +365,6 @@ loop:
...
@@ -384,7 +365,6 @@ loop:
watchDuration
:=
r
.
clock
.
Now
()
.
Sub
(
start
)
watchDuration
:=
r
.
clock
.
Now
()
.
Sub
(
start
)
if
watchDuration
<
1
*
time
.
Second
&&
eventCount
==
0
{
if
watchDuration
<
1
*
time
.
Second
&&
eventCount
==
0
{
r
.
metrics
.
numberOfShortWatches
.
Inc
()
return
fmt
.
Errorf
(
"very short watch: %s: Unexpected watch close - watch lasted less than a second and no items received"
,
r
.
name
)
return
fmt
.
Errorf
(
"very short watch: %s: Unexpected watch close - watch lasted less than a second and no items received"
,
r
.
name
)
}
}
klog
.
V
(
4
)
.
Infof
(
"%s: Watch close - %v total %v items received"
,
r
.
name
,
r
.
expectedType
,
eventCount
)
klog
.
V
(
4
)
.
Infof
(
"%s: Watch close - %v total %v items received"
,
r
.
name
,
r
.
expectedType
,
eventCount
)
...
@@ -403,9 +383,4 @@ func (r *Reflector) setLastSyncResourceVersion(v string) {
...
@@ -403,9 +383,4 @@ func (r *Reflector) setLastSyncResourceVersion(v string) {
r
.
lastSyncResourceVersionMutex
.
Lock
()
r
.
lastSyncResourceVersionMutex
.
Lock
()
defer
r
.
lastSyncResourceVersionMutex
.
Unlock
()
defer
r
.
lastSyncResourceVersionMutex
.
Unlock
()
r
.
lastSyncResourceVersion
=
v
r
.
lastSyncResourceVersion
=
v
rv
,
err
:=
strconv
.
Atoi
(
v
)
if
err
==
nil
{
r
.
metrics
.
lastResourceVersion
.
Set
(
float64
(
rv
))
}
}
}
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