From 56bd55d733dc0c83abd72fa2b4166a0f9ca64cbe Mon Sep 17 00:00:00 2001 From: Corey Daley Date: Wed, 22 Mar 2017 15:22:27 -0400 Subject: [PATCH] updating build timing types to fall in line with the ones in origin --- pkg/api/helpers.go | 26 +++++++++++++------------- pkg/api/types.go | 26 ++++++++++---------------- pkg/build/strategies/sti/sti_test.go | 2 +- pkg/util/status/build_status_test.go | 13 ++++++++----- 4 files changed, 32 insertions(+), 35 deletions(-) diff --git a/pkg/api/helpers.go b/pkg/api/helpers.go index b70a975bd..eb7a06cb0 100644 --- a/pkg/api/helpers.go +++ b/pkg/api/helpers.go @@ -3,7 +3,7 @@ package api import "time" // RecordStageAndStepInfo records details about each build stage and step -func RecordStageAndStepInfo(stages Stages, stageName StageName, stepName StepName, startTime time.Time, endTime time.Time) Stages { +func RecordStageAndStepInfo(stages []StageInfo, stageName StageName, stepName StepName, startTime time.Time, endTime time.Time) []StageInfo { // Make sure that the stages slice is initialized if len(stages) == 0 { stages = make([]StageInfo, 0) @@ -11,15 +11,15 @@ func RecordStageAndStepInfo(stages Stages, stageName StageName, stepName StepNam // If the stage already exists update the endTime and Duration, and append the new step. for stageKey, stageVal := range stages { - if stageVal.StageName == stageName { - stages[stageKey].Duration = endTime.Sub(stages[stageKey].StartTime) + if stageVal.Name == stageName { + stages[stageKey].DurationMilliseconds = endTime.Sub(stages[stageKey].StartTime).Nanoseconds() / int64(time.Millisecond) if len(stages[stageKey].Steps) == 0 { stages[stageKey].Steps = make([]StepInfo, 0) } stages[stageKey].Steps = append(stages[stageKey].Steps, StepInfo{ - StepName: stepName, - StartTime: startTime, - Duration: endTime.Sub(startTime), + Name: stepName, + StartTime: startTime, + DurationMilliseconds: endTime.Sub(startTime).Nanoseconds() / int64(time.Millisecond), }) return stages } @@ -28,15 +28,15 @@ func RecordStageAndStepInfo(stages Stages, stageName StageName, stepName StepNam // If the stageName does not exist, add it to the slice along with the new step. steps := make([]StepInfo, 0) steps = append(steps, StepInfo{ - StepName: stepName, - StartTime: startTime, - Duration: endTime.Sub(startTime), + Name: stepName, + StartTime: startTime, + DurationMilliseconds: endTime.Sub(startTime).Nanoseconds() / int64(time.Millisecond), }) stages = append(stages, StageInfo{ - StageName: stageName, - StartTime: startTime, - Duration: endTime.Sub(startTime), - Steps: steps, + Name: stageName, + StartTime: startTime, + DurationMilliseconds: endTime.Sub(startTime).Nanoseconds() / int64(time.Millisecond), + Steps: steps, }) return stages } diff --git a/pkg/api/types.go b/pkg/api/types.go index a5531abde..da2e1bdbe 100644 --- a/pkg/api/types.go +++ b/pkg/api/types.go @@ -345,7 +345,7 @@ type Result struct { // BuildInfo contains information about the build process. type BuildInfo struct { // Stages contains details about each build stage. - Stages Stages + Stages []StageInfo // FailureReason is a camel case reason that is used by the machine to reply // back to the OpenShift builder with information why any of the steps in the @@ -353,22 +353,19 @@ type BuildInfo struct { FailureReason FailureReason } -// Stages is a slice of build stages that have been recorded. -type Stages []StageInfo - // StageInfo contains details about a build stage. type StageInfo struct { - // StageName is the identifier for each build stage. - StageName StageName + // Name is the identifier for each build stage. + Name StageName // StartTime identifies when this stage started. StartTime time.Time - // Duration identifies how long this stage ran. - Duration time.Duration + // DurationMilliseconds identifies how long this stage ran. + DurationMilliseconds int64 // Steps contains details about each build step within a build stage. - Steps Steps + Steps []StepInfo } // StageName is the identifier for each build stage. @@ -392,19 +389,16 @@ const ( StageRetrieve StageName = "RetrieveArtifacts" ) -// Steps is a slice of build steps that have been recorded within each build stage. -type Steps []StepInfo - // StepInfo contains details about a build step. type StepInfo struct { - // StepName is the identifier for each build step. - StepName StepName + // Name is the identifier for each build step. + Name StepName // StartTime identifies when this step started. StartTime time.Time - // Duration identifies how long this step ran. - Duration time.Duration + // DurationMilliseconds identifies how long this step ran. + DurationMilliseconds int64 } // StepName is the identifier for each build step. diff --git a/pkg/build/strategies/sti/sti_test.go b/pkg/build/strategies/sti/sti_test.go index 9d549e7fa..313aedf0f 100644 --- a/pkg/build/strategies/sti/sti_test.go +++ b/pkg/build/strategies/sti/sti_test.go @@ -239,7 +239,7 @@ func TestLayeredBuild(t *testing.T) { }, BuildResult: &api.Result{ BuildInfo: api.BuildInfo{ - Stages: api.Stages{}, + Stages: []api.StageInfo{}, }, }, ExecuteError: errMissingRequirements, diff --git a/pkg/util/status/build_status_test.go b/pkg/util/status/build_status_test.go index e0b6095a5..5de3848f6 100644 --- a/pkg/util/status/build_status_test.go +++ b/pkg/util/status/build_status_test.go @@ -60,15 +60,18 @@ func TestAddNewStepToStage(t *testing.T) { func TestUpdateStageDuration(t *testing.T) { buildInfo := new(api.BuildInfo) - buildInfo.Stages = api.RecordStageAndStepInfo(buildInfo.Stages, api.StagePullImages, api.StepPullPreviousImage, time.Now(), time.Now()) - duration := buildInfo.Stages[0].Duration + startTime := time.Now() + + buildInfo.Stages = api.RecordStageAndStepInfo(buildInfo.Stages, api.StagePullImages, api.StepPullPreviousImage, startTime, time.Now()) addDuration, _ := time.ParseDuration("5m") - buildInfo.Stages = api.RecordStageAndStepInfo(buildInfo.Stages, api.StagePullImages, api.StepPullBuilderImage, time.Now(), time.Now().Add(addDuration)) + endTime := time.Now().Add(addDuration) - if !(buildInfo.Stages[0].Duration > duration) { - t.Errorf("Stage Duration was not updated, expected %#v, got %#v", buildInfo.Stages[0].StartTime.Add(duration), buildInfo.Stages[0].Duration) + buildInfo.Stages = api.RecordStageAndStepInfo(buildInfo.Stages, api.StagePullImages, api.StepPullBuilderImage, time.Now(), endTime) + + if buildInfo.Stages[0].DurationMilliseconds != (endTime.Sub(startTime).Nanoseconds() / int64(time.Millisecond)) { + t.Errorf("Stage Duration was not updated, expected %#v, got %#v", (endTime.Sub(startTime).Nanoseconds() / int64(time.Millisecond)), buildInfo.Stages[0].DurationMilliseconds) } }