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

Unified 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: simplify step duration computation 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | appengine/cmd/milo/swarming/build.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: appengine/cmd/milo/logdog/logDogBuild.go
diff --git a/appengine/cmd/milo/logdog/logDogBuild.go b/appengine/cmd/milo/logdog/logDogBuild.go
index 9302f72bbb1dc8c4d6fae93eaa2e17d2551376c7..4944fa2b303586433f356b39f4f1a433b65b1eaa 100644
--- a/appengine/cmd/milo/logdog/logDogBuild.go
+++ b/appengine/cmd/milo/logdog/logDogBuild.go
@@ -10,6 +10,7 @@ import (
"time"
"github.com/luci/luci-go/appengine/cmd/milo/resp"
+ "github.com/luci/luci-go/common/clock"
"github.com/luci/luci-go/common/logdog/types"
"github.com/luci/luci-go/common/logging"
miloProto "github.com/luci/luci-go/common/proto/milo"
@@ -17,11 +18,9 @@ import (
)
// Given a logdog/milo step, translate it to a BuildComponent struct.
-func miloBuildStep(
- c context.Context, url string, anno *miloProto.Step, name string) *resp.BuildComponent {
- comp := &resp.BuildComponent{}
+func miloBuildStep(c context.Context, url string, anno *miloProto.Step, name string) *resp.BuildComponent {
asc := anno.GetStepComponent()
- comp.Label = asc.Name
+ comp := &resp.BuildComponent{Label: asc.Name}
switch asc.Status {
case miloProto.Status_RUNNING:
comp.Status = resp.Running
@@ -85,7 +84,22 @@ func miloBuildStep(
comp.LevelsDeep = 0
// Timestamps
- comp.Started = asc.Started.Time().Format(time.RFC3339)
+ started := asc.Started.Time()
+ ended := asc.Ended.Time()
+ if !started.IsZero() {
+ comp.Started = started.Format(time.RFC3339)
+ }
+ if !ended.IsZero() {
+ comp.Finished = ended.Format(time.RFC3339)
+ }
+
+ till := ended
+ if asc.Status == miloProto.Status_RUNNING {
+ till = clock.Now(c)
+ }
+ if !started.IsZero() && !till.IsZero() {
+ comp.Duration = uint64((till.Sub(started)) / time.Second)
+ }
// This should be the exact same thing.
comp.Text = asc.Text
@@ -94,11 +108,9 @@ func miloBuildStep(
}
// AddLogDogToBuild takes a set of logdog streams and populate a milo build.
-func AddLogDogToBuild(
- c context.Context, url string, s *Streams,
- build *resp.MiloBuild) {
+func AddLogDogToBuild(c context.Context, url string, s *Streams, build *resp.MiloBuild) {
if s.MainStream == nil {
- panic("Missing main stream")
+ panic("missing main stream")
}
// Now Fetch the main annotation of the build.
mainAnno := s.MainStream.Data
« 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