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

Unified Diff: milo/buildsource/swarming/build.go

Issue 2975023002: [milo] remove linkBase and calculate links directly. (Closed)
Patch Set: rebase 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « milo/buildsource/buildbucket/pubsub.go ('k') | milo/buildsource/swarming/build_test.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: milo/buildsource/swarming/build.go
diff --git a/milo/buildsource/swarming/build.go b/milo/buildsource/swarming/build.go
index 50dc83772ef378332f5f8927bbf468d4cfddae54..118b25e5301004f2d3310a6a53db216f2028d742 100644
--- a/milo/buildsource/swarming/build.go
+++ b/milo/buildsource/swarming/build.go
@@ -14,6 +14,7 @@ import (
"golang.org/x/net/context"
+ "github.com/luci/gae/service/info"
swarming "github.com/luci/luci-go/common/api/swarming/swarming/v1"
"github.com/luci/luci-go/common/errors"
"github.com/luci/luci-go/common/logging"
@@ -546,7 +547,7 @@ func failedToStart(c context.Context, build *resp.MiloBuild, res *swarming.Swarm
return addTaskToBuild(c, host, res, build)
}
-func (bl *BuildLoader) SwarmingBuildImpl(c context.Context, svc swarmingService, linkBase, taskID string) (*resp.MiloBuild, error) {
+func (bl *BuildLoader) SwarmingBuildImpl(c context.Context, svc swarmingService, taskID string) (*resp.MiloBuild, error) {
// Fetch the data from Swarming
var logDogStreamAddr *types.StreamAddr
@@ -657,11 +658,16 @@ func (bl *BuildLoader) SwarmingBuildImpl(c context.Context, svc swarmingService,
if lds != nil && lds.MainStream != nil && lds.MainStream.Data != nil {
s = lds.MainStream.Data
}
- ub = swarmingURLBuilder(linkBase)
+
+ if ub, err = swarmingURLBuilderForTask(c, taskID); err != nil {
+ return nil, err
+ }
default:
s = &miloProto.Step{}
- ub = swarmingURLBuilder(linkBase)
+ if ub, err = swarmingURLBuilderForTask(c, taskID); err != nil {
+ return nil, err
+ }
}
if s != nil {
@@ -730,10 +736,27 @@ func botPageURL(swarmingHostname, botID string) string {
// swarmingURLBuilder is a logdog.URLBuilder that builds Milo swarming log
// links.
//
-// The string value for this should be the "linkBase" parameter value supplied
-// to swarmingBuildImpl.
+// Make one of these with swarmingURLBuilderForTask.
type swarmingURLBuilder string
+// swarmingURLBuilderForTask returns a URLBuilder that builds links relative to
+// the current milo hostname's /swarming/task/<id> endpoint.
+func swarmingURLBuilderForTask(c context.Context, task string) (rawpresentation.URLBuilder, error) {
Ryan Tseng 2017/07/12 03:52:56 Honestly relative urls are fine, most other places
iannucci 2017/07/12 18:08:36 Done.
+ hostname, err := info.ModuleHostname(c, "", "", "")
+ if err != nil {
+ return nil, err
+ }
+ // version.module.hostname.tld
+ toks := strings.SplitN(hostname, ".", 3)
+ if len(toks) != 3 {
+ return nil, errors.Reason("unable to determine base URL").
+ InternalReason("bad ModuleHostname %q", hostname).Err()
+ }
+ return swarmingURLBuilder(fmt.Sprintf(
+ "https://%s-dot-%s-dot-%s/swarming/task/%s", toks[0], toks[1], toks[2], task,
Ryan Tseng 2017/07/12 03:52:56 "/swarming/task/" + task is sufficient Probably
iannucci 2017/07/12 18:08:36 Done.
+ )), nil
+}
+
func (b swarmingURLBuilder) BuildLink(l *miloProto.Link) *resp.Link {
u, err := url.Parse(string(b))
if err != nil {
@@ -744,11 +767,7 @@ func (b swarmingURLBuilder) BuildLink(l *miloProto.Link) *resp.Link {
case *miloProto.Link_LogdogStream:
ls := t.LogdogStream
- if u.Path == "" {
- u.Path = ls.Name
- } else {
- u.Path = strings.TrimSuffix(u.Path, "/") + "/" + ls.Name
- }
+ u.Path += "/" + ls.Name
link := resp.NewLink(l.Label, u.String())
if link.Label == "" {
link.Label = ls.Name
« no previous file with comments | « milo/buildsource/buildbucket/pubsub.go ('k') | milo/buildsource/swarming/build_test.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698