Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(589)

Side by Side Diff: milo/common/model/build_summary.go

Issue 2979283002: Add manifest links and hack to index on revision. (Closed)
Patch Set: Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2017 The LUCI Authors. 1 // Copyright 2017 The LUCI Authors.
2 // 2 //
3 // Licensed under the Apache License, Version 2.0 (the "License"); 3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License. 4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at 5 // You may obtain a copy of the License at
6 // 6 //
7 // http://www.apache.org/licenses/LICENSE-2.0 7 // http://www.apache.org/licenses/LICENSE-2.0
8 // 8 //
9 // Unless required by applicable law or agreed to in writing, software 9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS, 10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and 12 // See the License for the specific language governing permissions and
13 // limitations under the License. 13 // limitations under the License.
14 14
15 package model 15 package model
16 16
17 import ( 17 import (
18 "bytes"
19 "crypto/sha256"
18 "time" 20 "time"
19 21
20 "github.com/luci/gae/service/datastore" 22 "github.com/luci/gae/service/datastore"
23
24 "github.com/luci/luci-go/common/data/cmpbin"
21 ) 25 )
22 26
23 // BuildSummary is a datastore model which is used for storing staandardized 27 // BuildSummary is a datastore model which is used for storing staandardized
24 // summarized build data, and is used for backend-agnostic views (i.e. builders, 28 // summarized build data, and is used for backend-agnostic views (i.e. builders,
25 // console). It contains only data that: 29 // console). It contains only data that:
26 // * is necessary to render these simplified views 30 // * is necessary to render these simplified views
27 // * is present in all implementations (buildbot, buildbucket) 31 // * is present in all implementations (buildbot, buildbucket)
28 // 32 //
29 // This entity will live as a child of the various implementation's 33 // This entity will live as a child of the various implementation's
30 // representations of a build (e.g. buildbotBuild). It has various 'tag' fields 34 // representations of a build (e.g. buildbotBuild). It has various 'tag' fields
31 // so that it can be queried by the various backend-agnostic views. 35 // so that it can be queried by the various backend-agnostic views.
32 type BuildSummary struct { 36 type BuildSummary struct {
33 // _id for a BuildSummary is always 1 37 // _id for a BuildSummary is always 1
34 _ int64 `gae:"$id,1"` 38 _ int64 `gae:"$id,1"`
35 39
36 // BuildKey will always point to the "real" build, i.e. a buildbotBuild or 40 // BuildKey will always point to the "real" build, i.e. a buildbotBuild or
37 // a buildbucketBuild. It is always the parent key for the BuildSummary. 41 // a buildbucketBuild. It is always the parent key for the BuildSummary.
38 BuildKey *datastore.Key `gae:"$parent"` 42 BuildKey *datastore.Key `gae:"$parent"`
39 43
40 // Global identifier for the builder that this Build belongs to, i.e.: 44 // Global identifier for the builder that this Build belongs to, i.e.:
41 // "buildbot/<mastername>/<buildername>" 45 // "buildbot/<mastername>/<buildername>"
42 // "buildbucket/<bucketname>/<buildername>" 46 // "buildbucket/<bucketname>/<buildername>"
43 BuilderID string 47 BuilderID string
44 48
45 // KnownConsoleHash is used for backfilling and must always equal the ra w
46 // value of:
47 //
48 // sha256(sorted(ConsoleEpochs.keys())
49 //
50 // This is used to identify BuildSummaries which haven't yet been includ ed in
51 // some new Console definition (or which have been removed from a Consol e
52 // definition).
53 KnownConsoleHash []byte
54
55 // ConsoleEpochs is used for backfilling, and is a series of cmpbin tupl es:
56 //
57 // (console_name[str], recorded_epoch[int])
58 //
59 // This maps which epoch (version) of a console definition this BuildSum mary
60 // belongs to. Whenever a console definition changes, its epoch increase s. The
61 // backfiller will then identify BuildSummary objects which are out of d ate
62 // and update them.
63 ConsoleEpochs [][]byte
64
65 // ConsoleTags contains query tags for the console view. These are cmpbi n
66 // tuples which look like:
67 //
68 // (console_name[str], sort_criteria[tuple], sort_values[tuple])
69 //
70 // `sort_criteria` are defined by the console definition, and will likel y look
71 // like (manifest_name[str], repo_url[str]), but other sort_criteria may be
72 // added later.
73 //
74 // `sort_values` are defined by the selected sort_criteria, and will lik ely
75 // look like (commit_revision[str],). In any event, this string is opaqu e and
76 // only to be used by the console itself.
77 ConsoleTags [][]byte
78
79 // Created is the time when the Build was first created. Due to pending 49 // Created is the time when the Build was first created. Due to pending
80 // queues, this may be substantially before Summary.Start. 50 // queues, this may be substantially before Summary.Start.
81 Created time.Time 51 Created time.Time
82 52
83 // Summary summarizes relevant bits about the overall build. 53 // Summary summarizes relevant bits about the overall build.
84 Summary Summary 54 Summary Summary
85 55
86 // CurrentStep summarizes relevant bits about the currently running step (if 56 // CurrentStep summarizes relevant bits about the currently running step (if
87 // any). Only expected to be set if !Summary.Status.Terminal(). 57 // any). Only expected to be set if !Summary.Status.Terminal().
88 CurrentStep Summary 58 CurrentStep Summary
89 59
90 // Manifests is a list of links to source manifests that this build repo rted. 60 // Manifests is a list of links to source manifests that this build repo rted.
91 Manifests []ManifestLink 61 Manifests []ManifestLink
92 62
93 // Patches is the list of patches which are associated with this build. 63 // Patches is the list of patches which are associated with this build.
94 // We reserve the multi-patch case for advanced (multi-repo) tryjobs... 64 // We reserve the multi-patch case for advanced (multi-repo) tryjobs...
95 // Typically there will only be one patch associated with a build. 65 // Typically there will only be one patch associated with a build.
96 Patches []PatchInfo 66 Patches []PatchInfo
67
68 // ManifestRevisionIndex has a single entry for each
69 // sha256(console ++ manifest_name ++ revision.decode('hex'))
70 // which matched for this build. ++ is cmpbin concatenation.
71 //
72 // The list of interested consoles is compiled at build summarization ti me.
73 ManifestRevisionIndex [][]byte
97 } 74 }
75
76 // AddManifestRevisionIndex adds a new entry to ManifestRevisionIndex.
77 //
78 // `revision` should be the hex-decoded git revision.
79 //
80 // It's up to the caller to ensure that entries in ManifestRevisionIndex aren't
81 // duplicated.
82 func (bs *BuildSummary) AddManifestRevisionIndex(console, manifest string, revis ion []byte) {
83 var buf bytes.Buffer
84 cmpbin.WriteString(&buf, console)
85 cmpbin.WriteString(&buf, manifest)
86 cmpbin.WriteBytes(&buf, revision)
87 hash := sha256.Sum256(buf.Bytes())
88 bs.ManifestRevisionIndex = append(bs.ManifestRevisionIndex, hash[:])
89 }
OLDNEW
« milo/api/resp/build.go ('K') | « milo/buildsource/buildbucket/pubsub.go ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698