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

Side by Side 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The LUCI Authors. All rights reserved. 1 // Copyright 2015 The LUCI Authors. All rights reserved.
2 // Use of this source code is governed under the Apache License, Version 2.0 2 // Use of this source code is governed under the Apache License, Version 2.0
3 // that can be found in the LICENSE file. 3 // that can be found in the LICENSE file.
4 4
5 package swarming 5 package swarming
6 6
7 import ( 7 import (
8 "bytes" 8 "bytes"
9 "fmt" 9 "fmt"
10 "net/http" 10 "net/http"
11 "net/url" 11 "net/url"
12 "strings" 12 "strings"
13 "time" 13 "time"
14 14
15 "golang.org/x/net/context" 15 "golang.org/x/net/context"
16 16
17 "github.com/luci/gae/service/info"
17 swarming "github.com/luci/luci-go/common/api/swarming/swarming/v1" 18 swarming "github.com/luci/luci-go/common/api/swarming/swarming/v1"
18 "github.com/luci/luci-go/common/errors" 19 "github.com/luci/luci-go/common/errors"
19 "github.com/luci/luci-go/common/logging" 20 "github.com/luci/luci-go/common/logging"
20 "github.com/luci/luci-go/common/proto/google" 21 "github.com/luci/luci-go/common/proto/google"
21 miloProto "github.com/luci/luci-go/common/proto/milo" 22 miloProto "github.com/luci/luci-go/common/proto/milo"
22 "github.com/luci/luci-go/common/sync/parallel" 23 "github.com/luci/luci-go/common/sync/parallel"
23 "github.com/luci/luci-go/logdog/client/annotee" 24 "github.com/luci/luci-go/logdog/client/annotee"
24 "github.com/luci/luci-go/logdog/client/coordinator" 25 "github.com/luci/luci-go/logdog/client/coordinator"
25 "github.com/luci/luci-go/logdog/common/types" 26 "github.com/luci/luci-go/logdog/common/types"
26 "github.com/luci/luci-go/milo/api/resp" 27 "github.com/luci/luci-go/milo/api/resp"
(...skipping 512 matching lines...) Expand 10 before | Expand all | Expand 10 after
539 infoComp := infoComponent(model.InfraFailure, 540 infoComp := infoComponent(model.InfraFailure,
540 "LogDog stream not found", "Job likely failed to start.") 541 "LogDog stream not found", "Job likely failed to start.")
541 infoComp.Started = build.Summary.Started 542 infoComp.Started = build.Summary.Started
542 infoComp.Finished = build.Summary.Finished 543 infoComp.Finished = build.Summary.Finished
543 infoComp.Duration = build.Summary.Duration 544 infoComp.Duration = build.Summary.Duration
544 infoComp.Verbosity = resp.Interesting 545 infoComp.Verbosity = resp.Interesting
545 build.Components = append(build.Components, infoComp) 546 build.Components = append(build.Components, infoComp)
546 return addTaskToBuild(c, host, res, build) 547 return addTaskToBuild(c, host, res, build)
547 } 548 }
548 549
549 func (bl *BuildLoader) SwarmingBuildImpl(c context.Context, svc swarmingService, linkBase, taskID string) (*resp.MiloBuild, error) { 550 func (bl *BuildLoader) SwarmingBuildImpl(c context.Context, svc swarmingService, taskID string) (*resp.MiloBuild, error) {
550 // Fetch the data from Swarming 551 // Fetch the data from Swarming
551 var logDogStreamAddr *types.StreamAddr 552 var logDogStreamAddr *types.StreamAddr
552 553
553 fetchParams := swarmingFetchParams{ 554 fetchParams := swarmingFetchParams{
554 fetchRes: true, 555 fetchRes: true,
555 fetchLog: true, 556 fetchLog: true,
556 557
557 // Cancel if LogDog annotation stream parameters are present in the tag set. 558 // Cancel if LogDog annotation stream parameters are present in the tag set.
558 taskResCallback: func(res *swarming.SwarmingRpcsTaskResult) (can celLogs bool) { 559 taskResCallback: func(res *swarming.SwarmingRpcsTaskResult) (can celLogs bool) {
559 // If the build hasn't started yet, then there is no Log Dog log stream to 560 // If the build hasn't started yet, then there is no Log Dog log stream to
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
650 comp := infoComponent(model.InfraFailure, "Milo annotati on parser", err.Error()) 651 comp := infoComponent(model.InfraFailure, "Milo annotati on parser", err.Error())
651 comp.SubLink = append(comp.SubLink, resp.LinkSet{ 652 comp.SubLink = append(comp.SubLink, resp.LinkSet{
652 resp.NewLink("swarming task", taskPageURL(svc.ge tHost(), taskID)), 653 resp.NewLink("swarming task", taskPageURL(svc.ge tHost(), taskID)),
653 }) 654 })
654 build.Components = append(build.Components, comp) 655 build.Components = append(build.Components, comp)
655 } 656 }
656 657
657 if lds != nil && lds.MainStream != nil && lds.MainStream.Data != nil { 658 if lds != nil && lds.MainStream != nil && lds.MainStream.Data != nil {
658 s = lds.MainStream.Data 659 s = lds.MainStream.Data
659 } 660 }
660 » » ub = swarmingURLBuilder(linkBase) 661
662 » » if ub, err = swarmingURLBuilderForTask(c, taskID); err != nil {
663 » » » return nil, err
664 » » }
661 665
662 default: 666 default:
663 s = &miloProto.Step{} 667 s = &miloProto.Step{}
664 » » ub = swarmingURLBuilder(linkBase) 668 » » if ub, err = swarmingURLBuilderForTask(c, taskID); err != nil {
669 » » » return nil, err
670 » » }
665 } 671 }
666 672
667 if s != nil { 673 if s != nil {
668 if err := addTaskToMiloStep(c, svc.getHost(), fr.res, s); err != nil { 674 if err := addTaskToMiloStep(c, svc.getHost(), fr.res, s); err != nil {
669 return nil, err 675 return nil, err
670 } 676 }
671 rawpresentation.AddLogDogToBuild(c, ub, s, &build) 677 rawpresentation.AddLogDogToBuild(c, ub, s, &build)
672 } 678 }
673 679
674 if err := addTaskToBuild(c, svc.getHost(), fr.res, &build); err != nil { 680 if err := addTaskToBuild(c, svc.getHost(), fr.res, &build); err != nil {
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
723 729
724 // botPageURL returns a URL to a human-consumable page of a swarming bot. 730 // botPageURL returns a URL to a human-consumable page of a swarming bot.
725 // Supports server aliases. 731 // Supports server aliases.
726 func botPageURL(swarmingHostname, botID string) string { 732 func botPageURL(swarmingHostname, botID string) string {
727 return fmt.Sprintf("https://%s/restricted/bot/%s", swarmingHostname, bot ID) 733 return fmt.Sprintf("https://%s/restricted/bot/%s", swarmingHostname, bot ID)
728 } 734 }
729 735
730 // swarmingURLBuilder is a logdog.URLBuilder that builds Milo swarming log 736 // swarmingURLBuilder is a logdog.URLBuilder that builds Milo swarming log
731 // links. 737 // links.
732 // 738 //
733 // The string value for this should be the "linkBase" parameter value supplied 739 // Make one of these with swarmingURLBuilderForTask.
734 // to swarmingBuildImpl.
735 type swarmingURLBuilder string 740 type swarmingURLBuilder string
736 741
742 // swarmingURLBuilderForTask returns a URLBuilder that builds links relative to
743 // the current milo hostname's /swarming/task/<id> endpoint.
744 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.
745 hostname, err := info.ModuleHostname(c, "", "", "")
746 if err != nil {
747 return nil, err
748 }
749 // version.module.hostname.tld
750 toks := strings.SplitN(hostname, ".", 3)
751 if len(toks) != 3 {
752 return nil, errors.Reason("unable to determine base URL").
753 InternalReason("bad ModuleHostname %q", hostname).Err()
754 }
755 return swarmingURLBuilder(fmt.Sprintf(
756 "https://%s-dot-%s-dot-%s/swarming/task/%s", toks[0], toks[1], t oks[2], task,
Ryan Tseng 2017/07/12 03:52:56 "/swarming/task/" + task is sufficient Probably
iannucci 2017/07/12 18:08:36 Done.
757 )), nil
758 }
759
737 func (b swarmingURLBuilder) BuildLink(l *miloProto.Link) *resp.Link { 760 func (b swarmingURLBuilder) BuildLink(l *miloProto.Link) *resp.Link {
738 u, err := url.Parse(string(b)) 761 u, err := url.Parse(string(b))
739 if err != nil { 762 if err != nil {
740 return nil 763 return nil
741 } 764 }
742 765
743 switch t := l.Value.(type) { 766 switch t := l.Value.(type) {
744 case *miloProto.Link_LogdogStream: 767 case *miloProto.Link_LogdogStream:
745 ls := t.LogdogStream 768 ls := t.LogdogStream
746 769
747 » » if u.Path == "" { 770 » » u.Path += "/" + ls.Name
748 » » » u.Path = ls.Name
749 » » } else {
750 » » » u.Path = strings.TrimSuffix(u.Path, "/") + "/" + ls.Name
751 » » }
752 link := resp.NewLink(l.Label, u.String()) 771 link := resp.NewLink(l.Label, u.String())
753 if link.Label == "" { 772 if link.Label == "" {
754 link.Label = ls.Name 773 link.Label = ls.Name
755 } 774 }
756 return link 775 return link
757 776
758 case *miloProto.Link_Url: 777 case *miloProto.Link_Url:
759 return resp.NewLink(l.Label, t.Url) 778 return resp.NewLink(l.Label, t.Url)
760 779
761 default: 780 default:
762 return nil 781 return nil
763 } 782 }
764 } 783 }
765 784
766 func swarmingTags(v []string) map[string]string { 785 func swarmingTags(v []string) map[string]string {
767 res := make(map[string]string, len(v)) 786 res := make(map[string]string, len(v))
768 for _, tag := range v { 787 for _, tag := range v {
769 var value string 788 var value string
770 parts := strings.SplitN(tag, ":", 2) 789 parts := strings.SplitN(tag, ":", 2)
771 if len(parts) == 2 { 790 if len(parts) == 2 {
772 value = parts[1] 791 value = parts[1]
773 } 792 }
774 res[parts[0]] = value 793 res[parts[0]] = value
775 } 794 }
776 return res 795 return res
777 } 796 }
OLDNEW
« 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