@@ -63,23 +63,13 @@ func NewServerLeaseCounter(pc clock.PassiveClock, leaseLister coordinationv1list
63
63
// fallback count is returned. This fallback count is updated upon successful
64
64
// discovery of valid leases.
65
65
func (lc * ServerLeaseCounter ) Count () int {
66
- // Since the number of proxy servers is generally small (1-10), we opted against
67
- // using a LIST and WATCH pattern and instead list all leases on each call.
68
- // TODO: Switch to an informer-based system and use events rather than a polling loop.
69
- start := time .Now ()
70
- defer func () {
71
- latency := time .Now ().Sub (start )
72
- metrics .Metrics .ObserveLeaseListLatency (latency )
73
- }()
74
66
leases , err := lc .leaseLister .List (lc .selector )
75
67
if err != nil {
76
68
klog .Errorf ("Could not list leases to update server count, using fallback count (%v): %v" , lc .fallbackCount , err )
77
69
78
70
return lc .fallbackCount
79
71
}
80
72
81
- metrics .Metrics .ObserveLeaseList (200 , "" )
82
-
83
73
count := 0
84
74
for _ , lease := range leases {
85
75
if util .IsLeaseValid (lc .pc , * lease ) {
@@ -104,6 +94,11 @@ func NewLeaseInformerWithMetrics(client kubernetes.Interface, namespace string,
104
94
return cache .NewSharedIndexInformer (
105
95
& cache.ListWatch {
106
96
ListFunc : func (options metav1.ListOptions ) (runtime.Object , error ) {
97
+ start := time .Now ()
98
+ defer func () {
99
+ latency := time .Now ().Sub (start )
100
+ metrics .Metrics .ObserveLeaseListLatency (latency )
101
+ }()
107
102
obj , err := client .CoordinationV1 ().Leases (namespace ).List (context .TODO (), options )
108
103
if err != nil {
109
104
klog .Errorf ("Could not list leases: %v" , err )
0 commit comments