@@ -24,10 +24,8 @@ import (
24
24
"net"
25
25
"net/url"
26
26
"reflect"
27
- "strconv"
28
27
"strings"
29
28
"sync"
30
- "sync/atomic"
31
29
"syscall"
32
30
"time"
33
31
@@ -96,17 +94,10 @@ func NewReflector(lw ListerWatcher, expectedType interface{}, store Store, resyn
96
94
return NewNamedReflector (naming .GetNameFromCallsite (internalPackages ... ), lw , expectedType , store , resyncPeriod )
97
95
}
98
96
99
- // reflectorDisambiguator is used to disambiguate started reflectors.
100
- // initialized to an unstable value to ensure meaning isn't attributed to the suffix.
101
- var reflectorDisambiguator = int64 (time .Now ().UnixNano () % 12345 )
102
-
103
97
// NewNamedReflector same as NewReflector, but with a specified name for logging
104
98
func NewNamedReflector (name string , lw ListerWatcher , expectedType interface {}, store Store , resyncPeriod time.Duration ) * Reflector {
105
- reflectorSuffix := atomic .AddInt64 (& reflectorDisambiguator , 1 )
106
99
r := & Reflector {
107
- name : name ,
108
- // we need this to be unique per process (some names are still the same) but obvious who it belongs to
109
- metrics : newReflectorMetrics (makeValidPrometheusMetricLabel (fmt .Sprintf ("reflector_" + name + "_%d" , reflectorSuffix ))),
100
+ name : name ,
110
101
listerWatcher : lw ,
111
102
store : store ,
112
103
expectedType : reflect .TypeOf (expectedType ),
@@ -174,8 +165,6 @@ func (r *Reflector) ListAndWatch(stopCh <-chan struct{}) error {
174
165
// to be served from cache and potentially be delayed relative to
175
166
// etcd contents. Reflector framework will catch up via Watch() eventually.
176
167
options := metav1.ListOptions {ResourceVersion : "0" }
177
- r .metrics .numberOfLists .Inc ()
178
- start := r .clock .Now ()
179
168
180
169
if err := func () error {
181
170
initTrace := trace .New ("Reflector " + r .name + " ListAndWatch" )
@@ -204,7 +193,6 @@ func (r *Reflector) ListAndWatch(stopCh <-chan struct{}) error {
204
193
return fmt .Errorf ("%s: Failed to list %v: %v" , r .name , r .expectedType , err )
205
194
}
206
195
initTrace .Step ("Objects listed" )
207
- r .metrics .listDuration .Observe (time .Since (start ).Seconds ())
208
196
listMetaInterface , err := meta .ListAccessor (list )
209
197
if err != nil {
210
198
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
204
return fmt .Errorf ("%s: Unable to understand list result %#v (%v)" , r .name , list , err )
217
205
}
218
206
initTrace .Step ("Objects extracted" )
219
- r .metrics .numberOfItemsInList .Observe (float64 (len (items )))
220
207
if err := r .syncWith (items , resourceVersion ); err != nil {
221
208
return fmt .Errorf ("%s: Unable to sync list result: %v" , r .name , err )
222
209
}
@@ -272,7 +259,6 @@ func (r *Reflector) ListAndWatch(stopCh <-chan struct{}) error {
272
259
TimeoutSeconds : & timeoutSeconds ,
273
260
}
274
261
275
- r .metrics .numberOfWatches .Inc ()
276
262
w , err := r .listerWatcher .Watch (options )
277
263
if err != nil {
278
264
switch err {
@@ -324,11 +310,6 @@ func (r *Reflector) watchHandler(w watch.Interface, resourceVersion *string, err
324
310
// Stopping the watcher should be idempotent and if we return from this function there's no way
325
311
// we're coming back in with the same watch interface.
326
312
defer w .Stop ()
327
- // update metrics
328
- defer func () {
329
- r .metrics .numberOfItemsInWatch .Observe (float64 (eventCount ))
330
- r .metrics .watchDuration .Observe (time .Since (start ).Seconds ())
331
- }()
332
313
333
314
loop:
334
315
for {
@@ -384,7 +365,6 @@ loop:
384
365
385
366
watchDuration := r .clock .Now ().Sub (start )
386
367
if watchDuration < 1 * time .Second && eventCount == 0 {
387
- r .metrics .numberOfShortWatches .Inc ()
388
368
return fmt .Errorf ("very short watch: %s: Unexpected watch close - watch lasted less than a second and no items received" , r .name )
389
369
}
390
370
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
383
r .lastSyncResourceVersionMutex .Lock ()
404
384
defer r .lastSyncResourceVersionMutex .Unlock ()
405
385
r .lastSyncResourceVersion = v
406
-
407
- rv , err := strconv .Atoi (v )
408
- if err == nil {
409
- r .metrics .lastResourceVersion .Set (float64 (rv ))
410
- }
411
386
}
0 commit comments