use reflect.deepEqual for noop object comparison

This commit is contained in:
Han Kang 2019-06-11 17:31:36 -07:00
parent 9c44ba22ca
commit 63440fef78

View File

@ -19,6 +19,7 @@ package legacyregistry
import ( import (
"fmt" "fmt"
"net/http" "net/http"
"reflect"
"sync" "sync"
"github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus"
@ -98,7 +99,7 @@ func Register(c metrics.KubeCollector) error {
globalRegistryFactory.registrationLock.Lock() globalRegistryFactory.registrationLock.Lock()
defer globalRegistryFactory.registrationLock.Unlock() defer globalRegistryFactory.registrationLock.Unlock()
if globalRegistryFactory.globalRegistry == (noopRegistry{}) { if reflect.DeepEqual(globalRegistryFactory.globalRegistry, noopRegistry{}) {
globalRegistryFactory.registerQueue = append(globalRegistryFactory.registerQueue, c) globalRegistryFactory.registerQueue = append(globalRegistryFactory.registerQueue, c)
return nil return nil
} }
@ -113,7 +114,7 @@ func MustRegister(cs ...metrics.KubeCollector) {
globalRegistryFactory.registrationLock.Lock() globalRegistryFactory.registrationLock.Lock()
defer globalRegistryFactory.registrationLock.Unlock() defer globalRegistryFactory.registrationLock.Unlock()
if globalRegistryFactory.globalRegistry == (noopRegistry{}) { if reflect.DeepEqual(globalRegistryFactory.globalRegistry, noopRegistry{}) {
for _, c := range cs { for _, c := range cs {
globalRegistryFactory.mustRegisterQueue = append(globalRegistryFactory.mustRegisterQueue, c) globalRegistryFactory.mustRegisterQueue = append(globalRegistryFactory.mustRegisterQueue, c)
} }