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

Side by Side Diff: milo/buildsource/swarming/build.go

Issue 2975023002: [milo] remove linkBase and calculate links directly. (Closed)
Patch Set: common url base 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"
(...skipping 528 matching lines...) Expand 10 before | Expand all | Expand 10 after
539 infoComp := infoComponent(model.InfraFailure, 539 infoComp := infoComponent(model.InfraFailure,
540 "LogDog stream not found", "Job likely failed to start.") 540 "LogDog stream not found", "Job likely failed to start.")
541 infoComp.Started = build.Summary.Started 541 infoComp.Started = build.Summary.Started
542 infoComp.Finished = build.Summary.Finished 542 infoComp.Finished = build.Summary.Finished
543 infoComp.Duration = build.Summary.Duration 543 infoComp.Duration = build.Summary.Duration
544 infoComp.Verbosity = resp.Interesting 544 infoComp.Verbosity = resp.Interesting
545 build.Components = append(build.Components, infoComp) 545 build.Components = append(build.Components, infoComp)
546 return addTaskToBuild(c, host, res, build) 546 return addTaskToBuild(c, host, res, build)
547 } 547 }
548 548
549 func (bl *BuildLoader) SwarmingBuildImpl(c context.Context, svc swarmingService, linkBase, taskID string) (*resp.MiloBuild, error) { 549 func (bl *BuildLoader) SwarmingBuildImpl(c context.Context, svc swarmingService, taskID string) (*resp.MiloBuild, error) {
550 // Fetch the data from Swarming 550 // Fetch the data from Swarming
551 var logDogStreamAddr *types.StreamAddr 551 var logDogStreamAddr *types.StreamAddr
552 552
553 fetchParams := swarmingFetchParams{ 553 fetchParams := swarmingFetchParams{
554 fetchRes: true, 554 fetchRes: true,
555 fetchLog: true, 555 fetchLog: true,
556 556
557 // Cancel if LogDog annotation stream parameters are present in the tag set. 557 // Cancel if LogDog annotation stream parameters are present in the tag set.
558 taskResCallback: func(res *swarming.SwarmingRpcsTaskResult) (can celLogs bool) { 558 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 559 // 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()) 650 comp := infoComponent(model.InfraFailure, "Milo annotati on parser", err.Error())
651 comp.SubLink = append(comp.SubLink, resp.LinkSet{ 651 comp.SubLink = append(comp.SubLink, resp.LinkSet{
652 resp.NewLink("swarming task", taskPageURL(svc.ge tHost(), taskID)), 652 resp.NewLink("swarming task", taskPageURL(svc.ge tHost(), taskID)),
653 }) 653 })
654 build.Components = append(build.Components, comp) 654 build.Components = append(build.Components, comp)
655 } 655 }
656 656
657 if lds != nil && lds.MainStream != nil && lds.MainStream.Data != nil { 657 if lds != nil && lds.MainStream != nil && lds.MainStream.Data != nil {
658 s = lds.MainStream.Data 658 s = lds.MainStream.Data
659 } 659 }
660 » » ub = swarmingURLBuilder(linkBase) 660 » » ub = swarmingURLBuilder(taskID)
661 661
662 default: 662 default:
663 s = &miloProto.Step{} 663 s = &miloProto.Step{}
664 » » ub = swarmingURLBuilder(linkBase) 664 » » ub = swarmingURLBuilder(taskID)
665 } 665 }
666 666
667 if s != nil { 667 if s != nil {
668 if err := addTaskToMiloStep(c, svc.getHost(), fr.res, s); err != nil { 668 if err := addTaskToMiloStep(c, svc.getHost(), fr.res, s); err != nil {
669 return nil, err 669 return nil, err
670 } 670 }
671 rawpresentation.AddLogDogToBuild(c, ub, s, &build) 671 rawpresentation.AddLogDogToBuild(c, ub, s, &build)
672 } 672 }
673 673
674 if err := addTaskToBuild(c, svc.getHost(), fr.res, &build); err != nil { 674 if err := addTaskToBuild(c, svc.getHost(), fr.res, &build); err != nil {
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
720 func taskPageURL(swarmingHostname, taskID string) string { 720 func taskPageURL(swarmingHostname, taskID string) string {
721 return fmt.Sprintf("https://%s/task?id=%s&show_raw=1&wide_logs=true", sw armingHostname, taskID) 721 return fmt.Sprintf("https://%s/task?id=%s&show_raw=1&wide_logs=true", sw armingHostname, taskID)
722 } 722 }
723 723
724 // botPageURL returns a URL to a human-consumable page of a swarming bot. 724 // botPageURL returns a URL to a human-consumable page of a swarming bot.
725 // Supports server aliases. 725 // Supports server aliases.
726 func botPageURL(swarmingHostname, botID string) string { 726 func botPageURL(swarmingHostname, botID string) string {
727 return fmt.Sprintf("https://%s/restricted/bot/%s", swarmingHostname, bot ID) 727 return fmt.Sprintf("https://%s/restricted/bot/%s", swarmingHostname, bot ID)
728 } 728 }
729 729
730 // URLBase is the routing prefix for swarming endpoints. It's here so that it
731 // can be a constant between the swarmingURLBuilder and the frontend.
732 const URLBase = "/swarming/task"
733
730 // swarmingURLBuilder is a logdog.URLBuilder that builds Milo swarming log 734 // swarmingURLBuilder is a logdog.URLBuilder that builds Milo swarming log
731 // links. 735 // links.
732 // 736 //
733 // The string value for this should be the "linkBase" parameter value supplied 737 // It should be the swarming task id.
734 // to swarmingBuildImpl.
735 type swarmingURLBuilder string 738 type swarmingURLBuilder string
736 739
737 func (b swarmingURLBuilder) BuildLink(l *miloProto.Link) *resp.Link { 740 func (b swarmingURLBuilder) BuildLink(l *miloProto.Link) *resp.Link {
738 u, err := url.Parse(string(b))
739 if err != nil {
740 return nil
741 }
742
743 switch t := l.Value.(type) { 741 switch t := l.Value.(type) {
744 case *miloProto.Link_LogdogStream: 742 case *miloProto.Link_LogdogStream:
745 ls := t.LogdogStream 743 ls := t.LogdogStream
746 744
747 » » if u.Path == "" { 745 » » link := resp.NewLink(l.Label, fmt.Sprintf("%s/%s/%s", URLBase, b , 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())
753 if link.Label == "" { 746 if link.Label == "" {
754 link.Label = ls.Name 747 link.Label = ls.Name
755 } 748 }
756 return link 749 return link
757 750
758 case *miloProto.Link_Url: 751 case *miloProto.Link_Url:
759 return resp.NewLink(l.Label, t.Url) 752 return resp.NewLink(l.Label, t.Url)
760 753
761 default: 754 default:
762 return nil 755 return nil
763 } 756 }
764 } 757 }
765 758
766 func swarmingTags(v []string) map[string]string { 759 func swarmingTags(v []string) map[string]string {
767 res := make(map[string]string, len(v)) 760 res := make(map[string]string, len(v))
768 for _, tag := range v { 761 for _, tag := range v {
769 var value string 762 var value string
770 parts := strings.SplitN(tag, ":", 2) 763 parts := strings.SplitN(tag, ":", 2)
771 if len(parts) == 2 { 764 if len(parts) == 2 {
772 value = parts[1] 765 value = parts[1]
773 } 766 }
774 res[parts[0]] = value 767 res[parts[0]] = value
775 } 768 }
776 return res 769 return res
777 } 770 }
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