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

Side by Side Diff: milo/appengine/buildbot/build.go

Issue 2778693005: Milo: Use LogDog URLs in top-level "Logs" field. (Closed)
Patch Set: comments Created 3 years, 8 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 | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The LUCI Authors. All rights reserved. 1 // Copyright 2016 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 buildbot 5 package buildbot
6 6
7 import ( 7 import (
8 "encoding/json" 8 "encoding/json"
9 "errors" 9 "errors"
10 "fmt" 10 "fmt"
(...skipping 497 matching lines...) Expand 10 before | Expand all | Expand 10 after
508 508
509 // updatePostProcessBuild transforms a build from its raw JSON format into the 509 // updatePostProcessBuild transforms a build from its raw JSON format into the
510 // format that should be presented to users. 510 // format that should be presented to users.
511 // 511 //
512 // Post-processing includes: 512 // Post-processing includes:
513 // - If the build is LogDog-only, promotes aliases (LogDog links) to 513 // - If the build is LogDog-only, promotes aliases (LogDog links) to
514 // first-class links in the build. 514 // first-class links in the build.
515 func updatePostProcessBuild(b *buildbotBuild) { 515 func updatePostProcessBuild(b *buildbotBuild) {
516 // If this is a LogDog-only build, we want to promote the LogDog links. 516 // If this is a LogDog-only build, we want to promote the LogDog links.
517 if loc, ok := b.getPropertyValue("log_location").(string); ok && strings .HasPrefix(loc, "logdog://") { 517 if loc, ok := b.getPropertyValue("log_location").(string); ok && strings .HasPrefix(loc, "logdog://") {
518 linkMap := map[string]string{}
518 for sidx := range b.Steps { 519 for sidx := range b.Steps {
519 » » » promoteLogDogLinks(&b.Steps[sidx], sidx == 0) 520 » » » promoteLogDogLinks(&b.Steps[sidx], sidx == 0, linkMap)
521 » » }
522
523 » » // Update "Logs". This field is part of BuildBot, and is the ama lgamation
524 » » // of all logs in the build's steps. Since each log is out of co ntext of its
525 » » // original step, we can't apply the promotion logic; instead, w e will use
526 » » // the link map to map any old URLs that were matched in "promot eLogDogLnks"
527 » » // to their new URLs.
528 » » for _, link := range b.Logs {
529 » » » // "link" is in the form: [NAME, URL]
530 » » » if len(link) != 2 {
531 » » » » continue
532 » » » }
533
534 » » » if newURL, ok := linkMap[link[1]]; ok {
535 » » » » link[1] = newURL
536 » » » }
520 } 537 }
521 } 538 }
522 } 539 }
523 540
524 // promoteLogDogLinks updates the links in a BuildBot step to 541 // promoteLogDogLinks updates the links in a BuildBot step to
525 // promote LogDog links. 542 // promote LogDog links.
526 // 543 //
527 // A build's links come in one of three forms: 544 // A build's links come in one of three forms:
528 // - Log Links, which link directly to BuildBot build logs. 545 // - Log Links, which link directly to BuildBot build logs.
529 // - URL Links, which are named links to arbitrary URLs. 546 // - URL Links, which are named links to arbitrary URLs.
530 // - Aliases, which attach to the label in one of the other types of links and 547 // - Aliases, which attach to the label in one of the other types of links and
531 // augment it with additional named links. 548 // augment it with additional named links.
532 // 549 //
533 // LogDog uses aliases exclusively to attach LogDog logs to other links. When 550 // LogDog uses aliases exclusively to attach LogDog logs to other links. When
534 // the build is LogDog-only, though, the original links are actually junk. What 551 // the build is LogDog-only, though, the original links are actually junk. What
535 // we want to do is remove the original junk links and replace them with their 552 // we want to do is remove the original junk links and replace them with their
536 // alias counterparts, so that the "natural" BuildBot links are actually LogDog 553 // alias counterparts, so that the "natural" BuildBot links are actually LogDog
537 // links. 554 // links.
538 func promoteLogDogLinks(s *buildbotStep, isInitialStep bool) { 555 //
556 // As URLs are re-mapped, the supplied "linkMap" will be updated to map the old
557 // URLs to the new ones.
558 func promoteLogDogLinks(s *buildbotStep, isInitialStep bool, linkMap map[string] string) {
539 type stepLog struct { 559 type stepLog struct {
540 label string 560 label string
541 url string 561 url string
542 } 562 }
543 563
544 remainingAliases := stringset.New(len(s.Aliases)) 564 remainingAliases := stringset.New(len(s.Aliases))
545 for linkAnchor := range s.Aliases { 565 for linkAnchor := range s.Aliases {
546 remainingAliases.Add(linkAnchor) 566 remainingAliases.Add(linkAnchor)
547 } 567 }
548 568
(...skipping 24 matching lines...) Expand all
573 // Any link named "logdog" (Annotee cosmetic implementat ion detail) will 593 // Any link named "logdog" (Annotee cosmetic implementat ion detail) will
574 // inherit the name of the original log. 594 // inherit the name of the original log.
575 if !isLog { 595 if !isLog {
576 if aliasStepLog.label == "logdog" { 596 if aliasStepLog.label == "logdog" {
577 aliasStepLog.label = sl.label 597 aliasStepLog.label = sl.label
578 } 598 }
579 } 599 }
580 600
581 result[i] = &aliasStepLog 601 result[i] = &aliasStepLog
582 } 602 }
603
604 // If we performed mapping, add the OLD -> NEW URL mapping to li nkMap.
605 //
606 // Since multpiple aliases can apply to a single log, and we hav e to pick
607 // one, here, we'll arbitrarily pick the last one. This is maybe more
608 // consistent than the first one because linkMap, itself, will e nd up
609 // holding the last mapping for any given URL.
610 if len(result) > 0 {
611 linkMap[sl.url] = result[len(result)-1].url
612 }
613
583 return result 614 return result
584 } 615 }
585 616
586 // Update step logs. 617 // Update step logs.
587 newLogs := make([][]string, 0, len(s.Logs)) 618 newLogs := make([][]string, 0, len(s.Logs))
588 for _, l := range s.Logs { 619 for _, l := range s.Logs {
589 for _, res := range maybePromoteAliases(&stepLog{l[0], l[1]}, tr ue) { 620 for _, res := range maybePromoteAliases(&stepLog{l[0], l[1]}, tr ue) {
590 newLogs = append(newLogs, []string{res.label, res.url}) 621 newLogs = append(newLogs, []string{res.label, res.url})
591 } 622 }
592 } 623 }
(...skipping 20 matching lines...) Expand all
613 var newAliases map[string][]*buildbotLinkAlias 644 var newAliases map[string][]*buildbotLinkAlias
614 if l := remainingAliases.Len(); l > 0 { 645 if l := remainingAliases.Len(); l > 0 {
615 newAliases = make(map[string][]*buildbotLinkAlias, l) 646 newAliases = make(map[string][]*buildbotLinkAlias, l)
616 remainingAliases.Iter(func(v string) bool { 647 remainingAliases.Iter(func(v string) bool {
617 newAliases[v] = s.Aliases[v] 648 newAliases[v] = s.Aliases[v]
618 return true 649 return true
619 }) 650 })
620 } 651 }
621 s.Aliases = newAliases 652 s.Aliases = newAliases
622 } 653 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698