mirror of
https://github.com/openshift/source-to-image.git
synced 2026-02-05 12:44:54 +01:00
updating build timing types to fall in line with the ones in origin
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -239,7 +239,7 @@ func TestLayeredBuild(t *testing.T) {
|
||||
},
|
||||
BuildResult: &api.Result{
|
||||
BuildInfo: api.BuildInfo{
|
||||
Stages: api.Stages{},
|
||||
Stages: []api.StageInfo{},
|
||||
},
|
||||
},
|
||||
ExecuteError: errMissingRequirements,
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user