| OLD | NEW |
| 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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 case 4: | 60 case 4: |
| 61 status = resp.InfraFailure // Exception | 61 status = resp.InfraFailure // Exception |
| 62 case 5: | 62 case 5: |
| 63 status = resp.WaitingDependency // Retry | 63 status = resp.WaitingDependency // Retry |
| 64 default: | 64 default: |
| 65 panic(fmt.Errorf("Unknown status %d", s)) | 65 panic(fmt.Errorf("Unknown status %d", s)) |
| 66 } | 66 } |
| 67 return | 67 return |
| 68 } | 68 } |
| 69 | 69 |
| 70 // parseTimes translates a buildbot time tuple (start/end) into a triplet | 70 // buildbotTimeToTime converts a buildbot time representation (pointer to float |
| 71 // of seconds since epoch) to a native time.Time object. |
| 72 func buildbotTimeToTime(t *float64) (result time.Time) { |
| 73 » if t != nil { |
| 74 » » result = time.Unix(int64(*t), int64(*t*1e9)%1e9).UTC() |
| 75 » } |
| 76 » return |
| 77 } |
| 78 |
| 79 // parseTimes translates a buildbot time tuple (start, end) into a triplet |
| 71 // of (Started time, Ending time, duration). | 80 // of (Started time, Ending time, duration). |
| 72 func parseTimes(times []*float64) (started, ended time.Time, duration time.Durat
ion) { | 81 // If times[1] is nil and buildFinished is not, ended will be set to buildFinish
ed |
| 82 // time. |
| 83 func parseTimes(buildFinished *float64, times []*float64) (started, ended time.T
ime, duration time.Duration) { |
| 73 if len(times) != 2 { | 84 if len(times) != 2 { |
| 74 panic(fmt.Errorf("Expected 2 floats for times, got %v", times)) | 85 panic(fmt.Errorf("Expected 2 floats for times, got %v", times)) |
| 75 } | 86 } |
| 76 if times[0] == nil { | 87 if times[0] == nil { |
| 77 // Some steps don't have timing info. In that case, just return
nils. | 88 // Some steps don't have timing info. In that case, just return
nils. |
| 78 return | 89 return |
| 79 } | 90 } |
| 80 » started = time.Unix(int64(*times[0]), int64(*times[0]*1e9)%1e9).UTC() | 91 » started = buildbotTimeToTime(times[0]) |
| 81 » if times[1] != nil { | 92 » switch { |
| 82 » » ended = time.Unix(int64(*times[1]), int64(*times[1]*1e9)%1e9).UT
C() | 93 » case times[1] != nil: |
| 94 » » ended = buildbotTimeToTime(times[1]) |
| 83 duration = ended.Sub(started) | 95 duration = ended.Sub(started) |
| 84 » } else { | 96 » case buildFinished != nil: |
| 97 » » ended = buildbotTimeToTime(buildFinished) |
| 98 » » duration = ended.Sub(started) |
| 99 » default: |
| 85 duration = time.Since(started) | 100 duration = time.Since(started) |
| 86 } | 101 } |
| 87 return | 102 return |
| 88 } | 103 } |
| 89 | 104 |
| 90 // getBanner parses the OS information from the build and maybe returns a banner
. | 105 // getBanner parses the OS information from the build and maybe returns a banner
. |
| 91 func getBanner(c context.Context, b *buildbotBuild) *resp.LogoBanner { | 106 func getBanner(c context.Context, b *buildbotBuild) *resp.LogoBanner { |
| 92 logging.Infof(c, "OS: %s/%s", b.OSFamily, b.OSVersion) | 107 logging.Infof(c, "OS: %s/%s", b.OSFamily, b.OSVersion) |
| 93 osLogo := func() *resp.Logo { | 108 osLogo := func() *resp.Logo { |
| 94 result := &resp.Logo{} | 109 result := &resp.Logo{} |
| (...skipping 25 matching lines...) Expand all Loading... |
| 120 // TODO(hinoka): use b.toStatus() | 135 // TODO(hinoka): use b.toStatus() |
| 121 // Status | 136 // Status |
| 122 var status resp.Status | 137 var status resp.Status |
| 123 if b.Currentstep != nil { | 138 if b.Currentstep != nil { |
| 124 status = resp.Running | 139 status = resp.Running |
| 125 } else { | 140 } else { |
| 126 status = result2Status(b.Results) | 141 status = result2Status(b.Results) |
| 127 } | 142 } |
| 128 | 143 |
| 129 // Timing info | 144 // Timing info |
| 130 » started, ended, duration := parseTimes(b.Times) | 145 » started, ended, duration := parseTimes(nil, b.Times) |
| 131 | 146 |
| 132 // Link to bot and original build. | 147 // Link to bot and original build. |
| 133 server := "build.chromium.org/p" | 148 server := "build.chromium.org/p" |
| 134 if b.Internal { | 149 if b.Internal { |
| 135 server = "uberchromegw.corp.google.com/i" | 150 server = "uberchromegw.corp.google.com/i" |
| 136 } | 151 } |
| 137 bot := &resp.Link{ | 152 bot := &resp.Link{ |
| 138 Label: b.Slave, | 153 Label: b.Slave, |
| 139 URL: fmt.Sprintf("https://%s/%s/buildslaves/%s", server, b.Mas
ter, b.Slave), | 154 URL: fmt.Sprintf("https://%s/%s/buildslaves/%s", server, b.Mas
ter, b.Slave), |
| 140 } | 155 } |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 } | 190 } |
| 176 | 191 |
| 177 return sum | 192 return sum |
| 178 } | 193 } |
| 179 | 194 |
| 180 var rLineBreak = regexp.MustCompile("<br */?>") | 195 var rLineBreak = regexp.MustCompile("<br */?>") |
| 181 | 196 |
| 182 // components takes a full buildbot build struct and extract step info from all | 197 // components takes a full buildbot build struct and extract step info from all |
| 183 // of the steps and returns it as a list of milo Build Components. | 198 // of the steps and returns it as a list of milo Build Components. |
| 184 func components(b *buildbotBuild) (result []*resp.BuildComponent) { | 199 func components(b *buildbotBuild) (result []*resp.BuildComponent) { |
| 200 endingTime := b.Times[1] |
| 185 for _, step := range b.Steps { | 201 for _, step := range b.Steps { |
| 186 if step.Hidden == true { | 202 if step.Hidden == true { |
| 187 continue | 203 continue |
| 188 } | 204 } |
| 189 bc := &resp.BuildComponent{ | 205 bc := &resp.BuildComponent{ |
| 190 Label: step.Name, | 206 Label: step.Name, |
| 191 } | 207 } |
| 192 // Step text sometimes contains <br>, which we want to parse int
o new lines. | 208 // Step text sometimes contains <br>, which we want to parse int
o new lines. |
| 193 for _, t := range step.Text { | 209 for _, t := range step.Text { |
| 194 for _, line := range rLineBreak.Split(t, -1) { | 210 for _, line := range rLineBreak.Split(t, -1) { |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 284 baseLink = append(baseLink, aliasLink) | 300 baseLink = append(baseLink, aliasLink) |
| 285 } | 301 } |
| 286 | 302 |
| 287 if len(baseLink) > 0 { | 303 if len(baseLink) > 0 { |
| 288 bc.SubLink = append(bc.SubLink, baseLink
) | 304 bc.SubLink = append(bc.SubLink, baseLink
) |
| 289 } | 305 } |
| 290 } | 306 } |
| 291 } | 307 } |
| 292 | 308 |
| 293 // Figure out the times. | 309 // Figure out the times. |
| 294 » » bc.Started, bc.Finished, bc.Duration = parseTimes(step.Times) | 310 » » bc.Started, bc.Finished, bc.Duration = parseTimes(endingTime, st
ep.Times) |
| 295 | 311 |
| 296 result = append(result, bc) | 312 result = append(result, bc) |
| 297 } | 313 } |
| 298 return | 314 return |
| 299 } | 315 } |
| 300 | 316 |
| 301 // parseProp returns a representation of v based off k, and a boolean to | 317 // parseProp returns a representation of v based off k, and a boolean to |
| 302 // specify whether or not to hide it altogether. | 318 // specify whether or not to hide it altogether. |
| 303 func parseProp(prop map[string]Prop, k string, v interface{}) (string, bool) { | 319 func parseProp(prop map[string]Prop, k string, v interface{}) (string, bool) { |
| 304 switch k { | 320 switch k { |
| (...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 644 var newAliases map[string][]*buildbotLinkAlias | 660 var newAliases map[string][]*buildbotLinkAlias |
| 645 if l := remainingAliases.Len(); l > 0 { | 661 if l := remainingAliases.Len(); l > 0 { |
| 646 newAliases = make(map[string][]*buildbotLinkAlias, l) | 662 newAliases = make(map[string][]*buildbotLinkAlias, l) |
| 647 remainingAliases.Iter(func(v string) bool { | 663 remainingAliases.Iter(func(v string) bool { |
| 648 newAliases[v] = s.Aliases[v] | 664 newAliases[v] = s.Aliases[v] |
| 649 return true | 665 return true |
| 650 }) | 666 }) |
| 651 } | 667 } |
| 652 s.Aliases = newAliases | 668 s.Aliases = newAliases |
| 653 } | 669 } |
| OLD | NEW |