@@ -51,7 +51,7 @@ type clusterAccessor struct {
51
51
lockedStateLock sync.RWMutex
52
52
53
53
// lockedState is the state of the clusterAccessor. This includes the connection (e.g. client, cache)
54
- // and health checking information (e.g. lastProbeSuccessTimestamp , consecutiveFailures).
54
+ // and health checking information (e.g. lastProbeSuccessTime , consecutiveFailures).
55
55
// lockedStateLock must be *always* held (via lock or rLock) before accessing this field.
56
56
lockedState clusterAccessorLockedState
57
57
@@ -151,11 +151,11 @@ type clusterAccessorHealthProbeConfig struct {
151
151
}
152
152
153
153
// clusterAccessorLockedState is the state of the clusterAccessor. This includes the connection (e.g. client, cache)
154
- // and health checking information (e.g. lastProbeSuccessTimestamp , consecutiveFailures).
154
+ // and health checking information (e.g. lastProbeSuccessTime , consecutiveFailures).
155
155
// lockedStateLock must be *always* held (via lock or rLock) before accessing this field.
156
156
type clusterAccessorLockedState struct {
157
- // lastConnectionCreationErrorTimestamp is the timestamp when connection creation failed the last time.
158
- lastConnectionCreationErrorTimestamp time.Time
157
+ // lastConnectionCreationErrorTime is the time when connection creation failed the last time.
158
+ lastConnectionCreationErrorTime time.Time
159
159
160
160
// connection holds the connection state (e.g. client, cache) of the clusterAccessor.
161
161
connection * clusterAccessorLockedConnectionState
@@ -167,7 +167,7 @@ type clusterAccessorLockedState struct {
167
167
// private key in every single Reconcile.
168
168
clientCertificatePrivateKey * rsa.PrivateKey
169
169
170
- // healthChecking holds the health checking state (e.g. lastProbeSuccessTimestamp , consecutiveFailures)
170
+ // healthChecking holds the health checking state (e.g. lastProbeSuccessTime , consecutiveFailures)
171
171
// of the clusterAccessor.
172
172
healthChecking clusterAccessorLockedHealthCheckingState
173
173
}
@@ -201,14 +201,14 @@ type clusterAccessorLockedConnectionState struct {
201
201
watches sets.Set [string ]
202
202
}
203
203
204
- // clusterAccessorLockedHealthCheckingState holds the health checking state (e.g. lastProbeSuccessTimestamp ,
204
+ // clusterAccessorLockedHealthCheckingState holds the health checking state (e.g. lastProbeSuccessTime ,
205
205
// consecutiveFailures) of the clusterAccessor.
206
206
type clusterAccessorLockedHealthCheckingState struct {
207
- // lastProbeTimestamp is the time when the health probe was executed last.
208
- lastProbeTimestamp time.Time
207
+ // lastProbeTime is the time when the health probe was executed last.
208
+ lastProbeTime time.Time
209
209
210
- // lastProbeSuccessTimestamp is the time when the health probe was successfully executed last.
211
- lastProbeSuccessTimestamp time.Time
210
+ // lastProbeSuccessTime is the time when the health probe was successfully executed last.
211
+ lastProbeSuccessTime time.Time
212
212
213
213
// consecutiveFailures is the number of consecutive health probe failures.
214
214
consecutiveFailures int
@@ -261,7 +261,11 @@ func (ca *clusterAccessor) Connect(ctx context.Context) (retErr error) {
261
261
if retErr != nil {
262
262
log .Error (retErr , "Connect failed" )
263
263
connectionUp .WithLabelValues (ca .cluster .Name , ca .cluster .Namespace ).Set (0 )
264
- ca .lockedState .lastConnectionCreationErrorTimestamp = time .Now ()
264
+ ca .lockedState .lastConnectionCreationErrorTime = time .Now ()
265
+ // A client creation just failed, so let's count this as a failed probe.
266
+ ca .lockedState .healthChecking .lastProbeTime = time .Now ()
267
+ // Note: Intentionally not modifying lastProbeSuccessTime.
268
+ ca .lockedState .healthChecking .consecutiveFailures ++
265
269
} else {
266
270
connectionUp .WithLabelValues (ca .cluster .Name , ca .cluster .Namespace ).Set (1 )
267
271
}
@@ -288,9 +292,9 @@ func (ca *clusterAccessor) Connect(ctx context.Context) (retErr error) {
288
292
now := time .Now ()
289
293
ca .lockedState .healthChecking = clusterAccessorLockedHealthCheckingState {
290
294
// A client was just created successfully, so let's set the last probe times.
291
- lastProbeTimestamp : now ,
292
- lastProbeSuccessTimestamp : now ,
293
- consecutiveFailures : 0 ,
295
+ lastProbeTime : now ,
296
+ lastProbeSuccessTime : now ,
297
+ consecutiveFailures : 0 ,
294
298
}
295
299
ca .lockedState .connection = & clusterAccessorLockedConnectionState {
296
300
restConfig : connection .RESTConfig ,
@@ -350,7 +354,7 @@ func (ca *clusterAccessor) HealthCheck(ctx context.Context) (bool, bool) {
350
354
ca .lock (ctx )
351
355
defer ca .unlock (ctx )
352
356
353
- ca .lockedState .healthChecking .lastProbeTimestamp = time .Now ()
357
+ ca .lockedState .healthChecking .lastProbeTime = time .Now ()
354
358
355
359
unauthorizedErrorOccurred := false
356
360
switch {
@@ -371,7 +375,7 @@ func (ca *clusterAccessor) HealthCheck(ctx context.Context) (bool, bool) {
371
375
healthChecksTotal .WithLabelValues (ca .cluster .Name , ca .cluster .Namespace , "error" ).Inc ()
372
376
default :
373
377
ca .lockedState .healthChecking .consecutiveFailures = 0
374
- ca .lockedState .healthChecking .lastProbeSuccessTimestamp = ca .lockedState .healthChecking .lastProbeTimestamp
378
+ ca .lockedState .healthChecking .lastProbeSuccessTime = ca .lockedState .healthChecking .lastProbeTime
375
379
log .V (6 ).Info ("Health probe succeeded" )
376
380
healthCheck .WithLabelValues (ca .cluster .Name , ca .cluster .Namespace ).Set (1 )
377
381
healthChecksTotal .WithLabelValues (ca .cluster .Name , ca .cluster .Namespace , "success" ).Inc ()
@@ -462,25 +466,22 @@ func (ca *clusterAccessor) Watch(ctx context.Context, watcher Watcher) error {
462
466
return nil
463
467
}
464
468
465
- func (ca * clusterAccessor ) GetLastProbeSuccessTimestamp (ctx context.Context ) time. Time {
469
+ func (ca * clusterAccessor ) GetHealthCheckingState (ctx context.Context ) HealthCheckingState {
466
470
ca .rLock (ctx )
467
471
defer ca .rUnlock (ctx )
468
472
469
- return ca .lockedState .healthChecking .lastProbeSuccessTimestamp
470
- }
471
-
472
- func (ca * clusterAccessor ) GetLastProbeTimestamp (ctx context.Context ) time.Time {
473
- ca .rLock (ctx )
474
- defer ca .rUnlock (ctx )
475
-
476
- return ca .lockedState .healthChecking .lastProbeTimestamp
473
+ return HealthCheckingState {
474
+ LastProbeTime : ca .lockedState .healthChecking .lastProbeTime ,
475
+ LastProbeSuccessTime : ca .lockedState .healthChecking .lastProbeSuccessTime ,
476
+ ConsecutiveFailures : ca .lockedState .healthChecking .consecutiveFailures ,
477
+ }
477
478
}
478
479
479
- func (ca * clusterAccessor ) GetLastConnectionCreationErrorTimestamp (ctx context.Context ) time.Time {
480
+ func (ca * clusterAccessor ) GetLastConnectionCreationErrorTime (ctx context.Context ) time.Time {
480
481
ca .rLock (ctx )
481
482
defer ca .rUnlock (ctx )
482
483
483
- return ca .lockedState .lastConnectionCreationErrorTimestamp
484
+ return ca .lockedState .lastConnectionCreationErrorTime
484
485
}
485
486
486
487
func (ca * clusterAccessor ) rLock (ctx context.Context ) {
0 commit comments