Skip to content

Commit 10c7a97

Browse files
author
OpenShift Bot
authored
Merge pull request #13307 from coreydaley/add_build_substatus
Merged by openshift-bot
2 parents 33052f6 + 915246a commit 10c7a97

33 files changed

+2050
-242
lines changed

api/protobuf-spec/github_com_openshift_origin_pkg_build_api_v1.proto

+39
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/swagger-spec/oapi-v1.json

+52
Original file line numberDiff line numberDiff line change
@@ -24394,6 +24394,13 @@
2439424394
"output": {
2439524395
"$ref": "v1.BuildStatusOutput",
2439624396
"description": "output describes the Docker image the build has produced."
24397+
},
24398+
"stages": {
24399+
"type": "array",
24400+
"items": {
24401+
"$ref": "v1.StageInfo"
24402+
},
24403+
"description": "stages contains details about each stage that occurs during the build including start time, duration (in milliseconds), and the steps that occured within each stage."
2439724404
}
2439824405
}
2439924406
},
@@ -24417,6 +24424,51 @@
2441724424
}
2441824425
}
2441924426
},
24427+
"v1.StageInfo": {
24428+
"id": "v1.StageInfo",
24429+
"description": "StageInfo contains details about a build stage.",
24430+
"properties": {
24431+
"name": {
24432+
"type": "string",
24433+
"description": "name is a unique identifier for each build stage that occurs."
24434+
},
24435+
"startTime": {
24436+
"type": "string",
24437+
"description": "startTime is a timestamp representing the server time when this Stage started. It is represented in RFC3339 form and is in UTC."
24438+
},
24439+
"durationMilliseconds": {
24440+
"type": "integer",
24441+
"format": "int64",
24442+
"description": "durationMilliseconds identifies how long the stage took to complete in milliseconds. Note: the duration of a stage can exceed the sum of the duration of the steps within the stage as not all actions are accounted for in explicit build steps."
24443+
},
24444+
"steps": {
24445+
"type": "array",
24446+
"items": {
24447+
"$ref": "v1.StepInfo"
24448+
},
24449+
"description": "steps contains details about each step that occurs during a build stage including start time and duration in milliseconds."
24450+
}
24451+
}
24452+
},
24453+
"v1.StepInfo": {
24454+
"id": "v1.StepInfo",
24455+
"description": "StepInfo contains details about a build step.",
24456+
"properties": {
24457+
"name": {
24458+
"type": "string",
24459+
"description": "name is a unique identifier for each build step."
24460+
},
24461+
"startTime": {
24462+
"type": "string",
24463+
"description": "startTime is a timestamp representing the server time when this Step started. it is represented in RFC3339 form and is in UTC."
24464+
},
24465+
"durationMilliseconds": {
24466+
"type": "integer",
24467+
"format": "int64",
24468+
"description": "durationMilliseconds identifies how long the step took to complete in milliseconds."
24469+
}
24470+
}
24471+
},
2442024472
"v1.BuildLog": {
2442124473
"id": "v1.BuildLog",
2442224474
"description": "BuildLog is the (unused) resource associated with the build log redirector",

api/swagger-spec/openshift-openapi-spec.json

+50
Original file line numberDiff line numberDiff line change
@@ -68300,6 +68300,13 @@
6830068300
"description": "reason is a brief CamelCase string that describes any failure and is meant for machine parsing and tidy display in the CLI.",
6830168301
"type": "string"
6830268302
},
68303+
"stages": {
68304+
"description": "stages contains details about each stage that occurs during the build including start time, duration (in milliseconds), and the steps that occured within each stage.",
68305+
"type": "array",
68306+
"items": {
68307+
"$ref": "#/definitions/v1.StageInfo"
68308+
}
68309+
},
6830368310
"startTimestamp": {
6830468311
"description": "startTimestamp is a timestamp representing the server time when this Build started running in a Pod. It is represented in RFC3339 form and is in UTC.",
6830568312
"$ref": "#/definitions/unversioned.Time"
@@ -76213,6 +76220,49 @@
7621376220
}
7621476221
}
7621576222
},
76223+
"v1.StageInfo": {
76224+
"description": "StageInfo contains details about a build stage.",
76225+
"properties": {
76226+
"durationMilliseconds": {
76227+
"description": "durationMilliseconds identifies how long the stage took to complete in milliseconds. Note: the duration of a stage can exceed the sum of the duration of the steps within the stage as not all actions are accounted for in explicit build steps.",
76228+
"type": "integer",
76229+
"format": "int64"
76230+
},
76231+
"name": {
76232+
"description": "name is a unique identifier for each build stage that occurs.",
76233+
"type": "string"
76234+
},
76235+
"startTime": {
76236+
"description": "startTime is a timestamp representing the server time when this Stage started. It is represented in RFC3339 form and is in UTC.",
76237+
"$ref": "#/definitions/unversioned.Time"
76238+
},
76239+
"steps": {
76240+
"description": "steps contains details about each step that occurs during a build stage including start time and duration in milliseconds.",
76241+
"type": "array",
76242+
"items": {
76243+
"$ref": "#/definitions/v1.StepInfo"
76244+
}
76245+
}
76246+
}
76247+
},
76248+
"v1.StepInfo": {
76249+
"description": "StepInfo contains details about a build step.",
76250+
"properties": {
76251+
"durationMilliseconds": {
76252+
"description": "durationMilliseconds identifies how long the step took to complete in milliseconds.",
76253+
"type": "integer",
76254+
"format": "int64"
76255+
},
76256+
"name": {
76257+
"description": "name is a unique identifier for each build step.",
76258+
"type": "string"
76259+
},
76260+
"startTime": {
76261+
"description": "startTime is a timestamp representing the server time when this Step started. it is represented in RFC3339 form and is in UTC.",
76262+
"$ref": "#/definitions/unversioned.Time"
76263+
}
76264+
}
76265+
},
7621676266
"v1.SubjectAccessReview": {
7621776267
"description": "SubjectAccessReview is an object for requesting information about whether a user or group can perform an action",
7621876268
"required": [

pkg/build/api/helpers.go

+54
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
package api
22

33
import (
4+
"time"
5+
46
kapi "k8s.io/kubernetes/pkg/api"
7+
"k8s.io/kubernetes/pkg/api/unversioned"
8+
9+
"github.com/golang/glog"
510
)
611

712
// BuildToPodLogOptions builds a PodLogOptions object out of a BuildLogOptions.
@@ -75,3 +80,52 @@ func HasTriggerType(triggerType BuildTriggerType, bc *BuildConfig) bool {
7580
matches := FindTriggerPolicy(triggerType, bc)
7681
return len(matches) > 0
7782
}
83+
84+
// RecordStageAndStepInfo records details about each build stage and step
85+
func RecordStageAndStepInfo(stages []StageInfo, stageName StageName, stepName StepName, startTime unversioned.Time, endTime unversioned.Time) []StageInfo {
86+
// If the stage already exists in the slice, update the DurationMilliseconds, and append the new step.
87+
for stageKey, stageVal := range stages {
88+
if stageVal.Name == stageName {
89+
for _, step := range stages[stageKey].Steps {
90+
if step.Name == stepName {
91+
glog.Warningf("error recording build timing information, step %v already exists in stage %v", stepName, stageName)
92+
}
93+
}
94+
stages[stageKey].DurationMilliseconds = endTime.Time.Sub(stages[stageKey].StartTime.Time).Nanoseconds() / int64(time.Millisecond)
95+
if len(stages[stageKey].Steps) == 0 {
96+
stages[stageKey].Steps = make([]StepInfo, 0)
97+
}
98+
stages[stageKey].Steps = append(stages[stageKey].Steps, StepInfo{
99+
Name: stepName,
100+
StartTime: startTime,
101+
DurationMilliseconds: endTime.Time.Sub(startTime.Time).Nanoseconds() / int64(time.Millisecond),
102+
})
103+
return stages
104+
}
105+
}
106+
107+
// If the stageName does not exist, add it to the slice along with the new step.
108+
var steps []StepInfo
109+
steps = append(steps, StepInfo{
110+
Name: stepName,
111+
StartTime: startTime,
112+
DurationMilliseconds: endTime.Time.Sub(startTime.Time).Nanoseconds() / int64(time.Millisecond),
113+
})
114+
stages = append(stages, StageInfo{
115+
Name: stageName,
116+
StartTime: startTime,
117+
DurationMilliseconds: endTime.Time.Sub(startTime.Time).Nanoseconds() / int64(time.Millisecond),
118+
Steps: steps,
119+
})
120+
return stages
121+
}
122+
123+
// AppendStageAndStepInfo appends the step info from one stages slice into another.
124+
func AppendStageAndStepInfo(stages []StageInfo, stagesToMerge []StageInfo) []StageInfo {
125+
for _, stage := range stagesToMerge {
126+
for _, step := range stage.Steps {
127+
stages = RecordStageAndStepInfo(stages, stage.Name, step.Name, step.StartTime, unversioned.NewTime(step.StartTime.Add(time.Duration(step.DurationMilliseconds)*time.Millisecond)))
128+
}
129+
}
130+
return stages
131+
}

pkg/build/api/types.go

+88
Original file line numberDiff line numberDiff line change
@@ -287,8 +287,96 @@ type BuildStatus struct {
287287

288288
// Output describes the Docker image the build has produced.
289289
Output BuildStatusOutput
290+
291+
// Stages contains details about each stage that occurs during the build
292+
// including start time, duration (in milliseconds), and the steps that
293+
// occured within each stage.
294+
Stages []StageInfo
295+
}
296+
297+
// StageInfo contains details about a build stage.
298+
type StageInfo struct {
299+
// Name is a unique identifier for each build stage that occurs.
300+
Name StageName
301+
302+
// StartTime is a timestamp representing the server time when this Stage started.
303+
// It is represented in RFC3339 form and is in UTC.
304+
StartTime unversioned.Time
305+
306+
// DurationMilliseconds identifies how long the stage took
307+
// to complete in milliseconds.
308+
// Note: the duration of a stage can exceed the sum of the duration of the steps within
309+
// the stage as not all actions are accounted for in explicit build steps.
310+
DurationMilliseconds int64
311+
312+
// Steps contains details about each step that occurs during a build stage
313+
// including start time and duration in milliseconds.
314+
Steps []StepInfo
290315
}
291316

317+
// StageName is the identifier for each build stage.
318+
type StageName string
319+
320+
// Valid values for StageName
321+
const (
322+
// StageFetchInputs fetches any inputs such as source code.
323+
StageFetchInputs StageName = "FetchInputs"
324+
325+
// StagePullImages pulls any images that are needed such as
326+
// base images or input images.
327+
StagePullImages StageName = "PullImages"
328+
329+
// StageBuild performs the steps necessary to build the image.
330+
StageBuild StageName = "Build"
331+
332+
// StagePostCommit executes any post commit steps.
333+
StagePostCommit StageName = "PostCommit"
334+
335+
// StagePushImage pushes the image to the node.
336+
StagePushImage StageName = "PushImage"
337+
)
338+
339+
// StepInfo contains details about a build step.
340+
type StepInfo struct {
341+
// Name is a unique identifier for each build step.
342+
Name StepName
343+
344+
// StartTime is a timestamp representing the server time when this Step started.
345+
// it is represented in RFC3339 form and is in UTC.
346+
StartTime unversioned.Time
347+
348+
// DurationMilliseconds identifies how long the step took
349+
// to complete in milliseconds.
350+
DurationMilliseconds int64
351+
}
352+
353+
// StepName is a unique identifier for each build step.
354+
type StepName string
355+
356+
// Valid values for StepName
357+
const (
358+
// StepExecPostCommitHook executes the buildconfigs post commit hook.
359+
StepExecPostCommitHook StepName = "RunPostCommitHook"
360+
361+
// StepFetchGitSource fetches the source code for the build.
362+
StepFetchGitSource StepName = "FetchGitSource"
363+
364+
// StepPullBaseImage pulls the base image for the build.
365+
StepPullBaseImage StepName = "PullBaseImage"
366+
367+
// StepPullInputImage pulls the input image for the build.
368+
StepPullInputImage StepName = "PullInputImage"
369+
370+
// StepPushImage pushed the image to the registry.
371+
StepPushImage StepName = "PushImage"
372+
373+
// StepPushDockerImage pushes the docker image to the registry.
374+
StepPushDockerImage StepName = "PushDockerImage"
375+
376+
//StepDockerBuild performs the docker build
377+
StepDockerBuild StepName = "DockerBuild"
378+
)
379+
292380
// BuildPhase represents the status of a build at a point in time.
293381
type BuildPhase string
294382

0 commit comments

Comments
 (0)