Skip to content

Commit 97bf1fb

Browse files
committed
cmd/coordinator: break up status into active vs pending builds
Currently all builds start and think they're running, but most are just fighting over a mutex to grab a builder. That will be fixed, but in the meantime it's nice to see what's actually working vs what's waiting on e.g. arm5 hardware which won't be available for hours. This is a baby step towards more monitoring. Currently this is just HTML output, but the same data could be exported via JSON or something else later for graphing. Updates golang/go#19178 (add a buildlet scheduler) Updates golang/go#15760 (monitor everything) Change-Id: I36e16ea0919afe8023fe7fedd981f2e857f0d6df Reviewed-on: https://go-review.googlesource.com/40397 Reviewed-by: Brad Fitzpatrick <[email protected]>
1 parent c328d04 commit 97bf1fb

File tree

2 files changed

+24
-7
lines changed

2 files changed

+24
-7
lines changed

cmd/coordinator/coordinator.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import (
3939
"sort"
4040
"strings"
4141
"sync"
42+
"sync/atomic"
4243
"time"
4344

4445
"go4.org/syncutil"
@@ -1469,6 +1470,7 @@ func (st *buildStatus) build() error {
14691470
if err != nil {
14701471
return fmt.Errorf("failed to get a buildlet: %v", err)
14711472
}
1473+
atomic.StoreInt32(&st.hasBuildlet, 1)
14721474
defer bc.Close()
14731475
st.mu.Lock()
14741476
st.bc = bc
@@ -2874,6 +2876,8 @@ type buildStatus struct {
28742876
ctx context.Context // used to start the build
28752877
cancel context.CancelFunc // used to cancel context; for use by setDone only
28762878

2879+
hasBuildlet int32 // atomic: non-zero if this build has a buildlet; for status.go.
2880+
28772881
mu sync.Mutex // guards following
28782882
failURL string // if non-empty, permanent URL of failure
28792883
bc *buildlet.Client // nil initially, until pool returns one
@@ -3013,9 +3017,6 @@ func (st *buildStatus) htmlStatusLine(full bool) template.HTML {
30133017
defer st.mu.Unlock()
30143018

30153019
urlPrefix := "https://go-review.googlesource.com/#/q/"
3016-
if strings.Contains(st.name, "gccgo") {
3017-
urlPrefix = "https://code.google.com/p/gofrontend/source/detail?r="
3018-
}
30193020

30203021
var buf bytes.Buffer
30213022
fmt.Fprintf(&buf, "<a href='https://github.com/golang/go/wiki/DashboardBuilders'>%s</a> rev <a href='%s%s'>%s</a>",

cmd/coordinator/status.go

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"runtime"
1616
"sort"
1717
"strings"
18+
"sync/atomic"
1819
"time"
1920
)
2021

@@ -39,7 +40,12 @@ func handleStatus(w http.ResponseWriter, r *http.Request) {
3940
NumGoroutine: runtime.NumGoroutine(),
4041
}
4142
for _, st := range status {
42-
data.Active = append(data.Active, st)
43+
if atomic.LoadInt32(&st.hasBuildlet) != 0 {
44+
data.ActiveBuilds++
45+
data.Active = append(data.Active, st)
46+
} else {
47+
data.Pending = append(data.Pending, st)
48+
}
4349
}
4450
// TODO: make this prettier.
4551
var buf bytes.Buffer
@@ -59,6 +65,7 @@ func handleStatus(w http.ResponseWriter, r *http.Request) {
5965
data.RemoteBuildlets = template.HTML(remoteBuildletStatus())
6066

6167
sort.Sort(byAge(data.Active))
68+
sort.Sort(byAge(data.Pending))
6269
sort.Sort(sort.Reverse(byAge(data.Recent)))
6370
if errTryDeps != nil {
6471
data.TrybotsErr = errTryDeps.Error()
@@ -116,11 +123,13 @@ func diskFree() string {
116123

117124
// statusData is the data that fills out statusTmpl.
118125
type statusData struct {
119-
Total int // number of total builds active
126+
Total int // number of total builds (including those waiting for a buildlet)
127+
ActiveBuilds int // number of running builds (subset of Total with a buildlet)
120128
NumFD int
121129
NumGoroutine int
122130
Uptime time.Duration
123-
Active []*buildStatus
131+
Active []*buildStatus // have a buildlet
132+
Pending []*buildStatus // waiting on a buildlet
124133
Recent []*buildStatus
125134
TrybotsErr string
126135
Trybots template.HTML
@@ -147,7 +156,7 @@ var statusTmpl = template.Must(template.New("status").Parse(`
147156
</header>
148157
149158
<h2>Running</h2>
150-
<p>{{printf "%d" .Total}} total builds active. Uptime {{printf "%s" .Uptime}}. Version {{.Version}}.
159+
<p>{{printf "%d" .Total}} total builds; {{printf "%d" .ActiveBuilds}} active. Uptime {{printf "%s" .Uptime}}. Version {{.Version}}.
151160
152161
<h2 id=trybots><a href='#trybots'>🔗</a> Active Trybot Runs</h2>
153162
{{- if .TrybotsErr}}
@@ -173,6 +182,13 @@ var statusTmpl = template.Must(template.New("status").Parse(`
173182
{{end}}
174183
</ul>
175184
185+
<h2 id=pending><a href='#pending'>🔗</a> Pending builds</h2>
186+
<ul>
187+
{{range .Pending}}
188+
<li><pre>{{.HTMLStatusLine}}</pre></li>
189+
{{end}}
190+
</ul>
191+
176192
<h2 id=completed><a href='#completed'>🔗</a> Recently completed</h2>
177193
<ul>
178194
{{range .Recent}}

0 commit comments

Comments
 (0)