blob: 983ead6b13e3ba732fe680619260d8e1411d62b0 [file] [log] [blame]
Brad Fitzpatrickd5491eb2015-01-05 03:02:59 +00001// Copyright 2011 The Go Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style
3// license that can be found in the LICENSE file.
4
5// Package types contains common types used by the Go continuous build
6// system.
7package types
8
Brad Fitzpatrick2fce5182016-10-06 16:49:13 +00009import "time"
10
Brad Fitzpatrickd5491eb2015-01-05 03:02:59 +000011// BuildStatus is the data structure that's marshalled as JSON
Andrew Gerrandf7f45282016-04-22 12:33:11 +100012// for the https://build.golang.org/?mode=json page.
Brad Fitzpatrickd5491eb2015-01-05 03:02:59 +000013type BuildStatus struct {
14 // Builders is a list of all known builders.
15 // The order that builders appear is the same order as the build results for a revision.
16 Builders []string `json:"builders"`
17
18 // Revisions are the revisions shown on the front page of build.golang.org,
19 // in the same order. It starts with the "go" repo, from recent to old, and then
20 // it has 1 each of the subrepos, with only their most recent commit.
21 Revisions []BuildRevision `json:"revisions"`
22}
23
24// BuildRevision is the status of a commit across all builders.
Andrew Gerrandf7f45282016-04-22 12:33:11 +100025// It corresponds to a single row of https://build.golang.org/
Brad Fitzpatrickd5491eb2015-01-05 03:02:59 +000026type BuildRevision struct {
27 // Repo is "go" for the main repo, else "tools", "crypto", "net", etc.
28 // These are repos as listed at https://go.googlesource.com/
29 Repo string `json:"repo"`
30
31 // Revision is the full git hash of the repo.
32 Revision string `json:"revision"`
33
34 // GoRevision is the full git hash of the "go" repo, if Repo is not "go" itself.
35 // Otherwise this is empty.
36 GoRevision string `json:"goRevision,omitempty"`
37
Austin Clements8b843f12015-04-16 18:29:32 -040038 // Date is the commit date of this revision, formatted in RFC3339.
39 Date string `json:"date"`
40
Austin Clementscf973362015-11-04 10:16:59 -050041 // Branch is the branch of this commit, e.g. "master" or "dev.ssa".
42 Branch string `json:"branch"`
43
Brad Fitzpatrickf4148b52017-12-12 19:05:47 +000044 // GoBranch is the branch of the GoRevision, for subrepos.
45 // It is empty for the main repo.
46 // Otherwise it's of the form "master", "release-branch.go1.8", etc.
47 GoBranch string `json:"goBranch,omitempty"`
48
Austin Clementscf973362015-11-04 10:16:59 -050049 // Author is the author of this commit in standard git form
50 // "Name <email>".
51 Author string `json:"author"`
52
53 // Desc is the commit message of this commit. It may be
54 // truncated.
55 Desc string `json:"desc"`
56
Brad Fitzpatrickd5491eb2015-01-05 03:02:59 +000057 // Results are the build results for each of the builders in
58 // the same length slice BuildStatus.Builders.
59 // Each string is either "" (if no data), "ok", or the URL to failure logs.
60 Results []string `json:"results"`
61}
Brad Fitzpatrick2fce5182016-10-06 16:49:13 +000062
63// SpanRecord is a datastore entity we write only at the end of a span
64// (roughly a "step") of the build.
65type SpanRecord struct {
66 BuildID string
67 IsTry bool // is trybot run
68 GoRev string
69 Rev string // same as GoRev for repo "go"
70 Repo string // "go", "net", etc.
71 Builder string // "linux-amd64-foo"
72 OS string // "linux"
73 Arch string // "amd64"
74
75 Event string
76 Error string // empty for no error
77 Detail string
78 StartTime time.Time
79 EndTime time.Time
80 Seconds float64
81}
82
83// BuildRecord is the datastore entity we write both at the beginning
84// and end of a build. Some fields are not updated until the end.
85type BuildRecord struct {
Brad Fitzpatrick6ae87502018-05-04 02:42:17 +000086 ID string
87 ProcessID string
88 StartTime time.Time
89 IsTry bool // is trybot run
Dmitri Shuralyov2dd45482020-04-09 16:22:50 -040090 IsSlowBot bool // is an explicitly requested "slowbot" builder
Brad Fitzpatrick6ae87502018-05-04 02:42:17 +000091 GoRev string
92 Rev string // same as GoRev for repo "go"
93 Repo string // "go", "net", etc.
94 Builder string // "linux-amd64-foo"
95 ContainerHost string // "" means GKE; "cos" means Container-Optimized OS
96 OS string // "linux"
97 Arch string // "amd64"
Brad Fitzpatrick2fce5182016-10-06 16:49:13 +000098
99 EndTime time.Time
100 Seconds float64
101 Result string // empty string, "ok", "fail"
Andrew Bonventre6ce37fe2019-10-01 09:52:44 -0400102 FailureURL string `datastore:",noindex"` // deprecated; use LogURL
103 LogURL string `datastore:",noindex"`
Brad Fitzpatrick2fce5182016-10-06 16:49:13 +0000104
105 // TODO(bradfitz): log which reverse buildlet we got?
106 // Buildlet string
107}
Brad Fitzpatrick15521bc2017-02-24 17:50:49 +0000108
109type ReverseBuilder struct {
110 Name string
111 HostType string
112 ConnectedSec float64
113 IdleSec float64 `json:",omitempty"`
114 BusySec float64 `json:",omitempty"`
115 Version string // buildlet version
116 Busy bool
117}
118
119// ReverseHostStatus is part of ReverseBuilderStatus.
120type ReverseHostStatus struct {
121 HostType string // dashboard.Hosts key
122 Connected int // number of connected buildlets
123 Expect int // expected number, from dashboard.Hosts config
124 Idle int
125 Busy int
126 Waiters int // number of builds waiting on a buildlet host of this type
127
128 // Machines are all connected buildlets of this host type,
129 // keyed by machine self-reported unique name.
130 Machines map[string]*ReverseBuilder
131}
132
Kevin Burke315d0bd2017-04-03 07:51:28 -0700133// ReverseBuilderStatus is https://farmer.golang.org/status/reverse.json
Brad Fitzpatrick15521bc2017-02-24 17:50:49 +0000134//
135// It is used by monitoring and the Mac VMWare infrastructure to
136// adjust the Mac VMs based on deaths and demand.
137type ReverseBuilderStatus struct {
138 // Machines maps from the connected builder name (anything unique) to its status.
139 HostTypes map[string]*ReverseHostStatus
140}
141
142func (s *ReverseBuilderStatus) Host(hostType string) *ReverseHostStatus {
143 if s.HostTypes == nil {
144 s.HostTypes = make(map[string]*ReverseHostStatus)
145 }
146 hs, ok := s.HostTypes[hostType]
147 if ok {
148 return hs
149 }
150 hs = &ReverseHostStatus{HostType: hostType}
151 s.HostTypes[hostType] = hs
152 return hs
153}
Dmitri Shuralyovad59fb12019-01-11 16:44:01 -0500154
155// MajorMinor is a major-minor version pair.
156type MajorMinor struct {
157 Major, Minor int
158}
159
160// Less reports whether a is less than b.
161func (a MajorMinor) Less(b MajorMinor) bool {
162 if a.Major != b.Major {
163 return a.Major < b.Major
164 }
165 return a.Minor < b.Minor
166}
Brad Fitzpatrick6191a532019-11-19 18:23:13 +0000167
168// BuildletWaitStatus is the periodic messages we send to "gomote create"
169// clients or show on trybot status pages to tell the user who long
170// they're expected to wait.
171type BuildletWaitStatus struct {
Brad Fitzpatricka24f9652019-12-04 03:45:10 +0000172 // Message is a free-form message to send to the user's gomote binary.
173 // If present, all other fields are ignored.
174 Message string `json:"message"`
175
176 // Ahead are the number of waiters ahead of this buildlet request.
177 Ahead int `json:"ahead"`
Brad Fitzpatrick6191a532019-11-19 18:23:13 +0000178
179 // TODO: add number of active builds, and number of builds
180 // creating. And for how long. And maybe an estimate of how
181 // long those builds typically take? But recognize which are
182 // dynamic vs static (reverse) builder types and don't say
183 // that "1 is creating" on a reverse buildlet that can't
184 // actually "create" any. (It can just wait for one register
185 // itself)
186}
Brad Fitzpatrick773315a2019-12-11 07:12:43 +0000187
188// ActivePostSubmitBuild is a summary of an active build that the
189// coordinator's doing. Each one is rendered on build.golang.org as a
190// blue gopher which links to StatusURL to watch the build live.
191type ActivePostSubmitBuild struct {
192 Builder string `json:"builder"` // "linux-amd64"
193 Commit string `json:"commit"` // hash of commit being tested
194 GoCommit string `json:"goCommit,omitempty"` // hash of Go commit, or empty for the main repo
195 StatusURL string `json:"statusURL"`
196}