| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package logdog | 5 package logdog |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "fmt" | 8 "fmt" |
| 9 "strings" | 9 "strings" |
| 10 "time" | 10 "time" |
| 11 | 11 |
| 12 "github.com/luci/luci-go/appengine/cmd/milo/resp" | 12 "github.com/luci/luci-go/appengine/cmd/milo/resp" |
| 13 "github.com/luci/luci-go/common/clock" |
| 13 "github.com/luci/luci-go/common/logdog/types" | 14 "github.com/luci/luci-go/common/logdog/types" |
| 14 "github.com/luci/luci-go/common/logging" | 15 "github.com/luci/luci-go/common/logging" |
| 15 miloProto "github.com/luci/luci-go/common/proto/milo" | 16 miloProto "github.com/luci/luci-go/common/proto/milo" |
| 16 "golang.org/x/net/context" | 17 "golang.org/x/net/context" |
| 17 ) | 18 ) |
| 18 | 19 |
| 19 // Given a logdog/milo step, translate it to a BuildComponent struct. | 20 // Given a logdog/milo step, translate it to a BuildComponent struct. |
| 20 func miloBuildStep( | 21 func miloBuildStep(c context.Context, url string, anno *miloProto.Step, name str
ing) *resp.BuildComponent { |
| 21 » c context.Context, url string, anno *miloProto.Step, name string) *resp.
BuildComponent { | |
| 22 » comp := &resp.BuildComponent{} | |
| 23 asc := anno.GetStepComponent() | 22 asc := anno.GetStepComponent() |
| 24 » comp.Label = asc.Name | 23 » comp := &resp.BuildComponent{Label: asc.Name} |
| 25 switch asc.Status { | 24 switch asc.Status { |
| 26 case miloProto.Status_RUNNING: | 25 case miloProto.Status_RUNNING: |
| 27 comp.Status = resp.Running | 26 comp.Status = resp.Running |
| 28 | 27 |
| 29 case miloProto.Status_SUCCESS: | 28 case miloProto.Status_SUCCESS: |
| 30 comp.Status = resp.Success | 29 comp.Status = resp.Success |
| 31 | 30 |
| 32 case miloProto.Status_FAILURE: | 31 case miloProto.Status_FAILURE: |
| 33 if anno.GetFailureDetails() != nil { | 32 if anno.GetFailureDetails() != nil { |
| 34 switch anno.GetFailureDetails().Type { | 33 switch anno.GetFailureDetails().Type { |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 URL: strings.Join([]string{url, name, "stdout"}, "/"), | 77 URL: strings.Join([]string{url, name, "stdout"}, "/"), |
| 79 } | 78 } |
| 80 | 79 |
| 81 // This should always be a step. | 80 // This should always be a step. |
| 82 comp.Type = resp.Step | 81 comp.Type = resp.Step |
| 83 | 82 |
| 84 // This should always be 0 | 83 // This should always be 0 |
| 85 comp.LevelsDeep = 0 | 84 comp.LevelsDeep = 0 |
| 86 | 85 |
| 87 // Timestamps | 86 // Timestamps |
| 88 » comp.Started = asc.Started.Time().Format(time.RFC3339) | 87 » started := asc.Started.Time() |
| 88 » ended := asc.Ended.Time() |
| 89 » if !started.IsZero() { |
| 90 » » comp.Started = started.Format(time.RFC3339) |
| 91 » } |
| 92 » if !ended.IsZero() { |
| 93 » » comp.Finished = ended.Format(time.RFC3339) |
| 94 » } |
| 95 |
| 96 » till := ended |
| 97 » if asc.Status == miloProto.Status_RUNNING { |
| 98 » » till = clock.Now(c) |
| 99 » } |
| 100 » if !started.IsZero() && !till.IsZero() { |
| 101 » » comp.Duration = uint64((till.Sub(started)) / time.Second) |
| 102 » } |
| 89 | 103 |
| 90 // This should be the exact same thing. | 104 // This should be the exact same thing. |
| 91 comp.Text = asc.Text | 105 comp.Text = asc.Text |
| 92 | 106 |
| 93 return comp | 107 return comp |
| 94 } | 108 } |
| 95 | 109 |
| 96 // AddLogDogToBuild takes a set of logdog streams and populate a milo build. | 110 // AddLogDogToBuild takes a set of logdog streams and populate a milo build. |
| 97 func AddLogDogToBuild( | 111 func AddLogDogToBuild(c context.Context, url string, s *Streams, build *resp.Mil
oBuild) { |
| 98 » c context.Context, url string, s *Streams, | |
| 99 » build *resp.MiloBuild) { | |
| 100 if s.MainStream == nil { | 112 if s.MainStream == nil { |
| 101 » » panic("Missing main stream") | 113 » » panic("missing main stream") |
| 102 } | 114 } |
| 103 // Now Fetch the main annotation of the build. | 115 // Now Fetch the main annotation of the build. |
| 104 mainAnno := s.MainStream.Data | 116 mainAnno := s.MainStream.Data |
| 105 | 117 |
| 106 // Now fill in each of the step components. | 118 // Now fill in each of the step components. |
| 107 // TODO(hinoka): This is totes cachable. | 119 // TODO(hinoka): This is totes cachable. |
| 108 for _, name := range mainAnno.SubstepLogdogNameBase { | 120 for _, name := range mainAnno.SubstepLogdogNameBase { |
| 109 fullname := strings.Join([]string{name, "annotations"}, "/") | 121 fullname := strings.Join([]string{name, "annotations"}, "/") |
| 110 anno, ok := s.Streams[fullname] | 122 anno, ok := s.Streams[fullname] |
| 111 if !ok { | 123 if !ok { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 130 for _, prop := range mainAnno.GetStepComponent().Property { | 142 for _, prop := range mainAnno.GetStepComponent().Property { |
| 131 propGroup.Property = append(propGroup.Property, &resp.Property{ | 143 propGroup.Property = append(propGroup.Property, &resp.Property{ |
| 132 Key: prop.Name, | 144 Key: prop.Name, |
| 133 Value: prop.Value, | 145 Value: prop.Value, |
| 134 }) | 146 }) |
| 135 } | 147 } |
| 136 build.PropertyGroup = append(build.PropertyGroup, propGroup) | 148 build.PropertyGroup = append(build.PropertyGroup, propGroup) |
| 137 | 149 |
| 138 return | 150 return |
| 139 } | 151 } |
| OLD | NEW |