@@ -81,6 +81,22 @@ type reverseBuildletPool struct {
81
81
// we bound how many can be running at once. Fortunately there aren't many left.
82
82
oldInUse map [* buildlet.Client ]bool
83
83
84
+ // hostLastGood tracks when buildlets were last seen to be
85
+ // healthy. It's only used by the health reporting code (in
86
+ // status.go). The reason it's a map on reverseBuildletPool
87
+ // rather than a field on each reverseBuildlet is because we
88
+ // also want to track the last known health time of buildlets
89
+ // that aren't currently connected.
90
+ //
91
+ // Each buildlet's health is recorded in the map twice, under
92
+ // two different keys: 1) its reported host name, and 2) its
93
+ // hostType + ":" + its reported host name. It's recorded both
94
+ // ways so the status code can check for both globally-unique
95
+ // hostnames that change host types (e.g. our Macs), as well
96
+ // as hostnames that aren't globally unique and are expected
97
+ // to be found with different hostTypes (e.g. our ppc64le
98
+ // machines as both POWER8 and POWER9 host types, but with the
99
+ // same names).
84
100
hostLastGood map [string ]time.Time
85
101
}
86
102
@@ -208,6 +224,14 @@ func (p *reverseBuildletPool) healthCheckBuildletLoop(b *reverseBuildlet) {
208
224
}
209
225
}
210
226
227
+ // recordHealthy updates the two map entries in hostLastGood recording
228
+ // that b is healthy.
229
+ func (p * reverseBuildletPool ) recordHealthy (b * reverseBuildlet ) {
230
+ t := time .Now ()
231
+ p .hostLastGood [b .hostname ] = t
232
+ p .hostLastGood [b .hostType + ":" + b .hostname ] = t
233
+ }
234
+
211
235
func (p * reverseBuildletPool ) healthCheckBuildlet (b * reverseBuildlet ) bool {
212
236
if b .client .IsBroken () {
213
237
return false
@@ -217,7 +241,7 @@ func (p *reverseBuildletPool) healthCheckBuildlet(b *reverseBuildlet) bool {
217
241
panic ("previous health check still running" )
218
242
}
219
243
if b .inUse {
220
- p .hostLastGood [ b . hostname ] = time . Now ( )
244
+ p .recordHealthy ( b )
221
245
p .mu .Unlock ()
222
246
return true // skip busy buildlets
223
247
}
@@ -257,9 +281,8 @@ func (p *reverseBuildletPool) healthCheckBuildlet(b *reverseBuildlet) bool {
257
281
}
258
282
b .inUse = false
259
283
b .inHealthCheck = false
260
- now := time .Now ()
261
- b .inUseTime = now
262
- p .hostLastGood [b .hostname ] = now
284
+ b .inUseTime = time .Now ()
285
+ p .recordHealthy (b )
263
286
go p .noteBuildletAvailable (b .hostType )
264
287
return true
265
288
}
@@ -479,7 +502,7 @@ func (p *reverseBuildletPool) addBuildlet(b *reverseBuildlet) {
479
502
defer p .noteBuildletAvailable (b .hostType )
480
503
defer p .mu .Unlock ()
481
504
p .buildlets = append (p .buildlets , b )
482
- p .hostLastGood [ b . hostname ] = time . Now ( )
505
+ p .recordHealthy ( b )
483
506
go p .healthCheckBuildletLoop (b )
484
507
}
485
508
0 commit comments