Skip to content

Commit 26e1579

Browse files
committed
internal/pool: move the reverse buildlet pool into a pool package
This is a set in a series of steps which will move everything buildlet pool related into a pool package. Updates golang/go#36841 Updates golang/go#38337 Change-Id: Ic7a0ccd7838345036df2e72b13084070541cb63c Reviewed-on: https://go-review.googlesource.com/c/build/+/227769 Run-TryBot: Carlos Amedee <carlos@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Alexander Rakoczy <alex@golang.org>
1 parent 1f68cb0 commit 26e1579

File tree

7 files changed

+132
-58
lines changed

7 files changed

+132
-58
lines changed

cmd/coordinator/coordinator.go

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,11 @@ func main() {
254254

255255
mustInitMasterKeyCache(sc)
256256

257+
// TODO(golang.org/issue/38337): remove package level variables where possible.
258+
// TODO(golang.org/issue/36841): remove after key functions are moved into
259+
// a shared package.
260+
pool.SetBuilderMasterKey(masterKey())
261+
257262
err := pool.InitGCE(sc, vmDeleteTimeout, testFiles, &basePinErr, isGCERemoteBuildlet, *buildEnvName, *mode)
258263
if err != nil {
259264
if *mode == "" {
@@ -317,12 +322,12 @@ func main() {
317322
http.HandleFunc("/debug/goroutines", handleDebugGoroutines)
318323
http.HandleFunc("/builders", handleBuilders)
319324
http.HandleFunc("/temporarylogs", handleLogs)
320-
http.HandleFunc("/reverse", handleReverse)
325+
http.HandleFunc("/reverse", pool.HandleReverse)
321326
http.Handle("/revdial", revdialv2.ConnHandler())
322327
http.HandleFunc("/style.css", handleStyleCSS)
323328
http.HandleFunc("/try", serveTryStatus(false))
324329
http.HandleFunc("/try.json", serveTryStatus(true))
325-
http.HandleFunc("/status/reverse.json", reversePool.ServeReverseStatusJSON)
330+
http.HandleFunc("/status/reverse.json", pool.ReversePool().ServeReverseStatusJSON)
326331
http.HandleFunc("/status/post-submit-active.json", handlePostSubmitActiveJSON)
327332
http.Handle("/dashboard", dh)
328333
http.Handle("/buildlet/create", requireBuildletProxyAuth(http.HandlerFunc(handleBuildletCreate)))
@@ -494,7 +499,7 @@ func mayBuildRev(rev buildgo.BuilderRev) bool {
494499
if pool.GCEBuildEnv().MaxBuilds > 0 && numCurrentBuilds() >= pool.GCEBuildEnv().MaxBuilds {
495500
return false
496501
}
497-
if buildConf.IsReverse() && !reversePool.CanBuild(buildConf.HostType) {
502+
if buildConf.IsReverse() && !pool.ReversePool().CanBuild(buildConf.HostType) {
498503
return false
499504
}
500505
return true
@@ -866,7 +871,7 @@ func findWorkLoop() {
866871
}
867872
const debugArm = false
868873
if debugArm {
869-
for !reversePool.CanBuild("host-linux-arm") {
874+
for !pool.ReversePool().CanBuild("host-linux-arm") {
870875
log.Printf("waiting for ARM to register.")
871876
time.Sleep(time.Second)
872877
}
@@ -1634,7 +1639,7 @@ func poolForConf(conf *dashboard.HostConfig) pool.Buildlet {
16341639
return pool.KubePool()
16351640
}
16361641
case conf.IsReverse:
1637-
return reversePool
1642+
return pool.ReversePool()
16381643
default:
16391644
panic(fmt.Sprintf("no buildlet pool for host type %q", conf.HostType))
16401645
}
@@ -1742,7 +1747,7 @@ func (st *buildStatus) expectedBuildletStartDuration() time.Duration {
17421747
return 2 * time.Minute
17431748
}
17441749
return time.Minute
1745-
case *reverseBuildletPool:
1750+
case *pool.ReverseBuildletPool:
17461751
goos, arch := st.conf.GOOS(), st.conf.GOARCH()
17471752
if goos == "darwin" {
17481753
if arch == "arm" || arch == "arm64" {
@@ -2430,6 +2435,8 @@ func (st *buildStatus) distTestList() (names []string, remoteErr, err error) {
24302435
return names, nil, nil
24312436
}
24322437

2438+
type token struct{}
2439+
24332440
// newTestSet returns a new testSet given the dist test names (strings from "go tool dist test -list")
24342441
// and benchmark items.
24352442
func (st *buildStatus) newTestSet(testStats *buildstats.TestStats, distTestNames []string, benchmarks []*buildgo.BenchmarkItem) (*testSet, error) {

cmd/coordinator/debug.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func handleDoSomeWork(work chan<- buildgo.BuilderRev) func(w http.ResponseWriter
3131
if r.Method == "GET" {
3232
w.Header().Set("Content-Type", "text/html; charset=utf-8")
3333
buf := new(bytes.Buffer)
34-
if err := tmplDoSomeWork.Execute(buf, reversePool.HostTypes()); err != nil {
34+
if err := tmplDoSomeWork.Execute(buf, pool.ReversePool().HostTypes()); err != nil {
3535
http.Error(w, fmt.Sprintf("dosomework: %v", err), http.StatusInternalServerError)
3636
}
3737
buf.WriteTo(w)

cmd/coordinator/metrics.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func reportMetrics(ctx context.Context) {
3838
func reportReverseCountMetrics(ctx context.Context) error {
3939
m := metrics.ReverseCount
4040
// 1. Gather # buildlets up per reverse builder type
41-
totals := reversePool.hostTypeCount()
41+
totals := pool.ReversePool().HostTypeCount()
4242
// 2. Write counts to Stackdriver
4343
ts := []*monpb.TimeSeries{}
4444
now := ptypes.TimestampNow()

cmd/coordinator/remote.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ func handleBuildletCreate(w http.ResponseWriter, r *http.Request) {
216216
// the higher priority gomote user.
217217
isReverse := hconf.IsReverse
218218
if isReverse {
219-
if hs := reversePool.buildReverseStatusJSON().HostTypes[hconf.HostType]; hs == nil {
219+
if hs := pool.ReversePool().BuildReverseStatusJSON().HostTypes[hconf.HostType]; hs == nil {
220220
sendText(fmt.Sprintf("host type %q is not elastic; no machines are connected", hconf.HostType))
221221
} else {
222222
sendText(fmt.Sprintf("host type %q is not elastic; %d of %d machines connected, %d busy",

cmd/coordinator/status.go

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -410,15 +410,7 @@ func fetchMakeMacStatus() (errs, warns []string) {
410410
func hostTypeChecker(hostType string) func(cw *checkWriter) {
411411
want := expectedHosts(hostType)
412412
return func(cw *checkWriter) {
413-
p := reversePool
414-
p.mu.Lock()
415-
defer p.mu.Unlock()
416-
n := 0
417-
for _, b := range p.buildlets {
418-
if b.hostType == hostType {
419-
n++
420-
}
421-
}
413+
n := pool.ReversePool().SingleHostTypeCount(hostType)
422414
if n < want {
423415
cw.errorf("%d connected; want %d", n, want)
424416
}
@@ -512,18 +504,22 @@ func reverseHostChecker(hosts []string) func(cw *checkWriter) {
512504
hostSet[v] = true
513505
}
514506

507+
// TODO(amedee): rethink how this is implemented. It has been
508+
// modified due to golang.org/issues/36841
509+
// instead of a single lock being held while all of the
510+
// operations are performed, there is now a lock held
511+
// durring each BuildletLastSeen call and again when
512+
// the buildlet host names are retrieved.
515513
return func(cw *checkWriter) {
516-
p := reversePool
517-
p.mu.Lock()
518-
defer p.mu.Unlock()
514+
p := pool.ReversePool()
519515

520516
now := time.Now()
521517
wantGoodSince := now.Add(-recentThreshold)
522518
numMissing := 0
523519
numGood := 0
524520
// Check last good times
525521
for _, host := range hosts {
526-
lastGood, ok := p.hostLastGood[host]
522+
lastGood, ok := p.BuildletLastSeen(host)
527523
if ok && lastGood.After(wantGoodSince) {
528524
numGood++
529525
continue
@@ -553,9 +549,9 @@ func reverseHostChecker(hosts []string) func(cw *checkWriter) {
553549
// And check that we don't have more than 1
554550
// connected of any type.
555551
count := map[string]int{}
556-
for _, b := range p.buildlets {
557-
if hostSet[b.hostname] {
558-
count[b.hostname]++
552+
for _, hostname := range p.BuildletHostnames() {
553+
if hostSet[hostname] {
554+
count[hostname]++
559555
}
560556
}
561557
for name, n := range count {
@@ -666,7 +662,7 @@ func handleStatus(w http.ResponseWriter, r *http.Request) {
666662
data.KubePoolStatus = template.HTML(buf.String())
667663
buf.Reset()
668664

669-
reversePool.WriteHTMLStatus(&buf)
665+
pool.ReversePool().WriteHTMLStatus(&buf)
670666
data.ReversePoolStatus = template.HTML(buf.String())
671667

672668
data.SchedState = sched.state()

0 commit comments

Comments
 (0)