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

Unified Diff: appengine/cmd/milo/buildbot/console.go

Issue 2196453002: Milo: Console view prototype (Closed) Base URL: https://chromium.googlesource.com/external/github.com/luci/luci-go@master
Patch Set: fixes Created 4 years, 4 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 side-by-side diff with in-line comments
Download patch
Index: appengine/cmd/milo/buildbot/console.go
diff --git a/appengine/cmd/milo/buildbot/console.go b/appengine/cmd/milo/buildbot/console.go
new file mode 100644
index 0000000000000000000000000000000000000000..05b6d7befb20a2ec4814572e121df295abf89477
--- /dev/null
+++ b/appengine/cmd/milo/buildbot/console.go
@@ -0,0 +1,92 @@
+// Copyright 2016 The LUCI Authors. All rights reserved.
+// Use of this source code is governed under the Apache License, Version 2.0
+// that can be found in the LICENSE file.
+
+package buildbot
+
+import (
+ "fmt"
+ "strings"
+
+ "github.com/luci/gae/service/datastore"
+ "github.com/luci/luci-go/appengine/cmd/milo/resp"
+ "github.com/luci/luci-go/common/clock"
+ log "github.com/luci/luci-go/common/logging"
+ "github.com/luci/luci-go/common/sync/parallel"
+ "golang.org/x/net/context"
+)
+
+// getFullBuilds fetches all of the recent builds from the datastore.
+func getFullBuilds(c context.Context, masterName, builderName string, finished bool) ([]*buildbotBuild, error) {
+ // TODO(hinoka): Builder specific structs.
+ ds := datastore.Get(c)
+ q := datastore.NewQuery("buildbotBuild")
+ q = q.Eq("finished", finished)
+ q = q.Eq("master", masterName)
+ q = q.Eq("builder", builderName)
+ q = q.Limit(25) // TODO(hinoka): This should be adjustable
+ q = q.Order("-number")
+ q.Finalize()
+ buildbots := make([]*buildbotBuild, 0, 25)
+ err := ds.GetAll(q, &buildbots)
+ return buildbots, err
+}
+
+func GetConsoleBuilds(
+ c context.Context, builders []resp.BuilderRef, commits []string) (
+ [][]*resp.ConsoleBuild, error) {
nodir 2016/08/04 23:13:12 document what indexes in the return value mean
hinoka 2016/08/05 00:10:41 Done.
+
+ results := make([][]*resp.ConsoleBuild, len(commits))
+ for i := range results {
+ results[i] = make([]*resp.ConsoleBuild, len(builders))
+ }
+ // HACK(hinoka): This fetches 25 full builds and then filters them. Replace this
+ // with something more reasonable.
+ // This is kind of a hack but it's okay for now.
+ err := parallel.FanOutIn(func(taskC chan<- func() error) {
+ for i, builder := range builders {
+ i := i // How do scopes werk
+ f := strings.SplitN(builder.Name, "/", 2)
nodir 2016/08/04 23:13:13 i am not sure what f stands for
hinoka 2016/08/05 00:10:42 Done.
+ if len(f) != 2 {
+ taskC <- func() error {
+ return fmt.Errorf("%s is an invalid builder name", builder.Name)
nodir 2016/08/04 23:13:12 builder var is captured, so there is a race you ne
hinoka 2016/08/05 00:10:41 Oh good catch
+ }
+ return
+ }
+ master := f[0]
+ builderName := f[1]
+ taskC <- func() error {
+ t1 := clock.Now(c)
+ builds, err := getFullBuilds(c, master, builderName, true)
+ if err != nil {
+ return err
+ }
+ t2 := clock.Now(c)
+ var currentStatus *resp.Status
+ for j, commit := range commits {
+ for _, build := range builds {
+ if build.Sourcestamp.Revision == commit {
nodir 2016/08/04 23:13:12 why does this have only one source stamp? a build
hinoka 2016/08/05 00:10:41 This is buildbot's own concept of sourcestamp, tha
+ results[j][i] = &resp.ConsoleBuild{
nodir 2016/08/04 23:13:12 since there is no "break" in the end of this `if`,
hinoka 2016/08/05 00:10:41 I think we should pick the latest one (This code w
+ Link: &resp.Link{
+ Label: strings.Join(build.Text, " "),
+ URL: fmt.Sprintf(
+ "/buildbot/%s/%s/%d", master, builderName, build.Number),
+ },
+ Status: build.toStatus(),
+ }
+ currentStatus = &results[j][i].Status
+ }
+ }
+ if currentStatus != nil && results[j][i] == nil {
+ results[j][i] = &resp.ConsoleBuild{Status: *currentStatus}
+ }
+ }
+ log.Debugf(c,
+ "Builder %s took %s to query, %s to compute.", builderName,
+ t2.Sub(t1), clock.Since(c, t2))
+ return nil
+ }
+ }
+ })
+ return results, err
+}

Powered by Google App Engine
This is Rietveld 408576698