Brad Fitzpatrick | d5491eb | 2015-01-05 03:02:59 +0000 | [diff] [blame] | 1 | // 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. |
| 7 | package types |
| 8 | |
Brad Fitzpatrick | 2fce518 | 2016-10-06 16:49:13 +0000 | [diff] [blame] | 9 | import "time" |
| 10 | |
Brad Fitzpatrick | d5491eb | 2015-01-05 03:02:59 +0000 | [diff] [blame] | 11 | // BuildStatus is the data structure that's marshalled as JSON |
Andrew Gerrand | f7f4528 | 2016-04-22 12:33:11 +1000 | [diff] [blame] | 12 | // for the https://build.golang.org/?mode=json page. |
Brad Fitzpatrick | d5491eb | 2015-01-05 03:02:59 +0000 | [diff] [blame] | 13 | type 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 Gerrand | f7f4528 | 2016-04-22 12:33:11 +1000 | [diff] [blame] | 25 | // It corresponds to a single row of https://build.golang.org/ |
Brad Fitzpatrick | d5491eb | 2015-01-05 03:02:59 +0000 | [diff] [blame] | 26 | type 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 Clements | 8b843f1 | 2015-04-16 18:29:32 -0400 | [diff] [blame] | 38 | // Date is the commit date of this revision, formatted in RFC3339. |
| 39 | Date string `json:"date"` |
| 40 | |
Austin Clements | cf97336 | 2015-11-04 10:16:59 -0500 | [diff] [blame] | 41 | // Branch is the branch of this commit, e.g. "master" or "dev.ssa". |
| 42 | Branch string `json:"branch"` |
| 43 | |
Brad Fitzpatrick | f4148b5 | 2017-12-12 19:05:47 +0000 | [diff] [blame] | 44 | // 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 Clements | cf97336 | 2015-11-04 10:16:59 -0500 | [diff] [blame] | 49 | // 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 Fitzpatrick | d5491eb | 2015-01-05 03:02:59 +0000 | [diff] [blame] | 57 | // 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 Fitzpatrick | 2fce518 | 2016-10-06 16:49:13 +0000 | [diff] [blame] | 62 | |
| 63 | // SpanRecord is a datastore entity we write only at the end of a span |
| 64 | // (roughly a "step") of the build. |
| 65 | type 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. |
| 85 | type BuildRecord struct { |
Brad Fitzpatrick | 6ae8750 | 2018-05-04 02:42:17 +0000 | [diff] [blame] | 86 | ID string |
| 87 | ProcessID string |
| 88 | StartTime time.Time |
| 89 | IsTry bool // is trybot run |
Dmitri Shuralyov | 2dd4548 | 2020-04-09 16:22:50 -0400 | [diff] [blame] | 90 | IsSlowBot bool // is an explicitly requested "slowbot" builder |
Brad Fitzpatrick | 6ae8750 | 2018-05-04 02:42:17 +0000 | [diff] [blame] | 91 | 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 Fitzpatrick | 2fce518 | 2016-10-06 16:49:13 +0000 | [diff] [blame] | 98 | |
| 99 | EndTime time.Time |
| 100 | Seconds float64 |
| 101 | Result string // empty string, "ok", "fail" |
Andrew Bonventre | 6ce37fe | 2019-10-01 09:52:44 -0400 | [diff] [blame] | 102 | FailureURL string `datastore:",noindex"` // deprecated; use LogURL |
| 103 | LogURL string `datastore:",noindex"` |
Brad Fitzpatrick | 2fce518 | 2016-10-06 16:49:13 +0000 | [diff] [blame] | 104 | |
| 105 | // TODO(bradfitz): log which reverse buildlet we got? |
| 106 | // Buildlet string |
| 107 | } |
Brad Fitzpatrick | 15521bc | 2017-02-24 17:50:49 +0000 | [diff] [blame] | 108 | |
| 109 | type 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. |
| 120 | type 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 Burke | 315d0bd | 2017-04-03 07:51:28 -0700 | [diff] [blame] | 133 | // ReverseBuilderStatus is https://farmer.golang.org/status/reverse.json |
Brad Fitzpatrick | 15521bc | 2017-02-24 17:50:49 +0000 | [diff] [blame] | 134 | // |
| 135 | // It is used by monitoring and the Mac VMWare infrastructure to |
| 136 | // adjust the Mac VMs based on deaths and demand. |
| 137 | type ReverseBuilderStatus struct { |
| 138 | // Machines maps from the connected builder name (anything unique) to its status. |
| 139 | HostTypes map[string]*ReverseHostStatus |
| 140 | } |
| 141 | |
| 142 | func (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 Shuralyov | ad59fb1 | 2019-01-11 16:44:01 -0500 | [diff] [blame] | 154 | |
| 155 | // MajorMinor is a major-minor version pair. |
| 156 | type MajorMinor struct { |
| 157 | Major, Minor int |
| 158 | } |
| 159 | |
| 160 | // Less reports whether a is less than b. |
| 161 | func (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 Fitzpatrick | 6191a53 | 2019-11-19 18:23:13 +0000 | [diff] [blame] | 167 | |
| 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. |
| 171 | type BuildletWaitStatus struct { |
Brad Fitzpatrick | a24f965 | 2019-12-04 03:45:10 +0000 | [diff] [blame] | 172 | // 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 Fitzpatrick | 6191a53 | 2019-11-19 18:23:13 +0000 | [diff] [blame] | 178 | |
| 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 Fitzpatrick | 773315a | 2019-12-11 07:12:43 +0000 | [diff] [blame] | 187 | |
| 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. |
| 191 | type 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 | } |