mirror of
https://github.com/kubernetes/client-go.git
synced 2025-06-28 07:57:20 +00:00
Fix duplicate metrics collector registration attempted error
Kubernetes-commit: 1da4f4a745bf536c34e377321a252b4774d1a7e0
This commit is contained in:
parent
394768f553
commit
755bbca820
8
tools/cache/reflector.go
vendored
8
tools/cache/reflector.go
vendored
@ -30,6 +30,7 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
"sync/atomic"
|
||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -98,12 +99,17 @@ func NewReflector(lw ListerWatcher, expectedType interface{}, store Store, resyn
|
|||||||
return NewNamedReflector(getDefaultReflectorName(internalPackages...), lw, expectedType, store, resyncPeriod)
|
return NewNamedReflector(getDefaultReflectorName(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
|
// we need this to be unique per process (some names are still the same)but obvious who it belongs to
|
||||||
metrics: newReflectorMetrics(makeValidPromethusMetricName(fmt.Sprintf("reflector_"+name+"_%07d", rand.Intn(1000000)))),
|
metrics: newReflectorMetrics(makeValidPromethusMetricName(fmt.Sprintf("reflector_"+name+"_%d", reflectorSuffix))),
|
||||||
listerWatcher: lw,
|
listerWatcher: lw,
|
||||||
store: store,
|
store: store,
|
||||||
expectedType: reflect.TypeOf(expectedType),
|
expectedType: reflect.TypeOf(expectedType),
|
||||||
|
Loading…
Reference in New Issue
Block a user