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

Side by Side Diff: appengine/cmd/milo/logdog/logDogBuild.go

Issue 2069283002: milo: fix step duration (Closed) Base URL: https://chromium.googlesource.com/external/github.com/luci/luci-go@master
Patch Set: gofmt Created 4 years, 6 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 | appengine/cmd/milo/swarming/build.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 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
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 » comp.Started = started.Format(time.RFC3339)
90 » comp.Finished = ended.Format(time.RFC3339)
estaab 2016/06/16 00:48:53 if you add if asc.Status == miloProto.Status_RUNN
nodir 2016/06/16 17:14:55 Done.
91 » if !started.IsZero() && (!ended.IsZero() || asc.Status == miloProto.Stat us_RUNNING) {
92 » » till := ended
93 » » if till.IsZero() {
94 » » » till = clock.Now(c)
95 » » }
96 » » comp.Duration = uint64((till.Sub(started)) / time.Second)
97 » }
89 98
90 // This should be the exact same thing. 99 // This should be the exact same thing.
91 comp.Text = asc.Text 100 comp.Text = asc.Text
92 101
93 return comp 102 return comp
94 } 103 }
95 104
96 // AddLogDogToBuild takes a set of logdog streams and populate a milo build. 105 // AddLogDogToBuild takes a set of logdog streams and populate a milo build.
97 func AddLogDogToBuild( 106 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 { 107 if s.MainStream == nil {
101 » » panic("Missing main stream") 108 » » panic("missing main stream")
102 } 109 }
103 // Now Fetch the main annotation of the build. 110 // Now Fetch the main annotation of the build.
104 mainAnno := s.MainStream.Data 111 mainAnno := s.MainStream.Data
105 112
106 // Now fill in each of the step components. 113 // Now fill in each of the step components.
107 // TODO(hinoka): This is totes cachable. 114 // TODO(hinoka): This is totes cachable.
108 for _, name := range mainAnno.SubstepLogdogNameBase { 115 for _, name := range mainAnno.SubstepLogdogNameBase {
109 fullname := strings.Join([]string{name, "annotations"}, "/") 116 fullname := strings.Join([]string{name, "annotations"}, "/")
110 anno, ok := s.Streams[fullname] 117 anno, ok := s.Streams[fullname]
111 if !ok { 118 if !ok {
(...skipping 18 matching lines...) Expand all
130 for _, prop := range mainAnno.GetStepComponent().Property { 137 for _, prop := range mainAnno.GetStepComponent().Property {
131 propGroup.Property = append(propGroup.Property, &resp.Property{ 138 propGroup.Property = append(propGroup.Property, &resp.Property{
132 Key: prop.Name, 139 Key: prop.Name,
133 Value: prop.Value, 140 Value: prop.Value,
134 }) 141 })
135 } 142 }
136 build.PropertyGroup = append(build.PropertyGroup, propGroup) 143 build.PropertyGroup = append(build.PropertyGroup, propGroup)
137 144
138 return 145 return
139 } 146 }
OLDNEW
« no previous file with comments | « no previous file | appengine/cmd/milo/swarming/build.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698